1/*! 2jQuery edit billing details v1.0 3| (c) CBS Foundation and other contributors 4| CBS/license 5*/ 6// When done loading: (also alias '$' for 'jQuery' inside this block) 7 8let $ = jQuery.noConflict(); 9 10jQuery(document).ready(function ($) { 11 12 $("button[id^='edit-button-'], button[id^='cancel-button-']").click(function () { 13 var method_number = $(this).attr('id').split('-').pop(); 14 // Toggle input fields 15 $("[id='cc-number-" + method_number + "']").toggle(); 16 $("[id='edit-cc-number-" + method_number + "']").toggle(); 17 $("[id='cc-exp-" + method_number + "']").toggle(); 18 $("[id='edit-cc-exp-" + method_number + "']").toggle(); 19 $("[id='cvv-label-" + method_number + "']").toggle(); 20 $("[id='edit-cvv-" + method_number + "']").toggle(); 21 $("[id='cc-address-" + method_number + "']").toggle(); 22 $("[id='edit-cc-address-" + method_number + "']").toggle(); 23 $("[id='cc-zip-" + method_number + "']").toggle(); 24 $("[id='edit-cc-zip-" + method_number + "']").toggle(); 25 // Toggle buttons 26 $("button[id='edit-button-" + method_number + "']").toggle(); 27 $("button[id='cancel-button-" + method_number + "']").toggle(); 28 $("input[id='save-button-" + method_number + "']").toggle(); 29 $("button[id='unlock-delete-button-" + method_number + "']").toggle(); 30 }); 31 32 $("button[id^='unlock-delete-button-'], button[id^='cancel-delete-button-']").click(function () { 33 34 var method_number = $(this).attr('id').split('-').pop(); 35 // Toggle confirmation message 36 $("[id='delete-confirm-msg-" + method_number + "']").toggle(); 37 38 // Toggle buttons 39 $("button[id='unlock-delete-button-" + method_number + "']").toggle(); 40 $("button[id='edit-button-" + method_number + "']").toggle(); 41 $("input[id='delete-button-" + method_number + "']").toggle(); 42 $("button[id='cancel-delete-button-" + method_number + "']").toggle(); 43 44 }); 45 46 $("#Add-new-card").click(function () { 47 $("#method-card").show(); 48 $("#hide-method-bar-card").hide(); 49 $(".woocommerce-error").hide(); 50 $(".woocommerce-message").hide(); 51 }); 52 53 $("#cancel_button_card").click(function () { 54 $("#method-card").hide(); 55 $("#hide-method-bar-card").show(); 56 return false; 57 }); 58 59 $("#Add-new-bank").click(function () { 60 $("#method-bank").show(); 61 $("#hide-method-bar-bank").hide(); 62 $(".woocommerce-error").hide(); 63 $(".woocommerce-message").hide(); 64 }); 65 66 $("#cancel_button_bank").click(function () { 67 $("#method-bank").hide(); 68 $("#hide-method-bar-bank").show(); 69 return false; 70 }); 71 72 // checkout: Ebizcharge payment method 73 // on ebizcharge load 74 loadExpiry(); 75 loadBankDetails(); 76 // on saved radio click 77 $(document.body).on('ready click change', '#ebizcharge-use-stored-payment-info-yes', function () { 78 loadExpiry(); 79 }); 80 // on update radio click 81 $(document.body).on('ready click change', '#ebizcharge-use-update-payment-info-yes', function () { 82 loadExpiry(); 83 loadAvs(); 84 }); 85 // on saved select box click/change 86 $(document.body).on('ready click change', 'select[id=ebizcharge-stored-card]', function () { 87 loadExpiry(); 88 }); 89 // on update select box click/change 90 $(document.body).on('ready click change', 'select[id=ebizcharge_update_cc]', function () { 91 loadExpiry(); 92 loadAvs(); 93 }); 94 // on saved bank select box click/change 95 $(document.body).on('ready click change', 'select[id=ebizcharge-stored-bank]', function () { 96 loadBankDetails(); 97 }); 98 99 function loadExpiry() { 100 var methodId = $('select[id=ebizcharge-stored-card]').val(); 101 $('#exp_month_saved').val($('#exp_month_saved_' + methodId).val()); 102 $('#exp_year_saved').val($('#exp_year_saved_' + methodId).val()); 103 $('#card_number_saved').val($('#card_number_saved_' + methodId).val()); 104 $('#card_type_saved').val($('#card_type_saved_' + methodId).val()); 105 106 var methodIdUpdate = $('select[id=ebizcharge_update_cc]').val(); 107 $('#exp_month_update').val($('#exp_month_update_' + methodIdUpdate).val()); 108 $('#exp_year_update').val($('#exp_year_update_' + methodIdUpdate).val()); 109 $('#card_number_update').val($('#card_number_update_' + methodIdUpdate).val()); 110 $('#card_type_update').val($('#card_type_update_' + methodIdUpdate).val()); 111 } 112 113 function loadAvs() { 114 var methodId = $('select[id=ebizcharge_update_cc]').val(); 115 $('#avs_street').val($('#avs_street_' + methodId).val()); 116 $('#avs_zip').val($('#avs_zip_' + methodId).val()); 117 } 118
119 function loadBankDetails() { 120 var methodIdBank = $('select[id=ebizcharge-stored-bank]').val(); 121 $('#ac_holder_saved').val($('#ac_holder_saved_' + methodIdBank).val()); 122 $('#ac_type_saved').val($('#ac_type_saved_' + methodIdBank).val()); 123 $('#ac_number_saved').val($('#ac_number_saved_' + methodIdBank).val()); 124 $('#routing_saved').val($('#routing_saved_' + methodIdBank).val()); 125 } 126 127 function saved_card_fields_validated() { 128 let exp_month_saved = true; 129 let exp_year_saved = true; 130 let cvvS = true; 131 let cvvSLength = $("#cvvS").val().length; 132 133 let expiryMonthS = $('#exp_month_saved').val(); 134 let expiryYearS = $('#exp_year_saved').val(); 135 let expiryMonthYearS = expiryMonthS + "/" + expiryYearS; 136 137 let currentDateS = new Date(); 138 let currentMonthS = currentDateS.getMonth() + 1; 139 if (currentMonthS < 10) { 140 currentMonthS = "0" + currentMonthS; 141 } 142 let currentYearS = currentDateS.getFullYear(); 143 let currentMonthYearS = currentMonthS + "/" + currentYearS; 144 145 let validDate = validateMonthYear(expiryMonthYearS, currentMonthYearS); // -1 - 0 - 1 146 147 if (expiryMonthS == '') { 148 monthYearResults(".expmonthyear-saved-error", "#exp_month_saved", "<p>Expiration Date is required</p>"); 149 exp_month_saved = false; 150 } else { 151 $("#exp_month_saved").css({"border": "", "border-radius": "", "padding": ""}).removeClass('sixpixel'); 152 } 153 154 if (expiryYearS == '') { 155 monthYearResults(".expmonthyear-saved-error", "#exp_year_saved", "<p>Expiration Date is required</p>"); 156 exp_year_saved = false; 157 } else { 158 $("#exp_year_saved").css({"border": "", "border-radius": "", "padding": ""}).removeClass('sixpixel'); 159 } 160 161 if (expiryMonthS != '' && expiryYearS != '' && validDate < 0) { 162 monthYearResults(".expmonthyear-saved-error", "#exp_month_saved", "<p>Expiration Date is invalid</p>"); 163 exp_month_saved = false; 164 } 165 166 if (expiryMonthS != '' && expiryYearS != '' && validDate >= 0) { 167 $('.expmonthyear-saved-error').html(""); 168 $('.expmonthyear-saved-error').hide(); 169 } 170 171 var selectedCardSVal = $("#ebizcharge-stored-card option:selected").val(); 172 var selectedCardTypeS = $("#card_type_saved_" + selectedCardSVal).val(); 173 174 if ($('#cvvS').val() == '') { 175 cvvResults(".cvv-saved-error", "#cvvS", "<p>CVV is required</p>"); 176 cvvS = false; 177 178 } else if (selectedCardTypeS != 'A' && cvvSLength != 3) { 179 cvvResults(".cvv-saved-error", "#cvvS", "<p>CVV is required, 3 digits</p>"); 180 cvvS = false; 181 182 } else if (selectedCardTypeS == 'A' && cvvSLength != 4) { 183 cvvResults(".cvv-saved-error", "#cvvS", "<p>CVV is required, 4 digits</p>"); 184 cvvS = false; 185 186 } else { 187 $("#cvvS").css({"border": "", "box-shadow": ""}); 188 $('.cvv-saved-error').html(""); 189 $('.cvv-saved-error').hide(); 190 } 191 192 return exp_month_saved && exp_year_saved && cvvS; 193 } 194 195 function update_card_fields_validated() { 196 let avs_street = true; 197 let avs_zip = true; 198 let exp_month_update = true; 199 let exp_year_update = true; 200 let cvvU = true; 201 let cvvULength = $("#cvvU").val().length; 202 203 let expiryMonthU = $('#exp_month_update').val(); 204 let expiryYearU = $('#exp_year_update').val(); 205 let expiryMonthYearU = expiryMonthU + "/" + expiryYearU; 206 207 let currentDateU = new Date(); 208 let currentMonthU = currentDateU.getMonth() + 1; 209 if (currentMonthU < 10) { 210 currentMonthU = "0" + currentMonthU; 211 } 212 let currentYearU = currentDateU.getFullYear(); 213 let currentMonthYearU = currentMonthU + "/" + currentYearU; 214 215 let validDate = validateMonthYear(expiryMonthYearU, currentMonthYearU); // -1 - 0 - 1 216 217 if (expiryMonthU == '') { 218 monthYearResults(".expmonthyear-update-error", "#exp_month_update", "<p>Expiration Date is required</p>"); 219 exp_month_update = false; 220 } else {
221 $("#exp_month_update").css({"border": "", "border-radius": "", "padding": ""}).removeClass('sixpixel'); 222 } 223 224 if (expiryYearU == '') { 225 monthYearResults(".expmonthyear-update-error", "#exp_year_update", "<p>Expiration Date is required</p>"); 226 exp_year_update = false; 227 } else { 228 $("#exp_year_update").css({"border": "", "border-radius": "", "padding": ""}).removeClass('sixpixel'); 229 } 230 231 if (expiryMonthU != '' && expiryYearU != '' && validDate < 0) { 232 monthYearResults(".expmonthyear-update-error", "#exp_month_update", "<p>Expiration Date is invalid</p>"); 233 exp_month_update = false; 234 } 235 236 if (expiryMonthU != '' && expiryYearU != '' && validDate >= 0) { 237 $('.expmonthyear-update-error').html(""); 238 $('.expmonthyear-update-error').hide(); 239 } 240 241 if ($('#avs_street').val() == '') { 242 $("#avs_street").focus(); 243 //$(".avs_street").css("color", "red"); 244 $("#avs_street").css({"border": "1px solid red", "box-shadow": "inset 2px 0 0 red"}); 245 $('.billing-update-error').html("<p>Billing Street is required</p>"); 246 $('.billing-update-error').show(); 247 avs_street = false; 248 } else { 249 //$(".avs_street").css("color", ""); 250 $("#avs_street").css({"border": "", "box-shadow": ""}); 251 $('.billing-update-error').html(""); 252 $('.billing-update-error').hide(); 253 } 254 255 if ($('#avs_zip').val() == '') { 256 $("#avs_zip").focus(); 257 //$(".avs_zip").css("color", "red"); 258 $("#avs_zip").css({"border": "1px solid red", "box-shadow": "inset 2px 0 0 red"}); 259 $('.avs-update-error').html("<p>Zip/Postal Code is required</p>"); 260 $('.avs-update-error').show(); 261 avs_zip = false; 262 } else { 263 //$(".avs_zip").css("color", ""); 264 $("#avs_zip").css({"border": "", "box-shadow": ""}); 265 $('.avs-update-error').html(""); 266 $('.avs-update-error').hide(); 267 } 268 269 var selectedCardUVal = $("#ebizcharge_update_cc option:selected").val(); 270 var selectedCardTypeU = $("#card_type_update_" + selectedCardUVal).val(); 271 272 if ($('#cvvU').val() == '') { 273 cvvResults(".cvv-update-error", "#cvvU", "<p>CVV is required</p>"); 274 cvvU = false; 275 276 } else if (selectedCardTypeU != 'A' && cvvULength != 3) { 277 cvvResults(".cvv-update-error", "#cvvU", "<p>CVV is required, 3 digits</p>"); 278 cvvU = false; 279 280 } else if (selectedCardTypeU == 'A' && cvvULength != 4) { 281 cvvResults(".cvv-update-error", "#cvvU", "<p>CVV is required, 4 digits</p>"); 282 cvvU = false; 283 284 } else { 285 $("#cvvU").css({"border": "", "box-shadow": ""}); 286 $('.cvv-update-error').html(""); 287 $('.cvv-update-error').hide(); 288 } 289 290 return exp_month_update && exp_year_update && avs_street && avs_zip && cvvU; 291 } 292 293 function new_card_fields_validated() { 294 let ccholder = true; 295 let ccnum = true; 296 let cardtype = true; 297 let expmonth = true; 298 let expyear = true; 299 let cvv = true; 300 let numLength = $("#ccnum").val().length; 301 let cvvLength = $("#cvv").val().length; 302 303 let expiryMonth = $('#expmonth').val(); 304 let expiryYear = $('#expyear').val(); 305 let expiryMonthYear = expiryMonth + "/" + expiryYear; 306 307 let currentDate = new Date(); 308 let currentMonth = currentDate.getMonth() + 1; 309 if (currentMonth < 10) { 310 currentMonth = "0" + currentMonth; 311 } 312 let currentYear = currentDate.getFullYear(); 313 let currentMonthYear = currentMonth + "/" + currentYear; 314 315 let validDate = validateMonthYear(expiryMonthYear, currentMonthYear); // -1 - 0 - 1 316 317 if ($('#ccholder').val() == '') { 318 $("#ccholder").focus(); 319 //$(".ccholder").css("color", "red");
320 $("#ccholder").css({"border": "1px solid red", "box-shadow": "inset 2px 0 0 red"}); 321 $('.ccholder-new-error').html("<p>Name on Card is required</p>"); 322 $('.ccholder-new-error').show(); 323 ccholder = false; 324 } else { 325 //$(".ccholder").css("color", ""); 326 $("#ccholder").css({"border": "", "box-shadow": ""}); 327 $('.ccholder-new-error').html(""); 328 $('.ccholder-new-error').hide(); 329 } 330 331 if ($('#ccnum').val() == '') { 332 ccnumResults("<p>Credit Card Number is required</p>"); 333 ccnum = false; 334 335 } else if (numLength < 15 || numLength > 16) { 336 ccnumResults("<p>Credit Card Number is required, 15-16 digits</p>"); 337 ccnum = false; 338 339 } else { 340 $("#ccnum").css({"border": "", "box-shadow": ""}); 341 $('.ccnum-new-error').html(""); 342 $('.ccnum-new-error').hide(); 343 } 344 345 if ($('#cardtype').val() == '') { 346 $("#cardtype").focus(); 347 //$("#cardtype").css("color", "red"); 348 $("#cardtype").css({"border": "1px solid red", "border-radius": "2px"}); 349 $('.cardtype-new-error').html("<p>Credit Card Type is required</p>"); 350 $('.cardtype-new-error').show(); 351 cardtype = false; 352 353 } else { 354 //$(".cardtype").css("color", ""); 355 $("#cardtype").css({"border": "", "border-radius": "", "padding": ""}); 356 $('.cardtype-new-error').html(""); 357 $('.cardtype-new-error').hide(); 358 } 359 360 if (expiryMonth == '') { 361 monthYearResults(".expmonthyear-new-error", "#expmonth", "<p>Expiration Month is required</p>"); 362 expmonth = false; 363 } else { 364 $("#expmonth").css({"border": "", "border-radius": "", "padding": ""}).removeClass('sixpixel'); 365 } 366 367 if (expiryYear == '') { 368 monthYearResults(".expmonthyear-new-error", "#expyear", "<p>Expiration Year is required</p>"); 369 expyear = false; 370 } else { 371 $("#expyear").css({"border": "", "border-radius": "", "padding": ""}).removeClass('sixpixel'); 372 } 373 374 if (expiryMonth != '' && expiryYear != '' && validDate < 0) { 375 monthYearResults(".expmonthyear-new-error", "#expmonth", "<p>Expiration Date is invalid</p>"); 376 expmonth = false; 377 } 378 379 if (expmonth != '' && expyear != '' && validDate >= 0) { 380 $('.expmonthyear-new-error').html(""); 381 $('.expmonthyear-new-error').hide(); 382 } 383 384 if ($('#cvv').val() == '') { 385 cvvResults(".cvv-new-error", "#cvv", "<p>CVV is required</p>"); 386 cvv = false; 387 388 } else if ($('#cardtype').val() != 'American Express' && cvvLength != 3) { 389 cvvResults(".cvv-new-error", "#cvv", "<p>CVV is required, 3 digits</p>"); 390 cvv = false; 391 392 } else if ($('#cardtype').val() == 'American Express' && cvvLength != 4) { 393 cvvResults(".cvv-new-error", "#cvv", "<p>CVV is required, 4 digits</p>"); 394 cvv = false; 395 396 } else { 397 $("#cvv").css({"border": "", "box-shadow": ""}); 398 $('.cvv-new-error').html(""); 399 $('.cvv-new-error').hide(); 400 } 401 402 return ccholder && ccnum && cardtype && expmonth && expyear && cvv; 403 } 404 405 function new_bank_fields_validated() { 406 let acholder = true; 407 let acnum = true; 408 let routingnum = true; 409 var anumLength = $("#acnum").val().length; 410 var rnumLength = $("#routingnum").val().length; 411 412 if ($('#acholder').val() == '') { 413 $("#acholder").focus(); 414 //$(".acholder").css("color", "red"); 415 $("#acholder").css({"border": "1px solid red", "box-shadow": "inset 2px 0 0 red"}); 416 $('.acholder-error').html("<p>Account Holder is required</p>"); 417 $('.acholder-error').show(); 418 acholder = false; 419 } else { 420 //$(".acholder").css("color", ""); 421 $("#acholder").css({"border": "", "box-shadow": ""}); 422 $('.acholder-error').html(""); 423 $('.acholder-error').hide(); 424 } 425 426 if ($('#acnum').val() == '') { 427 $("#acnum").focus(); 428 //$(".acnum").css("color", "red");
429 $("#acnum").css({"border": "1px solid red", "box-shadow": "inset 2px 0 0 red"}); 430 $('.acnum-error').html("<p>Account Number is required</p>"); 431 $('.acnum-error').show(); 432 acnum = false; 433 } else if (anumLength < 9 || anumLength > 14) { 434 $("#acnum").focus(); 435 //$(".acnum").css("color", "red"); 436 $("#acnum").css({"border": "1px solid red", "box-shadow": "inset 2px 0 0 red"}); 437 $('.acnum-error').html("<p>Account Number is required, 9-14 digits</p>"); 438 $('.acnum-error').show(); 439 acnum = false; 440 } else { 441 $(".acnum").css("color", ""); 442 $("#acnum").css({"border": "", "box-shadow": ""}); 443 $('.acnum-error').html(""); 444 $('.acnum-error').hide(); 445 } 446 447 if ($('#routingnum').val() == '') { 448 $("#routingnum").focus(); 449 //$(".routingnum").css("color", "red"); 450 $("#routingnum").css({"border": "1px solid red", "box-shadow": "inset 2px 0 0 red"}); 451 $('.routingnum-error').html("<p>Routing Number is required</p>"); 452 $('.routingnum-error').show(); 453 routingnum = false; 454 } else if (rnumLength != 9) { 455 $("#routingnum").focus(); 456 //$(".routingnum").css("color", "red"); 457 $("#routingnum").css({"border": "1px solid red", "box-shadow": "inset 2px 0 0 red"}); 458 $('.routingnum-error').html("<p>Routing Number is required, 9 digits</p>"); 459 $('.routingnum-error').show(); 460 routingnum = false; 461 } else { 462 $(".routingnum").css("color", ""); 463 $("#routingnum").css({"border": "", "box-shadow": ""}); 464 $('.routingnum-error').html(""); 465 $('.routingnum-error').hide(); 466 } 467 468 return acholder && acnum && routingnum; 469 } 470 471 function cvvResults(clas, id, msg) { 472 $(id).focus(); 473 $(id).css({"border": "1px solid red", "box-shadow": "inset 2px 0 0 red"}); 474 $(clas).html(msg); 475 $(clas).show(); 476 } 477 478 function ccnumResults(msg) { 479 $("#ccnum").focus(); 480 $("#ccnum").css({"border": "1px solid red", "box-shadow": "inset 2px 0 0 red"}); 481 $('.ccnum-new-error').html(msg); 482 $('.ccnum-new-error').show(); 483 } 484 485 function monthYearResults(clas, id, msg) { 486 $(id).focus(); 487 $(id).css({"border": "1px solid red", "border-radius": "2px"}); 488 $(clas).html(msg); 489 $(clas).show(); 490 } 491 492 function validateMonthYear(expiryDate, currentDate) { 493 var m1 = expiryDate.split("/"); 494 var m2 = currentDate.split("/"); 495 var res = -1; 496 497 if (parseInt(m1[1]) > parseInt(m2[1])) { 498 res = 1; 499 } else if (parseInt(m1[1]) == parseInt(m2[1])) { 500 if (parseInt(m1[0]) > parseInt(m2[0])) { 501 res = 1; 502 } else if (parseInt(m1[0]) == parseInt(m2[0])) { 503 res = 0; 504 } 505 } 506 return res; 507 } 508 509 // 3DS functions 510 if ($("#Is3DS2Enabled").val() == true) { 511 var SecurityToken = { 512 Password: "", 513 UserId: "", 514 SecurityId: $('#SecurityId').val() 515 }; 516 517 eBiz3DSecure = new EBiz3DSecure(JSON.stringify(SecurityToken)); 518 } 519 520 function EBiz3DSecureValidation() { 521 return new Promise((theSuccess, theFailure) => { 522 try { 523 if (eBiz3DSecure.JWT == null || eBiz3DSecure.JWT == "") { 524 console.log('Merchant is not enabled for 3D Secure, continue with payment without 3D Secure'); 525 theSuccess('NO_JWT') 526 } 527 const inputData = class InputData { 528 static CardType = $('#cardtype').val() 529 static CardNumber = $('#ccnum').val() 530 //static NameOnCard = $('#ccholder').val() 531 static ExpireMonth = $('#expmonth').val() 532 static ExpireYear = $('#expyear').val() 533 //static SecurityCode = $('#cvv').val() 534 static Amount = $('#orderAmount').val()
535 static OrderNumber = $('#orderNumber').val() 536 static CurrencyCode = $('#storeCurrency').val() 537 static BillingAddress = $('#billing_address_1').val() + ' ' + $('#billing_address_2').val() 538 //static BillingAddress2 = $('#billing_address_2').val() 539 static BillingCity = $('#billing_city').val() 540 static BillingCountryCode = "840" 541 static BillingFirstName = $('#billing_first_name').val() 542 static BillingLastName = $('#billing_last_name').val() 543 static BillingPhone = $('#billing_phone').val() 544 static BillingPostalCode = $('#billing_postcode').val() 545 static BillingState = "CA"; 546 static Zip = $('#billing_postcode').val() 547 static ShippingCountryCode = "840" 548 static Email = $('#billing_email').val() 549 static phone = $('#billing_phone').val() 550 static TransactionType = "C" 551 static TransactionMode = "S" 552 } 553 554 eBiz3DSecure.EBiz3DSecureCheck(inputData) 555 .then(successData => { 556 theSuccess(successData) 557 558 }).catch(failureData => { 559 if (failureData.bypass3DS2OnError ?? false) { 560 theSuccess('bypass3DS2OnError') 561 } else { 562 // show error message and don't continue to payment process 563 theFailure(eBiz3DSecure.GetErrorMessage(failureData)) 564 } 565 }); 566 } catch (error) { 567 console.log('error', error); 568 theFailure(error); 569 } 570 }); 571 } 572 573 function EBiz3DSecureValidationCall() { 574 EBiz3DSecureValidation() 575 .then(response => { 576 $("#place_order").prop("disabled", false) 577 hideLoader() 578 if (response === 'NO_JWT' || response === 'bypass3DS2OnError') { 579 $("#WCPlaceOrder").val(true) 580 $('#place_order').submit() 581 return true 582 } else { 583 //alert("Payment is authorized by 3D Secure."); 584 $("#CAVV").val(response.cavv) 585 $("#XID").val(response.xid) 586 $("#ECI").val(response.eciFlag) 587 $("#Pares").val(response.paResStatus) 588 $("#DSTransactionId").val(response.transactionId) 589 $("#WCPlaceOrder").val(true) 590 $('#place_order').submit() 591 return true 592 } 593 }).catch(error => { 594 $("#WCPlaceOrder").val(false); 595 $("#place_order").prop("disabled", false); 596 hideLoader(); 597 alert(error ?? "Payment is not Authorized by 3D Secure."); 598 return false; 599 }); 600 } 601 602 function ebiz3DSecureValidationCallback() { 603 return EBiz3DSecureValidation() 604 .then(response => { 605 return response; // Promise resolved 606 }).catch(error => { 607 throw error; // Throw the error for handling elsewhere if needed 608 }); 609 } 610 611 $(document.body).on('click', '#place_order', function (event) { 612 // Check payment methods is EbizCharge selected 613 let selectedPaymentRadio = $("input[type='radio'][name='payment_method']:checked"); 614 615 if (selectedPaymentRadio.length > 0 && selectedPaymentRadio.val() == 'ebizcharge') { 616 event.preventDefault(); 617 618 let is3DS2Enabled = $("#Is3DS2Enabled").val() == true; 619 620 if ($("#ebizcharge-cc-payment").is(':checked')) { 621 var selectedRadio = $("input[type='radio'][name='ebizcharge-use-stored-payment-info']:checked"); 622 if (selectedRadio.length > 0) { 623 let selectedRadioVal = selectedRadio.val(); 624 625 if (selectedRadioVal == 'yes') { 626 // return saved_card_fields_validated(); 627 if (saved_card_fields_validated()) { 628 $('#place_order').submit(); 629 } 630 631 } 632 633 if (selectedRadioVal == 'update') { 634 // return update_card_fields_validated(); 635 if (update_card_fields_validated()) { 636 $('#place_order').submit(); 637 } 638 } 639 640 if (selectedRadioVal == 'no') { 641 642 if (new_card_fields_validated()) { 643 if (is3DS2Enabled) { 644 $('#place_order').attr("disabled", "disabled"); 645 showLoader(); 646 return EBiz3DSecureValidationCall(); 647 } else { 648 $('#place_order').submit(); 649 } 650 } else { 651 return false 652 } 653 } 654 655 } else { 656 if (new_card_fields_validated()) { 657 if (is3DS2Enabled) { 658 event.preventDefault(); 659 $('#place_order').attr("disabled", "disabled"); 660 showLoader(); 661 return EBiz3DSecureValidationCall(); 662 } else { 663 $('#place_order').submit(); 664 } 665 } else { 666 return false; 667 } 668 } 669 } 670
671 if ($("#ebizcharge-bank-payment").is(':checked')) { 672 let selectedBankRadio = $("input[type='radio'][name='ebizcharge-use-stored-bank-info']:checked") 673 if (selectedBankRadio.length > 0) { 674 let selectedBankRadioVal = selectedBankRadio.val() 675 676 if (selectedBankRadioVal == 'yes') { 677 $('#place_order').submit(); 678 // return true 679 } 680 681 if (selectedBankRadioVal == 'no') { 682 if (new_bank_fields_validated()) { 683 $('#place_order').submit(); 684 } 685 } 686 } else { 687 // return new_bank_fields_validated(); 688 if (new_bank_fields_validated()) { 689 $('#place_order').submit(); 690 } 691 } 692 } 693 } 694 }); 695 696 const calculateSurcharge = () => { 697 const isSurchargeEnabled = $("#surcharge_enabled").val(); 698 let cc = ''; 699 let selectedCardId = ''; 700 701 if (isSurchargeEnabled && $("#ebizcharge-cc-payment").is(':checked')) { 702 let selectedRadio = $("input[type='radio'][name='ebizcharge-use-stored-payment-info']:checked"); 703 704 if (selectedRadio.length > 0) { 705 let selectedRadioVal = selectedRadio.val(); 706 707 if (selectedRadioVal === 'yes') { 708 selectedCardId = $("#ebizcharge-stored-card option:selected").val(); 709 } else if (selectedRadioVal === 'update') { 710 selectedCardId = $("#ebizcharge_update_cc option:selected").val(); 711 } 712 } 713 714 cc = $("#ccnum").val(); 715 if (((cc !== '' && cc.length > 14) || selectedCardId !== '')) { 716 const data = { 717 action: 'calculate_surcharge', 718 'surcharge_enabled': isSurchargeEnabled, 719 'zip': $("#billing_postcode").val(), 720 'cc': cc, 721 'method_id': selectedCardId, 722 }; 723 724 $.ajax({
725 type: 'POST', 726 url: ajax_object.ajax_url, 727 data: data, 728 beforeSend: () => { 729 showLoader(); 730 }, 731 success: function (response) { 732 if (response.success) { 733 $('#ebiz-surcharge').html(response.data); 734 $('#surcharge_amount').val(response.surcharge_amount); 735 } 736 }, 737 complete: () => { 738 hideLoader(); 739 } 740 }); 741 } 742 } 743 } 744 745 // surcharge 746 $(document.body).on('change', '#billing_postcode, #ccnum, #ebizcharge-stored-card, #ebizcharge_update_cc, #ebizcharge-use-stored-payment-info', calculateSurcharge); 747 748 $(document.body).on('change', '#ebizcharge-bank-payment', function () { 749 if ($("#ebizcharge-bank-payment").is(':checked')) { 750 $('#ebiz-surcharge').hide(); 751 } 752 }); 753 754 $(document.body).on('change', '#ebizcharge-cc-payment', function () { 755 if ($("#ebizcharge-cc-payment").is(':checked')) { 756 $('#ebiz-surcharge').show(); 757 } 758 }); 759 760 761 const hideLoader = () => { 762 $('div.blockUI.blockOverlay').css('display', 'none') 763 } 764 765 const showLoader = () => { 766 $('div.blockUI.blockOverlay').css('display', 'block') 767 } 768});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.