| 1 |
jQuery( document ).ready( function( $ ) { |
| 2 |
|
| 3 |
$( document ).on( "click", ".card-update", function( e ) { |
| 4 |
var update_mode = $( this ).attr( "data-update_mode" ); |
| 5 |
var check = true; |
| 6 |
if ( "" == $( "#cc_number" ).val() ) { |
| 7 |
check = false; |
| 8 |
} |
| 9 |
if ( undefined == $( "#cc_expyy" ).get( 0 ) || undefined == $( "#cc_expmm" ).get( 0 ) ) { |
| 10 |
check = false; |
| 11 |
} else if ( "" == $( "#cc_expyy option:selected" ).val() || "" == $( "#cc_expmm option:selected" ).val() ) { |
| 12 |
check = false; |
| 13 |
} else if ( "----" == $( "#cc_expyy option:selected" ).val() || "--" == $( "#cc_expmm option:selected" ).val() ) { |
| 14 |
check = false; |
| 15 |
} |
| 16 |
if ( "" == $( "#cc_seccd" ).val() ) { |
| 17 |
check = false; |
| 18 |
} |
| 19 |
if ( ! check ) { |
| 20 |
alert( sbps_params.message.error_token ); |
| 21 |
return false; |
| 22 |
} |
| 23 |
|
| 24 |
$( "input[name='update']" ).val( update_mode ); |
| 25 |
var cc_expyy = $( "#cc_expyy option:selected" ).val(); |
| 26 |
var cc_expmm = $( "#cc_expmm option:selected" ).val(); |
| 27 |
|
| 28 |
com_sbps_system.generateToken({ |
| 29 |
merchantId : sbps_params.sbps_merchantId, |
| 30 |
serviceId : sbps_params.sbps_serviceId, |
| 31 |
ccNumber : $( "#cc_number" ).val(), |
| 32 |
ccExpiration : cc_expyy.toString() + cc_expmm.toString(), |
| 33 |
securityCode : $( "#cc_seccd" ).val() |
| 34 |
}, afterGenerateToken ); |
| 35 |
return false; |
| 36 |
}); |
| 37 |
|
| 38 |
$( document ).on( "click", "#card-delete", function( e ) { |
| 39 |
if ( ! confirm( sbps_params.message.confirm_deletion ) ) { |
| 40 |
return; |
| 41 |
} |
| 42 |
$( "input[name='update']" ).val( 'delete' ); |
| 43 |
$( "#member-card-info" ).submit(); |
| 44 |
}); |
| 45 |
}); |
| 46 |
|
| 47 |
var afterGenerateToken = function( response ) { |
| 48 |
console.log( response ); |
| 49 |
if ( response.result == "OK" ) { |
| 50 |
document.getElementById( "token" ).value = response.tokenResponse.token; |
| 51 |
document.getElementById( "tokenKey" ).value = response.tokenResponse.tokenKey; |
| 52 |
document.getElementById( "member-card-info" ).submit(); |
| 53 |
} else { |
| 54 |
console.log( response.errorCode ); |
| 55 |
var message = sbps_params.message.error_token; |
| 56 |
if ( 5 == response.errorCode.length ) { |
| 57 |
var error_type = response.errorCode.substr( 0, 2 ); |
| 58 |
var error_field = response.errorCode.substr( 2, 3 ); |
| 59 |
if ( '99' != error_type ) { |
| 60 |
if ( '003' == error_field ) { |
| 61 |
message = sbps_params.message.error_card_number; |
| 62 |
} else if ( '004' == error_field ) { |
| 63 |
message = sbps_params.message.error_card_expym; |
| 64 |
} else if ( '005' == error_field ) { |
| 65 |
message = sbps_params.message.error_card_seccd; |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
alert( message ); |
| 70 |
return false; |
| 71 |
} |
| 72 |
} |
| 73 |
|