From da7ac32703e3ffa3ec88734fb6786b8ae6a75284 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 24 Jan 2022 14:24:47 +1100 Subject: [PATCH] Decorate stripe payment intents with payment hashes and gateway ids --- app/PaymentDrivers/Stripe/ACSS.php | 4 +++ app/PaymentDrivers/Stripe/ApplePay.php | 4 +++ app/PaymentDrivers/Stripe/BECS.php | 5 +++- app/PaymentDrivers/Stripe/Bancontact.php | 4 +++ app/PaymentDrivers/Stripe/BrowserPay.php | 4 +++ app/PaymentDrivers/Stripe/Charge.php | 4 +++ app/PaymentDrivers/Stripe/CreditCard.php | 7 +++-- app/PaymentDrivers/Stripe/EPS.php | 5 +++- app/PaymentDrivers/Stripe/FPX.php | 5 +++- app/PaymentDrivers/Stripe/GIROPAY.php | 5 +++- app/PaymentDrivers/Stripe/PRZELEWY24.php | 5 +++- app/PaymentDrivers/Stripe/SEPA.php | 4 +++ app/PaymentDrivers/Stripe/SOFORT.php | 5 +++- app/PaymentDrivers/Stripe/iDeal.php | 5 +++- app/PaymentDrivers/StripePaymentDriver.php | 33 +++++++++++++--------- 15 files changed, 76 insertions(+), 23 deletions(-) diff --git a/app/PaymentDrivers/Stripe/ACSS.php b/app/PaymentDrivers/Stripe/ACSS.php index f82b4782de1f..63867db54dd1 100644 --- a/app/PaymentDrivers/Stripe/ACSS.php +++ b/app/PaymentDrivers/Stripe/ACSS.php @@ -143,6 +143,10 @@ class ACSS 'payment_method_types' => ['acss_debit'], 'customer' => $this->stripe->findOrCreateCustomer(), 'description' => $this->stripe->decodeUnicodeString(ctrans('texts.invoices') . ': ' . collect($data['invoices'])->pluck('invoice_number')), + 'metadata' => [ + 'payment_hash' => $this->stripe->payment_hash->hash, + 'gateway_type_id' => GatewayType::ACSS, + ], 'payment_method_options' => [ 'acss_debit' => [ 'mandate_options' => [ diff --git a/app/PaymentDrivers/Stripe/ApplePay.php b/app/PaymentDrivers/Stripe/ApplePay.php index 658900cd5d47..36e925c5f0a1 100644 --- a/app/PaymentDrivers/Stripe/ApplePay.php +++ b/app/PaymentDrivers/Stripe/ApplePay.php @@ -48,6 +48,10 @@ class ApplePay $data['intent'] = \Stripe\PaymentIntent::create([ 'amount' => $data['stripe_amount'], 'currency' => $this->stripe_driver->client->getCurrencyCode(), + 'metadata' => [ + 'payment_hash' => $this->stripe_driver->payment_hash->hash, + 'gateway_type_id' => GatewayType::APPLE_PAY, + ], ], $this->stripe_driver->stripe_connect_auth); $this->stripe_driver->payment_hash->data = array_merge((array) $this->stripe_driver->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]); diff --git a/app/PaymentDrivers/Stripe/BECS.php b/app/PaymentDrivers/Stripe/BECS.php index a225dc3f214d..11e550601083 100644 --- a/app/PaymentDrivers/Stripe/BECS.php +++ b/app/PaymentDrivers/Stripe/BECS.php @@ -56,7 +56,10 @@ class BECS 'setup_future_usage' => 'off_session', 'customer' => $this->stripe->findOrCreateCustomer(), 'description' => $this->stripe->decodeUnicodeString(ctrans('texts.invoices') . ': ' . collect($data['invoices'])->pluck('invoice_number')), - + 'metadata' => [ + 'payment_hash' => $this->stripe->payment_hash->hash, + 'gateway_type_id' => GatewayType::BECS, + ], ], $this->stripe->stripe_connect_auth); $data['pi_client_secret'] = $intent->client_secret; diff --git a/app/PaymentDrivers/Stripe/Bancontact.php b/app/PaymentDrivers/Stripe/Bancontact.php index 303dfa41d2e5..4c23fd8e2dba 100644 --- a/app/PaymentDrivers/Stripe/Bancontact.php +++ b/app/PaymentDrivers/Stripe/Bancontact.php @@ -52,6 +52,10 @@ class Bancontact 'payment_method_types' => ['bancontact'], 'customer' => $this->stripe->findOrCreateCustomer(), 'description' => $this->stripe->decodeUnicodeString(ctrans('texts.invoices') . ': ' . collect($data['invoices'])->pluck('invoice_number')), + 'metadata' => [ + 'payment_hash' => $this->stripe->payment_hash->hash, + 'gateway_type_id' => GatewayType::BANCONTACT, + ], ], $this->stripe->stripe_connect_auth); diff --git a/app/PaymentDrivers/Stripe/BrowserPay.php b/app/PaymentDrivers/Stripe/BrowserPay.php index b5ba9c7ca57f..7aa18353d762 100644 --- a/app/PaymentDrivers/Stripe/BrowserPay.php +++ b/app/PaymentDrivers/Stripe/BrowserPay.php @@ -71,6 +71,10 @@ class BrowserPay implements MethodInterface 'currency' => $this->stripe->client->getCurrencyCode(), 'customer' => $this->stripe->findOrCreateCustomer(), 'description' => $this->stripe->decodeUnicodeString(ctrans('texts.invoices') . ': ' . collect($data['invoices'])->pluck('invoice_number')), + 'metadata' => [ + 'payment_hash' => $this->stripe->payment_hash->hash, + 'gateway_type_id' => GatewayType::APPLE_PAY, + ], ]; $data['gateway'] = $this->stripe; diff --git a/app/PaymentDrivers/Stripe/Charge.php b/app/PaymentDrivers/Stripe/Charge.php index 351399841c4e..222390eeb2fb 100644 --- a/app/PaymentDrivers/Stripe/Charge.php +++ b/app/PaymentDrivers/Stripe/Charge.php @@ -78,6 +78,10 @@ class Charge 'customer' => $cgt->gateway_customer_reference, 'confirm' => true, 'description' => $description, + 'metadata' => [ + 'payment_hash' => $payment_hash->hash, + 'gateway_type_id' => GatewayType::CREDIT_CARD, + ], ]; $response = $this->stripe->createPaymentIntent($data, $this->stripe->stripe_connect_auth); diff --git a/app/PaymentDrivers/Stripe/CreditCard.php b/app/PaymentDrivers/Stripe/CreditCard.php index 1959cc7a05b1..4fb3691010d7 100644 --- a/app/PaymentDrivers/Stripe/CreditCard.php +++ b/app/PaymentDrivers/Stripe/CreditCard.php @@ -63,10 +63,13 @@ class CreditCard 'currency' => $this->stripe->client->getCurrencyCode(), 'customer' => $this->stripe->findOrCreateCustomer(), 'description' => $this->stripe->decodeUnicodeString(ctrans('texts.invoices') . ': ' . collect($data['invoices'])->pluck('invoice_number')), + 'metadata' => [ + 'payment_hash' => $this->stripe->payment_hash->hash, + 'gateway_type_id' => GatewayType::CREDIT_CARD, + ], + 'setup_future_usage' => 'off_session', ]; - $payment_intent_data['setup_future_usage'] = 'off_session'; - $data['intent'] = $this->stripe->createPaymentIntent($payment_intent_data); $data['gateway'] = $this->stripe; diff --git a/app/PaymentDrivers/Stripe/EPS.php b/app/PaymentDrivers/Stripe/EPS.php index 35abb4c69a5c..4d7b3db3a8a4 100644 --- a/app/PaymentDrivers/Stripe/EPS.php +++ b/app/PaymentDrivers/Stripe/EPS.php @@ -52,7 +52,10 @@ class EPS 'payment_method_types' => ['eps'], 'customer' => $this->stripe->findOrCreateCustomer(), 'description' => $this->stripe->decodeUnicodeString(ctrans('texts.invoices') . ': ' . collect($data['invoices'])->pluck('invoice_number')), - + 'metadata' => [ + 'payment_hash' => $this->stripe->payment_hash->hash, + 'gateway_type_id' => GatewayType::EPS, + ], ], $this->stripe->stripe_connect_auth); $data['pi_client_secret'] = $intent->client_secret; diff --git a/app/PaymentDrivers/Stripe/FPX.php b/app/PaymentDrivers/Stripe/FPX.php index 0bf85e48512e..8a73ce6c98d4 100644 --- a/app/PaymentDrivers/Stripe/FPX.php +++ b/app/PaymentDrivers/Stripe/FPX.php @@ -53,7 +53,10 @@ class FPX 'payment_method_types' => ['fpx'], 'customer' => $this->stripe->findOrCreateCustomer(), 'description' => $this->stripe->decodeUnicodeString(ctrans('texts.invoices') . ': ' . collect($data['invoices'])->pluck('invoice_number')), - + 'metadata' => [ + 'payment_hash' => $this->stripe->payment_hash->hash, + 'gateway_type_id' => GatewayType::FPX, + ], ], $this->stripe->stripe_connect_auth); $data['pi_client_secret'] = $intent->client_secret; diff --git a/app/PaymentDrivers/Stripe/GIROPAY.php b/app/PaymentDrivers/Stripe/GIROPAY.php index dbbdc5f79962..e9dbb4d0cca6 100644 --- a/app/PaymentDrivers/Stripe/GIROPAY.php +++ b/app/PaymentDrivers/Stripe/GIROPAY.php @@ -52,7 +52,10 @@ class GIROPAY 'payment_method_types' => ['giropay'], 'customer' => $this->stripe->findOrCreateCustomer(), 'description' => $this->stripe->decodeUnicodeString(ctrans('texts.invoices') . ': ' . collect($data['invoices'])->pluck('invoice_number')), - + 'metadata' => [ + 'payment_hash' => $this->stripe->payment_hash->hash, + 'gateway_type_id' => GatewayType::GIROPAY, + ], ], $this->stripe->stripe_connect_auth); $data['pi_client_secret'] = $intent->client_secret; diff --git a/app/PaymentDrivers/Stripe/PRZELEWY24.php b/app/PaymentDrivers/Stripe/PRZELEWY24.php index 64988894fc84..d93acbb9c22b 100644 --- a/app/PaymentDrivers/Stripe/PRZELEWY24.php +++ b/app/PaymentDrivers/Stripe/PRZELEWY24.php @@ -52,7 +52,10 @@ class PRZELEWY24 'payment_method_types' => ['p24'], 'customer' => $this->stripe->findOrCreateCustomer(), 'description' => $this->stripe->decodeUnicodeString(ctrans('texts.invoices') . ': ' . collect($data['invoices'])->pluck('invoice_number')), - + 'metadata' => [ + 'payment_hash' => $this->stripe->payment_hash->hash, + 'gateway_type_id' => GatewayType::PRZELEWY24, + ], ], $this->stripe->stripe_connect_auth); $data['pi_client_secret'] = $intent->client_secret; diff --git a/app/PaymentDrivers/Stripe/SEPA.php b/app/PaymentDrivers/Stripe/SEPA.php index cc4129d6a920..ac2d0ccd81f6 100644 --- a/app/PaymentDrivers/Stripe/SEPA.php +++ b/app/PaymentDrivers/Stripe/SEPA.php @@ -54,6 +54,10 @@ class SEPA 'setup_future_usage' => 'off_session', 'customer' => $this->stripe->findOrCreateCustomer(), 'description' => $this->stripe->decodeUnicodeString(ctrans('texts.invoices') . ': ' . collect($data['invoices'])->pluck('invoice_number')), + 'metadata' => [ + 'payment_hash' => $this->stripe->payment_hash->hash, + 'gateway_type_id' => GatewayType::SEPA, + ], ], $this->stripe->stripe_connect_auth); $data['pi_client_secret'] = $intent->client_secret; diff --git a/app/PaymentDrivers/Stripe/SOFORT.php b/app/PaymentDrivers/Stripe/SOFORT.php index 383061ceabce..a35993073671 100644 --- a/app/PaymentDrivers/Stripe/SOFORT.php +++ b/app/PaymentDrivers/Stripe/SOFORT.php @@ -52,7 +52,10 @@ class SOFORT 'payment_method_types' => ['sofort'], 'customer' => $this->stripe->findOrCreateCustomer(), 'description' => $this->stripe->decodeUnicodeString(ctrans('texts.invoices') . ': ' . collect($data['invoices'])->pluck('invoice_number')), - + 'metadata' => [ + 'payment_hash' => $this->stripe->payment_hash->hash, + 'gateway_type_id' => GatewayType::SOFORT, + ], ], $this->stripe->stripe_connect_auth); $data['pi_client_secret'] = $intent->client_secret; diff --git a/app/PaymentDrivers/Stripe/iDeal.php b/app/PaymentDrivers/Stripe/iDeal.php index 1f16122ae1b8..8358c949fefc 100644 --- a/app/PaymentDrivers/Stripe/iDeal.php +++ b/app/PaymentDrivers/Stripe/iDeal.php @@ -52,7 +52,10 @@ class iDeal 'payment_method_types' => ['ideal'], 'customer' => $this->stripe->findOrCreateCustomer(), 'description' => $this->stripe->decodeUnicodeString(ctrans('texts.invoices') . ': ' . collect($data['invoices'])->pluck('invoice_number')), - + 'metadata' => [ + 'payment_hash' => $this->stripe->payment_hash->hash, + 'gateway_type_id' => GatewayType::IDEAL, + ], ], $this->stripe->stripe_connect_auth); $data['pi_client_secret'] = $intent->client_secret; diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 39f896be0583..6c2a1b1c7763 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -25,25 +25,26 @@ use App\Models\PaymentHash; use App\Models\PaymentType; use App\Models\SystemLog; use App\PaymentDrivers\Stripe\ACH; +use App\PaymentDrivers\Stripe\ACSS; use App\PaymentDrivers\Stripe\Alipay; use App\PaymentDrivers\Stripe\ApplePay; +use App\PaymentDrivers\Stripe\BECS; +use App\PaymentDrivers\Stripe\Bancontact; +use App\PaymentDrivers\Stripe\BrowserPay; use App\PaymentDrivers\Stripe\Charge; use App\PaymentDrivers\Stripe\Connect\Verify; use App\PaymentDrivers\Stripe\CreditCard; -use App\PaymentDrivers\Stripe\ImportCustomers; -use App\PaymentDrivers\Stripe\SOFORT; -use App\PaymentDrivers\Stripe\SEPA; -use App\PaymentDrivers\Stripe\PRZELEWY24; -use App\PaymentDrivers\Stripe\GIROPAY; -use App\PaymentDrivers\Stripe\iDeal; use App\PaymentDrivers\Stripe\EPS; -use App\PaymentDrivers\Stripe\Bancontact; -use App\PaymentDrivers\Stripe\BECS; -use App\PaymentDrivers\Stripe\ACSS; -use App\PaymentDrivers\Stripe\BrowserPay; use App\PaymentDrivers\Stripe\FPX; +use App\PaymentDrivers\Stripe\GIROPAY; +use App\PaymentDrivers\Stripe\ImportCustomers; +use App\PaymentDrivers\Stripe\Jobs\PaymentIntentWebhook; +use App\PaymentDrivers\Stripe\PRZELEWY24; +use App\PaymentDrivers\Stripe\SEPA; +use App\PaymentDrivers\Stripe\SOFORT; use App\PaymentDrivers\Stripe\UpdatePaymentMethods; use App\PaymentDrivers\Stripe\Utilities; +use App\PaymentDrivers\Stripe\iDeal; use App\Utils\Traits\MakesHash; use Exception; use Illuminate\Http\RedirectResponse; @@ -472,10 +473,7 @@ class StripePaymentDriver extends BaseDriver $response = null; try { - // $response = $this->stripe - // ->refunds - // ->create(['charge' => $payment->transaction_reference, 'amount' => $this->convertToStripeAmount($amount, $this->client->currency()->precision, $this->client->currency())], $meta); - + $response = \Stripe\Refund::create([ 'charge' => $payment->transaction_reference, 'amount' => $this->convertToStripeAmount($amount, $this->client->currency()->precision, $this->client->currency()) @@ -532,6 +530,13 @@ class StripePaymentDriver extends BaseDriver // Allow app to catch up with webhook request. sleep(2); + //payment_intent.succeeded - this will confirm or cancel the payment + if($request->type === 'payment_intent.succeeded'){ + PaymentIntentWebhook::dispatch($request->all(), $request->company_key, $this->company_gateway->id)->delay(10); + // PaymentIntentWebhook::dispatch($request->all(), $request->company_key, $this->company_gateway->id); + return response()->json([], 200); + } + if ($request->type === 'charge.succeeded' || $request->type === 'payment_intent.succeeded') { foreach ($request->data as $transaction) {