Answer the question
In order to leave comments, you need to log in
How can I check if I already have a subscription or not?
Hello.
I continue to torment Stipe and subscribe. After a user has subscribed to a certain plan, I need to issue some kind of warning when re-entering the page in the style of "You are already subscribed!", and how to delimit pages on the site (only for subscribers / for everyone). Maybe there is some built-in decorator?
# view for subscribing user to monthly plan
@login_required
def checkout(request):
publish_key = settings.STRIPE_PUBLISHABLE_KEY
if request.method == 'POST':
token = request.POST['stripeToken']
try:
customer = stripe.Customer.create(description="Customer for " + request.user.email,
source=token)
customer.subscriptions.create(plan='test') # id=1 is monthly
except stripe.error.CardError:
pass
user = request.user
return render(request, 'checkout.html', {'user': user, 'publish_key': publish_key})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question