Advertisement
cloudtuts

TapPay JS

Aug 25th, 2017
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var CWTPFW;
  2.  
  3. (function($){
  4.  
  5.     CWTPFW={
  6.  
  7.         FORM:false,
  8.  
  9.         Init:function(){
  10.  
  11.             this.FORM=$('form.woocommerce-checkout');
  12.  
  13.             $(document).on('click', '#place_order', this.SubmitCheckout);
  14.  
  15.             $(document).on('change', '#wc-cwtpfw-cc-form:input', this.FormChange);
  16.  
  17.             $(document).on('CWTPFW_Error', this.Error);
  18.  
  19.             $(document).on('checkout_error', this.ClearToken);
  20.  
  21.         },
  22.  
  23.         FormChange:function(){
  24.             $('.wc-cwtpfw-error, .cwtpfw_token').remove();
  25.         },
  26.  
  27.         IsChosen:function(){
  28.             return $('#payment_method_cwtpfw').is(':checked');
  29.         },
  30.  
  31.         SubmitCheckout:function(){
  32.  
  33.             var strNumber,
  34.                     strCVC,
  35.                     expire,
  36.                     exp_month,
  37.                     exp_year;
  38.  
  39.             if(CWTPFW.IsChosen()){
  40.  
  41.                 strNumber       =$('#cwtpfw-card-number').val().replace(/\s+/g, '');
  42.  
  43.                 strCVC          =$('#cwtpfw-card-cvc').val();
  44.                 stdExpire       =$('#cwtpfw-card-expiry').payment('cardExpiryVal');
  45.                 strExpMon       =stdExpire.month.length==1?'0'+stdExpire.month:stdExpire.month;
  46.                 strExpYear  =stdExpire.year-2000;
  47.  
  48.                 TPDirect.card.createToken(strNumber, strExpMon, strExpYear, strCVC, CWTPFW.Response);
  49.  
  50.                 return false;
  51.             }
  52.  
  53.         },
  54.  
  55.         Error:function(e, responseObject){
  56.  
  57.             console.log(responseObject);
  58.  
  59.             var message=responseObject.response.error.message;
  60.  
  61.             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){
  62.                 message=wc_tappay_params.invalid_request_error;
  63.             }
  64.  
  65.             if('card_error'===responseObject.response.error.type&&wc_tappay_params.hasOwnProperty(responseObject.response.error.code)){
  66.                 message=wc_tappay_params[responseObject.response.error.code];
  67.             }
  68.  
  69.             $('.wc-cwtpfw-error, .cwtpfw_token').remove();
  70.             $('#cwtpfw-card-number').closest('p').before('<ul class="woocommerce_error woocommerce-error wc-cwtpfw-error"><li>'+message+'</li></ul>');
  71.  
  72.         },
  73.  
  74.         Response:function(result){
  75.  
  76.             console.log(result);
  77.  
  78.             var strData     ='Card: '+((result.status!=0)?'No Prime':result.card.prime)+" \n"+'Message : '+result.msg+"\n"+'Status : '+result.status,
  79.                     strToken    =result.card.prime;
  80.  
  81.             if(result.status!=0){
  82.                 $(document).trigger('CWTPFW_Error', {response:result.status});
  83.             }
  84.  
  85.             CWTPFW.Form.append('<input type="hidden" class="cwtpfw_token" name="cwtpfw_token" value="'+strToken+'" />');
  86.  
  87.             //CWTPFW.Form.submit();
  88.  
  89.         },
  90.  
  91.         ClearToken:function(){
  92.            
  93.         }
  94.  
  95.     };
  96.  
  97.     /*
  98.     $(document).ready(function(){
  99.         CWTPFW.Init();
  100.     });
  101.     */
  102.  
  103. }(jQuery));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement