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# is required</p>"); 333 ccnum = false; 334 335 } else if (numLength < 15 || numLength > 16) { 336 ccnumResults("<p>Credit Card# 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 < 5 || anumLength > 17) { 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, 5-17 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 logOrder( '3DS setting is enabled'); 520 } else { 521 logOrder('3DS setting is disabled') 522 } 523 524 function EBiz3DSecureValidation() { 525 return new Promise((theSuccess, theFailure) => { 526 try { 527 if (eBiz3DSecure.JWT == null || eBiz3DSecure.JWT == "") { 528 logOrder('Merchant is not enabled for 3D Secure, continue with payment without 3DSecure'); 529 theSuccess('NO_JWT') 530 } 531 const inputData = class InputData { 532 static CardType = $('#cardtype').val() 533 static CardNumber = $('#ccnum').val() 534 //static NameOnCard = $('#ccholder').val() 535 static ExpireMonth = $('#expmonth').val() 536 static ExpireYear = $('#expyear').val() 537 //static SecurityCode = $('#cvv').val() 538 static Amount = $('#orderAmount').val()
539 static OrderNumber = $('#orderNumber').val() 540 static CurrencyCode = $('#storeCurrency').val() 541 static BillingAddress = $('#billing_address_1').val() + ' ' + $('#billing_address_2').val() 542 //static BillingAddress2 = $('#billing_address_2').val() 543 static BillingCity = $('#billing_city').val() 544 static BillingCountryCode = "840" 545 static BillingFirstName = $('#billing_first_name').val() 546 static BillingLastName = $('#billing_last_name').val() 547 static BillingPhone = $('#billing_phone').val() 548 static BillingPostalCode = $('#billing_postcode').val() 549 static BillingState = "CA"; 550 static Zip = $('#billing_postcode').val() 551 static ShippingCountryCode = "840" 552 static Email = $('#billing_email').val() 553 static phone = $('#billing_phone').val() 554 static TransactionType = "C" 555 static TransactionMode = "S" 556 } 557 558 eBiz3DSecure.EBiz3DSecureCheck(inputData) 559 .then(successData => { 560 logOrder(successData) 561 theSuccess(successData) 562 563 }).catch(failureData => { 564 565 if (failureData.bypass3DS2OnError ?? false) { 566 logOrder('bypass3DS2OnError is true, continue with payment without 3DSecure.') 567 theSuccess('bypass3DS2OnError') 568 } else { 569 // show error message and don't continue to payment process 570 theFailure(eBiz3DSecure.GetErrorMessage(failureData)) 571 } 572 }) 573 } catch (error) { 574 console.log('error', error); 575 theFailure(error); 576 } 577 }); 578 } 579 580 function EBiz3DSecureValidationCall() { 581 EBiz3DSecureValidation() 582 .then(response => { 583 $("#place_order").prop("disabled", false) 584 hideLoader() 585 if (response === 'NO_JWT' || response === 'bypass3DS2OnError') { 586 $("#WCPlaceOrder").val(true) 587 submitOrder() 588 return true 589 } else { 590 //alert("Payment is authorized by 3D Secure."); 591 $("#CAVV").val(response.cavv) 592 $("#XID").val(response.xid) 593 $("#ECI").val(response.eciFlag) 594 $("#Pares").val(response.paResStatus) 595 $("#DSTransactionId").val(response.dsTransactionId) 596 $("#WCPlaceOrder").val(true) 597 logOrder('Payment is Authorized by 3D Secure. dsTransactionId: ' + response.dsTransactionId) 598 submitOrder() 599 600 return true 601 } 602 }).catch(error => { 603 $("#WCPlaceOrder").val(false); 604 $("#place_order").prop("disabled", false); 605 hideLoader(); 606 let msg = error ?? "Payment is not Authorized by 3D Secure." 607 logOrder(msg) 608 alert(msg) 609 return false; 610 }) 611 } 612 613 function logOrder(msg) { 614 const data = { 615 action: 'log_ebizcharge_order', 616 'order_id': $('#orderNumber').val(), 617 'data': msg, 618 } 619 jQuery.post(ebiz_ajax_object.ebiz_ajax_url, data, function (response) { 620 if (response) { 621 console.log('log success') 622 } 623 }) 624 } 625 626 function submitOrder() { 627 628 $('form#order_review').length > 0 629 ? $('form#order_review').submit() 630 : $('#place_order').submit(); 631 } 632 633 $(document.body).on('click', '#place_order', function (event) { 634 // Check payment methods is EbizCharge selected 635 let selectedPaymentRadio = $("input[type='radio'][name='payment_method']:checked"); 636 637 if (selectedPaymentRadio.length > 0 && selectedPaymentRadio.val() == 'ebizcharge') { 638 event.preventDefault(); 639 640 let is3DS2Enabled = $("#Is3DS2Enabled").val() == true; 641 642 if ($("#ebizcharge-cc-payment").is(':checked')) { 643 var selectedRadio = $("input[type='radio'][name='ebizcharge-use-stored-payment-info']:checked"); 644 if (selectedRadio.length > 0) { 645 let selectedRadioVal = selectedRadio.val(); 646 647 if (selectedRadioVal == 'yes') { 648 // return saved_card_fields_validated(); 649 if (saved_card_fields_validated()) { 650 submitOrder() 651 } 652 653 } 654 655 if (selectedRadioVal == 'update') { 656 // return update_card_fields_validated(); 657 if (update_card_fields_validated()) { 658 submitOrder() 659 } 660 } 661 662 if (selectedRadioVal == 'no') { 663 664 if (new_card_fields_validated()) { 665 if (is3DS2Enabled) { 666 $('#place_order').attr("disabled", "disabled"); 667 showLoader() 668 return EBiz3DSecureValidationCall() 669 } else { 670 submitOrder() 671 } 672 } else { 673 return false 674 } 675 } 676 677 } else { 678 if (new_card_fields_validated()) { 679 if (is3DS2Enabled) { 680 event.preventDefault(); 681 $('#place_order').attr("disabled", "disabled"); 682 showLoader(); 683 return EBiz3DSecureValidationCall(); 684 } else { 685 submitOrder(); 686 } 687 } else { 688 return false; 689 } 690 } 691 } 692
693 if ($("#ebizcharge-bank-payment").is(':checked')) { 694 let selectedBankRadio = $("input[type='radio'][name='ebizcharge-use-stored-bank-info']:checked") 695 if (selectedBankRadio.length > 0) { 696 let selectedBankRadioVal = selectedBankRadio.val() 697 698 if (selectedBankRadioVal == 'yes') { 699 submitOrder(); 700 // return true 701 } 702 703 if (selectedBankRadioVal == 'no') { 704 if (new_bank_fields_validated()) { 705 submitOrder(); 706 } 707 } 708 } else { 709 // return new_bank_fields_validated(); 710 if (new_bank_fields_validated()) { 711 submitOrder(); 712 } 713 } 714 } 715 } 716 }); 717 718 const hideLoader = () => { 719 $('div.blockUI.blockOverlay').css('display', 'none') 720 } 721 722 const showLoader = () => { 723 $('div.blockUI.blockOverlay').css('display', 'block') 724 } 725 726 const getOrderId = () => { 727 const orderIdMatch = window.location.href.match(/(?:[?&]order-pay=|\/order-pay\/)(\d+)/) 728 return orderIdMatch ? orderIdMatch[1] : ''; 729 } 730 731 const calculateSurcharge = () => { 732 733 const isSurchargeEnabled = $("#surcharge_enabled").val(); 734 let cc = '' 735 let selectedCardId = '' 736 let zip = $("#billing_postcode").val() 737 738 if (isSurchargeEnabled && $("#ebizcharge-cc-payment").is(':checked')) { 739 let selectedRadio = $("input[type='radio'][name='ebizcharge-use-stored-payment-info']:checked"); 740 cc = $("#ccnum").val(); 741 742 if (selectedRadio.length > 0) { 743 let selectedRadioVal = selectedRadio.val(); 744 745 if (selectedRadioVal === 'yes') { 746 selectedCardId = $("#ebizcharge-stored-card option:selected").val(); 747 cc = '' 748 749 } else if (selectedRadioVal === 'update') { 750 selectedCardId = $("#ebizcharge_update_cc option:selected").val(); 751 cc = '' 752 zip = $("#avs_zip").val() 753 } 754 } 755 756 if (((cc !== '' && cc.length > 14) || selectedCardId !== '')) { 757 // Extract order id from the URL using a regular expression 758 const orderId = getOrderId() 759 const data = { 760 action: 'calculate_surcharge', 761 'surcharge_enabled': isSurchargeEnabled, 762 'zip': zip, 763 'cc': cc, 764 'method_id': selectedCardId, 765 'order_id': orderId 766 } 767 768 showLoader() 769 770 jQuery.post(ebiz_ajax_object.ebiz_ajax_url, data, function (response) { 771 if (response.success) { 772 $('#ebiz-surcharge').html(response.data); 773 $('#surcharge_amount').val(response.surcharge_amount); 774 } 775 }).always(function () { 776 hideLoader() 777 }) 778 779 } else { 780 $('#ebiz-surcharge').html($('#ebiz-surcharge-zero').html()) 781 } 782 } 783 } 784 785 // admin order match 786 if (getOrderId() !== '') { 787 calculateSurcharge() 788 } 789 790 $(document).on('click', 'input[name="ebizcharge-use-stored-payment-info"]', function () { 791 calculateSurcharge() 792 }) 793 794 // surcharge 795 $(document.body).on( 796 'change', 797 '#billing_postcode, #avs_zip, #ccnum, #ebizcharge-stored-card, #ebizcharge_update_cc, #ebizcharge-use-stored-payment-info', 798 calculateSurcharge 799 ) 800 801 $(document.body).on('change', '#ebizcharge-bank-payment', function () { 802 if ($("#ebizcharge-bank-payment").is(':checked')) { 803 $('#ebiz-surcharge').hide(); 804 } 805 }) 806 807 $(document.body).on('change', '#ebizcharge-cc-payment', function () { 808 if ($("#ebizcharge-cc-payment").is(':checked')) { 809 $('#ebiz-surcharge').show(); 810 } 811 }) 812 813})
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.