Python 在django中使用条带API获取计划量
我有以下基于类的视图,用于处理django应用程序和stripe API之间的get/post:Python 在django中使用条带API获取计划量,python,django,stripe-payments,Python,Django,Stripe Payments,我有以下基于类的视图,用于处理django应用程序和stripe API之间的get/post: class StripeApi(View): @staticmethod def get(request): return render(request, 'index.html', { 'stripe_pub_key': settings.STRIPE_PUBLISHAB
class StripeApi(View):
@staticmethod
def get(request):
return render(request, 'index.html',
{
'stripe_pub_key': settings.STRIPE_PUBLISHABLE_KEY
})
@staticmethod
def post(request):
charge = stripe.Customer.create(
source=request.POST['stripeToken'],
email=request.POST['stripeEmail'],
plan=request.POST['plan'],
description='Charge for {}'.format(request.POST.get("stripeEmail", "")),
)
paym = stripe.Charge.retrieve(
source=request.POST['stripeToken'],
amount=request.POST.get("amount", "")
)
return render(request, 'stripe.html',
{
'charge_id': charge.id,
'created': charge.created,
'email': request.POST['stripeEmail'],
'plan': request.POST['plan'],
'amount': request.POST.get("amount", "")
})
以及以下发送必要参数的HTML:
<form action="stripe/" method="POST">
<input type="hidden" value="test12months" id="plan" name="plan">
<input type="hidden" value="stripeEmail" id="stripeEmail" name="stripeEmail">
<input type="hidden" value="amount" id="amount" name="amount">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_secret"
data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
data-name="12 Months"
data-description="12 Months Subscription (19.99$ per year)"
data-amount= "1999"
data-locale="auto">
</script>
</form>
问题是,当我尝试添加金额时,出现以下错误:
Exception Value:retrieve()在添加金额时至少接受2个参数(给定1个)
有人能帮我找出如何检索特定创建计划的金额吗?要检索计划的金额,您需要拨打电话:
您的呼叫无效:要检索费用,您需要传递其ID,在本例中,您没有ID,因为您没有直接创建费用,而是创建了一个,并且条带自动为您创建了费用
plan = stripe.Plan.retrieve(request.POST['plan'])
amount = plan.amount