PluginProbe
Welcart e-Commerce / 2.11.30
Welcart e-Commerce v2.11.30
2.12.4 2.12.3 2.11.35 2.12.2 2.12.1 2.11.34 2.11.33 2.11.32 2.11.31 2.11.30 1.3.16 1.3.17 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 All 292 releases
usc-e-shop / js / cart_escott.js

cart_escott.js in Welcart e-Commerce 2.11.30, at js/cart_escott.js

301 lines 10.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready( function($) {
2 $('body input[type="submit"]').each( function(i,e) {
3 if( "confirm" == $(this).attr("name") ) {
4 $(this).parents("form").attr("id","delivery-form");
5 }
6 });
7 var token_dialog = '<div id="escott-token-dialog">'
8 +'<div id="escott-token-response"></div>'
9 +'<div id="escott-token-response-loading"></div>'
10 +'<div id="escott-token-form"></div>'
11 +'<div class="send settlement_form_send">'
12 +'<input type="button" id="escott_token_cancel" class="back_to_delivery_button" value="'+uscesL10n.escott_token_btn_cancel+'" />&nbsp;&nbsp;'
13 +'<input type="button" id="escott_token_next" class="to_confirm_button" value="'+uscesL10n.escott_token_btn_next+'" />'
14 +'</div>'
15 +'</div>';
16 $("#delivery-form").after(token_dialog);
17 $("#escott-token-dialog .send").css("text-align","center");
18 $("#escott-token-dialog").css("display","none");
19 if ( 'on' == escott_params.sec3d_activate ) {
20 var agree_dialog = '<div id="escott-agree-dialog">'
21 +'<textarea class="escott_agreement_message" readonly>'+escott_params.message.agreement+'</textarea>'
22 +'<div class="send agree_form_send">'
23 +'<input type="button" id="escott_agree_cancel" class="back_to_delivery_button" value="'+escott_params.message.disagree+'" />&nbsp;&nbsp;'
24 +'<input type="button" id="escott_agree_next" class="to_confirm_button" value="'+escott_params.message.agree+'" />'
25 +'</div>'
26 +'</div><input type="hidden" id="escott_agree" value="">';
27 $("#delivery-form").after(agree_dialog);
28 $("#escott-agree-dialog .send").css("text-align","center");
29 $("#escott-agree-dialog").css("display","none");
30 }
31 });
32 jQuery( function($) {
33
34 const isNumberString = n => typeof n === 'string' && n !== '' && !isNaN(n);
35
36 cartEScott = {
37 changePayType: function(cnum) {
38 var first_c = cnum.substr(0,1);
39 var second_c = cnum.substr(1,1);
40 if( '4' == first_c || '5' == first_c || ( '3' == first_c && '5' == second_c ) ) {
41 $("#paytype_default").prop("disabled",true).css("display","none");
42 $("#paytype4535").prop("disabled",false).css("display","inline");
43 $("#paytype37").prop("disabled",true).css("display","none");
44 $("#paytype36").prop("disabled",true).css("display","none");
45 } else if( '3' == first_c && '6' == second_c ) {
46 $("#paytype_default").prop("disabled",true).css("display","none");
47 $("#paytype4535").prop("disabled",true).css("display","none");
48 $("#paytype37").prop("disabled",true).css("display","none");
49 $("#paytype36").prop("disabled",false).css("display","inline");
50 } else if( '3' == first_c && '7' == second_c ) {
51 $("#paytype_default").prop("disabled",true).css("display","none");
52 $("#paytype4535").prop("disabled",true).css("display","none");
53 $("#paytype37").prop("disabled",false).css("display","inline");
54 $("#paytype36").prop("disabled",true).css("display","none");
55 } else {
56 $("#paytype_default").prop("disabled",false).css("display","inline");
57 $("#paytype4535").prop("disabled",true).css("display","none");
58 $("#paytype37").prop("disabled",true).css("display","none");
59 $("#paytype36").prop("disabled",true).css("display","none");
60 }
61 },
62
63 openTokenDialog: function() {
64 $("#escott-token-response").html("");
65 $("#escott-token-response-loading").html('<img src="'+uscesL10n.loaderurl+'" />');
66
67 $.ajax({
68 url: uscesL10n.front_ajaxurl,
69 type: "POST",
70 cache: false,
71 dataType: "json",
72 data: {
73 usces_ajax_action: "escott_token_dialog",
74 wc_nonce: $("#wc_nonce").val()
75 }
76 }).done( function(retVal,dataType) {
77 if( retVal.status == "OK" ) {
78 $("#escott-token-form").html("");
79 $("#escott-token-form").append(retVal.result);
80 if( retVal.member == "quick" ) {
81 if( $("#cardno").val() != undefined ) {
82 cartEScott.changePayType($("#cardno").val());
83 }
84 } else {
85 $("#cardno").bind( "change", function() {
86 cartEScott.changePayType($(this).val());
87 });
88 }
89 }
90 $("#escott-token-dialog select").css("width","auto");
91 $("#escott-token-response-loading").html("");
92 }).fail( function(retVal) {
93 $("#escott-token-response-loading").html("");
94 });
95 return false;
96 },
97
98 cardChange: function() {
99 $("#escott-token-response").html("");
100 $("#escott-token-response-loading").html('<img src="'+uscesL10n.loaderurl+'" />');
101
102 $.ajax({
103 url: uscesL10n.front_ajaxurl,
104 type: "POST",
105 cache: false,
106 dataType: 'json',
107 data: {
108 usces_ajax_action: "escott_token_dialog",
109 card_change: "1",
110 wc_nonce: $("#wc_nonce").val()
111 }
112 }).done( function(retVal,dataType) {
113 if( retVal.status == "OK" ) {
114 $("#escott-token-form").html("");
115 $("#escott-token-form").append(retVal.result);
116 //if( retVal.member == "quick" ) {
117 // cartEScott.changePayType($("#cardno").val());
118 //} else {
119 $("#cardno").bind( "change", function() {
120 cartEScott.changePayType($(this).val());
121 });
122 //}
123 }
124 $("#escott-token-dialog select").css("width","auto");
125 $("#escott-token-response-loading").html("");
126 }).fail( function(retVal) {
127 $("#escott-token-response-loading").html("");
128 });
129 return false;
130 },
131
132 getToken: function() {
133 $("#escott-token-response").html("");
134
135 var check = true;
136 if( !isNumberString($("#cardno").val()) ) {
137 check = false;
138 }
139 if( undefined == $("#expyy").get(0) || undefined == $("#expmm").get(0) ) {
140 check = false;
141 } else if( !isNumberString($("#expyy option:selected").val()) || !isNumberString($("#expmm option:selected").val()) ) {
142 check = false;
143 }
144 if( $("#seccd").val() != undefined ) {
145 if( !isNumberString($("#seccd").val()) ) {
146 check = false;
147 }
148 }
149 if ( !isValidInput($("#cardname").val()) ) {
150 check = false;
151 }
152 if( !check ) {
153 alert(uscesL10n.escott_token_error_message);
154 return false;
155 }
156
157 var cardno = $("#cardno").val();
158 var expyy = $("#expyy option:selected").val();
159 if( "" != expyy ) {
160 expyy = expyy.substr(-2,2);
161 }
162 var expmm = $("#expmm option:selected").val();
163 var seccd = ( $("#seccd").val() != undefined ) ? $("#seccd").val() : "";
164 var paytype = ( $("#paytype").val() != undefined ) ? $("#paytype").val() : cartEScott.getPayType();
165 $("input[name='paytype']").val(paytype);
166 if( $("#quick_member").attr("type") == "hidden" ) {
167 $("input[name='quick_member']").val($("#quick_member").val());
168 } else if( $("#quick_member").prop("checked") ) {
169 $("input[name='quick_member']").val($("#quick_member").val());
170 }
171 if( $("#card_change").val() != undefined ) {
172 $("input[name='card_change']").val($("#card_change").val());
173 }
174
175 SpsvApi.spsvCreateToken(cardno,expyy,expmm,seccd,"","","","","");
176 },
177
178 getPayType: function() {
179 var paytype = "01";
180 if( !$("#paytype_default").prop("disabled") ) {
181 paytype = $("#paytype_default option:selected").val();
182 } else if( !$("#paytype4535").prop("disabled") ) {
183 paytype = $("#paytype4535 option:selected").val();
184 } else if( !$("#paytype37").prop("disabled") ) {
185 paytype = $("#paytype37 option:selected").val();
186 } else if( !$("#paytype36").prop("disabled") ) {
187 paytype = $("#paytype36 option:selected").val();
188 }
189 return paytype;
190 }
191 };
192
193 $("#escott-token-dialog").dialog({
194 bgiframe: true,
195 autoOpen: false,
196 height: "auto",
197 width: "auto",
198 resizable: true,
199 modal: true,
200 create: function() {
201 $("#escott-token-dialog").parent(".ui-dialog").attr("id","escott-dialog");
202 },
203 open: function() {
204 cartEScott.openTokenDialog();
205 },
206 close: function() {
207 $("#escott-token-form").html("");
208 }
209 });
210
211 $(document).on( "click", ".to_confirm_button", function(e) {
212 if( $("#payment_name_"+uscesL10n.escott_token_payment_id).prop("checked") ) {
213 if ( 'on' == escott_params.sec3d_activate && '' == $("#escott_agree").val() ) {
214 $("#escott-agree-dialog").dialog("open");
215 return false;
216 } else {
217 $("#escott-token-dialog").dialog("option","title",uscesL10n.escott_token_dialog_title);
218 $("#escott-token-dialog").dialog("open");
219 return false;
220 }
221 }
222 });
223
224 $(document).on( "click", "#escott_card_change", function(e) {
225 e.preventDefault();
226 cartEScott.cardChange();
227 });
228
229 $(document).on( "click", "#escott_token_next", function(e) {
230 if( !$("#escott_card_change").length ) {
231 cartEScott.getToken();
232 } else {
233 var paytype = ( $("#paytype").val() != undefined ) ? $("#paytype").val() : cartEScott.getPayType();
234 $("input[name='paytype']").val(paytype);
235 $("input[name='quick_member']").val("add");
236 $("input[name='card_change']").val("");
237 $("#delivery-form").submit();
238 }
239 });
240
241 $(document).on( "click", "#escott_token_cancel", function(e) {
242 if( $("#escott_agree").length ) {
243 $("#escott_agree").val("");
244 }
245 $("#escott-token-dialog").dialog("close");
246 });
247
248 $("#escott-agree-dialog").dialog({
249 bgiframe: true,
250 autoOpen: false,
251 height: "400",
252 width: "200",
253 resizable: true,
254 modal: true,
255 create: function() {
256 $("#escott-agree-dialog").parent(".ui-dialog").attr("id","escott-dialog");
257 },
258 open: function() {
259 },
260 close: function() {
261 }
262 });
263
264 $(document).on( "click", "#escott_agree_next", function(e) {
265 $("#escott_agree").val("agree");
266 $("#escott-agree-dialog").dialog("close");
267 $("#escott-token-dialog").dialog("option","title",uscesL10n.escott_token_dialog_title);
268 $("#escott-token-dialog").dialog("open");
269 return false;
270 });
271
272 $(document).on( "click", "#escott_agree_cancel", function(e) {
273 $("#escott_agree").val("");
274 $("#escott-agree-dialog").dialog("close");
275 });
276 });
277
278 function setToken(token,card) {
279 if( token ) {
280 document.getElementById("token").value = token;
281 document.getElementById("billingname").value = document.getElementById("cardname").value;
282 document.getElementById("delivery-form").submit();
283 } else {
284 document.getElementById("escott-token-response").value = "";
285 }
286 }
287
288 function isValidInput(str) {
289 let len = str.length;
290 if( 0 === len ) {
291 return false;
292 }
293 for( let i = 0; i < len; i++ ) {
294 let char = str.charAt(i);
295 if( !( char >= 'A' && char <= 'Z' ) && !( char >= 'a' && char <= 'z' ) && char !== ' ' ) {
296 return false;
297 }
298 }
299 return true;
300 }
301