From d45571d7f9d68e6fa6f82371b846098054070a3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Wed, 9 Dec 2020 15:17:48 +0100 Subject: [PATCH 1/5] wip --- .../ClientPortal/PaymentController.php | 1 + app/Models/Client.php | 1 + app/PaymentDrivers/BaseDriver.php | 5 + app/PaymentDrivers/CustomPaymentDriver.php | 45 ++++-- resources/lang/en/texts.php | 2 + .../checkout/credit_card.blade.php.old | 128 ------------------ .../gateways/custom/landing_page.blade.php | 1 - .../gateways/custom/payment.blade.php | 33 +++++ 8 files changed, 73 insertions(+), 143 deletions(-) delete mode 100644 resources/views/portal/ninja2020/gateways/checkout/credit_card.blade.php.old delete mode 100644 resources/views/portal/ninja2020/gateways/custom/landing_page.blade.php create mode 100644 resources/views/portal/ninja2020/gateways/custom/payment.blade.php diff --git a/app/Http/Controllers/ClientPortal/PaymentController.php b/app/Http/Controllers/ClientPortal/PaymentController.php index 61cdc83456be..b3bbf2a94bcb 100644 --- a/app/Http/Controllers/ClientPortal/PaymentController.php +++ b/app/Http/Controllers/ClientPortal/PaymentController.php @@ -232,6 +232,7 @@ class PaymentController extends Controller public function response(PaymentResponseRequest $request) { $gateway = CompanyGateway::find($request->input('company_gateway_id'))->firstOrFail(); + $payment_hash = PaymentHash::whereRaw('BINARY `hash`= ?', [$request->payment_hash])->first(); return $gateway diff --git a/app/Models/Client.php b/app/Models/Client.php index 922beefd2098..7c0d648756de 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -462,6 +462,7 @@ class Client extends BaseModel implements HasLocalePreference $payment_methods = []; foreach ($gateways as $gateway) { + foreach ($gateway->driver($this)->gatewayTypes() as $type) { if (isset($gateway->fees_and_limits) && property_exists($gateway->fees_and_limits, $type)) { if ($this->validGatewayForAmount($gateway->fees_and_limits->{$type}, $amount)) { diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 7e097c704b53..4d4b017beecf 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -460,4 +460,9 @@ class BaseDriver extends AbstractPaymentDriver return $this; } + + public function getCompanyGatewayId(): int + { + return $this->company_gateway->id; + } } diff --git a/app/PaymentDrivers/CustomPaymentDriver.php b/app/PaymentDrivers/CustomPaymentDriver.php index 03c76eb7007f..492ecfe66e51 100644 --- a/app/PaymentDrivers/CustomPaymentDriver.php +++ b/app/PaymentDrivers/CustomPaymentDriver.php @@ -12,9 +12,12 @@ namespace App\PaymentDrivers; +use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; use App\Models\Payment; +use App\Models\PaymentType; +use App\Models\SystemLog; /** * Class CustomPaymentDriver. @@ -28,7 +31,7 @@ class CustomPaymentDriver extends BaseDriver /** * Returns the gateway types. */ - public function gatewayTypes() :array + public function gatewayTypes(): array { $types = [ GatewayType::CREDIT_CARD, @@ -37,18 +40,6 @@ class CustomPaymentDriver extends BaseDriver return $types; } - public function authorize($payment_method) - { - } - - public function purchase($amount, $return_client_response = false) - { - } - - public function refund(Payment $payment, $amount, $return_client_response = false) - { - } - public function setPaymentMethod($payment_method_id) { $this->payment_method = $payment_method_id; @@ -58,11 +49,37 @@ class CustomPaymentDriver extends BaseDriver public function processPaymentView($data) { - return render('gateways.custom.landing_page', $data); + $data['title'] = $this->company_gateway->getConfigField('name'); + $data['instructions'] = $this->company_gateway->getConfigField('text'); + + $this->payment_hash->data = array_merge((array) $this->payment_hash->data, $data); + $this->payment_hash->save(); + + $data['gateway'] = $this; + + return render('gateways.custom.payment', $data); } public function processPaymentResponse($request) { + $data = [ + 'payment_method' => GatewayType::CREDIT_CARD, + 'payment_type' => PaymentType::CREDIT_CARD_OTHER, + 'amount' => $this->payment_hash->data->amount_with_fee, + 'transaction_reference' => \Illuminate\Support\Str::uuid(), + ]; + + $payment = $this->createPayment($data, Payment::STATUS_PENDING); + + SystemLogger::dispatch( + ['response' => $data, 'data' => $data], + SystemLog::CATEGORY_GATEWAY_RESPONSE, + SystemLog::EVENT_GATEWAY_SUCCESS, + SystemLog::TYPE_STRIPE, + $this->client, + ); + + return redirect()->route('client.payments.show', ['payment' => $this->encodePrimaryKey($payment->id)]); } /** diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 6538ce145461..e0fbc8dfca9f 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -3314,4 +3314,6 @@ return [ 'service' => 'Service', 'pay' => 'Pay', + + 'instructions' => 'Instructions', ]; diff --git a/resources/views/portal/ninja2020/gateways/checkout/credit_card.blade.php.old b/resources/views/portal/ninja2020/gateways/checkout/credit_card.blade.php.old deleted file mode 100644 index 71f54319f938..000000000000 --- a/resources/views/portal/ninja2020/gateways/checkout/credit_card.blade.php.old +++ /dev/null @@ -1,128 +0,0 @@ -@extends('portal.ninja2020.layout.app') -@section('meta_title', ctrans('texts.checkout_com')) - -@push('head') - - - - - - - -@endpush - -@section('body') -
- @csrf - - - - - - - - - - @isset($token) - - @endisset -
- -
-
-
- -
-
-

- {{ ctrans('texts.pay_now') }} -

-

- {{ ctrans('texts.complete_your_payment') }} -

-
-
-
- {{ ctrans('texts.payment_type') }} -
-
- {{ ctrans('texts.checkout_com') }} ({{ ctrans('texts.credit_card') }}) -
-
-
-
- {{ ctrans('texts.subtotal') }} -
-
- {{ App\Utils\Number::formatMoney($total['invoice_totals'], $client) }} -
-
- {{ ctrans('texts.gateway_fees') }} -
-
- {{ App\Utils\Number::formatMoney($total['fee_total'], $client) }} -
-
- {{ ctrans('texts.amount') }} -
-
- {{ App\Utils\Number::formatMoney($total['amount_with_fee'], $client) }} -
-
- @isset($token) -
-
- {{ ctrans('texts.card_number') }} -
-
- **** {{ ucfirst($token->meta->last4) }} -
-
-
- -
- @else -
-
- {{ ctrans('texts.token_billing_checkbox') }} -
-
- - -
-
-
-
- @if(app()->environment() == 'production') - - @else - - @endif -
-
- @endisset -
-
-
-
-@endsection \ No newline at end of file diff --git a/resources/views/portal/ninja2020/gateways/custom/landing_page.blade.php b/resources/views/portal/ninja2020/gateways/custom/landing_page.blade.php deleted file mode 100644 index 5129524a8bee..000000000000 --- a/resources/views/portal/ninja2020/gateways/custom/landing_page.blade.php +++ /dev/null @@ -1 +0,0 @@ -stubs \ No newline at end of file diff --git a/resources/views/portal/ninja2020/gateways/custom/payment.blade.php b/resources/views/portal/ninja2020/gateways/custom/payment.blade.php new file mode 100644 index 000000000000..7d3069f8bea6 --- /dev/null +++ b/resources/views/portal/ninja2020/gateways/custom/payment.blade.php @@ -0,0 +1,33 @@ +@extends('portal.ninja2020.layout.payments', ['gateway_title' => $title, 'card_title' => $title]) + +@section('gateway_content') +
+ @csrf + + + +
+ + @component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.payment_type')]) + {{ $title }} + @endcomponent + + @include('portal.ninja2020.gateways.includes.payment_details') + + @component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.instructions') ]) + {!! nl2br($instructions) !!} + @endcomponent + + @component('portal.ninja2020.components.general.card-element-single') + @include('portal.ninja2020.gateways.includes.pay_now') + @endcomponent +@endsection + +@section('gateway_footer') + +@endsection + From 37f79247aca6223829a5b6e7acd5e77272bca60b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Thu, 10 Dec 2020 12:19:13 +0100 Subject: [PATCH 2/5] remove payment options from custom driver --- .../gateways/custom/payment.blade.php | 22 +------------------ 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/resources/views/portal/ninja2020/gateways/custom/payment.blade.php b/resources/views/portal/ninja2020/gateways/custom/payment.blade.php index 7d3069f8bea6..d337c71897d9 100644 --- a/resources/views/portal/ninja2020/gateways/custom/payment.blade.php +++ b/resources/views/portal/ninja2020/gateways/custom/payment.blade.php @@ -1,33 +1,13 @@ @extends('portal.ninja2020.layout.payments', ['gateway_title' => $title, 'card_title' => $title]) @section('gateway_content') -
- @csrf - - - -
- @component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.payment_type')]) {{ $title }} @endcomponent @include('portal.ninja2020.gateways.includes.payment_details') - @component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.instructions') ]) + @component('portal.ninja2020.components.general.card-element-single') {!! nl2br($instructions) !!} @endcomponent - - @component('portal.ninja2020.components.general.card-element-single') - @include('portal.ninja2020.gateways.includes.pay_now') - @endcomponent @endsection - -@section('gateway_footer') - -@endsection - From 5c776d4911cb7f2da6a176249b1a7940524e03fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Thu, 10 Dec 2020 12:38:07 +0100 Subject: [PATCH 3/5] show custom driver with its label --- .../portal/ninja2020/invoices/payment.blade.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/resources/views/portal/ninja2020/invoices/payment.blade.php b/resources/views/portal/ninja2020/invoices/payment.blade.php index 66ecc2a0ece5..f911440f30ed 100644 --- a/resources/views/portal/ninja2020/invoices/payment.blade.php +++ b/resources/views/portal/ninja2020/invoices/payment.blade.php @@ -36,9 +36,15 @@ @@ -67,7 +73,7 @@
@if(!empty($invoice->number) && !is_null($invoice->number)) -
+
{{ ctrans('texts.invoice_number') }}
@@ -88,7 +94,7 @@
@endif -
+
{{ ctrans('texts.additional_info') }}
From 9df493883762cba27b8e7951ba8ee78630cc4c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Thu, 10 Dec 2020 12:38:23 +0100 Subject: [PATCH 4/5] change gateway type & remove processPayment --- app/PaymentDrivers/CustomPaymentDriver.php | 32 +++++++++------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/app/PaymentDrivers/CustomPaymentDriver.php b/app/PaymentDrivers/CustomPaymentDriver.php index 492ecfe66e51..00e111ba4105 100644 --- a/app/PaymentDrivers/CustomPaymentDriver.php +++ b/app/PaymentDrivers/CustomPaymentDriver.php @@ -34,7 +34,7 @@ class CustomPaymentDriver extends BaseDriver public function gatewayTypes(): array { $types = [ - GatewayType::CREDIT_CARD, + GatewayType::CUSTOM, ]; return $types; @@ -47,6 +47,12 @@ class CustomPaymentDriver extends BaseDriver return $this; } + /** + * View for displaying custom content of the driver. + * + * @param array $data + * @return mixed + */ public function processPaymentView($data) { $data['title'] = $this->company_gateway->getConfigField('name'); @@ -60,26 +66,14 @@ class CustomPaymentDriver extends BaseDriver return render('gateways.custom.payment', $data); } + /** + * Processing method for payment. Should never be reached with this driver. + * + * @return mixed + */ public function processPaymentResponse($request) { - $data = [ - 'payment_method' => GatewayType::CREDIT_CARD, - 'payment_type' => PaymentType::CREDIT_CARD_OTHER, - 'amount' => $this->payment_hash->data->amount_with_fee, - 'transaction_reference' => \Illuminate\Support\Str::uuid(), - ]; - - $payment = $this->createPayment($data, Payment::STATUS_PENDING); - - SystemLogger::dispatch( - ['response' => $data, 'data' => $data], - SystemLog::CATEGORY_GATEWAY_RESPONSE, - SystemLog::EVENT_GATEWAY_SUCCESS, - SystemLog::TYPE_STRIPE, - $this->client, - ); - - return redirect()->route('client.payments.show', ['payment' => $this->encodePrimaryKey($payment->id)]); + return redirect()->route('client.invoices'); } /** From 5f796aeab6a26d674962136f765a109dec678094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Thu, 10 Dec 2020 12:38:46 +0100 Subject: [PATCH 5/5] php-cs-fixer --- app/Models/Client.php | 1 - app/PaymentDrivers/CustomPaymentDriver.php | 13 +++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/app/Models/Client.php b/app/Models/Client.php index 7c0d648756de..922beefd2098 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -462,7 +462,6 @@ class Client extends BaseModel implements HasLocalePreference $payment_methods = []; foreach ($gateways as $gateway) { - foreach ($gateway->driver($this)->gatewayTypes() as $type) { if (isset($gateway->fees_and_limits) && property_exists($gateway->fees_and_limits, $type)) { if ($this->validGatewayForAmount($gateway->fees_and_limits->{$type}, $amount)) { diff --git a/app/PaymentDrivers/CustomPaymentDriver.php b/app/PaymentDrivers/CustomPaymentDriver.php index 00e111ba4105..3c5d4bad1967 100644 --- a/app/PaymentDrivers/CustomPaymentDriver.php +++ b/app/PaymentDrivers/CustomPaymentDriver.php @@ -12,12 +12,9 @@ namespace App\PaymentDrivers; -use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; use App\Models\Payment; -use App\Models\PaymentType; -use App\Models\SystemLog; /** * Class CustomPaymentDriver. @@ -49,9 +46,9 @@ class CustomPaymentDriver extends BaseDriver /** * View for displaying custom content of the driver. - * - * @param array $data - * @return mixed + * + * @param array $data + * @return mixed */ public function processPaymentView($data) { @@ -68,8 +65,8 @@ class CustomPaymentDriver extends BaseDriver /** * Processing method for payment. Should never be reached with this driver. - * - * @return mixed + * + * @return mixed */ public function processPaymentResponse($request) {