From 20c12533f810e666d199025cb332c6482ef0c6c2 Mon Sep 17 00:00:00 2001 From: Joshua Dwire Date: Thu, 29 Aug 2019 17:11:59 -0400 Subject: [PATCH] Fix support for currencies with varying precisions --- app/Ninja/PaymentDrivers/StripePaymentDriver.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Ninja/PaymentDrivers/StripePaymentDriver.php b/app/Ninja/PaymentDrivers/StripePaymentDriver.php index b7907cd3669f..a2a9eb02dd49 100644 --- a/app/Ninja/PaymentDrivers/StripePaymentDriver.php +++ b/app/Ninja/PaymentDrivers/StripePaymentDriver.php @@ -222,18 +222,21 @@ class StripePaymentDriver extends BasePaymentDriver // Need to use Stripe's new Payment Intent API. $this->prepareStripeAPI(); + // Get information about the currency we're using. + $currency = Cache::get('currencies')->where('code', strtoupper($data['currency']))->first(); + if ( ! empty($data['payment_intent'])) { // Find the existing payment intent. $intent = PaymentIntent::retrieve($data['payment_intent']); - if ( ! $intent->amount == $data['amount'] * 100) { + if ( ! $intent->amount == $data['amount'] * pow(10, $currency['precision'])) { // Make sure that the provided payment intent matches the invoice amount. throw new Exception('Incorrect PaymentIntent amount.'); } $intent->confirm(); } elseif ( ! empty($data['token']) || ! empty($data['payment_method'])) { $params = [ - 'amount' => $data['amount'] * 100, + 'amount' => $data['amount'] * pow(10, $currency['precision']), 'currency' => $data['currency'], 'confirmation_method' => 'manual', 'confirm' => true,