From 7468813cd879477a69f695a3959b6267e65fa0bf Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 16 Jun 2020 10:21:40 +1000 Subject: [PATCH 1/5] Working on Authorize payment flow --- .../ClientPortal/PaymentController.php | 2 +- .../Requests/Invoice/StoreInvoiceRequest.php | 4 ++ .../Requests/Invoice/UpdateInvoiceRequest.php | 4 ++ app/Models/Invoice.php | 1 + app/PaymentDrivers/AbstractPaymentDriver.php | 2 + .../Authorize/AuthorizeCreditCard.php | 36 ++++++++++++++++ app/PaymentDrivers/AuthorizePaymentDriver.php | 15 +++++++ app/PaymentDrivers/BaseDriver.php | 16 ++++++- .../authorize/add_credit_card.blade.php | 43 ++----------------- .../gateways/authorize/credit_card.blade.php | 40 +++++++++++++++++ 10 files changed, 120 insertions(+), 43 deletions(-) create mode 100644 app/PaymentDrivers/Authorize/AuthorizeCreditCard.php create mode 100644 resources/views/portal/ninja2020/gateways/authorize/credit_card.blade.php diff --git a/app/Http/Controllers/ClientPortal/PaymentController.php b/app/Http/Controllers/ClientPortal/PaymentController.php index 315157b8c1b9..3fb86c5be156 100644 --- a/app/Http/Controllers/ClientPortal/PaymentController.php +++ b/app/Http/Controllers/ClientPortal/PaymentController.php @@ -130,7 +130,7 @@ class PaymentController extends Controller return $gateway ->driver(auth()->user()->client) - ->setPaymentMethod('App\\PaymentDrivers\\Stripe\\Alipay') + ->setPaymentMethod($request->input('payment_method_id')) ->processPaymentResponse($request); } } diff --git a/app/Http/Requests/Invoice/StoreInvoiceRequest.php b/app/Http/Requests/Invoice/StoreInvoiceRequest.php index 2667ee259ce0..10f6d72a7c2e 100644 --- a/app/Http/Requests/Invoice/StoreInvoiceRequest.php +++ b/app/Http/Requests/Invoice/StoreInvoiceRequest.php @@ -67,6 +67,10 @@ class StoreInvoiceRequest extends Request $input['client_id'] = $this->decodePrimaryKey($input['client_id']); } + if (array_key_exists('assigned_user_id', $input) && is_string($input['assigned_user_id'])) { + $input['assigned_user_id'] = $this->decodePrimaryKey($input['assigned_user_id']); + } + if (isset($input['client_contacts'])) { foreach ($input['client_contacts'] as $key => $contact) { if (!array_key_exists('send_email', $contact) || !array_key_exists('id', $contact)) { diff --git a/app/Http/Requests/Invoice/UpdateInvoiceRequest.php b/app/Http/Requests/Invoice/UpdateInvoiceRequest.php index 41959bdc20f9..ba993f001f9d 100644 --- a/app/Http/Requests/Invoice/UpdateInvoiceRequest.php +++ b/app/Http/Requests/Invoice/UpdateInvoiceRequest.php @@ -65,6 +65,10 @@ class UpdateInvoiceRequest extends Request $input['client_id'] = $this->decodePrimaryKey($input['client_id']); } + if (array_key_exists('assigned_user_id', $input) && is_string($input['assigned_user_id'])) { + $input['assigned_user_id'] = $this->decodePrimaryKey($input['assigned_user_id']); + } + if (isset($input['invitations'])) { foreach ($input['invitations'] as $key => $value) { if (is_numeric($input['invitations'][$key]['id'])) { diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index edf9766bb51f..5db78dba1812 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -99,6 +99,7 @@ class Invoice extends BaseModel 'custom_surcharge_tax3', 'custom_surcharge_tax4', 'design_id', + 'assigned_user_id', ]; protected $casts = [ diff --git a/app/PaymentDrivers/AbstractPaymentDriver.php b/app/PaymentDrivers/AbstractPaymentDriver.php index fa9393843ae1..b6ec4ca28f5c 100644 --- a/app/PaymentDrivers/AbstractPaymentDriver.php +++ b/app/PaymentDrivers/AbstractPaymentDriver.php @@ -20,4 +20,6 @@ abstract class AbstractPaymentDriver abstract public function refund($amount, $transaction_reference, $return_client_response = false); + abstract public function bootPaymentMethod(); + } \ No newline at end of file diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php new file mode 100644 index 000000000000..913673f9592a --- /dev/null +++ b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php @@ -0,0 +1,36 @@ +authorize = $authorize; + } + + public function processPaymentView($data) + { + + } + +} \ No newline at end of file diff --git a/app/PaymentDrivers/AuthorizePaymentDriver.php b/app/PaymentDrivers/AuthorizePaymentDriver.php index 62560e07804d..a99fdf6958a2 100644 --- a/app/PaymentDrivers/AuthorizePaymentDriver.php +++ b/app/PaymentDrivers/AuthorizePaymentDriver.php @@ -33,6 +33,19 @@ class AuthorizePaymentDriver extends BaseDriver public $merchant_authentication; + public static $methods = [ + GatewayType::CREDIT_CARD => AuthorizeCreditCard::class, + ]; + + public function bootPaymentMethod() + { + + $class = self::$methods[$this->getPaymentMethodId()]; + + $this->payment_method = new $class($this); + + return $this; + } /** * Returns the gateway types */ @@ -97,6 +110,8 @@ class AuthorizePaymentDriver extends BaseDriver public function processPaymentView($data) { + return $this->bootPaymentMethod()->payment_method->processPaymentView($data); + } public function processPaymentResponse($request) diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 4c003978742b..ea9338c339b5 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -46,8 +46,13 @@ class BaseDriver extends AbstractPaymentDriver /* The client */ public $client; + /* The payment method id*/ + public $payment_method_id; + public $payment_method; + public $methods = []; + public function __construct(CompanyGateway $company_gateway, Client $client = null, $invitation = false) { $this->company_gateway = $company_gateway; @@ -85,14 +90,21 @@ class BaseDriver extends AbstractPaymentDriver */ public function refund($amount, $transaction_reference, $return_client_response = false) {} + /** + * Initializes an instance of the payment method + * @return object The payment method instance + */ + public function bootPaymentMethod() {} + /** * Set the inbound request payment method type for access. * * @param int $payment_method_id The Payment Method ID */ - public function setPaymentMethod($payment_method_id) + public function setPaymentMethod($method_id) { - $this->payment_method = $payment_method_id; + $this->payment_method_id = $payment_method_id; + return $this; } diff --git a/resources/views/portal/ninja2020/gateways/authorize/add_credit_card.blade.php b/resources/views/portal/ninja2020/gateways/authorize/add_credit_card.blade.php index aaeba35c1aaf..acc9b015a41a 100644 --- a/resources/views/portal/ninja2020/gateways/authorize/add_credit_card.blade.php +++ b/resources/views/portal/ninja2020/gateways/authorize/add_credit_card.blade.php @@ -31,46 +31,9 @@
-
-
- {{ ctrans('texts.name') }} -
-
- -
-
-
-
- {{ ctrans('texts.credit_card') }} -
-
- -
-
-
-
- {{ ctrans('texts.expiration_month') }} -
-
- -
-
-
-
- {{ ctrans('texts.expiration_year') }} -
-
- -
-
-
-
- {{ ctrans('texts.cvv') }} -
-
- -
-
+ + @include('portal.ninja2020.gateways.authorize.credit_card') +
{{ ctrans('texts.save_as_default') }} diff --git a/resources/views/portal/ninja2020/gateways/authorize/credit_card.blade.php b/resources/views/portal/ninja2020/gateways/authorize/credit_card.blade.php new file mode 100644 index 000000000000..178347e433c2 --- /dev/null +++ b/resources/views/portal/ninja2020/gateways/authorize/credit_card.blade.php @@ -0,0 +1,40 @@ +
+
+ {{ ctrans('texts.name') }} +
+
+ +
+
+
+
+ {{ ctrans('texts.credit_card') }} +
+
+ +
+
+
+
+ {{ ctrans('texts.expiration_month') }} +
+
+ +
+
+
+
+ {{ ctrans('texts.expiration_year') }} +
+
+ +
+
+
+
+ {{ ctrans('texts.cvv') }} +
+
+ +
+
From 2648690b48c1675c63ea0d149269229f604bb50e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 16 Jun 2020 10:31:05 +1000 Subject: [PATCH 2/5] authorize.net payment views --- .../Authorize/AuthorizeCreditCard.php | 9 +++ .../authorize/credit_card_payment.blade.php | 67 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 resources/views/portal/ninja2020/gateways/authorize/credit_card_payment.blade.php diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php index 913673f9592a..dcb862520a91 100644 --- a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php +++ b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php @@ -12,6 +12,7 @@ namespace App\PaymentDrivers\Authorize; +use App\Models\ClientGatewayToken; use App\PaymentDrivers\AuthorizePaymentDriver; /** @@ -30,7 +31,15 @@ class AuthorizeCreditCard public function processPaymentView($data) { + $tokens = ClientGatewayToken::where('client_id', $this->authorize->client->id) + ->where('company_gateway_key', $this->authorize->company_gateway->gateway_key) + ->where('gateway_type_id', $this->authorize->payment_method_id) + ->get(); + $data['tokens'] = $tokens; + $data['gateway'] = $this->authorize->company_gateway; + + return render('portal.ninja202.gateways.authorize.credit_card_payment', $data); } } \ No newline at end of file diff --git a/resources/views/portal/ninja2020/gateways/authorize/credit_card_payment.blade.php b/resources/views/portal/ninja2020/gateways/authorize/credit_card_payment.blade.php new file mode 100644 index 000000000000..5b0a6fc04a98 --- /dev/null +++ b/resources/views/portal/ninja2020/gateways/authorize/credit_card_payment.blade.php @@ -0,0 +1,67 @@ +@extends('portal.ninja2020.layout.app') +@section('meta_title', ctrans('texts.add_credit_card')) + +@push('head') + + +@endpush + +@section('body') +
+ @csrf + + + + + + +
+
+
+
+ +
+
+
+
+ @if($tokens->count() == 0) +
+ @include('portal.ninja2020.gateways.authorize.credit_card') + +
+
+ {{ ctrans('texts.save_as_default') }} +
+
+ +
+
+
+ +
+
+ @else + + @foreach($tokens as $token) + @endforeach + + @endif +
+
+
+
+
+@endsection + +@push('footer') + + @if($gateway->getConfigField('testMode')) + + @else + + @endif + + +@endpush \ No newline at end of file From b85b0913a6d6112257a40b86cc93bfb8bf6f9341 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 16 Jun 2020 13:49:45 +1000 Subject: [PATCH 3/5] Authorize.net payment via credit card --- app/PaymentDrivers/Authorize/AuthorizeCreditCard.php | 8 +++++--- app/PaymentDrivers/AuthorizePaymentDriver.php | 4 ++-- app/PaymentDrivers/BaseDriver.php | 8 +++++--- .../gateways/authorize/credit_card_payment.blade.php | 10 ++++++++-- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php index dcb862520a91..1f050c9bf767 100644 --- a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php +++ b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php @@ -32,14 +32,16 @@ class AuthorizeCreditCard public function processPaymentView($data) { $tokens = ClientGatewayToken::where('client_id', $this->authorize->client->id) - ->where('company_gateway_key', $this->authorize->company_gateway->gateway_key) + ->where('company_gateway_id', $this->authorize->company_gateway->id) ->where('gateway_type_id', $this->authorize->payment_method_id) ->get(); $data['tokens'] = $tokens; $data['gateway'] = $this->authorize->company_gateway; - - return render('portal.ninja202.gateways.authorize.credit_card_payment', $data); + $data['public_client_id'] = $this->authorize->init()->getPublicClientKey(); + $data['api_login_id'] = $this->authorize->company_gateway->getConfigField('apiLoginId'); + + return render('gateways.authorize.credit_card_payment', $data); } } \ No newline at end of file diff --git a/app/PaymentDrivers/AuthorizePaymentDriver.php b/app/PaymentDrivers/AuthorizePaymentDriver.php index a99fdf6958a2..0d05573d7167 100644 --- a/app/PaymentDrivers/AuthorizePaymentDriver.php +++ b/app/PaymentDrivers/AuthorizePaymentDriver.php @@ -38,9 +38,9 @@ class AuthorizePaymentDriver extends BaseDriver ]; public function bootPaymentMethod() - { + {info(print_r($this->getPaymentMethod(),1)); - $class = self::$methods[$this->getPaymentMethodId()]; + $class = self::$methods[$this->getPaymentMethod()]; $this->payment_method = new $class($this); diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index ea9338c339b5..e928eabb2fe3 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -51,7 +51,7 @@ class BaseDriver extends AbstractPaymentDriver public $payment_method; - public $methods = []; + public static $methods = []; public function __construct(CompanyGateway $company_gateway, Client $client = null, $invitation = false) { @@ -101,8 +101,10 @@ class BaseDriver extends AbstractPaymentDriver * * @param int $payment_method_id The Payment Method ID */ - public function setPaymentMethod($method_id) + public function setPaymentMethod($payment_method_id) { + info("setting payment method {$payment_method_id}"); + $this->payment_method_id = $payment_method_id; return $this; @@ -115,6 +117,6 @@ class BaseDriver extends AbstractPaymentDriver */ public function getPaymentMethod() { - return $this->payment_method; + return $this->payment_method_id; } } diff --git a/resources/views/portal/ninja2020/gateways/authorize/credit_card_payment.blade.php b/resources/views/portal/ninja2020/gateways/authorize/credit_card_payment.blade.php index 5b0a6fc04a98..220880a104c0 100644 --- a/resources/views/portal/ninja2020/gateways/authorize/credit_card_payment.blade.php +++ b/resources/views/portal/ninja2020/gateways/authorize/credit_card_payment.blade.php @@ -15,6 +15,8 @@ + +
@@ -38,15 +40,19 @@
- +
@else + @endif
From 8c260ece95b0c1148c284aa9a6bbd7a4ae356d38 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 16 Jun 2020 14:00:26 +1000 Subject: [PATCH 4/5] Get Authorize.net Transactions by refId --- .../Authorize/AuthorizeCreditCard.php | 6 ++ .../Authorize/AuthorizeTransactions.php | 66 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 app/PaymentDrivers/Authorize/AuthorizeTransactions.php diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php index 1f050c9bf767..ddeedc7fbac9 100644 --- a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php +++ b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php @@ -42,6 +42,12 @@ class AuthorizeCreditCard $data['api_login_id'] = $this->authorize->company_gateway->getConfigField('apiLoginId'); return render('gateways.authorize.credit_card_payment', $data); + + } + + public function processPaymentResponse($response) + { + } } \ No newline at end of file diff --git a/app/PaymentDrivers/Authorize/AuthorizeTransactions.php b/app/PaymentDrivers/Authorize/AuthorizeTransactions.php new file mode 100644 index 000000000000..fe2d169b77f8 --- /dev/null +++ b/app/PaymentDrivers/Authorize/AuthorizeTransactions.php @@ -0,0 +1,66 @@ +authorize = $authorize; + } + + function getTransactionDetails($transactionId) + { + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $this->authorize->init(); + + // Set the transaction's refId + $refId = 'ref' . time(); + + $request = new GetTransactionDetailsRequest(); + $request->setMerchantAuthentication($this->authorize->merchant_authentication); + $request->setTransId($transactionId); + + $controller = new GetTransactionDetailsController($request); + + $response = $controller->executeWithApiResponse($this->authorize->mode()); + + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) + { + echo "SUCCESS: Transaction Status:" . $response->getTransaction()->getTransactionStatus() . "\n"; + echo " Auth Amount:" . $response->getTransaction()->getAuthAmount() . "\n"; + echo " Trans ID:" . $response->getTransaction()->getTransId() . "\n"; + } + else + { + echo "ERROR : Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + + return $response; + } +} \ No newline at end of file From 48086f1516c15942864d9b4c90e87a694631af02 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 16 Jun 2020 14:01:10 +1000 Subject: [PATCH 5/5] Authorize .net --- app/PaymentDrivers/Authorize/AuthorizeCreditCard.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php index ddeedc7fbac9..439a88adf8c1 100644 --- a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php +++ b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php @@ -16,8 +16,8 @@ use App\Models\ClientGatewayToken; use App\PaymentDrivers\AuthorizePaymentDriver; /** - * Class BaseDriver - * @package App\PaymentDrivers + * Class AuthorizeCreditCard + * @package App\PaymentDrivers\Authorize * */ class AuthorizeCreditCard @@ -42,7 +42,7 @@ class AuthorizeCreditCard $data['api_login_id'] = $this->authorize->company_gateway->getConfigField('apiLoginId'); return render('gateways.authorize.credit_card_payment', $data); - + } public function processPaymentResponse($response)