Merge pull request #2943 from joshuadwire/develop

Fix support for currencies with varying precisions
This commit is contained in:
Hillel Coren 2019-08-30 10:56:29 +03:00 committed by GitHub
commit d9afbe0c4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -209,18 +209,21 @@ class StripePaymentDriver extends BasePaymentDriver
// Need to use Stripe's new Payment Intent API. // Need to use Stripe's new Payment Intent API.
$this->prepareStripeAPI(); $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'])) { if ( ! empty($data['payment_intent'])) {
// Find the existing payment intent. // Find the existing payment intent.
$intent = PaymentIntent::retrieve($data['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. // Make sure that the provided payment intent matches the invoice amount.
throw new Exception('Incorrect PaymentIntent amount.'); throw new Exception('Incorrect PaymentIntent amount.');
} }
$intent->confirm(); $intent->confirm();
} elseif ( ! empty($data['token']) || ! empty($data['payment_method'])) { } elseif ( ! empty($data['token']) || ! empty($data['payment_method'])) {
$params = [ $params = [
'amount' => $data['amount'] * 100, 'amount' => $data['amount'] * pow(10, $currency['precision']),
'currency' => $data['currency'], 'currency' => $data['currency'],
'confirmation_method' => 'manual', 'confirmation_method' => 'manual',
'confirm' => true, 'confirm' => true,