From b21a27373d60e666074ad4ada3fc316956a6e562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 17 Sep 2021 21:00:59 +0200 Subject: [PATCH] Generate PaymentIntent for payment requests --- app/PaymentDrivers/Stripe/SOFORT.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/PaymentDrivers/Stripe/SOFORT.php b/app/PaymentDrivers/Stripe/SOFORT.php index f9d6bfd2e0a6..2363268c802c 100644 --- a/app/PaymentDrivers/Stripe/SOFORT.php +++ b/app/PaymentDrivers/Stripe/SOFORT.php @@ -24,7 +24,7 @@ use App\PaymentDrivers\StripePaymentDriver; class SOFORT { /** @var StripePaymentDriver */ - public $stripe; + public StripePaymentDriver $stripe; public function __construct(StripePaymentDriver $stripe) { @@ -45,6 +45,14 @@ class SOFORT $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'] + ]); + + $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(); @@ -66,23 +74,23 @@ class SOFORT $this->stripe->payment_hash->save(); if ($request->redirect_status == 'succeeded') { - return $this->processSuccessfulPayment($request->source); + return $this->processSuccessfulPayment($request->payment_intent); } return $this->processUnsuccessfulPayment(); } - public function processSuccessfulPayment(string $source) + public function processSuccessfulPayment(string $payment_intent) { /* @todo: https://github.com/invoiceninja/invoiceninja/pull/3789/files#r436175798 */ $this->stripe->init(); $data = [ - 'payment_method' => $this->stripe->payment_hash->data->source, + 'payment_method' => $payment_intent, 'payment_type' => PaymentType::SOFORT, 'amount' => $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()), - 'transaction_reference' => $source, + 'transaction_reference' => $payment_intent, 'gateway_type_id' => GatewayType::SOFORT, ];