From 6aefbbf2c6bcbf3b434006bc72c5642a645adedf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 9 Aug 2024 01:09:20 +0200 Subject: [PATCH] Mollie: New payment flow (#73) * pass livewirePaymentView & processPaymentView thru base driver * add paymentData to the interface * mollie * credit card --- app/PaymentDrivers/Mollie/Bancontact.php | 23 ++++- app/PaymentDrivers/Mollie/BankTransfer.php | 23 ++++- app/PaymentDrivers/Mollie/CreditCard.php | 23 ++++- app/PaymentDrivers/Mollie/IDEAL.php | 23 ++++- app/PaymentDrivers/Mollie/KBC.php | 23 ++++- .../js/clients/payments/mollie-credit-card.js | 9 +- .../gateways/mollie/credit_card/pay.blade.php | 1 + .../mollie/credit_card/pay_livewire.blade.php | 87 +++++++++++++++++++ 8 files changed, 205 insertions(+), 7 deletions(-) create mode 100644 resources/views/portal/ninja2020/gateways/mollie/credit_card/pay_livewire.blade.php diff --git a/app/PaymentDrivers/Mollie/Bancontact.php b/app/PaymentDrivers/Mollie/Bancontact.php index 3df988bbb2ef..3a19ac358fb7 100644 --- a/app/PaymentDrivers/Mollie/Bancontact.php +++ b/app/PaymentDrivers/Mollie/Bancontact.php @@ -19,13 +19,14 @@ use App\Models\GatewayType; use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; +use App\PaymentDrivers\Common\LivewireMethodInterface; use App\PaymentDrivers\Common\MethodInterface; use App\PaymentDrivers\MolliePaymentDriver; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\View\View; -class Bancontact implements MethodInterface +class Bancontact implements MethodInterface, LivewireMethodInterface { protected MolliePaymentDriver $mollie; @@ -209,4 +210,24 @@ class Bancontact implements MethodInterface { return $this->processSuccessfulPayment($payment, 'open'); } + + /** + * @inheritDoc + */ + public function livewirePaymentView(array $data): string + { + // Doesn't support, it's offsite payment method. + + return ''; + } + + /** + * @inheritDoc + */ + public function paymentData(array $data): array + { + $this->paymentView($data); + + return $data; + } } diff --git a/app/PaymentDrivers/Mollie/BankTransfer.php b/app/PaymentDrivers/Mollie/BankTransfer.php index 7c5872714c06..642d4bfc84c6 100644 --- a/app/PaymentDrivers/Mollie/BankTransfer.php +++ b/app/PaymentDrivers/Mollie/BankTransfer.php @@ -19,6 +19,7 @@ use App\Models\GatewayType; use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; +use App\PaymentDrivers\Common\LivewireMethodInterface; use App\PaymentDrivers\Common\MethodInterface; use App\PaymentDrivers\MolliePaymentDriver; use Exception; @@ -28,7 +29,7 @@ use Illuminate\Routing\Redirector; use Illuminate\View\View; use Mollie\Api\Resources\Payment as ResourcesPayment; -class BankTransfer implements MethodInterface +class BankTransfer implements MethodInterface, LivewireMethodInterface { protected MolliePaymentDriver $mollie; @@ -206,4 +207,24 @@ class BankTransfer implements MethodInterface { return $this->processSuccessfulPayment($payment, 'open'); } + + /** + * @inheritDoc + */ + public function livewirePaymentView(array $data): string + { + // Doesn't support, it's offsite payment method. + + return ''; + } + + /** + * @inheritDoc + */ + public function paymentData(array $data): array + { + $this->paymentView($data); + + return $data; + } } diff --git a/app/PaymentDrivers/Mollie/CreditCard.php b/app/PaymentDrivers/Mollie/CreditCard.php index 627605974532..6e712c8f84b6 100644 --- a/app/PaymentDrivers/Mollie/CreditCard.php +++ b/app/PaymentDrivers/Mollie/CreditCard.php @@ -10,12 +10,13 @@ use App\Models\GatewayType; use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; +use App\PaymentDrivers\Common\LivewireMethodInterface; use App\PaymentDrivers\MolliePaymentDriver; use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; use Illuminate\View\View; -class CreditCard +class CreditCard implements LivewireMethodInterface { /** * @var MolliePaymentDriver @@ -37,7 +38,7 @@ class CreditCard */ public function paymentView(array $data) { - $data['gateway'] = $this->mollie; + $data = $this->paymentData($data); return render('gateways.mollie.credit_card.pay', $data); } @@ -257,4 +258,22 @@ class CreditCard { return redirect()->route('client.payment_methods.index'); } + + /** + * @inheritDoc + */ + public function livewirePaymentView(array $data): string + { + return 'gateways.mollie.credit_card.pay_livewire'; + } + + /** + * @inheritDoc + */ + public function paymentData(array $data): array + { + $data['gateway'] = $this->mollie; + + return $data; + } } diff --git a/app/PaymentDrivers/Mollie/IDEAL.php b/app/PaymentDrivers/Mollie/IDEAL.php index 3b19cad34f11..134853a6fe04 100644 --- a/app/PaymentDrivers/Mollie/IDEAL.php +++ b/app/PaymentDrivers/Mollie/IDEAL.php @@ -19,13 +19,14 @@ use App\Models\GatewayType; use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; +use App\PaymentDrivers\Common\LivewireMethodInterface; use App\PaymentDrivers\Common\MethodInterface; use App\PaymentDrivers\MolliePaymentDriver; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\View\View; -class IDEAL implements MethodInterface +class IDEAL implements MethodInterface, LivewireMethodInterface { protected MolliePaymentDriver $mollie; @@ -209,4 +210,24 @@ class IDEAL implements MethodInterface { return $this->processSuccessfulPayment($payment, 'open'); } + + /** + * @inheritDoc + */ + public function livewirePaymentView(array $data): string + { + // Doesn't support, it's offsite payment method. + + return ''; + } + + /** + * @inheritDoc + */ + public function paymentData(array $data): array + { + $this->paymentView($data); + + return $data; + } } diff --git a/app/PaymentDrivers/Mollie/KBC.php b/app/PaymentDrivers/Mollie/KBC.php index 00b87934a92d..0811d7567454 100644 --- a/app/PaymentDrivers/Mollie/KBC.php +++ b/app/PaymentDrivers/Mollie/KBC.php @@ -19,13 +19,14 @@ use App\Models\GatewayType; use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; +use App\PaymentDrivers\Common\LivewireMethodInterface; use App\PaymentDrivers\Common\MethodInterface; use App\PaymentDrivers\MolliePaymentDriver; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\View\View; -class KBC implements MethodInterface +class KBC implements MethodInterface, LivewireMethodInterface { protected MolliePaymentDriver $mollie; @@ -193,4 +194,24 @@ class KBC implements MethodInterface return redirect()->route('client.payments.show', ['payment' => $this->mollie->encodePrimaryKey($payment_record->id)]); } + + /** + * @inheritDoc + */ + public function livewirePaymentView(array $data): string + { + // Doesn't support, it's offsite payment method. + + return ''; + } + + /** + * @inheritDoc + */ + public function paymentData(array $data): array + { + $this->paymentView($data); + + return $data; + } } diff --git a/resources/js/clients/payments/mollie-credit-card.js b/resources/js/clients/payments/mollie-credit-card.js index c973f1147c58..c88f350494c4 100644 --- a/resources/js/clients/payments/mollie-credit-card.js +++ b/resources/js/clients/payments/mollie-credit-card.js @@ -8,6 +8,8 @@ * @license https://www.elastic.co/licensing/elastic-license */ +import { wait, instant } from '../wait'; + class _Mollie { constructor() { this.mollie = Mollie( @@ -166,4 +168,9 @@ class _Mollie { } } -new _Mollie().handle(); + +function boot() { + new _Mollie().handle(); +} + +instant() ? boot(): wait('#mollie-credit-card-payment').then(() => boot()); diff --git a/resources/views/portal/ninja2020/gateways/mollie/credit_card/pay.blade.php b/resources/views/portal/ninja2020/gateways/mollie/credit_card/pay.blade.php index 8939c3b2cdf1..a3809360716e 100644 --- a/resources/views/portal/ninja2020/gateways/mollie/credit_card/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/mollie/credit_card/pay.blade.php @@ -4,6 +4,7 @@ ctrans('texts.credit_card')]) @section('gateway_head') + diff --git a/resources/views/portal/ninja2020/gateways/mollie/credit_card/pay_livewire.blade.php b/resources/views/portal/ninja2020/gateways/mollie/credit_card/pay_livewire.blade.php new file mode 100644 index 000000000000..018fb9908b31 --- /dev/null +++ b/resources/views/portal/ninja2020/gateways/mollie/credit_card/pay_livewire.blade.php @@ -0,0 +1,87 @@ +
+ + + + + + + + + +
+ @csrf + + + + + + + + +
+ + + + @component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.payment_type')]) + {{ ctrans('texts.credit_card') }} + @endcomponent + + @include('portal.ninja2020.gateways.includes.payment_details') + + @component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.pay_with')]) + @if (count($tokens) > 0) + @foreach ($tokens as $token) + + @endforeach + @endif + + + @endcomponent + + @component('portal.ninja2020.components.general.card-element-single') +
+ + + + +
+ + + +
+
+ @endcomponent + + @include('portal.ninja2020.gateways.includes.save_card') + @include('portal.ninja2020.gateways.includes.pay_now') +
+ +@assets + + @vite('resources/js/clients/payments/mollie-credit-card.js') +@endassets