2
我正在构建一个使用Stripe让用户互相支付的Django应用程序。卖家需要将他们的账户连接到Stripe,以便将他们的访问权限和刷新令牌保存到数据库中。买家还可以在付款期间为服务捐款。在Django应用程序中的条带支付,可发布的关键错误
如果我尝试卖家收费,我得到一个错误,我真的不明白:
“无效的令牌ID:tok_355k8o2rGvbwWLbLbNKPAcOk用于创建此令牌的发布的关键是从不同的帐户。
也有一些是错误的卖方的访问令牌,但我无法弄清楚它是什么。我仔细检查过我的秘密和发布的钥匙,他们都OK。
这里是我使用du的一段代码环支付。
连接卖家与条纹:
def callback(request):
code = request.GET.get('code')
profile = UserProfile.objects.get(user=request.user)
r = requests.post('https://connect.stripe.com/oauth/token', params={
'client_secret': settings.STRIPE_SECRET_KEY,
'code': code,
'grant_type': 'authorization_code'
}).json()
try:
profile.access_token = r['access_token']
profile.refresh_token = r['refresh_token']
profile.save()
messages.success(request, "Your account was successfully connected to Stripe.")
except KeyError:
messages.error(request, "Unable to connect your account to Stripe.")
return redirect('home')
制作费:
def charge(request, item_id):
stripe.api_key = settings.STRIPE_SECRET_KEY
try:
item = Item.objects.get(pk=item_id)
profile = UserProfile.objects.get(user=item.owner)
access_token = profile.access_token
except Item.DoesNotExist:
raise Http404
if request.method == 'POST':
form = PaymentForm(request.POST)
if form.is_valid():
try:
charge = stripe.Charge.create(
# Multiply by 100 to get value in cents
amount=form.cleaned_data['amount'] * 100,
application_fee=form.cleaned_data['donation'] * 100,
currency='gbp',
card=form.cleaned_data['stripeToken'],
description="{} by {}".format(item.title, item.author),
api_key=access_token, # <-- This is the line where the error occurs
)
messages.success(request, "The payment was successful.")
except stripe.CardError, e:
messages.error(request, "The payment could not be completed.")
你有一个想法如何纠正呢?非常感谢。
它的工作原理类似于魅力。谢谢! – lukas
“你需要在表单上使用哪一个”是什么意思? –
您收集卡片详细信息的表单使用可发布密钥将卡片详细信息转换为卡片令牌:https://stripe.com/docs/tutorials/forms – brian