16

I want to confirm that a customer subscription has been cancelled. The Stripe API documentation only refers to returning "active" subscription. How can I get a listing of all the subscriptions?

Listing subscriptions

You can see a list of the customer's active subscriptions.

GET https://api.stripe.com/v1/customers/{CUSTOMER_ID}/subscriptions

Retrieving a customer's subscription

By default, you can see the 10 most recent active subscriptions stored on a customer directly on the customer object, but you can also retrieve details about a specific active subscription for a customer.

GET https://api.stripe.com/v1/customers/{CUSTOMER_ID}/subscriptions/{SUBSCRIPTION_ID}
Mark Amery
  • 143,130
  • 81
  • 406
  • 459
Barry MSIH
  • 3,525
  • 5
  • 32
  • 53

3 Answers3

8

As of the 7/06/16 API update:

You can now view canceled subscriptions by specifying status=canceled or status=all when listing subscriptions. In addition, you can now retrieve a canceled subscription by its ID.

https://stripe.com/docs/upgrades#api-changelog

So if you're using the ruby API, for example, you should be able to fetch canceled subscriptions like this:

Stripe::Subscription.all(status: 'canceled')

And get a list of all subscriptions, as you ask for above, like this:

Stripe::Subscription.all(status: 'all')
beth9watson
  • 96
  • 2
  • 5
  • 3
    Still getting this 'Invalid status: must be one of trialing, active, past_due, or unpaid' when using 'canceled' or 'all' as status – Jude Calimbas Dec 30 '16 at 09:28
  • 5
    Most of our code uses an older version of the API so our stripe account is still set to that version, so to use a newer version in our newer project I had to use the stripe.setApiVersion(versionString) call before being able to get cancelled subscriptions. Reference: https://stripe.com/docs/api#versioning – Alex Egli Jan 13 '17 at 03:08
4

Sorry for the confusion here! Stripe only returns active subscriptions; the API does not return canceled ones. However, you'll know that a subscription was canceled by watching for that event in your webhook URL. And, if the cancelation request is being made by your site (as opposed to an automatic cancelation due to payment failure), we'd throw an exception if that request failed.

Hope that helps, Larry

PS I work on Support at Stripe.

Larry Ullman
  • 2,161
  • 18
  • 10
  • 22
    This seems like bad design - we should at least be able to retrieve cancelled subscriptions through the API if we query for them directly by ID. – Mark Amery Oct 05 '15 at 14:45
  • 2
    Also in the Python library the returned exception is: `stripe.error.InvalidRequestError`. Having a more explicit exception like `stripe.error.CancelledSubscription` would be more helpful. – François Constant Mar 16 '16 at 00:13
  • 2
    I believe this is no longer true as of 2016. See: https://stripe.com/docs/upgrades#2016-07-06. – hirowatari Jan 08 '20 at 12:17
  • This was confusing for me also. I was able to retreive subscription via dashboard but not via console ... – knagode Jan 19 '22 at 10:47
-1

For PHP:

require_once('stripe/init.php');

\Stripe\Stripe::setApiKey(YOUR_STRIPE_SECRETKEY);

// Retrieve the request's body and parse it as JSON
$input = @file_get_contents("php://input");
$event_json = json_decode($input);

if($event_json->type=='customer.subscription.deleted')
{
    $stripe_customerid = $event_json->data->object->customer; // cus_123456
    $customer = \Stripe\Customer::retrieve($stripe_customerid);
    $usermail = $customer->email;
    // ...
}

With a canceled subscription, the most recent, unpaid invoice is closed, and no further invoices are generated. A customer.subscription.deleted event is triggered, following the charge.failed and invoice.payment_failed events that preceded it. You can see that a subscription was canceled automatically—as opposed to by your request—if the customer.subscription.deleted event’s request property is null.

Avatar
  • 14,622
  • 9
  • 119
  • 198