| 1 |
jQuery( document ).ready( function( $ ) { |
| 2 |
|
| 3 |
$( 'body input[type="submit"]' ).each( function( i, elem ) { |
| 4 |
if( "confirm" == $( this ).attr( "name" ) ) { |
| 5 |
$( this ).parents( "form" ).attr( "id", "delivery-form" ); |
| 6 |
} |
| 7 |
}); |
| 8 |
|
| 9 |
$( document ).on( "click", 'body input[type="submit"]', function( e ) { |
| 10 |
if( "confirm" == $( this ).attr( "name" ) && $( "#sbps_form" ).css( "display" ) != "none" ) { |
| 11 |
if( $( "input[name=cust_quick]" ).val() == undefined || "new" == $( "input[name=cust_quick]:checked" ).val() ) { |
| 12 |
|
| 13 |
var check = true; |
| 14 |
if( "" == $( "#cc_number" ).val() ) { |
| 15 |
check = false; |
| 16 |
} |
| 17 |
if( undefined == $( "#cc_expyy" ).get( 0 ) || undefined == $( "#cc_expmm" ).get( 0 ) ) { |
| 18 |
check = false; |
| 19 |
} else if( "" == $( "#cc_expyy option:selected" ).val() || "" == $( "#cc_expmm option:selected" ).val() ) { |
| 20 |
check = false; |
| 21 |
} else if( "----" == $( "#cc_expyy option:selected" ).val() || "--" == $( "#cc_expmm option:selected" ).val() ) { |
| 22 |
check = false; |
| 23 |
} |
| 24 |
if( "" == $( "#cc_seccd" ).val() ) { |
| 25 |
check = false; |
| 26 |
} |
| 27 |
if( !check ) { |
| 28 |
alert( sbps_params.message.error_token ); |
| 29 |
return false; |
| 30 |
} |
| 31 |
|
| 32 |
var cc_expyy = $( "#cc_expyy option:selected" ).val(); |
| 33 |
var cc_expmm = $( "#cc_expmm option:selected" ).val(); |
| 34 |
|
| 35 |
com_sbps_system.generateToken({ |
| 36 |
merchantId : sbps_params.sbps_merchantId, |
| 37 |
serviceId : sbps_params.sbps_serviceId, |
| 38 |
ccNumber : $( "#cc_number" ).val(), |
| 39 |
ccExpiration : cc_expyy.toString() + cc_expmm.toString(), |
| 40 |
securityCode : $( "#cc_seccd" ).val() |
| 41 |
}, afterGenerateToken ); |
| 42 |
return false; |
| 43 |
|
| 44 |
} else { |
| 45 |
$( "delivery-form" ).submit(); |
| 46 |
} |
| 47 |
} else { |
| 48 |
$( "delivery-form" ).submit(); |
| 49 |
} |
| 50 |
}); |
| 51 |
|
| 52 |
if( $( "input[name=cust_quick]" ).val() != undefined ) { |
| 53 |
$( document ).on( "click", ".cust_quick", function( e ) { |
| 54 |
if( "quick" == $( "input[name=cust_quick]:checked" ).val() ) { |
| 55 |
$( "#cc_number" ).prop( "disabled", true ); |
| 56 |
if( $( "#cust_manage" ).val() != undefined ) { |
| 57 |
$( "#cust_manage" ).prop( "disabled", true ); |
| 58 |
$( "#cust_manage_label" ).css( "color", "#848484" ); |
| 59 |
} |
| 60 |
$( "#cc_expmm" ).prop( "disabled", true ).css( "background-color", "#ebebe4" ); |
| 61 |
$( "#cc_expyy" ).prop( "disabled", true ).css( "background-color", "#ebebe4" ); |
| 62 |
$( "#cc_seccd" ).prop( "disabled", true ); |
| 63 |
} else { |
| 64 |
$( "#cc_number" ).prop( "disabled", false ); |
| 65 |
if( $( "#cust_manage" ).val() != undefined ) { |
| 66 |
$( "#cust_manage" ).prop( "disabled", false ); |
| 67 |
$( "#cust_manage_label" ).css( "color", "#000" ); |
| 68 |
} |
| 69 |
$( "#cc_expmm" ).prop( "disabled", false ).css( "background-color", "#fff" ); |
| 70 |
$( "#cc_expyy" ).prop( "disabled", false ).css( "background-color", "#fff" ); |
| 71 |
$( "#cc_seccd" ).prop( "disabled", false ); |
| 72 |
} |
| 73 |
}); |
| 74 |
$( "#cust_quick_use" ).prop( "checked", true ).trigger( "click" ); |
| 75 |
} |
| 76 |
}); |
| 77 |
|
| 78 |
var afterGenerateToken = function( response ) { |
| 79 |
//console.log( response ); |
| 80 |
if( response.result == "OK" ) { |
| 81 |
document.getElementById( "token" ).value = response.tokenResponse.token; |
| 82 |
document.getElementById( "tokenKey" ).value = response.tokenResponse.tokenKey; |
| 83 |
document.getElementById( "delivery-form" ).submit(); |
| 84 |
} else { |
| 85 |
//console.log( response.errorCode ); |
| 86 |
var message = sbps_params.message.error_token; |
| 87 |
if( 5 == response.errorCode.length ) { |
| 88 |
var error_type = response.errorCode.substr( 0, 2 ); |
| 89 |
var error_field = response.errorCode.substr( 2, 3 ); |
| 90 |
if( '99' != error_type ) { |
| 91 |
if( '003' == error_field ) { |
| 92 |
message = sbps_params.message.error_card_number; |
| 93 |
} else if( '004' == error_field ) { |
| 94 |
message = sbps_params.message.error_card_expym; |
| 95 |
} else if( '005' == error_field ) { |
| 96 |
message = sbps_params.message.error_card_seccd; |
| 97 |
} |
| 98 |
} |
| 99 |
} |
| 100 |
alert( message ); |
| 101 |
return false; |
| 102 |
} |
| 103 |
} |
| 104 |
|