From 4e608eb242d35a7649dda60f96a3de583a5dffe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 9 Aug 2024 01:09:29 +0200 Subject: [PATCH] GoCardless: New payment flow (#72) * pass livewirePaymentView & processPaymentView thru base driver * gocardless --- app/PaymentDrivers/GoCardless/ACH.php | 26 +++++++-- app/PaymentDrivers/GoCardless/DirectDebit.php | 27 +++++++-- .../GoCardless/InstantBankPay.php | 26 ++++++++- app/PaymentDrivers/GoCardless/SEPA.php | 27 +++++++-- .../gocardless/ach/pay_livewire.blade.php | 56 +++++++++++++++++++ .../direct_debit/pay_livewire.blade.php | 56 +++++++++++++++++++ .../gocardless/sepa/pay_livewire.blade.php | 56 +++++++++++++++++++ 7 files changed, 259 insertions(+), 15 deletions(-) create mode 100644 resources/views/portal/ninja2020/gateways/gocardless/ach/pay_livewire.blade.php create mode 100644 resources/views/portal/ninja2020/gateways/gocardless/direct_debit/pay_livewire.blade.php create mode 100644 resources/views/portal/ninja2020/gateways/gocardless/sepa/pay_livewire.blade.php diff --git a/app/PaymentDrivers/GoCardless/ACH.php b/app/PaymentDrivers/GoCardless/ACH.php index 694cac15b9af..7f6470232795 100644 --- a/app/PaymentDrivers/GoCardless/ACH.php +++ b/app/PaymentDrivers/GoCardless/ACH.php @@ -20,6 +20,7 @@ use App\Models\Invoice; 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\GoCardlessPaymentDriver; use App\Utils\Traits\MakesHash; @@ -31,7 +32,7 @@ use Illuminate\Routing\Redirector; use Illuminate\View\View; //@deprecated -class ACH implements MethodInterface +class ACH implements MethodInterface, LivewireMethodInterface { use MakesHash; @@ -146,9 +147,7 @@ class ACH implements MethodInterface */ public function paymentView(array $data): View { - $data['gateway'] = $this->go_cardless; - $data['amount'] = $this->go_cardless->convertToGoCardlessAmount($data['total']['amount_with_fee'], $this->go_cardless->client->currency()->precision); - $data['currency'] = $this->go_cardless->client->getCurrencyCode(); + $data = $this->paymentData($data); return render('gateways.gocardless.ach.pay', $data); } @@ -257,4 +256,23 @@ class ACH implements MethodInterface throw new PaymentFailed('Failed to process the payment.', 500); } + /** + * @inheritDoc + */ + public function livewirePaymentView(array $data): string + { + return 'gateways.gocardless.ach.pay_livewire'; + } + + /** + * @inheritDoc + */ + public function paymentData(array $data): array + { + $data['gateway'] = $this->go_cardless; + $data['amount'] = $this->go_cardless->convertToGoCardlessAmount($data['total']['amount_with_fee'], $this->go_cardless->client->currency()->precision); + $data['currency'] = $this->go_cardless->client->getCurrencyCode(); + + return $data; + } } diff --git a/app/PaymentDrivers/GoCardless/DirectDebit.php b/app/PaymentDrivers/GoCardless/DirectDebit.php index ab67f2862263..a7c17e608feb 100644 --- a/app/PaymentDrivers/GoCardless/DirectDebit.php +++ b/app/PaymentDrivers/GoCardless/DirectDebit.php @@ -21,6 +21,7 @@ use App\Models\Invoice; 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\GoCardlessPaymentDriver; use App\Utils\Traits\MakesHash; @@ -29,7 +30,7 @@ use Illuminate\Http\Request; use Illuminate\Routing\Redirector; use Illuminate\View\View; -class DirectDebit implements MethodInterface +class DirectDebit implements MethodInterface, LivewireMethodInterface { use MakesHash; @@ -218,9 +219,7 @@ class DirectDebit implements MethodInterface */ public function paymentView(array $data): View { - $data['gateway'] = $this->go_cardless; - $data['amount'] = $this->go_cardless->convertToGoCardlessAmount($data['total']['amount_with_fee'], $this->go_cardless->client->currency()->precision); - $data['currency'] = $this->go_cardless->client->getCurrencyCode(); + $data = $this->paymentData($data); return render('gateways.gocardless.direct_debit.pay', $data); } @@ -330,4 +329,24 @@ class DirectDebit implements MethodInterface throw new PaymentFailed('Failed to process the payment.', 500); } + + /** + * @inheritDoc + */ + public function livewirePaymentView(array $data): string + { + return 'gateways.gocardless.direct_debit.pay_livewire'; + } + + /** + * @inheritDoc + */ + public function paymentData(array $data): array + { + $data['gateway'] = $this->go_cardless; + $data['amount'] = $this->go_cardless->convertToGoCardlessAmount($data['total']['amount_with_fee'], $this->go_cardless->client->currency()->precision); + $data['currency'] = $this->go_cardless->client->getCurrencyCode(); + + return $data; + } } diff --git a/app/PaymentDrivers/GoCardless/InstantBankPay.php b/app/PaymentDrivers/GoCardless/InstantBankPay.php index 9133a47a68a3..b5688e3d9fca 100644 --- a/app/PaymentDrivers/GoCardless/InstantBankPay.php +++ b/app/PaymentDrivers/GoCardless/InstantBankPay.php @@ -9,13 +9,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\GoCardlessPaymentDriver; use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -class InstantBankPay implements MethodInterface +class InstantBankPay implements MethodInterface, LivewireMethodInterface { protected GoCardlessPaymentDriver $go_cardless; @@ -194,9 +195,8 @@ class InstantBankPay implements MethodInterface * Process unsuccessful payments for Direct Debit. * * @param ResourcesPayment $payment - * @return never */ - public function processUnsuccessfulPayment(\GoCardlessPro\Resources\Payment $payment) + public function processUnsuccessfulPayment(\GoCardlessPro\Resources\Payment $payment): void { PaymentFailureMailer::dispatch($this->go_cardless->client, $payment->status, $this->go_cardless->client->company, $this->go_cardless->payment_hash->data->amount_with_fee); @@ -221,4 +221,24 @@ class InstantBankPay implements MethodInterface $this->go_cardless->client->company, ); } + + /** + * @inheritDoc + */ + public function livewirePaymentView(array $data): string + { + // not supported, this is offsite payment method. + + return ''; + } + + /** + * @inheritDoc + */ + public function paymentData(array $data): array + { + $this->paymentView($data); + + return $data; + } } diff --git a/app/PaymentDrivers/GoCardless/SEPA.php b/app/PaymentDrivers/GoCardless/SEPA.php index d0f81228ceff..d2a797e80738 100644 --- a/app/PaymentDrivers/GoCardless/SEPA.php +++ b/app/PaymentDrivers/GoCardless/SEPA.php @@ -20,6 +20,7 @@ use App\Models\Invoice; 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\GoCardlessPaymentDriver; use App\Utils\Traits\MakesHash; @@ -29,7 +30,7 @@ use Illuminate\Http\Request; use Illuminate\Routing\Redirector; use Illuminate\View\View; -class SEPA implements MethodInterface +class SEPA implements MethodInterface, LivewireMethodInterface { use MakesHash; @@ -145,9 +146,7 @@ class SEPA implements MethodInterface */ public function paymentView(array $data): View { - $data['gateway'] = $this->go_cardless; - $data['amount'] = $this->go_cardless->convertToGoCardlessAmount($data['total']['amount_with_fee'], $this->go_cardless->client->currency()->precision); - $data['currency'] = $this->go_cardless->client->getCurrencyCode(); + $data = $this->paymentData($data); return render('gateways.gocardless.sepa.pay', $data); } @@ -257,4 +256,24 @@ class SEPA implements MethodInterface throw new PaymentFailed('Failed to process the payment.', 500); } + + /** + * @inheritDoc + */ + public function livewirePaymentView(array $data): string + { + return 'gateways.gocardless.sepa.pay_livewire'; + } + + /** + * @inheritDoc + */ + public function paymentData(array $data): array + { + $data['gateway'] = $this->go_cardless; + $data['amount'] = $this->go_cardless->convertToGoCardlessAmount($data['total']['amount_with_fee'], $this->go_cardless->client->currency()->precision); + $data['currency'] = $this->go_cardless->client->getCurrencyCode(); + + return $data; + } } diff --git a/resources/views/portal/ninja2020/gateways/gocardless/ach/pay_livewire.blade.php b/resources/views/portal/ninja2020/gateways/gocardless/ach/pay_livewire.blade.php new file mode 100644 index 000000000000..44253a35ab5f --- /dev/null +++ b/resources/views/portal/ninja2020/gateways/gocardless/ach/pay_livewire.blade.php @@ -0,0 +1,56 @@ +
+@if (count($tokens) > 0) + + + @include('portal.ninja2020.gateways.includes.payment_details') + +
+ @csrf + + + + + + +
+ + @component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.pay_with')]) + @if (count($tokens) > 0) + @foreach ($tokens as $token) + + @endforeach + @endisset + @endcomponent + + @else + @component('portal.ninja2020.components.general.card-element-single', ['title' => 'ACH', 'show_title' => false]) + {{ ctrans('texts.bank_account_not_linked') }} + {{ ctrans('texts.add_payment_method') }} + @endcomponent + @endif + + @if (count($tokens) > 0) + @include('portal.ninja2020.gateways.includes.pay_now') + @endif +
+ +@script + +@endscript + diff --git a/resources/views/portal/ninja2020/gateways/gocardless/direct_debit/pay_livewire.blade.php b/resources/views/portal/ninja2020/gateways/gocardless/direct_debit/pay_livewire.blade.php new file mode 100644 index 000000000000..22e6701137dd --- /dev/null +++ b/resources/views/portal/ninja2020/gateways/gocardless/direct_debit/pay_livewire.blade.php @@ -0,0 +1,56 @@ +
+@if (count($tokens) > 0) + + + @include('portal.ninja2020.gateways.includes.payment_details') + +
+ @csrf + + + + + + +
+ + @component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.pay_with')]) + @if (count($tokens) > 0) + @foreach ($tokens as $token) + + @endforeach + @endisset + @endcomponent + + @else + @component('portal.ninja2020.components.general.card-element-single', ['title' => 'Direct Debit', 'show_title' => false]) + {{ ctrans('texts.bank_account_not_linked') }} + + {{ ctrans('texts.add_payment_method') }} + @endcomponent + @endif + + @if (count($tokens) > 0) + @include('portal.ninja2020.gateways.includes.pay_now') + @endif +
+ +@script + +@endscript \ No newline at end of file diff --git a/resources/views/portal/ninja2020/gateways/gocardless/sepa/pay_livewire.blade.php b/resources/views/portal/ninja2020/gateways/gocardless/sepa/pay_livewire.blade.php new file mode 100644 index 000000000000..74e9ab9f1d39 --- /dev/null +++ b/resources/views/portal/ninja2020/gateways/gocardless/sepa/pay_livewire.blade.php @@ -0,0 +1,56 @@ +
+@if (count($tokens) > 0) + + + @include('portal.ninja2020.gateways.includes.payment_details') + +
+ @csrf + + + + + + +
+ + @component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.pay_with')]) + @if (count($tokens) > 0) + @foreach ($tokens as $token) + + @endforeach + @endisset + @endcomponent + + @else + @component('portal.ninja2020.components.general.card-element-single', ['title' => ctrans('texts.payment_type_SEPA'), 'show_title' => false]) + {{ ctrans('texts.bank_account_not_linked') }} + + {{ ctrans('texts.add_payment_method') }} + @endcomponent + @endif + + @if (count($tokens) > 0) + @include('portal.ninja2020.gateways.includes.pay_now') + @endif +
+ +@script + +@endscript