Reputation: 129
I have customer email. How to check does customer have valid subscription? I'm using cUrl. Thank you.
Upvotes: 4
Views: 2178
Reputation: 11
In Django or Python you can do this in just this simple way.
First install latest version of API SDK in your project and then write this simple code:
class HomePageView(TemplateView):
stripe.api_key=settings.STRIPE_SECRET_KEY
test=stripe.Customer.search(query="email:'[email protected]'",
expand=["data.subscriptions"],)
print(test)
template_name = 'home.html'
Upvotes: 1
Reputation: 864
Stripe allows expand responses. Fortunately subscriptions
property of customer
object is expandable. Thus, you can reduce the number of API requests and lines of intermediate code.
curl https://api.stripe.com/v1/customers/search \
-u $API_KEY: \
--data-urlencode query="email:'[email protected]'" \
-d "expand[]"="data.subscriptions" \
-G
Upvotes: 6
Reputation: 2204
This would be a two-step process:
First, find the ID of the customer by using their email like this:
curl https://api.stripe.com/v1/customers \
-u sk_xxx: \
-d [email protected] \
-G
Second, use the customer ID to list all their subscriptions like this:
curl https://api.stripe.com/v1/subscriptions \
-u sk_xxx: \
-d customer=cu_xxx \
-G
Upvotes: 1