[英]Python Django, Stripe charge, APIConnectionError
I'm trying to implement the Stripe card payment on my site, I'm fairly new to their API, looked at their examples, I prefer to have separate fields for cardnumber, expirydate, and cvc, so I didn't use the card object. 我正在尝试在我的网站上实现Stripe卡付款,我对他们的API还是很陌生,看了他们的示例,我更喜欢为卡号,有效期和cvc提供单独的字段,所以我没有使用卡宾语。 Followings are my codes: 以下是我的代码:
Javascript: The following is the final button click event at the checkout.html page, where a token is generated and various values in the hidden input fields are set, before submitting to the charge.html page. 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();
}
});
});
In the chargeView.py file, the post method is used to handle the form-post action from the checkout.html page, and create a charge as following; 在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)
I checked, there are values in amount, currency and source; 我检查了金额,货币和来源中的值; however, the charge does not go through with following errors; 但是,充电不会发生以下错误;
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')",))
After couple hours searching, I'm a bit clueless, any help or suggestion is appreciated, thanks ! 经过几个小时的搜索,我有点头绪,不胜感激,谢谢!
Jim 吉姆
我自己找到了答案,这是由于公司过时的OpenSSL认证所致,如果您的openSSL版本低于1.0.xx,则需要对其进行更新,我使用的是MAC OS,因此可以通过Brew进行更新,然后安装新版本的Python并将SSL链接到新的Python,require.txt下的所有依赖项都需要重新安装。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.