Skip to content

No way to add cancellation details when cancelling subscription #1816

@martinbean

Description

@martinbean

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:

$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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions