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] 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 61cdc83456..b3bbf2a94b 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 922beefd20..7c0d648756 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 7e097c704b..4d4b017bee 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 03c76eb700..492ecfe66e 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 6538ce1454..e0fbc8dfca 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 71f54319f9..0000000000 --- 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 5129524a8b..0000000000 --- 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 0000000000..7d3069f8be --- /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 +