Plugin Directory

Changeset 2768020


Ignore:
Timestamp:
08/08/2022 07:55:03 PM (4 years ago)
Author:
lucascreativecode
Message:

adicionado mensagem de erro ao observar credenciais invalidas

Location:
unienvios/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • unienvios/trunk/api.php

    r2752559 r2768020  
    4141      return $response;
    4242    } elseif (200 === $response['response']['code']) {
     43    }elseif($response['response']['code'] != 200){
     44      return ['status_code' => $response['response']['code'], 'message' => $response['response']['message'] ];
    4345    }
    44 
    4546    return json_decode($response['body']);
    4647  }
     
    125126
    126127    $response = wp_remote_post($endpoint, $options);
    127     echo "<pre>";
    128     var_dump($response);
    129     echo "</pre>";
    130128
    131129    if (is_wp_error($response)) {
  • unienvios/trunk/index.php

    r2765806 r2768020  
    2121    {
    2222
    23 
    2423        if (!class_exists('Unienvios')) {
    2524            require_once __DIR__ . '/ClassUnienvios.php';
     
    2726    }
    2827
    29 
    30     /* adds stylesheet file to the end of the queue */
    31     function unienvios_add_css_page_product()
    32     {
    33         $dir = plugin_dir_url(__FILE__);
    34         wp_enqueue_script( 'mask-jquery', plugins_url( 'assets/js/jquery.mask.js', __FILE__ ), array('jquery'), "0.1.0" );
    35         wp_enqueue_style('page-product-css', $dir . '/assets/css/page-product.css', array(), '0.1.0', 'all');
     28    $api = new API_UNIENVIOS('https://api.unienvios.com.br');
     29    $dados = [];
     30    $dados['email'] = sanitize_email( get_option('unienvios_options')['email'] );
     31    $dados['senha'] = get_option('unienvios_options')['senha'];
     32    $dados['cep'] =  "03330000";
     33    $dados['cart_subtotal'] = sanitize_text_field( doubleval($_POST['price_product']) );
     34
     35    $dimensoes = [
     36        'estimate_height' => sanitize_text_field( doubleval($_POST['estimate_height']) ),
     37        'estimate_width' => sanitize_text_field( doubleval($_POST['estimate_width']) ),
     38        'estimate_length' => sanitize_text_field( doubleval($_POST['estimate_length']) ),
     39        'estimate_weight' => sanitize_text_field( doubleval($_POST['estimate_weight']) ),
     40    ];
     41
     42
     43    $quotation = $api->create_quotation($dados, $dimensoes);
     44
     45    if(!isset($quotation->token)){
     46        function wpb_admin_notice_warn() {
     47            echo '<div class="notice notice-error is-dismissible">
     48                  <p>Unienvios Informa: Existe um erro nas configurações do plugin, verifique se a senha e o email estão atualizadas.</p>
     49                  </div>';
     50            }
     51            add_action( 'admin_notices', 'wpb_admin_notice_warn' );
     52    }else{
     53       
     54            /* adds stylesheet file to the end of the queue */
     55            function unienvios_add_css_page_product()
     56            {
     57                $dir = plugin_dir_url(__FILE__);
     58                wp_enqueue_script( 'mask-jquery', plugins_url( 'assets/js/jquery.mask.js', __FILE__ ), array('jquery'), "0.1.0" );
     59                wp_enqueue_style('page-product-css', $dir . '/assets/css/page-product.css', array(), '0.1.0', 'all');
     60            }
     61            add_action('wp_enqueue_scripts', 'unienvios_add_css_page_product', PHP_INT_MAX);
     62       
     63       
     64       
     65            add_action('woocommerce_shipping_init', 'unienvios_your_shipping_method_init');
     66       
     67            function unienvios_add_your_shipping_method($methods)
     68            {
     69       
     70                $api = new API_UNIENVIOS('https://api.unienvios.com.br');
     71                $dados = [];
     72                $dados['email'] = sanitize_email( get_option('unienvios_options')['email'] );
     73                $dados['senha'] = get_option('unienvios_options')['senha'];
     74                $dados['cep'] = sanitize_text_field("03330000");
     75                $dados['cart_subtotal'] = sanitize_text_field( doubleval(0) );
     76       
     77                $dimensoes = [
     78                    'estimate_height' => sanitize_text_field( doubleval(0) ),
     79                    'estimate_width' => sanitize_text_field( doubleval(0) ),
     80                    'estimate_length' => sanitize_text_field( doubleval(0) ),
     81                    'estimate_weight' => sanitize_text_field( doubleval(0) ),
     82                ];
     83       
     84                $quotation = $api->create_quotation($dados, $dimensoes);
     85                // echo "<pre>";
     86                // var_dump($quotation);
     87                // echo "</pre>";
     88                if ($quotation) {
     89       
     90                    foreach ($quotation->quotations as $key => $qut) {
     91                        $name_minusculo = preg_replace("/[^\w\s]/", "", iconv("UTF-8", "ASCII//TRANSLIT", $qut->name));
     92                        $name_minusculo = strtolower(str_replace(" ", "_", $name_minusculo));
     93                        $dados = ['id_metodo' => $name_minusculo, 'title' => $qut->name];
     94                        $methods[] = (new Unienvios($dados));
     95                    }
     96                }
     97       
     98                return $methods;
     99            }
     100       
     101       
     102            add_filter('woocommerce_shipping_methods', 'unienvios_add_your_shipping_method');
    36103    }
    37     add_action('wp_enqueue_scripts', 'unienvios_add_css_page_product', PHP_INT_MAX);
    38 
    39 
    40 
    41     add_action('woocommerce_shipping_init', 'unienvios_your_shipping_method_init');
    42 
    43     function unienvios_add_your_shipping_method($methods)
    44     {
    45 
    46         $api = new API_UNIENVIOS('https://api.unienvios.com.br');
    47         $dados = [];
    48         $dados['email'] = sanitize_email( get_option('unienvios_options')['email'] );
    49         $dados['senha'] = get_option('unienvios_options')['senha'];
    50         $dados['cep'] = sanitize_text_field("03330000");
    51         $dados['cart_subtotal'] = sanitize_text_field( doubleval(0) );
    52 
    53         $dimensoes = [
    54             'estimate_height' => sanitize_text_field( doubleval(0) ),
    55             'estimate_width' => sanitize_text_field( doubleval(0) ),
    56             'estimate_length' => sanitize_text_field( doubleval(0) ),
    57             'estimate_weight' => sanitize_text_field( doubleval(0) ),
    58         ];
    59 
    60         $quotation = $api->create_quotation($dados, $dimensoes);
    61         // echo "<pre>";
    62         // var_dump($quotation);
    63         // echo "</pre>";
    64         if ($quotation) {
    65 
    66             foreach ($quotation->quotations as $key => $qut) {
    67                 $name_minusculo = preg_replace("/[^\w\s]/", "", iconv("UTF-8", "ASCII//TRANSLIT", $qut->name));
    68                 $name_minusculo = strtolower(str_replace(" ", "_", $name_minusculo));
    69                 $dados = ['id_metodo' => $name_minusculo, 'title' => $qut->name];
    70                 $methods[] = (new Unienvios($dados));
    71             }
    72         }
    73 
    74         return $methods;
    75     }
    76 
    77 
    78     add_filter('woocommerce_shipping_methods', 'unienvios_add_your_shipping_method');
    79 }
     104
     105}
     106
    80107
    81108//salvar token
     
    153180
    154181    $dimensoes = [
    155         'estimate_height' => sanitize_text_field( doubleval($_POST['estimate_height']) ),
    156         'estimate_width' => sanitize_text_field( doubleval($_POST['estimate_width']) ),
    157         'estimate_length' => sanitize_text_field( doubleval($_POST['estimate_length']) ),
    158         'estimate_weight' => sanitize_text_field( doubleval($_POST['estimate_weight']) ),
     182        'estimate_height' => 0,
     183        'estimate_width' => 0,
     184        'estimate_length' => 0,
     185        'estimate_weight' => 0,
    159186    ];
    160187
  • unienvios/trunk/readme.txt

    r2765806 r2768020  
    55Requires at least: 4.7
    66Tested up to: 5.8
    7 Stable tag: 1.3.0
     7Stable tag: 1.3.1
    88Requires PHP: 7.2
    99License: GPLv3 or later
     
    7474* Adicionado prazo de entrega no carrinho
    7575= 1.3.0 =
     76
     77* Adicionado mensagem de erro ao verificar credencias
     78= 1.3.1 =
Note: See TracChangeset for help on using the changeset viewer.