Stack Exchange
Stack Exchange

Reputation: 175

How to check if customer is subscribed using curl and Stripe

In Stripe, to get the list of customers who are subscribed using the curl API offered by the online payment system Stripe, one only needs to call:

curl https://api.stripe.com/v1/customers -u sk_test_key:

This returns a list of customers in JSON format. You can run the code yourself as it uses the test data from Stripe.

What if I only want to check if a given customer is subscribed? for example customer ID cus_5uR2Kp7ukpBSBc

Upvotes: 7

Views: 10760

Answers (1)

Peter Raboud
Peter Raboud

Reputation: 411

First, it's probably not a great idea to put your test keys on SE. It can't be escalated to full control over your account, but anybody could come by and delete all your test customers for giggles (for example). You should probably roll your test keys at this point.

To your actual question, to find any active subscriptions on that customer, you can look at the subscriptions property on the customer response (https://stripe.com/docs/api#customer_object). If you're only interested in the subscriptions, and not the rest of the customer, you can use the list subscriptions endpoint (https://stripe.com/docs/api#list_subscriptions).

Either of these will list all subscriptions on the account, so if you're looking for a subscription to a particular plan, you'll need to iterate through and search for that plan id.

Upvotes: 9

Related Questions