From ae33cc1dc591b7bfb61d830d64152de680e79c70 Mon Sep 17 00:00:00 2001 From: Belle Aerni Date: Tue, 17 Jan 2023 15:03:00 -0800 Subject: [PATCH] Verify the transaction status --- src/library/Payment/Adapter/Stripe.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/library/Payment/Adapter/Stripe.php b/src/library/Payment/Adapter/Stripe.php index 69bc092b6..0160a1d76 100644 --- a/src/library/Payment/Adapter/Stripe.php +++ b/src/library/Payment/Adapter/Stripe.php @@ -141,6 +141,10 @@ class Payment_Adapter_Stripe implements \Box\InjectionAwareInterface [] ); + if (!isset($charge)) { + throw new \Exception("Failed to get the charge item from Stripe."); + } + $tx->txn_status = $charge->status; $tx->txn_id = $charge->id; $tx->amount = $charge->amount / 100; @@ -172,7 +176,13 @@ class Payment_Adapter_Stripe implements \Box\InjectionAwareInterface $this->logError($e, $tx); } - $tx->status = 'processed'; + $paymentStatus = match ($charge->status) { + 'succeeded' => 'processed', + 'pending' => 'received', + 'failed' => 'error', + }; + + $tx->status = $paymentStatus; $tx->updated_at = date('Y-m-d H:i:s'); $this->di['db']->store($tx); }