Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var CWTPFW;
- (function($){
- CWTPFW={
- FORM:false,
- Init:function(){
- this.FORM=$('form.woocommerce-checkout');
- $(document).on('click', '#place_order', this.SubmitCheckout);
- $(document).on('change', '#wc-cwtpfw-cc-form:input', this.FormChange);
- $(document).on('CWTPFW_Error', this.Error);
- $(document).on('checkout_error', this.ClearToken);
- },
- FormChange:function(){
- $('.wc-cwtpfw-error, .cwtpfw_token').remove();
- },
- IsChosen:function(){
- return $('#payment_method_cwtpfw').is(':checked');
- },
- SubmitCheckout:function(){
- var strNumber,
- strCVC,
- expire,
- exp_month,
- exp_year;
- if(CWTPFW.IsChosen()){
- strNumber =$('#cwtpfw-card-number').val().replace(/\s+/g, '');
- strCVC =$('#cwtpfw-card-cvc').val();
- stdExpire =$('#cwtpfw-card-expiry').payment('cardExpiryVal');
- strExpMon =stdExpire.month.length==1?'0'+stdExpire.month:stdExpire.month;
- strExpYear =stdExpire.year-2000;
- TPDirect.card.createToken(strNumber, strExpMon, strExpYear, strCVC, CWTPFW.Response);
- return false;
- }
- },
- Error:function(e, responseObject){
- console.log(responseObject);
- var message=responseObject.response.error.message;
- if('invalid_request_error'===responseObject.response.error.type||'api_connection_error'===responseObject.response.error.type||'api_error'===responseObject.response.error.type||'authentication_error'===responseObject.response.error.type||'rate_limit_error'===responseObject.response.error.type){
- message=wc_tappay_params.invalid_request_error;
- }
- if('card_error'===responseObject.response.error.type&&wc_tappay_params.hasOwnProperty(responseObject.response.error.code)){
- message=wc_tappay_params[responseObject.response.error.code];
- }
- $('.wc-cwtpfw-error, .cwtpfw_token').remove();
- $('#cwtpfw-card-number').closest('p').before('<ul class="woocommerce_error woocommerce-error wc-cwtpfw-error"><li>'+message+'</li></ul>');
- },
- Response:function(result){
- console.log(result);
- var strData ='Card: '+((result.status!=0)?'No Prime':result.card.prime)+" \n"+'Message : '+result.msg+"\n"+'Status : '+result.status,
- strToken =result.card.prime;
- if(result.status!=0){
- $(document).trigger('CWTPFW_Error', {response:result.status});
- }
- CWTPFW.Form.append('<input type="hidden" class="cwtpfw_token" name="cwtpfw_token" value="'+strToken+'" />');
- //CWTPFW.Form.submit();
- },
- ClearToken:function(){
- }
- };
- /*
- $(document).ready(function(){
- CWTPFW.Init();
- });
- */
- }(jQuery));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement