【发布时间】:2019-01-12 17:26:43
【问题描述】:
我正在尝试在我的网站上实现 Stripe 卡支付,我对他们的 API 相当陌生,查看了他们的示例,我更喜欢为卡号、到期日和 cvc 设置单独的字段,所以我没有使用卡片对象。以下是我的代码:
Javascript:以下是 checkout.html 页面上的最终按钮点击事件,其中生成令牌并设置隐藏输入字段中的各种值,然后提交到 charge.html 页面。
$("#cardPayBtn").click(function() {
var options = {
};
stripe.createToken(cardNumber, options).then(function(result) {
if (result.error) {
var errorElement = document.getElementById('cardErrors');
errorElement.textContent = result.error.message;
//alert(errorElement);
}
else {
$("#chargeAmount").val(parseInt($("#totalFee").val())*100);
$("#chargeCurrency").val("gbp");
$("#tokenSource").val(JSON.stringify(result.token));
$("#cardPaymentForm").submit();
}
});
});
在chargeView.py文件中,post方法用于处理checkout.html页面的form-post动作,并创建如下费用;
def post(self, request):
token = request.POST["tokenSource"]
chargeAmount = request.POST['chargeAmount']
chargeCurrency = request.POST['chargeCurrency']
charge = stripe.Charge.create(
amount=chargeAmount,
currency=chargeCurrency,
description='Example charge',
source=json.loads(token),
)
return render(request, self.template)
我查了,有金额、货币和来源的值;但是,收费并没有通过以下错误;
APIConnectionError at /photos/charge/
Unexpected error communicating with Stripe. If this problem persists,
let us know at support@stripe.com.
(Network error: SSLError: ("bad handshake: SysCallError(-1, 'Unexpected EOF')",))
经过几个小时的搜索,我有点无能为力,感谢任何帮助或建议,谢谢!
吉姆
【问题讨论】:
标签: python django stripe-payments