-
Notifications
You must be signed in to change notification settings - Fork 732
Description
Cashier Stripe Version
16.1.0
Laravel Version
12.43.1
PHP Version
8.5.1
Database Driver & Version
No response
Description
Stripe subscriptions support a cancellation_details array: https://docs.stripe.com/api/subscriptions/object#subscription_object-cancellation_details
Capturing cancellation reason is a huge quality of life improvement for subscription-based businesses, but when cancellation subscriptions with Cashier, there does not seem to be a way to provide this information. The $subscription->cancel() method accepts no parameters, and the cancellation details would need to be provided here:
cashier-stripe/src/Subscription.php
Lines 1052 to 1054 in 3a8f7c7
| $stripeSubscription = $this->updateStripeSubscription([ | |
| 'cancel_at_period_end' => true, | |
| ]); |
It would be nice if this method could be opened up to provide additional information such as cancellation details that may be captured by the application itself. Something like:
- public function cancel()
+ public function cancel(array $params = [])
{
- $stripeSubscription = $this->updateStripeSubscription([
- 'cancel_at_period_end' => true,
- ]);
+ $stripeSubscription = $this->updateStripeSubscription(array_merge($params, [
+ 'cancel_at_period_end' => true,
+ ]));
$this->stripe_status = $stripeSubscription->status;
// If the user was on trial, we will set the grace period to end when the trial
// would have ended. Otherwise, we'll retrieve the end of the billing period
// period and make that the end of the grace period for this current user.
if ($this->onTrial()) {
$this->ends_at = $this->trial_ends_at;
} else {
$this->ends_at = $this->currentPeriodEnd();
}
$this->save();
return $this;
}Or, alternatively to avoid let users set any parameter when cancelling a subscription:
- public function cancel()
+ public function cancel(string|null $reason = null, string|null $comments = null)
{
$stripeSubscription = $this->updateStripeSubscription([
'cancel_at_period_end' => true,
+ 'cancellation_details' => [
+ 'comment' => $comments,
+ 'feedback' => $reason,
+ ],
]);
$this->stripe_status = $stripeSubscription->status;
// If the user was on trial, we will set the grace period to end when the trial
// would have ended. Otherwise, we'll retrieve the end of the billing period
// period and make that the end of the grace period for this current user.
if ($this->onTrial()) {
$this->ends_at = $this->trial_ends_at;
} else {
$this->ends_at = $this->currentPeriodEnd();
}
$this->save();
return $this;
}Happy to contribute the pull request if this feature is wanted.
Steps To Reproduce
As above.