From e6a7a95743be07467abf3c6828234d5523693fb8 Mon Sep 17 00:00:00 2001 From: MrWeez Date: Fri, 8 May 2026 21:06:51 +0300 Subject: [PATCH] fix: stripe payments can fail due to payment amount rounding mismatch --- .../Stripe/StripeExtension.php | 25 +++---------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/app/Extensions/PaymentGateways/Stripe/StripeExtension.php b/app/Extensions/PaymentGateways/Stripe/StripeExtension.php index 783713ce6..96e592136 100644 --- a/app/Extensions/PaymentGateways/Stripe/StripeExtension.php +++ b/app/Extensions/PaymentGateways/Stripe/StripeExtension.php @@ -225,34 +225,17 @@ protected static function isValidStripePaymentPayload(Payment $payment, object $ { $currency = strtoupper((string) ($paymentIntent->currency ?? '')); $expectedCurrency = strtoupper($payment->currency_code); - $amountInSmallestUnit = (int) ($paymentIntent->amount_received ?? $paymentIntent->amount ?? 0); - $amountInDatabaseUnits = self::convertGatewayAmountToDatabaseUnits($amountInSmallestUnit, $currency); + $amountReceived = (int) ($paymentIntent->amount_received ?? $paymentIntent->amount ?? 0); + + $expectedAmount = self::convertAmount((float) $payment->total_price, $payment->currency_code); $isValid = $currency !== '' && $currency === $expectedCurrency - && $amountInDatabaseUnits === (int) $payment->total_price; + && $amountReceived === $expectedAmount; return $isValid; } - protected static function convertGatewayAmountToDatabaseUnits(int $gatewayAmount, string $currency): int - { - $currency = strtoupper($currency); - - if (in_array($currency, self::ZERO_DECIMAL_CURRENCIES, true)) { - $result = self::currencyHelper()->prepareForDatabase((float) $gatewayAmount); - return $result; - } - - if (in_array($currency, self::THREE_DECIMAL_CURRENCIES, true)) { - $result = self::currencyHelper()->prepareForDatabase($gatewayAmount / 1000); - return $result; - } - - $result = self::currencyHelper()->prepareForDatabase($gatewayAmount / 100); - return $result; - } - /** * @param Request $request */