diff --git a/CHANGELOG.md b/CHANGELOG.md index 76aa2a8..800ab77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Release Notes for Stripe +## Unreleased + +- `craft\stripe\services\Subscriptions::cancelSubscriptionByStripeId()` now has an optional `$params` argument, which can be used to pass additional parameters to the Stripe API. +- `craft\stripe\services\Subscriptions::resumeSubscriptionByStripeId()` now has an optional `$params` argument, which can be used to pass additional parameters to the Stripe API. + ## 1.7.2 - 2026-07-02 - Fixed a [high-severity](https://github.com/craftcms/cms/security/policy#severity--remediation) SQL injection vulnerability. (HCKRT-1509) diff --git a/src/services/Subscriptions.php b/src/services/Subscriptions.php index 9b5c33b..c4de3f0 100644 --- a/src/services/Subscriptions.php +++ b/src/services/Subscriptions.php @@ -345,21 +345,22 @@ public function deleteSubscriptionByStripeId(string $stripeId): void * * @param string $stripeId * @param bool $immediately + * @param array|null $params Additional parameters to send to the Stripe API when cancelling the subscription * @return bool * @throws \Throwable * @throws \yii\db\StaleObjectException */ - public function cancelSubscriptionByStripeId(string $stripeId, bool $immediately = false): bool + public function cancelSubscriptionByStripeId(string $stripeId, bool $immediately = false, ?array $params = null): bool { $stripe = Plugin::getInstance()->getApi()->getClient(); try { if ($immediately) { - $subscription = $stripe->subscriptions->cancel($stripeId); + $subscription = $stripe->subscriptions->cancel($stripeId, $params); } else { - $subscription = $stripe->subscriptions->update($stripeId, [ + $subscription = $stripe->subscriptions->update($stripeId, array_merge($params ?? [], [ 'cancel_at_period_end' => true, - ]); + ])); } Plugin::getInstance()->getSubscriptions()->createOrUpdateSubscription($subscription); } catch (\Exception $exception) { @@ -374,19 +375,20 @@ public function cancelSubscriptionByStripeId(string $stripeId, bool $immediately * Resumes subscription by Stripe id. * * @param string $stripeId + * @param array|null $params Additional parameters to send to the Stripe API when resuming the subscription * @return bool * @throws \Throwable * @throws \yii\db\StaleObjectException * @since 1.5.0 */ - public function resumeSubscriptionByStripeId(string $stripeId): bool + public function resumeSubscriptionByStripeId(string $stripeId, ?array $params = null): bool { $stripe = Plugin::getInstance()->getApi()->getClient(); try { - $subscription = $stripe->subscriptions->update($stripeId, [ + $subscription = $stripe->subscriptions->update($stripeId, array_merge($params ?? [], [ 'cancel_at_period_end' => false, - ]); + ])); Plugin::getInstance()->getSubscriptions()->createOrUpdateSubscription($subscription); } catch (\Exception $exception) { Craft::error($exception->getMessage(), 'stripe');