From cba76cd60851d17fba7996cec465e654d312e757 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 4 Sep 2024 13:48:23 +1000 Subject: [PATCH] Add back interface methods for new payment flows --- app/Export/CSV/ActivityExport.php | 5 +- app/Export/CSV/BaseExport.php | 24 +++---- app/PaymentDrivers/RotessaPaymentDriver.php | 4 +- app/PaymentDrivers/Stripe/Bancontact.php | 67 ++++++++++------- app/PaymentDrivers/Stripe/BankTransfer.php | 79 ++++++++++++--------- app/PaymentDrivers/Stripe/BrowserPay.php | 20 +++++- app/PaymentDrivers/Stripe/Charge.php | 6 +- app/PaymentDrivers/Stripe/CreditCard.php | 19 ++++- app/PaymentDrivers/Stripe/EPS.php | 65 ++++++++++------- app/PaymentDrivers/Stripe/FPX.php | 67 ++++++++++------- app/PaymentDrivers/Stripe/GIROPAY.php | 35 ++------- app/PaymentDrivers/Stripe/Klarna.php | 69 ++++++++++-------- app/PaymentDrivers/Stripe/PRZELEWY24.php | 67 ++++++++++------- app/PaymentDrivers/Stripe/SEPA.php | 71 ++++++++++-------- app/PaymentDrivers/Stripe/SOFORT.php | 65 ++++++++++------- app/PaymentDrivers/Stripe/iDeal.php | 67 ++++++++++------- 16 files changed, 427 insertions(+), 303 deletions(-) diff --git a/app/Export/CSV/ActivityExport.php b/app/Export/CSV/ActivityExport.php index bdbc232f6e4c..f9f60bbcdc61 100644 --- a/app/Export/CSV/ActivityExport.php +++ b/app/Export/CSV/ActivityExport.php @@ -101,8 +101,11 @@ class ActivityExport extends BaseExport $t = app('translator'); $t->replace(Ninja::transformTranslations($this->company->settings)); - $this->date_format = DateFormat::find($this->company->settings->date_format_id)->format; + /** @var \App\Models\DateFormat $df */ + $df = DateFormat::query()->find($this->company->settings->date_format_id); + $this->date_format = $df->format; + if (count($this->input['report_keys']) == 0) { $this->input['report_keys'] = array_values($this->entity_keys); } diff --git a/app/Export/CSV/BaseExport.php b/app/Export/CSV/BaseExport.php index 9d4bcd2bd4ec..a8fed6fff95c 100644 --- a/app/Export/CSV/BaseExport.php +++ b/app/Export/CSV/BaseExport.php @@ -845,7 +845,7 @@ class BaseExport /** * Apply Product Filters * - * @param Builder $query + * @param \Illuminate\Database\Eloquent\Builder $query * * @return Builder */ @@ -870,7 +870,7 @@ class BaseExport /** * Add Client Filter * - * @param Builder $query + * @param \Illuminate\Database\Eloquent\Builder $query * @param mixed $clients * * @return Builder @@ -893,7 +893,7 @@ class BaseExport /** * Add Vendor Filter * - * @param Builder $query + * @param \Illuminate\Database\Eloquent\Builder $query * @param string $vendors * * @return Builder @@ -917,7 +917,7 @@ class BaseExport /** * AddProjectFilter * - * @param Builder $query + * @param \Illuminate\Database\Eloquent\Builder $query * @param string $projects * * @return Builder @@ -941,7 +941,7 @@ class BaseExport /** * Add Category Filter * - * @param Builder $query + * @param \Illuminate\Database\Eloquent\Builder $query * @param string $expense_categories * * @return Builder @@ -966,7 +966,7 @@ class BaseExport /** * Add Payment Status Filters * - * @param Builder $query + * @param \Illuminate\Database\Eloquent\Builder $query * @param string $status * * @return Builder @@ -1024,10 +1024,10 @@ class BaseExport /** * Add RecurringInvoice Status Filter * - * @param Builder $query + * @param \Illuminate\Database\Eloquent\Builder $query * @param string $status * - * @return Builder + * @return \Illuminate\Database\Eloquent\Builder */ protected function addRecurringInvoiceStatusFilter(Builder $query, string $status): Builder { @@ -1067,7 +1067,7 @@ class BaseExport /** * Add QuoteStatus Filter * - * @param Builder $query + * @param \Illuminate\Database\Eloquent\Builder $query * @param string $status * * @return Builder @@ -1133,7 +1133,7 @@ class BaseExport /** * Add PurchaseOrder Status Filter * - * @param Builder $query + * @param \Illuminate\Database\Eloquent\Builder $query * @param string $status * * @return Builder @@ -1183,7 +1183,7 @@ class BaseExport /** * Add Invoice Status Filter * - * @param Builder $query + * @param \Illuminate\Database\Eloquent\Builder $query * @param string $status * @return Builder */ @@ -1249,7 +1249,7 @@ class BaseExport /** * Add Date Range * - * @param Builder $query + * @param \Illuminate\Database\Eloquent\Builder $query * @param ?string $table_name * @return Builder */ diff --git a/app/PaymentDrivers/RotessaPaymentDriver.php b/app/PaymentDrivers/RotessaPaymentDriver.php index 1c4a7cf6b5a5..05d941c4dcea 100644 --- a/app/PaymentDrivers/RotessaPaymentDriver.php +++ b/app/PaymentDrivers/RotessaPaymentDriver.php @@ -278,12 +278,12 @@ class RotessaPaymentDriver extends BaseDriver return $this->company_gateway->getConfigField('testMode') ? 'https://sandbox-api.rotessa.com/v1/' : 'https://api.rotessa.com/v1/'; } - public function processPaymentViewData(array $data) + public function processPaymentViewData(array $data): array { return $this->payment_method->paymentData($data); } - public function livewirePaymentView(array $data) + public function livewirePaymentView(array $data): string { return $this->payment_method->livewirePaymentView($data); } diff --git a/app/PaymentDrivers/Stripe/Bancontact.php b/app/PaymentDrivers/Stripe/Bancontact.php index a4b0d61fd095..f22a8898cc26 100644 --- a/app/PaymentDrivers/Stripe/Bancontact.php +++ b/app/PaymentDrivers/Stripe/Bancontact.php @@ -18,9 +18,10 @@ use App\Models\GatewayType; use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; +use App\PaymentDrivers\Common\LivewireMethodInterface; use App\PaymentDrivers\StripePaymentDriver; -class Bancontact +class Bancontact implements LivewireMethodInterface { /** @var StripePaymentDriver */ public StripePaymentDriver $stripe; @@ -37,32 +38,7 @@ class Bancontact public function paymentView(array $data) { - $this->stripe->init(); - - $data['gateway'] = $this->stripe; - $data['return_url'] = $this->buildReturnUrl(); - $data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()); - $data['client'] = $this->stripe->client; - $data['customer'] = $this->stripe->findOrCreateCustomer()->id; - $data['country'] = $this->stripe->client->country->iso_3166_2; - - $intent = \Stripe\PaymentIntent::create([ - 'amount' => $data['stripe_amount'], - 'currency' => 'eur', - 'payment_method_types' => ['bancontact'], - 'customer' => $this->stripe->findOrCreateCustomer(), - 'description' => $this->stripe->getDescription(false), - 'metadata' => [ - 'payment_hash' => $this->stripe->payment_hash->hash, - 'gateway_type_id' => GatewayType::BANCONTACT, - ], - - ], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)])); - - $data['pi_client_secret'] = $intent->client_secret; - - $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]); - $this->stripe->payment_hash->save(); + $data = $this->paymentData($data); return render('gateways.stripe.bancontact.pay', $data); } @@ -143,4 +119,41 @@ class Bancontact throw new PaymentFailed('Failed to process the payment.', 500); } + + public function paymentData(array $data): array + { + $this->stripe->init(); + + $data['gateway'] = $this->stripe; + $data['return_url'] = $this->buildReturnUrl(); + $data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()); + $data['client'] = $this->stripe->client; + $data['customer'] = $this->stripe->findOrCreateCustomer()->id; + $data['country'] = $this->stripe->client->country->iso_3166_2; + + $intent = \Stripe\PaymentIntent::create([ + 'amount' => $data['stripe_amount'], + 'currency' => 'eur', + 'payment_method_types' => ['bancontact'], + 'customer' => $this->stripe->findOrCreateCustomer(), + 'description' => $this->stripe->getDescription(false), + 'metadata' => [ + 'payment_hash' => $this->stripe->payment_hash->hash, + 'gateway_type_id' => GatewayType::BANCONTACT, + ], + + ], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)])); + + $data['pi_client_secret'] = $intent->client_secret; + + $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]); + $this->stripe->payment_hash->save(); + + return $data; + } + + public function livewirePaymentView(array $data): string + { + return 'gateways.stripe.bancontact.pay_livewire'; + } } diff --git a/app/PaymentDrivers/Stripe/BankTransfer.php b/app/PaymentDrivers/Stripe/BankTransfer.php index 4f7a1bac4392..2e8837a95e0a 100644 --- a/app/PaymentDrivers/Stripe/BankTransfer.php +++ b/app/PaymentDrivers/Stripe/BankTransfer.php @@ -19,12 +19,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\StripePaymentDriver; use App\Utils\Number; use App\Utils\Traits\MakesHash; use Stripe\PaymentIntent; -class BankTransfer +class BankTransfer implements LivewireMethodInterface { use MakesHash; @@ -38,37 +39,7 @@ class BankTransfer public function paymentView(array $data) { - $this->stripe->init(); - - $intent = \Stripe\PaymentIntent::create([ - 'amount' => $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()), - 'currency' => $this->stripe->client->currency()->code, - 'customer' => $this->stripe->findOrCreateCustomer()->id, - 'description' => $this->stripe->getDescription(false), - 'payment_method_types' => ['customer_balance'], - 'payment_method_data' => [ - 'type' => 'customer_balance', - ], - 'payment_method_options' => [ - 'customer_balance' => [ - 'funding_type' => 'bank_transfer', - 'bank_transfer' => $this->resolveBankType() - ], - ], - 'metadata' => [ - 'payment_hash' => $this->stripe->payment_hash->hash, - 'gateway_type_id' => GatewayType::DIRECT_DEBIT, - ], - ], $this->stripe->stripe_connect_auth); - - - $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency())]); - $this->stripe->payment_hash->save(); - - $data = []; - $data['return_url'] = $this->buildReturnUrl(); - $data['gateway'] = $this->stripe; - $data['client_secret'] = $intent ? $intent->client_secret : false; + $data = $this->paymentData($data); return render('gateways.stripe.bank_transfer.pay', $data); } @@ -317,4 +288,46 @@ class BankTransfer throw new PaymentFailed('Failed to process the payment.', 500); } -} + + public function paymentData(array $data): array + { + $this->stripe->init(); + + $intent = \Stripe\PaymentIntent::create([ + 'amount' => $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()), + 'currency' => $this->stripe->client->currency()->code, + 'customer' => $this->stripe->findOrCreateCustomer()->id, + 'description' => $this->stripe->getDescription(false), + 'payment_method_types' => ['customer_balance'], + 'payment_method_data' => [ + 'type' => 'customer_balance', + ], + 'payment_method_options' => [ + 'customer_balance' => [ + 'funding_type' => 'bank_transfer', + 'bank_transfer' => $this->resolveBankType() + ], + ], + 'metadata' => [ + 'payment_hash' => $this->stripe->payment_hash->hash, + 'gateway_type_id' => GatewayType::DIRECT_DEBIT, + ], + ], $this->stripe->stripe_connect_auth); + + + $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency())]); + $this->stripe->payment_hash->save(); + + $data = []; + $data['return_url'] = $this->buildReturnUrl(); + $data['gateway'] = $this->stripe; + $data['client_secret'] = $intent ? $intent->client_secret : false; + + return $data; + } + + public function livewirePaymentView(array $data): string + { + return 'gateways.stripe.bank_transfer.pay_livewire'; + } +} \ No newline at end of file diff --git a/app/PaymentDrivers/Stripe/BrowserPay.php b/app/PaymentDrivers/Stripe/BrowserPay.php index 09d71fcdb17c..126afec809c8 100644 --- a/app/PaymentDrivers/Stripe/BrowserPay.php +++ b/app/PaymentDrivers/Stripe/BrowserPay.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\StripePaymentDriver; use App\Utils\Ninja; @@ -29,7 +30,7 @@ use Stripe\ApplePayDomain; use Stripe\Exception\ApiErrorException; use Stripe\PaymentIntent; -class BrowserPay implements MethodInterface +class BrowserPay implements MethodInterface, LivewireMethodInterface { protected StripePaymentDriver $stripe; @@ -64,7 +65,8 @@ class BrowserPay implements MethodInterface return redirect()->route('client.payment_methods.index'); } - public function paymentView(array $data): View + + public function paymentData(array $data): array { $payment_intent_data = [ 'amount' => $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()), @@ -93,6 +95,13 @@ class BrowserPay implements MethodInterface 'requestPayerEmail' => true, ]; + return $data; + } + + public function paymentView(array $data): View + { + $data = $this->paymentData($data); + return render('gateways.stripe.browser_pay.pay', $data); } @@ -153,7 +162,7 @@ class BrowserPay implements MethodInterface $this->stripe->client->company, ); - return redirect()->route('client.payments.show', ['payment' => $payment->hashed_id]); + return redirect()->route('client.payments.show', ['payment' => $this->stripe->encodePrimaryKey($payment->id)]); } /** @@ -231,4 +240,9 @@ class BrowserPay implements MethodInterface return str_replace(['https://', '/public'], '', $domain); } + + public function livewirePaymentView(array $data): string + { + return 'gateways.stripe.browser_pay.pay_livewire'; + } } diff --git a/app/PaymentDrivers/Stripe/Charge.php b/app/PaymentDrivers/Stripe/Charge.php index 3a06e0974467..524542d9a8a4 100644 --- a/app/PaymentDrivers/Stripe/Charge.php +++ b/app/PaymentDrivers/Stripe/Charge.php @@ -50,7 +50,7 @@ class Charge { if ($cgt->gateway_type_id == GatewayType::BANK_TRANSFER) { return (new ACH($this->stripe))->tokenBilling($cgt, $payment_hash); - } elseif($cgt->gateway_type_id == GatewayType::ACSS) { + } elseif ($cgt->gateway_type_id == GatewayType::ACSS) { return (new ACSS($this->stripe))->tokenBilling($cgt, $payment_hash); } @@ -82,8 +82,8 @@ class Charge if ($cgt->gateway_type_id == GatewayType::BACS) { $data['payment_method_types'] = ['bacs_debit']; } - if($cgt->gateway_type_id == GatewayType::CREDIT_CARD){ - $data['payment_method_types'] = ["card","link"]; + if ($cgt->gateway_type_id == GatewayType::CREDIT_CARD) { + $data['payment_method_types'] = ["card","link"]; } /* Should improve token billing with client not present */ diff --git a/app/PaymentDrivers/Stripe/CreditCard.php b/app/PaymentDrivers/Stripe/CreditCard.php index eab1a98c3262..2c9154ae81ba 100644 --- a/app/PaymentDrivers/Stripe/CreditCard.php +++ b/app/PaymentDrivers/Stripe/CreditCard.php @@ -19,12 +19,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\Stripe\Jobs\UpdateCustomer; use App\PaymentDrivers\StripePaymentDriver; use Stripe\PaymentIntent; use Stripe\PaymentMethod; -class CreditCard +class CreditCard implements LivewireMethodInterface { public $stripe; @@ -57,7 +58,7 @@ class CreditCard return redirect()->route('client.payment_methods.index'); } - public function paymentView(array $data) + public function paymentData(array $data): array { $description = $this->stripe->getDescription(false); @@ -77,9 +78,21 @@ class CreditCard $data['intent'] = $this->stripe->createPaymentIntent($payment_intent_data); $data['gateway'] = $this->stripe; + return $data; + } + + public function paymentView(array $data) + { + $data = $this->paymentData($data); + return render('gateways.stripe.credit_card.pay', $data); } + public function livewirePaymentView(array $data): string + { + return 'gateways.stripe.credit_card.pay_livewire'; + } + public function paymentResponse(PaymentResponseRequest $request) { $this->stripe->init(); @@ -160,7 +173,7 @@ class CreditCard } } - return redirect()->route('client.payments.show', ['payment' => $payment->hashed_id]); + return redirect()->route('client.payments.show', ['payment' => $this->stripe->encodePrimaryKey($payment->id)]); } public function processUnsuccessfulPayment($server_response) diff --git a/app/PaymentDrivers/Stripe/EPS.php b/app/PaymentDrivers/Stripe/EPS.php index 8f1456fcebb0..98b23fdc2b9f 100644 --- a/app/PaymentDrivers/Stripe/EPS.php +++ b/app/PaymentDrivers/Stripe/EPS.php @@ -18,9 +18,10 @@ use App\Models\GatewayType; use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; +use App\PaymentDrivers\Common\LivewireMethodInterface; use App\PaymentDrivers\StripePaymentDriver; -class EPS +class EPS implements LivewireMethodInterface { /** @var StripePaymentDriver */ public StripePaymentDriver $stripe; @@ -37,31 +38,7 @@ class EPS public function paymentView(array $data) { - $this->stripe->init(); - - $data['gateway'] = $this->stripe; - $data['return_url'] = $this->buildReturnUrl(); - $data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()); - $data['client'] = $this->stripe->client; - $data['customer'] = $this->stripe->findOrCreateCustomer()->id; - $data['country'] = $this->stripe->client->country->iso_3166_2; - - $intent = \Stripe\PaymentIntent::create([ - 'amount' => $data['stripe_amount'], - 'currency' => 'eur', - 'payment_method_types' => ['eps'], - 'customer' => $this->stripe->findOrCreateCustomer(), - 'description' => $this->stripe->getDescription(false), - 'metadata' => [ - 'payment_hash' => $this->stripe->payment_hash->hash, - 'gateway_type_id' => GatewayType::EPS, - ], - ], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)])); - - $data['pi_client_secret'] = $intent->client_secret; - - $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]); - $this->stripe->payment_hash->save(); + $data = $this->paymentData($data); return render('gateways.stripe.eps.pay', $data); } @@ -142,4 +119,40 @@ class EPS throw new PaymentFailed('Failed to process the payment.', 500); } + + public function paymentData(array $data): array + { + $this->stripe->init(); + + $data['gateway'] = $this->stripe; + $data['return_url'] = $this->buildReturnUrl(); + $data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()); + $data['client'] = $this->stripe->client; + $data['customer'] = $this->stripe->findOrCreateCustomer()->id; + $data['country'] = $this->stripe->client->country->iso_3166_2; + + $intent = \Stripe\PaymentIntent::create([ + 'amount' => $data['stripe_amount'], + 'currency' => 'eur', + 'payment_method_types' => ['eps'], + 'customer' => $this->stripe->findOrCreateCustomer(), + 'description' => $this->stripe->getDescription(false), + 'metadata' => [ + 'payment_hash' => $this->stripe->payment_hash->hash, + 'gateway_type_id' => GatewayType::EPS, + ], + ], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)])); + + $data['pi_client_secret'] = $intent->client_secret; + + $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]); + $this->stripe->payment_hash->save(); + + return $data; + } + + public function livewirePaymentView(array $data): string + { + return 'gateways.stripe.eps.pay_livewire'; + } } diff --git a/app/PaymentDrivers/Stripe/FPX.php b/app/PaymentDrivers/Stripe/FPX.php index e97b25562c13..2a2222270a74 100644 --- a/app/PaymentDrivers/Stripe/FPX.php +++ b/app/PaymentDrivers/Stripe/FPX.php @@ -19,9 +19,10 @@ use App\Models\GatewayType; use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; +use App\PaymentDrivers\Common\LivewireMethodInterface; use App\PaymentDrivers\StripePaymentDriver; -class FPX +class FPX implements LivewireMethodInterface { /** @var StripePaymentDriver */ public StripePaymentDriver $stripe; @@ -38,31 +39,7 @@ class FPX public function paymentView(array $data) { - $this->stripe->init(); - - $data['gateway'] = $this->stripe; - $data['return_url'] = $this->buildReturnUrl(); - $data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()); - $data['client'] = $this->stripe->client; - $data['customer'] = $this->stripe->findOrCreateCustomer()->id; - $data['country'] = $this->stripe->client->country->iso_3166_2; - - $intent = \Stripe\PaymentIntent::create([ - 'amount' => $data['stripe_amount'], - 'currency' => $this->stripe->client->getCurrencyCode(), - 'payment_method_types' => ['fpx'], - 'customer' => $this->stripe->findOrCreateCustomer(), - 'description' => $this->stripe->getDescription(false), - 'metadata' => [ - 'payment_hash' => $this->stripe->payment_hash->hash, - 'gateway_type_id' => GatewayType::FPX, - ], - ], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)])); - - $data['pi_client_secret'] = $intent->client_secret; - - $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]); - $this->stripe->payment_hash->save(); + $data = $this->paymentData($data); return render('gateways.stripe.fpx.pay', $data); } @@ -143,4 +120,40 @@ class FPX throw new PaymentFailed('Failed to process the payment.', 400); } -} + + public function paymentData(array $data): array + { + $this->stripe->init(); + + $data['gateway'] = $this->stripe; + $data['return_url'] = $this->buildReturnUrl(); + $data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()); + $data['client'] = $this->stripe->client; + $data['customer'] = $this->stripe->findOrCreateCustomer()->id; + $data['country'] = $this->stripe->client->country->iso_3166_2; + + $intent = \Stripe\PaymentIntent::create([ + 'amount' => $data['stripe_amount'], + 'currency' => $this->stripe->client->getCurrencyCode(), + 'payment_method_types' => ['fpx'], + 'customer' => $this->stripe->findOrCreateCustomer(), + 'description' => $this->stripe->getDescription(false), + 'metadata' => [ + 'payment_hash' => $this->stripe->payment_hash->hash, + 'gateway_type_id' => GatewayType::FPX, + ], + ], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)])); + + $data['pi_client_secret'] = $intent->client_secret; + + $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]); + $this->stripe->payment_hash->save(); + + return $data; + } + + public function livewirePaymentView(array $data): string + { + return 'gateways.stripe.fpx.pay_livewire'; + } +} \ No newline at end of file diff --git a/app/PaymentDrivers/Stripe/GIROPAY.php b/app/PaymentDrivers/Stripe/GIROPAY.php index 44e0912b131f..0a37ecec7300 100644 --- a/app/PaymentDrivers/Stripe/GIROPAY.php +++ b/app/PaymentDrivers/Stripe/GIROPAY.php @@ -18,9 +18,10 @@ use App\Models\GatewayType; use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; +use App\PaymentDrivers\Common\LivewireMethodInterface; use App\PaymentDrivers\StripePaymentDriver; -class GIROPAY +class GIROPAY implements LivewireMethodInterface { /** @var StripePaymentDriver */ public StripePaymentDriver $stripe; @@ -37,31 +38,7 @@ class GIROPAY public function paymentView(array $data) { - $this->stripe->init(); - - $data['gateway'] = $this->stripe; - $data['return_url'] = $this->buildReturnUrl(); - $data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()); - $data['client'] = $this->stripe->client; - $data['customer'] = $this->stripe->findOrCreateCustomer()->id; - $data['country'] = $this->stripe->client->country->iso_3166_2; - - $intent = \Stripe\PaymentIntent::create([ - 'amount' => $data['stripe_amount'], - 'currency' => 'eur', - 'payment_method_types' => ['giropay'], - 'customer' => $this->stripe->findOrCreateCustomer(), - 'description' => $this->stripe->getDescription(false), - 'metadata' => [ - 'payment_hash' => $this->stripe->payment_hash->hash, - 'gateway_type_id' => GatewayType::GIROPAY, - ], - ], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)])); - - $data['pi_client_secret'] = $intent->client_secret; - - $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]); - $this->stripe->payment_hash->save(); + $data = $this->paymentData($data); return render('gateways.stripe.giropay.pay', $data); } @@ -142,7 +119,7 @@ class GIROPAY throw new PaymentFailed('Failed to process the payment.', 500); } - + public function paymentData(array $data): array { $this->stripe->init(); @@ -174,8 +151,8 @@ class GIROPAY return $data; } - public function livewirePaymentView(array $data): string + public function livewirePaymentView(array $data): string { - return 'gateways.stripe.giropay.pay_livewire'; + return 'gateways.giropay.pay_livewire'; } } diff --git a/app/PaymentDrivers/Stripe/Klarna.php b/app/PaymentDrivers/Stripe/Klarna.php index 09169e4f16a1..a78dd46073d4 100644 --- a/app/PaymentDrivers/Stripe/Klarna.php +++ b/app/PaymentDrivers/Stripe/Klarna.php @@ -18,9 +18,10 @@ use App\Models\GatewayType; use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; +use App\PaymentDrivers\Common\LivewireMethodInterface; use App\PaymentDrivers\StripePaymentDriver; -class Klarna +class Klarna implements LivewireMethodInterface { /** @var StripePaymentDriver */ public StripePaymentDriver $stripe; @@ -37,33 +38,7 @@ class Klarna public function paymentView(array $data) { - $this->stripe->init(); - - $data['gateway'] = $this->stripe; - $data['return_url'] = $this->buildReturnUrl(); - $data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()); - $data['client'] = $this->stripe->client; - $data['customer'] = $this->stripe->findOrCreateCustomer()->id; - $data['country'] = $this->stripe->client->country->iso_3166_2; - - $description = $this->stripe->getDescription(false); - - $intent = \Stripe\PaymentIntent::create([ - 'amount' => $data['stripe_amount'], - 'currency' => $this->stripe->client->getCurrencyCode(), - 'payment_method_types' => ['klarna'], - 'customer' => $this->stripe->findOrCreateCustomer(), - 'description' => $description, - 'metadata' => [ - 'payment_hash' => $this->stripe->payment_hash->hash, - 'gateway_type_id' => GatewayType::KLARNA, - ], - ], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)])); - - $data['pi_client_secret'] = $intent->client_secret; - - $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]); - $this->stripe->payment_hash->save(); + $data = $this->paymentData($data); return render('gateways.stripe.klarna.pay', $data); } @@ -142,4 +117,42 @@ class Klarna throw new PaymentFailed(ctrans('texts.gateway_error'), 500); } + + public function paymentData(array $data): array + { + $this->stripe->init(); + + $data['gateway'] = $this->stripe; + $data['return_url'] = $this->buildReturnUrl(); + $data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()); + $data['client'] = $this->stripe->client; + $data['customer'] = $this->stripe->findOrCreateCustomer()->id; + $data['country'] = $this->stripe->client->country->iso_3166_2; + + $description = $this->stripe->getDescription(false); + + $intent = \Stripe\PaymentIntent::create([ + 'amount' => $data['stripe_amount'], + 'currency' => $this->stripe->client->getCurrencyCode(), + 'payment_method_types' => ['klarna'], + 'customer' => $this->stripe->findOrCreateCustomer(), + 'description' => $description, + 'metadata' => [ + 'payment_hash' => $this->stripe->payment_hash->hash, + 'gateway_type_id' => GatewayType::KLARNA, + ], + ], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)])); + + $data['pi_client_secret'] = $intent->client_secret; + + $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]); + $this->stripe->payment_hash->save(); + + return $data; + } + + public function livewirePaymentView(array $data): string + { + return 'gateways.stripe.klarna.pay_livewire'; + } } diff --git a/app/PaymentDrivers/Stripe/PRZELEWY24.php b/app/PaymentDrivers/Stripe/PRZELEWY24.php index ce9bb79405ed..59efc245e6ed 100644 --- a/app/PaymentDrivers/Stripe/PRZELEWY24.php +++ b/app/PaymentDrivers/Stripe/PRZELEWY24.php @@ -18,9 +18,10 @@ use App\Models\GatewayType; use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; +use App\PaymentDrivers\Common\LivewireMethodInterface; use App\PaymentDrivers\StripePaymentDriver; -class PRZELEWY24 +class PRZELEWY24 implements LivewireMethodInterface { /** @var StripePaymentDriver */ public StripePaymentDriver $stripe; @@ -37,31 +38,7 @@ class PRZELEWY24 public function paymentView(array $data) { - $this->stripe->init(); - - $data['gateway'] = $this->stripe; - $data['return_url'] = $this->buildReturnUrl(); - $data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()); - $data['client'] = $this->stripe->client; - $data['customer'] = $this->stripe->findOrCreateCustomer()->id; - $data['country'] = $this->stripe->client->country->iso_3166_2; - - $intent = \Stripe\PaymentIntent::create([ - 'amount' => $data['stripe_amount'], - 'currency' => 'eur', - 'payment_method_types' => ['p24'], - 'customer' => $this->stripe->findOrCreateCustomer(), - 'description' => $this->stripe->getDescription(false), - 'metadata' => [ - 'payment_hash' => $this->stripe->payment_hash->hash, - 'gateway_type_id' => GatewayType::PRZELEWY24, - ], - ], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)])); - - $data['pi_client_secret'] = $intent->client_secret; - - $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]); - $this->stripe->payment_hash->save(); + $data = $this->paymentData($data); return render('gateways.stripe.przelewy24.pay', $data); } @@ -142,4 +119,40 @@ class PRZELEWY24 throw new PaymentFailed('Failed to process the payment.', 500); } -} + + public function paymentData(array $data): array + { + $this->stripe->init(); + + $data['gateway'] = $this->stripe; + $data['return_url'] = $this->buildReturnUrl(); + $data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()); + $data['client'] = $this->stripe->client; + $data['customer'] = $this->stripe->findOrCreateCustomer()->id; + $data['country'] = $this->stripe->client->country->iso_3166_2; + + $intent = \Stripe\PaymentIntent::create([ + 'amount' => $data['stripe_amount'], + 'currency' => 'eur', + 'payment_method_types' => ['p24'], + 'customer' => $this->stripe->findOrCreateCustomer(), + 'description' => $this->stripe->getDescription(false), + 'metadata' => [ + 'payment_hash' => $this->stripe->payment_hash->hash, + 'gateway_type_id' => GatewayType::PRZELEWY24, + ], + ], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)])); + + $data['pi_client_secret'] = $intent->client_secret; + + $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]); + $this->stripe->payment_hash->save(); + + return $data; + } + + public function livewirePaymentView(array $data): string + { + return 'gateways.stripe.przelewy24.pay_livewire'; + } +} \ No newline at end of file diff --git a/app/PaymentDrivers/Stripe/SEPA.php b/app/PaymentDrivers/Stripe/SEPA.php index 79f98e9f6239..8d724309bca4 100644 --- a/app/PaymentDrivers/Stripe/SEPA.php +++ b/app/PaymentDrivers/Stripe/SEPA.php @@ -19,9 +19,10 @@ use App\Models\GatewayType; use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; +use App\PaymentDrivers\Common\LivewireMethodInterface; use App\PaymentDrivers\StripePaymentDriver; -class SEPA +class SEPA implements LivewireMethodInterface { /** @var StripePaymentDriver */ public StripePaymentDriver $stripe; @@ -47,33 +48,7 @@ class SEPA public function paymentView(array $data) { - $data['gateway'] = $this->stripe; - $data['payment_method_id'] = GatewayType::SEPA; - $data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()); - $data['client'] = $this->stripe->client; - $data['customer'] = $this->stripe->findOrCreateCustomer()->id; - $data['country'] = $this->stripe->client->country->iso_3166_2; - $data['payment_hash'] = $this->stripe->payment_hash->hash; - - $intent_data = [ - 'amount' => $data['stripe_amount'], - 'currency' => 'eur', - 'payment_method_types' => ['sepa_debit'], - 'setup_future_usage' => 'off_session', - 'customer' => $this->stripe->findOrCreateCustomer(), - 'description' => $this->stripe->getDescription(false), - 'metadata' => [ - 'payment_hash' => $this->stripe->payment_hash->hash, - 'gateway_type_id' => GatewayType::SEPA, - ], - ]; - - $intent = \Stripe\PaymentIntent::create($intent_data, array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)])); - - $data['pi_client_secret'] = $intent->client_secret; - - $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]); - $this->stripe->payment_hash->save(); + $data = $this->paymentData($data); return render('gateways.stripe.sepa.pay', $data); } @@ -176,4 +151,42 @@ class SEPA return $this->stripe->processInternallyFailedPayment($this->stripe, $e); } } -} + + public function paymentData(array $data): array + { + $data['gateway'] = $this->stripe; + $data['payment_method_id'] = GatewayType::SEPA; + $data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()); + $data['client'] = $this->stripe->client; + $data['customer'] = $this->stripe->findOrCreateCustomer()->id; + $data['country'] = $this->stripe->client->country->iso_3166_2; + $data['payment_hash'] = $this->stripe->payment_hash->hash; + + $intent_data = [ + 'amount' => $data['stripe_amount'], + 'currency' => 'eur', + 'payment_method_types' => ['sepa_debit'], + 'setup_future_usage' => 'off_session', + 'customer' => $this->stripe->findOrCreateCustomer(), + 'description' => $this->stripe->getDescription(false), + 'metadata' => [ + 'payment_hash' => $this->stripe->payment_hash->hash, + 'gateway_type_id' => GatewayType::SEPA, + ], + ]; + + $intent = \Stripe\PaymentIntent::create($intent_data, array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)])); + + $data['pi_client_secret'] = $intent->client_secret; + + $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]); + $this->stripe->payment_hash->save(); + + return $data; + } + + public function livewirePaymentView(array $data): string + { + return 'gateways.stripe.sepa.pay_livewire'; + } +} \ No newline at end of file diff --git a/app/PaymentDrivers/Stripe/SOFORT.php b/app/PaymentDrivers/Stripe/SOFORT.php index 4a7faef870c0..01789b6849d5 100644 --- a/app/PaymentDrivers/Stripe/SOFORT.php +++ b/app/PaymentDrivers/Stripe/SOFORT.php @@ -18,9 +18,10 @@ use App\Models\GatewayType; use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; +use App\PaymentDrivers\Common\LivewireMethodInterface; use App\PaymentDrivers\StripePaymentDriver; -class SOFORT +class SOFORT implements LivewireMethodInterface { /** @var StripePaymentDriver */ public StripePaymentDriver $stripe; @@ -37,31 +38,7 @@ class SOFORT public function paymentView(array $data) { - $this->stripe->init(); - - $data['gateway'] = $this->stripe; - $data['return_url'] = $this->buildReturnUrl(); - $data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()); - $data['client'] = $this->stripe->client; - $data['customer'] = $this->stripe->findOrCreateCustomer()->id; - $data['country'] = $this->stripe->client->country->iso_3166_2; - - $intent = \Stripe\PaymentIntent::create([ - 'amount' => $data['stripe_amount'], - 'currency' => 'eur', - 'payment_method_types' => ['sofort'], - 'customer' => $this->stripe->findOrCreateCustomer(), - 'description' => $this->stripe->getDescription(false), - 'metadata' => [ - 'payment_hash' => $this->stripe->payment_hash->hash, - 'gateway_type_id' => GatewayType::SOFORT, - ], - ], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)])); - - $data['pi_client_secret'] = $intent->client_secret; - - $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]); - $this->stripe->payment_hash->save(); + $data = $this->paymentData($data); return render('gateways.stripe.sofort.pay', $data); } @@ -137,4 +114,40 @@ class SOFORT throw new PaymentFailed('Failed to process the payment.', 500); } + + public function paymentData(array $data): array + { + $this->stripe->init(); + + $data['gateway'] = $this->stripe; + $data['return_url'] = $this->buildReturnUrl(); + $data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()); + $data['client'] = $this->stripe->client; + $data['customer'] = $this->stripe->findOrCreateCustomer()->id; + $data['country'] = $this->stripe->client->country->iso_3166_2; + + $intent = \Stripe\PaymentIntent::create([ + 'amount' => $data['stripe_amount'], + 'currency' => 'eur', + 'payment_method_types' => ['sofort'], + 'customer' => $this->stripe->findOrCreateCustomer(), + 'description' => $this->stripe->getDescription(false), + 'metadata' => [ + 'payment_hash' => $this->stripe->payment_hash->hash, + 'gateway_type_id' => GatewayType::SOFORT, + ], + ], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)])); + + $data['pi_client_secret'] = $intent->client_secret; + + $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]); + $this->stripe->payment_hash->save(); + + return $data; + } + + public function livewirePaymentView(array $data): string + { + return 'gateways.stripe.sofort.pay_livewire'; + } } diff --git a/app/PaymentDrivers/Stripe/iDeal.php b/app/PaymentDrivers/Stripe/iDeal.php index 01b346b7801d..9116956b3727 100644 --- a/app/PaymentDrivers/Stripe/iDeal.php +++ b/app/PaymentDrivers/Stripe/iDeal.php @@ -18,9 +18,10 @@ use App\Models\GatewayType; use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; +use App\PaymentDrivers\Common\LivewireMethodInterface; use App\PaymentDrivers\StripePaymentDriver; -class iDeal +class iDeal implements LivewireMethodInterface { /** @var StripePaymentDriver */ public StripePaymentDriver $stripe; @@ -37,31 +38,7 @@ class iDeal public function paymentView(array $data) { - $this->stripe->init(); - - $data['gateway'] = $this->stripe; - $data['return_url'] = $this->buildReturnUrl(); - $data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()); - $data['client'] = $this->stripe->client; - $data['customer'] = $this->stripe->findOrCreateCustomer()->id; - $data['country'] = $this->stripe->client->country->iso_3166_2; - - $intent = \Stripe\PaymentIntent::create([ - 'amount' => $data['stripe_amount'], - 'currency' => 'eur', - 'payment_method_types' => ['ideal'], - 'customer' => $this->stripe->findOrCreateCustomer(), - 'description' => $this->stripe->getDescription(false), - 'metadata' => [ - 'payment_hash' => $this->stripe->payment_hash->hash, - 'gateway_type_id' => GatewayType::IDEAL, - ], - ], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)])); - - $data['pi_client_secret'] = $intent->client_secret; - - $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]); - $this->stripe->payment_hash->save(); + $data = $this->paymentData($data); return render('gateways.stripe.ideal.pay', $data); } @@ -142,4 +119,40 @@ class iDeal throw new PaymentFailed('Failed to process the payment.', 500); } -} + + public function paymentData(array $data): array + { + $this->stripe->init(); + + $data['gateway'] = $this->stripe; + $data['return_url'] = $this->buildReturnUrl(); + $data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()); + $data['client'] = $this->stripe->client; + $data['customer'] = $this->stripe->findOrCreateCustomer()->id; + $data['country'] = $this->stripe->client->country->iso_3166_2; + + $intent = \Stripe\PaymentIntent::create([ + 'amount' => $data['stripe_amount'], + 'currency' => 'eur', + 'payment_method_types' => ['ideal'], + 'customer' => $this->stripe->findOrCreateCustomer(), + 'description' => $this->stripe->getDescription(false), + 'metadata' => [ + 'payment_hash' => $this->stripe->payment_hash->hash, + 'gateway_type_id' => GatewayType::IDEAL, + ], + ], array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st", true)])); + + $data['pi_client_secret'] = $intent->client_secret; + + $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]); + $this->stripe->payment_hash->save(); + + return $data; + } + + public function livewirePaymentView(array $data): string + { + return 'gateways.stripe.ideal.pay_livewire'; + } +} \ No newline at end of file