Я пытаюсь создать полосовую подписку, а затем выставить счет клиенту за эту подписку.Мои транзакции с полосами отображаются на панели инструментов как «незавершенные», потому что они не оплачиваются.
Front-end создает токен, используя stripe.js, успешно используя предварительно созданную форму кредитной карты в виде полосок, но я не уверен, что мой внутренний код Python для создания подписки и ее оплатыправильно ..
Для подписки плата должна быть немедленной:
"collection_method": "charge_automatics",
...
if request.method == "POST":
try:
token = request.POST['stripeToken']
#Create Stripe Subscription Charge
subscription = stripe.Subscription.create(
customer=user_membership.stripe_customer_id,
items=[
{
"plan": selected_membership.stripe_plan_id,
},
],
)
#Charge Stripe Subscription
charge = stripe.Charge.create(
amount=selected_membership.stripe_price,
currency="usd",
source=token, # obtained with Stripe.js
description=selected_membership.description,
receipt_email=email,
)
return redirect(reverse('memberships:update_transactions',
kwargs={
'subscription_id': subscription.id
}))
except stripe.error.CardError as e:
messages.info(request, "Oops, your card has been declined")
...