Plugin Directory

Changeset 2066586


Ignore:
Timestamp:
04/10/2019 01:39:49 PM (7 years ago)
Author:
ipag
Message:

-Alteração Máscara Validade do cartão para MM/AA
-Correções chamada Pagseguro.

Location:
ipag-woocommerce/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ipag-woocommerce/trunk/classes/ipag-gateway-credito.php

    r2061198 r2066586  
    384384        }
    385385        callPagSeguroCard = function() {
    386 
    387386          var session = "<?php echo $this->pagsegurosession($this->pagseguro_email, $this->pagseguro_token, $this->pagseguro_ambiente); ?>";
     387
    388388          var cid = $j('#ipag_cc_cvv').val();
    389389          var number = $j('#cc_num').val();
    390390          number = number.replace(/\D/g ,"");
    391           var expiry = $j('#ipag_cc_expiry').val().split("/");
    392           var month = expiry[0];
    393 
    394           var year = expiry[1];
     391          var expiry_date = $j('#ipag_cc_expiry').val();
     392          var month = expiry_date.split("/")[0];
     393          var year = expiry_date.split("/")[1];
     394          var data = new Date();
     395          var ano = ""+data.getFullYear();
     396          year = ano.substring(0,2) + year;
    395397          var type = $j('#card_type').val();
    396 
    397398          var idToken = $j('#cartao_tokenpagseguro');
    398399
     
    405406
    406407        validaPagSeguroCartao = function() {
    407 
    408408          var cid = $j('#ipag_cc_cvv').val();
    409409          var number = $j('#cc_num').val();
    410           var expiry = $j('#ipag_cc_expiry').val().split("/");
    411           var month = expiry[0];
    412           var year = expiry[1];
     410         var expiry_date = $j('#ipag_cc_expiry').val();
     411         var month = expiry_date.split("/")[0];
     412         var year = expiry_date.split("/")[1];
     413          var data = new Date();
     414          var ano = ""+data.getFullYear();
     415          year = ano.substring(0,2) + year;
    413416          var type = $j('#card_type').val();
    414 
    415 
    416 
    417 
    418417          if(checkLength(cid,2) && checkLength(number.trim(),10) && checkLength(month,0) && checkLength(year,0) && checkLength(cid,2)){
    419 
    420418            callPagSeguroCard();
    421 
    422419          }
    423420        }
     
    426423          $j('#ipag_cc_cvv').keyup(function(){validaPagSeguroCartao()});
    427424          $j('#cc_num').keyup(function(){validaPagSeguroCartao()});
    428           $j('#ipag_cc_venc_month').change(function(){validaPagSeguroCartao()});
    429           $j('#ipag_cc_venc_year').change(function(){validaPagSeguroCartao()});
     425           $j('#ipag_cc_expiry').keyup(function(){validaPagSeguroCartao()});
    430426        });
    431427
     
    440436                expirationYear: year,
    441437                success: function(callback) {
    442                 console.log(callback);
     438
    443439                },
    444440                 error: function(callback) {
     
    499495            </p>
    500496             <p class="form-row">
    501                 <label for="ipag_cc_name"><?php _e('Validade do Cartão', 'ipag-gateway');?>&nbsp;<abbr class="required" title="Digite exatamente o nome escrito na frente do cartão">*</abbr></label>
    502                   <input type="tel" name="ipag_cc_expiry" id="ipag_cc_expiry" class="input-text half-fill" placeholder="<?php _e('MM / YYYY', 'ipag-woocommerce');?>" autocomplete="off"  style="font-size: 1.5em; padding: 8px;" />
     497                <label for="ipag_cc_expiry"><?php _e('Validade do Cartão (Formato MM/AA)', 'ipag-gateway');?>&nbsp;<abbr class="required" title="Digite exatamente o nome escrito na frente do cartão">*</abbr></label>
     498                  <input type="tel" name="ipag_cc_expiry" id="ipag_cc_expiry" class="input-text half-fill" placeholder="<?php _e('MM / AA', 'ipag-woocommerce');?>" autocomplete="off"  style="font-size: 1.5em; padding: 8px;" />
    503499            </p>
    504500
     
    528524        <script>
    529525            function ipagSelecionaBandeiraCredito(elem,cvvId,cardtype){
    530                 console.log('setting card type');
    531526                document.getElementById('card_type').value = elem.id;
    532527                document.getElementById(cvvId).value = '';
     
    600595
    601596            jQuery(document).ready(function(){
    602                 jQuery('#ipag_cc_expiry').mask('00/0000');
     597                jQuery('#ipag_cc_expiry').mask('00/00');
    603598                var cc_num = document.querySelector('#cc_num');
     599                 var expiry_date = document.querySelector('#ipag_cc_expiry');
     600                 expiry_date.onblur = function(e){
     601
     602                    if(this.value.length==5)
     603                    {
     604
     605                        var splittedval = this.value.split('/');
     606
     607                        if(splittedval[0]<1 || splittedval[0]>12 )
     608                        {
     609
     610                            this.value = '';
     611
     612                        }
     613                    } else {
     614                              this.value = ''; }
     615                }
    604616
    605617                cc_num.onkeyup = function (e) {
     
    632644    public function expiryMesValido($mes, $ano)
    633645    {
     646        $ano = substr(date('Y'), 0, 2).$ano;
    634647        if (strlen($mes) == 2) {
    635648            $intMes = intval($mes);
     
    657670    {
    658671        $valid = false;
     672        $ano = substr(date('Y'), 0, 2).$ano;
    659673
    660674        if (strlen($ano) == 4) {
     
    746760        $mes = date('m');
    747761        $ano2d = preg_replace('/^[\d]{2}/', '', $ano);
    748         $cc_val_ano2d = preg_replace('/^[\d]{2}/', '', $cc_val_ano);
     762
    749763        $anovalid1 = true;
    750         if ($cc_val_ano2d < $ano2d) {
     764        if ($cc_val_ano < $ano2d) {
    751765            $anovalid1 = false;
    752766        }
    753         if ($cc_val_ano == $ano && $cc_val_mes < $mes) {
     767        if ($cc_val_ano == $ano2d && $cc_val_mes < $mes) {
    754768            $anovalid1 = false;
    755769        }
     
    757771        $cardTokenPS = (isset($_POST['cartao_tokenpagseguro'])) ? $_POST['cartao_tokenpagseguro'] : '';
    758772
    759         $this->writeLog('fingerprint PagSeguro Cartão '.print_r($fingerprintPS, true));
    760         if ($this->pagseguro_habilitado) {
     773        if ($this->pagseguro_habilitado == 'yes') {
     774
     775            $this->writeLog('Hash PagSeguro Cartão '.print_r($_POST['cartao_hashpagseguro'], true));
     776            $this->writeLog('Token PagSeguro Cartão '.print_r($_POST['cartao_tokenpagseguro'], true));
    761777            //check pagseguro enabled
    762             if (!isset($_POST['cartao_hashpagseguro']) || !isset($_POST['cartao_tokenpagseguro'])) {
    763                 $error_message = __(' Erro ao processar pagamento PagSeguro, entre em contato com o lojista!', 'ipag-gateway');
     778            if (empty($_POST['cartao_hashpagseguro']) || empty($_POST['cartao_tokenpagseguro'])) {
     779                $this->writeLog('Erro: Recuperação do token PagSeguro. ');
     780                $error_message = __(' Não foi possível processar o cartão. Verifique os dados do cartão!', 'ipag-gateway');
    764781                wc_add_notice(__('Payment error:', 'ipag-gateway').$error_message, 'error');
    765782                $fingerprintPS = '';
     
    775792        }
    776793
    777         if (in_array($cc_metodo, $this->accepted_cards) && $this->cartaoValido($cc_numero) && !empty($cc_nome) && strlen($cc_cvv) > 2 && !empty($cc_numero) && $anovalid1) {
     794        if (in_array($cc_metodo, $this->accepted_cards) && $this->cartaoValido($cc_numero) && !empty($cc_nome) && strlen($cc_cvv) > 2 && !empty($cc_numero) && $anovalid1 && $this->expiryMesValido($cc_val_mes, $cc_val_ano)) {
    778795
    779796            $payload = array(
     
    790807                'cvv_cartao'       => $cc_cvv,
    791808                'mes_cartao'       => $cc_val_mes,
    792                 'ano_cartao'       => preg_replace('/^[\d]{2}/', '', $cc_val_ano),
     809                'ano_cartao'       => $cc_val_ano,
    793810                'cpf_cartao'       => $cc_cpf,
    794811                'nome'             => $args['billingName'],
     
    870887                $error_message = __(' Invalid credit card. Please choose another one!', 'ipag-gateway');
    871888                wc_add_notice(__('Payment error:', 'ipag-gateway').$error_message, 'error');
    872             } elseif (!$anovalid1) {
     889            } elseif (!$anovalid1 || !$this->expiryMesValido($cc_val_mes, $cc_val_ano)) {
    873890                $error_message = __(' Validade do cartão expirada! ', 'ipag-gateway');
    874891                wc_add_notice(__('Payment error:', 'ipag-gateway').$error_message, 'error');
  • ipag-woocommerce/trunk/ipag-gateway.php

    r2052892 r2066586  
    3838                add_action('woocommerce_order_details_after_order_table', array('WC_Gateway_iPag_Boleto', 'pending_payment_message'), 5);
    3939                add_action('woocommerce_order_details_after_order_table', array('WC_Gateway_iPag_ItauShopline', 'pending_payment_message'), 5);
     40                add_action('woocommerce_before_checkout_form', array('WC_iPag_Loader', 'reset_session'));
    4041
    4142                if (is_admin()) {
     
    101102
    102103            $sql = "CREATE TABLE IF NOT EXISTS $table_name (
    103                                                         id INT(11) NOT NULL AUTO_INCREMENT,
    104                                                         order_id INT(11) NOT NULL,
    105                                                         trans_id VARCHAR(128) NOT NULL,
    106                                                         status INT(11) NOT NULL,
    107                                                         payment_date DATE NOT NULL,
    108                                                         PRIMARY KEY pkipag_id (id)
    109                                                         ) $collate;";
     104                                                                id INT(11) NOT NULL AUTO_INCREMENT,
     105                                                                order_id INT(11) NOT NULL,
     106                                                                trans_id VARCHAR(128) NOT NULL,
     107                                                                status INT(11) NOT NULL,
     108                                                                payment_date DATE NOT NULL,
     109                                                                PRIMARY KEY pkipag_id (id)
     110                                                                ) $collate;";
    110111
    111112            $wpdb->query($sql);
Note: See TracChangeset for help on using the changeset viewer.