Skip to content

Commit 243e1e9

Browse files
committed
Improved error handling when using wrong cart input
Jquerified form sending
1 parent f533764 commit 243e1e9

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Test cards can be located here: https://stripe.com/docs/testing
1919
When a order is complete, it can be viewed in admin with shipping details and completion status.
2020

2121
##Changelog
22+
### [1.0.5] - 2016-08-24
23+
#### Added
24+
- Improved error handling when using wrong card input
25+
2226
### [1.0.4] - 2016-08-19
2327
#### Removed
2428
- Customer carts have been temporary disabled due to some inconsistent errors.

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Project settings
33
#
44
group = no.iskald
5-
version = 1.0.4
5+
version = 1.0.5
66
projectName = store
77
appName = no.iskald.payup
88
displayName = PayUp! Store

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "payup",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "",
55
"scripts": {
66
"build": "./gradlew build",

src/main/resources/site/services/checkout/checkout.html

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,28 @@
66

77
function stripeResponseHandler(status, response) {
88
if (status != 200) {
9-
document.getElementById('payment-result').innerHTML = response;
9+
console.error(response);
10+
document.getElementById('payment-result').innerHTML = response.error.message;
1011
} else {
1112
var paymentForm = document.getElementById('payment-form');
12-
var formData = new FormData(paymentForm);
13-
formData.append('token', response.id);
14-
var xhr = new XMLHttpRequest();
15-
xhr.open('POST', completeCheckoutUrl, true);
16-
xhr.send(formData);
17-
xhr.onreadystatechange = function (e) {
18-
var DONE = 4;
19-
if (xhr.readyState === DONE) {
20-
if (xhr.status === 200) {
21-
document.querySelector('.payup-payment').style = "display:none;";
22-
document.getElementById('payment-result').innerHTML = e.target.response;
23-
}
24-
if (xhr.status === 500) {
25-
document.getElementById('payment-result').innerHTML = "An error occured. Please try again";
26-
}
13+
var formData = $(paymentForm).serializeArray();
14+
formData.push({name: "token", value: response.id});
15+
$.ajax({
16+
type: "POST",
17+
url: completeCheckoutUrl,
18+
data: $.param(formData),
19+
success: function(data) {
20+
$('.payup-payment').hide();
21+
$('#payment-result').html(data);
22+
},
23+
error: function(data) {
24+
console.error(data);
25+
$('#payment-result').html("An error occured. Please try again");
26+
},
27+
complete: function(data) {
28+
refreshCart();
2729
}
28-
refreshCart();
29-
};
30+
});
3031
}
3132
}
3233

0 commit comments

Comments
 (0)