1jQuery( function( $ ) { 2 'use strict'; 3 4 /** 5 * Object to handle Authnet payment forms. 6 */ 7 var wc_authnet_form = { 8 9 /** 10 * Initialize event handlers and UI state. 11 */ 12 init: function() { 13 // checkout page 14 if ( $( 'form.woocommerce-checkout' ).length ) { 15 this.form = $( 'form.woocommerce-checkout' ); 16 } 17 18 $( 'form.woocommerce-checkout' ) 19 .on( 20 'checkout_place_order_authnet', 21 this.onSubmit 22 ); 23 24 $( 'form.woocommerce-checkout' ) 25 .on( 26 'checkout_place_order_authnet-echeck', 27 this.onSubmit 28 ); 29 30 // pay order page 31 if ( $( 'form#order_review' ).length ) { 32 this.form = $( 'form#order_review' ); 33 } 34 35 $( 'form#order_review' ) 36 .on( 37 'submit', 38 this.onSubmit 39 ); 40 41 // add payment method page 42 if ( $( 'form#add_payment_method' ).length ) { 43 this.form = $( 'form#add_payment_method' ); 44 } 45 46 $( 'form#add_payment_method' ) 47 .on( 48 'submit', 49 this.onSubmit 50 ); 51 52 $( document ) 53 .on( 54 'change', 55 '#wc-authnet-cc-form :input, #authnet-echeck-cc-form :input', 56 this.onCCFormChange 57 ) 58 .on( 59 'authnetError', 60 this.onError 61 ) 62 .on( 63 'checkout_error', 64 this.clearToken 65 ); 66 }, 67 68 isAuthnetChosen: function() { 69 return $( '#payment_method_authnet' ).is( ':checked' ) && ( ! $( 'input[name="wc-authnet-payment-token"]:checked' ).length || 'new' === $( 'input[name="wc-authnet-payment-token"]:checked' ).val() ); 70 }, 71 72 isAuthneteCheckChosen: function() { 73 return $( '#payment_method_authnet-echeck' ).is( ':checked' ) && ( ! $( 'input[name="wc-authnet-echeck-payment-token"]:checked' ).length || 'new' === $( 'input[name="wc-authnet-echeck-payment-token"]:checked' ).val() ); 74 }, 75 76 hasToken: function() { 77 return ( 0 < $( 'input.authnet_nonce' ).length ) && ( 0 < $( 'input.authnet_data_descriptor' ).length ); 78 }, 79 80 block: function() { 81 wc_authnet_form.form.block( { 82 message: null, 83 overlayCSS: { 84 background: '#fff', 85 opacity: 0.6 86 } 87 } ); 88 }, 89 90 unblock: function() { 91 wc_authnet_form.form.unblock(); 92 }, 93 94 onError: function( e, responseObject ) { 95 //console.log(responseObject.response); 96 var message = responseObject.response.text; 97 98 $( '.wc-authnet-error, .authnet_nonce' ).remove(); 99 $( '.wc-authnet-error, .authnet_data_descriptor' ).remove(); 100 if ( wc_authnet_form.isAuthneteCheckChosen() ) { 101 $( '#authnet-echeck-account-name' ).closest( 'p' ).before( '<ul class="woocommerce_error woocommerce-error wc-authnet-error"><li>' + message + '</li></ul>' ); 102 } else { 103 $( '#authnet-card-number' ).closest( 'p' ).before( '<ul class="woocommerce_error woocommerce-error wc-authnet-error"><li>' + message + '</li></ul>' ); 104 } 105 wc_authnet_form.unblock(); 106 }, 107 108 onSubmit: function( e ) { 109 var authData = {}; 110 var secureData = {}; 111 112 if ( wc_authnet_form.isAuthnetChosen() && ! wc_authnet_form.hasToken() ) { 113 e.preventDefault(); 114 wc_authnet_form.block(); 115 116 var card_allowed = false, 117 card = $( '#authnet-card-number' ).val(), 118 cvc = $( '#authnet-card-cvc' ).val(), 119 expires = $( '#authnet-card-expiry' ).payment( 'cardExpiryVal' ), 120 first_name = $( '#billing_first_name' ).length ? $( '#billing_first_name' ).val() : wc_authnet_params.billing_first_name, 121 last_name = $( '#billing_last_name' ).length ? $( '#billing_last_name' ).val() : wc_authnet_params.billing_last_name; 122 123 if ( $( '#authnet-card-number' ).hasClass( 'identified' ) ) { 124 wc_authnet_params.allowed_card_types.forEach(function (card_type) { 125 if ( $( '#authnet-card-number' ).hasClass( card_type.replace( 'diners-club', 'dinersclub' ) ) ) { 126 card_allowed = true; 127 } 128 }); 129 130 if ( ! card_allowed ) { 131 $( '.wc-authnet-error, .authnet_nonce' ).remove(); 132 $( '.wc-authnet-error, .authnet_data_descriptor' ).remove(); 133 $( '#authnet-card-number' ).closest( 'p' ).before( '<ul class="woocommerce_error woocommerce-error wc-authnet-error"><li>' + wc_authnet_params.card_disallowed_error + '</li></ul>' ); 134 wc_authnet_form.unblock(); 135 return false; 136 } 137 } 138 139 if ( cvc === '' ) { 140 $( '.wc-authnet-error, .authnet_nonce' ).remove(); 141 $( '.wc-authnet-error, .authnet_data_descriptor' ).remove(); 142 $( '#authnet-card-number' ).closest( 'p' ).before( '<ul class="woocommerce_error woocommerce-error wc-authnet-error"><li>' + wc_authnet_params.no_cvv_error + '</li></ul>' ); 143 wc_authnet_form.unblock(); 144 return false; 145 } 146 147 authData.clientKey = wc_authnet_params.client_key; 148 authData.apiLoginID = wc_authnet_params.login_id; 149 150 var cardData = {}; 151 cardData.cardNumber = card.replace( /\s/g, '' ); 152 cardData.month = expires.month.toString(); 153 cardData.year = expires.year.toString().slice( -2 ); 154 cardData.cardCode = cvc; 155 if ( first_name && last_name ) { 156 cardData.fullName = first_name + ' ' + last_name; 157 } 158 159 secureData.authData = authData; 160 secureData.cardData = cardData; 161 162 Accept.dispatchData( secureData, wc_authnet_form.onAuthnetResponse ); 163 164 // Prevent form submitting 165 return false; 166 } else if ( wc_authnet_form.isAuthneteCheckChosen() && ! wc_authnet_form.hasToken() ) { 167 e.preventDefault(); 168 wc_authnet_form.block(); 169 170 var routing_number = $( '#authnet-echeck-routing-number' ).val(), 171 account_number = $( '#authnet-echeck-account-number' ).val(), 172 account_name = $( '#authnet-echeck-account-name' ).val(), 173 holder_type = $( '[name="authnet-echeck-holder-type"]' ).val(), 174 account_type = holder_type == 'business' ? 'businessChecking' : $( '[name="authnet-echeck-account-type"]' ).val(), 175 first_name = $( '#billing_first_name' ).length ? $( '#billing_first_name' ).val() : wc_authnet_echeck_params.billing_first_name, 176 last_name = $( '#billing_last_name' ).length ? $( '#billing_last_name' ).val() : wc_authnet_echeck_params.billing_last_name; 177 178 if ( routing_number === '' ) { 179 $( '.wc-authnet-error, .authnet_nonce' ).remove(); 180 $( '.wc-authnet-error, .authnet_data_descriptor' ).remove(); 181 $( '#authnet-echeck-account-name' ).closest( 'p' ).before( '<ul class="woocommerce_error woocommerce-error wc-authnet-error"><li>' + wc_authnet_echeck_params.no_routing_number_error + '</li></ul>' ); 182 wc_authnet_form.unblock(); 183 return false; 184 } 185 186 if ( account_number === '' ) { 187 $( '.wc-authnet-error, .authnet_nonce' ).remove(); 188 $( '.wc-authnet-error, .authnet_data_descriptor' ).remove(); 189 $( '#authnet-echeck-account-name' ).closest( 'p' ).before( '<ul class="woocommerce_error woocommerce-error wc-authnet-error"><li>' + wc_authnet_echeck_params.no_account_number_error + '</li></ul>' ); 190 wc_authnet_form.unblock(); 191 return false; 192 } 193 194 authData.clientKey = wc_authnet_echeck_params.client_key; 195 authData.apiLoginID = wc_authnet_echeck_params.login_id; 196 197 var bankData = {}; 198 bankData.accountNumber = account_number; 199 bankData.routingNumber = routing_number; 200 bankData.nameOnAccount = account_name; 201 bankData.accountType = account_type; 202 203 //console.log( bankData ); 204 205 if ( bankData.nameOnAccount === '' && first_name && last_name ) { 206 bankData.nameOnAccount = first_name + ' ' + last_name; 207 } 208 209 secureData.authData = authData; 210 secureData.bankData = bankData; 211 212 Accept.dispatchData( secureData, wc_authnet_form.onAuthnetResponse ); 213 214 // Prevent form submitting 215 return false; 216 } 217 }, 218 219 onCCFormChange: function() { 220 $( '.wc-authnet-error, .authnet_nonce' ).remove(); 221 $( '.wc-authnet-error, .authnet_data_descriptor' ).remove(); 222 }, 223 224 onAuthnetResponse: function( response ) { 225 226 if ( response.messages.resultCode === "Error" ) { 227 var i = 0; 228 while ( i < response.messages.message.length ) { 229 //console.log( response.messages.message[i].code + ": " + response.messages.message[i].text ); 230 $( document ).trigger( 'authnetError', { response: response.messages.message[i] } ); 231 i = i + 1; 232 } 233 } else { 234 //console.log(response); 235 // insert the token into the form so it gets submitted to the server 236 wc_authnet_form.form.append( "<input type='hidden' class='authnet_nonce' name='authnet_nonce' value='" + response.opaqueData.dataValue + "'/>" ); 237 wc_authnet_form.form.append( "<input type='hidden' class='authnet_data_descriptor' name='authnet_data_descriptor' value='" + response.opaqueData.dataDescriptor + "'/>" ); 238 wc_authnet_form.form.submit(); 239 } 240 }, 241 242 clearToken: function() { 243 $( '.authnet_nonce' ).remove(); 244 $( '.authnet_data_descriptor' ).remove(); 245 } 246 }; 247
248 wc_authnet_form.init(); 249} );
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.