From 83ced6d34020838ac646c2b3092b0e9657b3c81c 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 ++++++++++++++++--- 4 files changed, 91 insertions(+), 15 deletions(-) diff --git a/app/PaymentDrivers/GoCardless/ACH.php b/app/PaymentDrivers/GoCardless/ACH.php index e52e8ce54101..9a8d051373e8 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 624f04eebe7c..e6eca049f5f8 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; @@ -197,9 +198,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); @@ -224,4 +224,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; + } }