diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7886e41..3a147fc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,6 +3,7 @@ on: workflow_dispatch: push: branches: + - v4 - develop - main pull_request: diff --git a/CHANGELOG.md b/CHANGELOG.md index 74a37f2..ab93961 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,22 @@ # Release Notes for Stripe for Craft Commerce -## 5.0.0 +## 5.0.1 - 2024-04-09 + +- Fixed a bug where floating point rounding precision could cause payments/refunds to fail. ([#296](https://github.com/craftcms/commerce-stripe/pull/296)) +- Fixed a PHP error that could occur when handling a webhook request. ([#294](https://github.com/craftcms/commerce-stripe/issues/294)) + +## 5.0.0 - 2024-03-25 - Stripe now requires Craft Commerce 5.0.0-beta.1 or later. +## 4.1.2.2 - 2024-04-09 + +- Fixed a PHP error that could occur when handling a webhook request. ([#294](https://github.com/craftcms/commerce-stripe/issues/294)) + +## 4.1.2.1 - 2024-03-28 + +- Fixed a bug where floating point precision could cause payments/refunds to fail. ([#296](https://github.com/craftcms/commerce-stripe/pull/296)) + ## 4.1.2 - 2024-03-25 - Fixed a bug where redirects could break when adding a new payment source. ([#259](https://github.com/craftcms/commerce-stripe/issues/259), [#289](https://github.com/craftcms/commerce-stripe/issues/289)) @@ -59,6 +72,11 @@ - Deprecated creating new payment sources via the `commerce/subscriptions/subscribe` action. - Fixed a bug where `craft\commerce\stripe\base\SubscriptionGateway::getSubscriptionPlans()` was returning incorrectly-formatted data. +## 3.1.2 - 2024-04-09 + +- Fixed a PHP error that could occur when handling a webhook request. ([#294](https://github.com/craftcms/commerce-stripe/issues/294)) +- Plans’ data is now updated when the associated plan is updated in Stripe. ([#240](https://github.com/craftcms/commerce-stripe/issues/240)) + ## 3.1.1 - 2023-05-10 - Stripe customers’ default payment methods are now kept in sync with Craft users’ primary payment sources. ([#235](https://github.com/craftcms/commerce-stripe/issues/235)) diff --git a/src/base/SubscriptionGateway.php b/src/base/SubscriptionGateway.php index dafc434..82b5aef 100644 --- a/src/base/SubscriptionGateway.php +++ b/src/base/SubscriptionGateway.php @@ -869,7 +869,9 @@ protected function handleInvoiceCreated(array $data): void ])); } - $canBePaid = empty($stripeInvoice['paid']) && $stripeInvoice['billing'] === 'charge_automatically'; + $stripeInvoiceBilling = isset($stripeInvoice['billing']) && $stripeInvoice['billing'] ? $stripeInvoice['billing'] : null; + + $canBePaid = empty($stripeInvoice['paid']) && $stripeInvoiceBilling === 'charge_automatically'; if (StripePlugin::getInstance()->getSettings()->chargeInvoicesImmediately && $canBePaid) { $invoice = $this->getStripeClient()->invoices->retrieve($stripeInvoice['id']); diff --git a/src/gateways/PaymentIntents.php b/src/gateways/PaymentIntents.php index 9bf8c3b..aa22ed9 100644 --- a/src/gateways/PaymentIntents.php +++ b/src/gateways/PaymentIntents.php @@ -288,7 +288,7 @@ public function refund(Transaction $transaction): RequestResponseInterface try { $request = [ 'charge' => $transaction->reference, - 'amount' => $transaction->paymentAmount * (10 ** $currencyService->getSubunitFor($currency)), + 'amount' => (int) bcmul($transaction->paymentAmount, 10 ** $currencyService->getSubunitFor($currency)), ]; $refund = $this->getStripeClient()->refunds->create($request); @@ -304,7 +304,7 @@ public function refund(Transaction $transaction): RequestResponseInterface if ($stripePaymentIntent->status == 'succeeded') { $refund = $this->getStripeClient()->refunds->create([ 'payment_intent' => $stripePaymentIntent->id, - 'amount' => $transaction->paymentAmount * (10 ** $currencyService->getSubunitFor($currency)), + 'amount' => (int) bcmul($transaction->paymentAmount, 10 ** $currencyService->getSubunitFor($currency)), ]); return $this->createPaymentResponseFromApiResource($refund); @@ -640,7 +640,7 @@ protected function authorizeOrPurchase(Transaction $transaction, PaymentIntentFo } // Normalized amount for Stripe into minor units - $amount = $transaction->paymentAmount * (10 ** $currencyService->getSubunitFor($currency)); + $amount = (int) bcmul($transaction->paymentAmount, 10 ** $currencyService->getSubunitFor($currency)); /** @var PaymentIntentForm $form */ if ($form->paymentFormType == self::PAYMENT_FORM_TYPE_CHECKOUT) {