-
Notifications
You must be signed in to change notification settings - Fork 5
/
checkout.js
executable file
·78 lines (68 loc) · 2.31 KB
/
checkout.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
jQuery('form.checkout').on('submit', function (e){
var paymentMethod = jQuery('input[name=payment_method]:checked').val();
if("pointcheckout_card" === paymentMethod ) {
e.preventDefault();
e.stopImmediatePropagation();
return pointcheckoutCardFormHandler(jQuery(this));
}
});
function showError(form, data) {
// Remove notices from all sources
jQuery( '.woocommerce-error, .woocommerce-message' ).remove();
// Add new errors returned by this event
if ( data.messages ) {
form.prepend( '<div class="woocommerce-NoticeGroup-updateOrderReview">' + data.messages + '</div>' );
} else {
form.prepend( data );
}
// Lose focus for all fields
form.find( '.input-text, select, input:checkbox' ).blur();
// Scroll to top
jQuery( 'html, body' ).animate( {
scrollTop: ( jQuery( form ).offset().top - 100 )
}, 1000 );
}
function pointcheckoutCardFormHandler(form) {
if (form.is(".processing")) return !1;
initPointCheckoutCardPayment(form);
}
function initPointCheckoutCardPayment(form) {
var data = jQuery(form).serialize();
var ajaxUrl = wc_checkout_params.checkout_url;
jQuery.ajax({
'url': ajaxUrl,
'type': 'POST',
'dataType': 'json',
'data': data,
'async': false
}).complete(function (response) {
data = '';
if(response.form) {
data = response;
}
else{
var code = response.responseText;
var newstring = code.replace(/<script[^>]*>(.*)<\/script>/, "");
if (newstring.indexOf("<!--WC_START-->") >= 0) {
newstring = newstring.split("<!--WC_START-->")[1];
}
if (newstring.indexOf("<!--WC_END-->") >= 0) {
newstring = newstring.split("<!--WC_END-->")[0];
}
try {
data = jQuery.parseJSON( newstring );
}
catch(e) {}
}
if(data.result == 'failure') {
showError(form, data);
return !1;
}
if (data.form) {
jQuery('#frm_pointcheckout_card_payment').remove();
jQuery('body').append(data.form);
window.success = true;
jQuery( "#frm_pointcheckout_card_payment" ).submit();
}
});
}