我有以下类基础视图,它处理我的django应用程序和条带API之间的get / post:
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>
问题是我在尝试添加amount
时出现以下错误:
Exception Value: retrieve() takes at least 2 arguments (1 given)
时 amount
。
有人可以帮我解释如何检索特定创建计划的金额?
答案 0 :(得分:1)
要检索计划金额,您需要发出plan retrieval来电:
plan = stripe.Plan.retrieve(request.POST['plan'])
amount = plan.amount
您的charge retrieval来电无效:要收取费用,您需要传递其身份证明,在这种情况下,您不会因为您没有直接创建费用 - 而是,您创建了subscription,Stripe会自动为您收取费用。