1jQuery( function( $ ) { 2 'use strict'; 3 4 try { 5 var ab = AsiabillPay(wc_asiabill_params.token); 6 }catch( error ) { 7 console.log( error ); 8 return; 9 } 10 11 let initAsiabillPaymentSdk = { 12 13 is_init : false, 14 form : null, 15 checkPage : wc_asiabill_params.checkoutPayPage, 16 17 init : function () { 18 19 this.form = $( 'form.woocommerce-checkout' ); 20 21 if( !this.form.length ){ 22 this.form = $( '#order_review' ); 23 } 24 25 if( !this.form.length ){ 26 console.log(this.form); 27 initAsiabillPaymentSdk.errorMessage('The form undefined') 28 return false; 29 } 30 31 if( this.checkPage === 'no' ){ 32 initAsiabillPaymentSdk.createElements(); 33 } 34 $( document.body ).on( 'updated_checkout', function() { 35 initAsiabillPaymentSdk.createElements(); 36 }); 37 38 }, 39 40 createElements: function () { 41 ab.elementInit("payment_steps", { 42 formId: 'asiabill-card', 43 formWrapperId: 'asiabill-card-element', 44 frameId: 'asiabill-card-frame', 45 customerId: '', 46 autoValidate:false, 47 layout: wc_asiabill_params.layout 48 }).then((res) => { 49 console.log("initRES", res) 50 }).catch((err) => { 51 console.log("initERR", err) 52 }); 53 54 55 let btn = $('#place_order,.vi-wcaio-sidebar-cart-bt-checkout-place_order'); 56 57 58 btn.on('click',function () { 59 return initAsiabillPaymentSdk.checkoutOrder(); 60 }); 61 }, 62 63 checkoutOrder : function () { 64 65 if( this.checkPage === 'no' ){ 66 var billing = wc_asiabill_params.billing; 67 }else { 68 69 var billing = { 70 "address": { 71 "city": $( '#billing_city' ).val(), 72 "country": $( '#billing_country' ).val(), 73 "line1": $( '#billing_address_1' ).val(), 74 "line2": $( '#billing_address_2' ).val(), 75 "postalCode": $( '#billing_postcode' ).val(), 76 "state": $( '#billing_state' ).val() 77 }, 78 "email": $( '#billing_email' ).val(), 79 "firstName": $( '#billing_first_name' ).val(), 80 "lastName": $( '#billing_last_name' ).val() , 81 "phone": $( '#billing_phone' ).val() 82 }; 83 } 84 85 let paymentMethodObj = { 86 "billingDetail": billing, 87 "card": { 88 "cardNo": "", 89 "cardExpireMonth": "", 90 "cardExpireYear": "", 91 "cardSecurityCode": "", 92 "issuingBank": "" 93 }, 94 "customerId": '', 95 }; 96 97 initAsiabillPaymentSdk.errorMessage(''); 98 99 if($('#payment_method_wc_asiabill_creditcard').is( ':checked' )){ 100 101 let token = $('input[name=wc-wc_asiabill_creditcard-payment-token]:checked').val(); 102 103 if( token != undefined && token!== 'new' ){ 104 // 使ç¨tokenæ¯ä» 105 return true 106 } 107 else { 108 // 使ç¨å¡æ¯ä» 109 $( '.asiabill-payment' ).remove(); 110 ab.confirmPaymentMethod({ 111 apikey: wc_asiabill_params.token, 112 trnxDetail: paymentMethodObj 113 }).then((result) => { 114 if( result.data.code === "0" ){ 115 // ä¿åæå 116 initAsiabillPaymentSdk.form.append( 117 $( '<input type="hidden" />' ) 118 .addClass( 'asiabill-payment' ) 119 .attr( 'name', 'asiabill_payment' ) 120 .val( result.data.data.customerPaymentMethodId ) 121 ); 122 initAsiabillPaymentSdk.form.append( 123 $( '<input type="hidden" />' ) 124 .addClass( 'asiabill-payment' ) 125 .attr( 'name', 'asiabill_check_page' ) 126 .val( initAsiabillPaymentSdk.checkPage ) 127 ); 128 initAsiabillPaymentSdk.form.trigger( 'submit' ); 129 } 130 else { 131 // ä¿å失败 132 initAsiabillPaymentSdk.errorMessage(result.data.message); 133 } 134 }); 135 return false; 136 } 137 138 } 139 }, 140 141 errorMessage : function (message = ''){ 142 if( message.trim() !== '' ){ 143 $( document.body ).trigger( 'checkout_error',message ); 144 $('#asiabill-card-error').html(message).removeClass('hide'); 145 }else{ 146 $('#asiabill-card-error').html('').addClass('hide'); 147 } 148 } 149 150 151 }; 152 153 window.addEventListener("getErrorMessage", e => { 154 initAsiabillPaymentSdk.errorMessage(e.detail.errorMessage); 155 });
156 157 initAsiabillPaymentSdk.init(); 158 159 160}); 161 162 163 164 165 166 167 168 169 170 171 172
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.