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. 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.
$("#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;
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 [email protected].
(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