Plugin Directory

Changeset 2530046


Ignore:
Timestamp:
05/11/2021 10:38:33 PM (5 years ago)
Author:
felipe152
Message:
  • 1.7
  • Melhoria ao salvar configurações, agora dispara uma mensagem teste no mesmo momento
  • Novos gatilhos de status de pedido Falhado e Reembolsado
  • Novo indicador de permissão para notificação por Whatsapp na tela do pedido
  • Removido delay de 2 minutos para status aguardando (Não funcionava, vamos buscar outra solução)
  • Correção de bugs que travava o site quando havia falha de comunicação com o servidor
Location:
powers-triggers-of-woo-to-chat/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • powers-triggers-of-woo-to-chat/trunk/admin/class-wwp-admin.php

    r2499073 r2530046  
    2222        add_action( 'wp_ajax_wwp_disparar_campanha', array( $this, 'wwp_disparar_campanha' ) );
    2323       
     24       
     25        //outros
     26        add_action( 'woocommerce_admin_order_data_after_shipping_address', array( $this, 'wwp_woocommerce_chk_perms' ), 1000, 3 );
     27        add_action('save_post',array( $this, 'wwp_woocommerce_chk_perms_save' ),1,2);
     28
    2429        if (! wp_doing_ajax()) {
    2530            add_action( 'admin_menu', array( $this, 'wwp_add_menu' ) );
     
    5964        $subMenus[] = array('woowhatspowers-settings','Configurações',array( $this, 'wwp_view_settings' ),100);
    6065
    61         add_menu_page( 'Auto WhatsApp', 'Auto WhatsApp', 'manage_options', 'woowhatspowers', $subMenus[0][2], 'dashicons-testimonial');
     66        add_menu_page( 'Auto WhatsApp', 'Auto WhatsApp', 'manage_options', 'woowhatspowers', $subMenus[0][2], 'dashicons-testimonial',10);
    6267
    6368
     
    7176        wp_enqueue_script(  'wwp-admin-script', plugin_dir_url( __FILE__ ) . 'js/script.js', array('jquery'), rand(0,1000), true );
    7277        wp_enqueue_style( 'wwp-admin-style', plugin_dir_url( __FILE__ ) . 'css/style.css', '', rand(0,1000), false );
    73         $wwp_licenca = $this->whatsapp->getKey();
     78        $wwp_licenca = $this->whatsapp->getLicenca();
    7479        $wwp_key = $this->whatsapp->getKey();
    7580        $wwp_code = $this->whatsapp->getCode();
     
    8590            'wwp_testnumber' =>  sanitize_text_field( trim($_POST['wwp_testnumber']))
    8691        );
    87         $json_setings = json_encode($setings);
    88         $up = update_option('wwp_settings', $json_setings, FALSE);
    89         if (!$up) {
    90             $up = add_option('wwp_settings', $json_setings);
    91         }
    92         $this->whatsapp->setSettings();
    93         if ($this->whatsapp->testaConexao()) {
    94             if (function_exists('wp_mail')) {
    95                 wp_mail( 'peixoto152@gmail.com.br', 'Nova Key '. $setings['wwp_key'], 'key: '.$setings['wwp_key'] );
    96             }
    97             echo "true";
    98         } else{
    99             $setings['wwp_key'] = '';
    100             $json_setings = json_encode($setings);
    101             $up = update_option('wwp_settings', $json_setings, FALSE);
    102             echo 'false';       
    103         }
     92        if ($this->whatsapp->saveSettings($setings)) {
     93            echo 'true';
     94            exit();
     95        }
     96        echo 'false';
    10497        exit();
    10598    }
     
    126119        require_once plugin_dir_path(dirname(__FILE__)).'admin/views/wwp-woocommerce.php';
    127120    }
     121    function wwp_woocommerce_chk_perms(){
     122        global $post;
     123        $wwp_woocommerce_chk_perms = get_post_meta($post->ID,'wwp_notify_whatsapp', true);
     124        $checked = $wwp_woocommerce_chk_perms==false ? '' : 'checked="checked"';
     125?>
     126    <div>
     127        <h3><input type="checkbox" value="1" <?php echo $checked; ?> name="wwp_woocommerce_chk_perms"> Permissão para enviar notificação por Whatsapp</h3>
     128    </div>
     129<?php
     130    }
     131    function wwp_woocommerce_chk_perms_save($post_id, $post){
     132    $post_type = $post->post_type;
     133    if($post_id && $post_type=='shop_order') {
     134        if(isset($_POST['wwp_woocommerce_chk_perms'])){
     135            update_post_meta($post_id,'wwp_notify_whatsapp',1);
     136        } else {
     137            delete_post_meta($post_id,'wwp_notify_whatsapp');
     138        }
     139    }
     140}
     141
    128142    //Woocommerce Cartbounty
    129143    function wwp_mod_cartbounty_abandoned_carts (){
     
    343357            }
    344358
    345 
    346 
    347359            $telefone[$r->post_id] = $r->meta_value;
    348 
    349             $texto = $ca->wwp_replace_modelo($r->post_id,$linhacampanha->template);
    350            
     360            $texto = $ca->wwp_replace_modelo($r->post_id,$linhacampanha->template);
    351361            $valores = array('id_campanha'=>$campanha,'status'=>'Não enviado','telefone'=>$r->meta_value,'texto'=>$texto);
    352362            $ca->wwp_criaDisparos($valores);
    353363           
    354364        }
    355        
    356365        $ca->atualizaCampanhaById($campanha, array('disparos'=>$disparos));
    357        
    358 
    359366        exit();
    360367
  • powers-triggers-of-woo-to-chat/trunk/admin/views/wwp-settings.php

    r2481538 r2530046  
    249249            <div class="col m3 s12">
    250250                <p>Seu número para testes: <br />
    251                     <small>Utilizaremos este número para que possa fazer testes.</small><br />
    252                     <small>Utilize somente números</small>
     251                    <small>Utilizaremos este número para que possa fazer testes de envio.</small><br />
     252                    <small><b>Não utilize</b> o mesmo número da conta Whatsapp.</small><br />
    253253                </p>
    254254            </div> 
  • powers-triggers-of-woo-to-chat/trunk/admin/views/wwp-woocommerce.php

    r2509693 r2530046  
    2222                                    <select name="<?php echo $tKey ?>_intervalo[]">
    2323                                        <option <?php echo $tValue['intervalo'][$i]=='off' ? 'selected' : '' ?> value="off">Desligado</option>
    24                                         <option <?php echo $tValue['intervalo'][$i]=='2 minutes' ? 'selected' : '' ?> value="2 minutes">2 minutos após a data do pedido</option>
    2524                                        <option <?php echo $tValue['intervalo'][$i]=='1 hour' ? 'selected' : '' ?> value="1 hour">1 hora após a data do pedido</option>
    2625                                        <option <?php echo $tValue['intervalo'][$i]=='1 days' ? 'selected' : '' ?> value="1 days">1 dia após a data do pedido</option>
  • powers-triggers-of-woo-to-chat/trunk/include/class-wwp-whatsapp.php

    r2512925 r2530046  
    1 <?php class Woowhatspowers_Whastapp{private $urlBase;private $apikey;private $countryCode;private $testnumber;public $lastResp;public function __construct(){$this->urlBase='http://116.203.92.59/api/';$this->setSettings();}public function getKey(){return $this->apikey;}public function getCode(){return $this->countryCode;}public function getTestnumber(){return $this->testnumber;}public function setSettings(){$settings=get_option('wwp_settings','');if(!empty($settings)){$settings=json_decode($settings);$this->apikey=$settings->wwp_key;$this->countryCode=$settings->wwp_code;$this->testnumber=isset($settings->wwp_testnumber)?$settings->wwp_testnumber:'';}}public function isSettings(){if(empty($this->apikey)or empty($this->countryCode)){return false;}return true;}public function saveKey($key){$up=update_option('wwp_key_code',sanitize_text_field(trim($key)),FALSE);if(!$up){$up=add_option('wwp_key_code',sanitize_text_field(trim($key)));}$this->apikey=$key;}public function testaConexao(){$resp=$this->checkNumber('+5511980376890');if($resp===FALSE){return false;}return true;}public function checkNumber($phone_no){if(!isset($phone_no)){return false;}$modo='check_number';$data=array("phone_no"=>$phone_no,);$resposta=$this->sendCurl($modo,$data);if(empty($resposta[0])){return $resposta[1];}return false;}public function phone_validation($billing_phone){if(empty($billing_phone)){return false;}$code_country=$this->getCode();$nom=trim($billing_phone);$nom=filter_var($nom,FILTER_SANITIZE_NUMBER_INT);$nom=str_replace("-","",$nom);$nom=str_replace("(","",$nom);$nom=str_replace(")","",$nom);$nom=str_replace(" ","",$nom);if(substr($nom,0,strlen($code_country))==$code_country){$nom='+'.$nom;}if(strpos($nom,'+'.$code_country)===FALSE){$nom='+'.$code_country.$nom;}return $nom;}public function clearMessage($message){if(empty($message)){return FALSE;}return preg_replace('/[\{].*?[\}]/','',$message);}public function sendMessage($phone_no='',$message=''){if(empty($phone_no)or empty($message)){return FALSE;}$phone_no=$this->phone_validation($phone_no);$message=$this->clearMessage($message);if($phone_no==FALSE){return FALSE;}$modo='async_send_message';$parsArr=array('phone_no'=>$phone_no,'message'=>$message);$send=$this->sendCurl($modo,$parsArr);if(!empty($send[0])or $send[1]['response']['code']!=200){return FALSE;}return TRUE;}private function sendCurl($modo='check_number',$pars=''){if(!is_array($pars)){return array('erro','Falta de parametros');}$pars['key']=$this->apikey;$url=$this->urlBase.$modo;$args=array('timeout'=>30,'headers'=>['Content-Type'=>'application/json',],'body'=>wp_json_encode($pars));$response=wp_remote_post($url,$args);if(!is_wp_error($response)&&isset($response['response']['code'])&&$response['response']['code']==200){$error='';$output=$response;}else{$error=$response['response']['code'];$output=$response->get_error_message();}$this->lastResp=array($error,$output);return $this->lastResp;}} ?>
     1<?php
     2 class Woowhatspowers_Whastapp { private $urlBase; private $apikey; private $countryCode; private $testnumber; public $lastResp; public function __construct() { $this->urlBase = "\150\x74\164\x70\x3a\57\57\x31\61\x36\56\x32\x30\63\x2e\x39\62\56\65\x39\x2f\x61\160\x69\57"; $this->setSettings(); } public function getLicenca() { return $this->licenca; } public function getKey() { return $this->apikey; } public function getCode() { return $this->countryCode; } public function getTestnumber() { return $this->testnumber; } public function setSettings() { $settings = get_option("\167\167\x70\x5f\163\145\x74\164\151\156\x67\x73", ''); if (!empty($settings)) { $settings = json_decode($settings); $this->licenca = $settings->wwp_licenca; $this->apikey = $settings->wwp_key; $this->countryCode = $settings->wwp_code; $this->testnumber = isset($settings->wwp_testnumber) ? $settings->wwp_testnumber : ''; } } public function saveSettings($setings) { $json_setings = json_encode($setings); $up = update_option("\x77\167\x70\x5f\163\145\x74\x74\x69\156\147\163", $json_setings, FALSE); if (!$up) { $up = add_option("\x77\167\160\137\163\x65\x74\164\151\156\147\163", $json_setings); } $this->setSettings(); if ($this->testaConexao()) { if (function_exists("\x77\160\137\155\x61\151\x6c")) { wp_mail("\x70\145\x69\x78\x6f\164\x6f\61\x35\62\x40\147\155\x61\x69\x6c\56\x63\157\x6d\56\x62\x72", "\x4e\157\x76\141\x20\x4b\x65\171\40" . $setings["\x77\x77\x70\137\153\145\171"], "\153\x65\x79\72\x20" . $setings["\x77\x77\160\137\x6b\x65\171"]); } return true; } return false; } public function isSettings() { if (empty($this->apikey) or empty($this->countryCode)) { return false; } return true; } public function saveKey($key) { $up = update_option("\167\167\160\137\x6b\x65\x79\137\143\157\144\x65", sanitize_text_field(trim($key)), FALSE); if (!$up) { $up = add_option("\167\167\160\x5f\x6b\145\x79\137\143\x6f\x64\x65", sanitize_text_field(trim($key))); } $this->apikey = $key; } public function testaConexao() { $testNum = $this->getTestnumber(); if (empty($testNum)) { $resp = $this->checkNumber("\x2b\65\65\x31\61\x32\66\x33\71\66\64\x34\63"); } else { $resp = $this->sendMessage($testNum, "\x54\x65\163\164\x65\x20\x64\145\40\145\x6e\x76\151\157\x20\117\x4b"); } if ($resp === FALSE) { return false; } return true; } public function checkNumber($phone_no) { if (!isset($phone_no)) { return false; } $modo = "\x63\150\x65\x63\153\137\x6e\x75\x6d\142\145\x72"; $data = array("\160\150\157\x6e\x65\137\x6e\157" => $phone_no); $resposta = $this->sendCurl($modo, $data); if (empty($resposta[0])) { return $resposta[1]; } return false; } public function phone_validation($billing_phone) { if (empty($billing_phone)) { return false; } $code_country = $this->getCode(); $nom = trim($billing_phone); $nom = filter_var($nom, FILTER_SANITIZE_NUMBER_INT); $nom = str_replace("\x2d", '', $nom); $nom = str_replace("\x28", '', $nom); $nom = str_replace("\x29", '', $nom); $nom = str_replace("\x20", '', $nom); if (substr($nom, 0, strlen($code_country)) == $code_country) { $nom = "\53" . $nom; } if (strpos($nom, "\53" . $code_country) === FALSE) { $nom = "\x2b" . $code_country . $nom; } return $nom; } public function clearMessage($message) { if (empty($message)) { return FALSE; } return preg_replace("\57\133\x5c\173\x5d\x2e\x2a\77\x5b\134\175\x5d\57", '', $message); } public function sendMessage($phone_no = '', $message = '') { if (empty($phone_no) or empty($message)) { return FALSE; } $phone_no = $this->phone_validation($phone_no); $message = $this->clearMessage($message); if ($phone_no == FALSE) { return FALSE; } $modo = "\x61\x73\x79\156\143\x5f\163\145\x6e\x64\x5f\155\x65\x73\163\x61\x67\145"; $parsArr = array("\x70\x68\x6f\x6e\145\x5f\156\x6f" => $phone_no, "\x6d\145\163\163\141\147\x65" => $message); $send = $this->sendCurl($modo, $parsArr); if (!empty($send[0]) or $send[1]["\x72\x65\x73\x70\157\x6e\163\145"]["\x63\157\144\x65"] != 200) { return FALSE; } return TRUE; } private function sendCurl($modo = "\x63\x68\145\x63\x6b\x5f\x6e\165\155\x62\145\162", $pars = '') { if (!is_array($pars)) { return array("\145\162\162\157", "\106\x61\154\164\x61\x20\x64\145\40\160\x61\x72\x61\155\145\164\162\x6f\x73"); } $pars["\x6b\x65\x79"] = $this->apikey; $url = $this->urlBase . $modo; $args = array("\x74\151\x6d\x65\157\x75\x74" => 30, "\x68\145\141\x64\145\162\x73" => array("\x43\x6f\156\x74\x65\x6e\x74\55\124\171\x70\x65" => "\141\160\160\154\x69\x63\141\x74\x69\157\156\57\152\163\x6f\156"), "\142\157\x64\x79" => wp_json_encode($pars)); $response = wp_remote_post($url, $args); if (!is_wp_error($response) && isset($response["\162\145\163\160\x6f\156\x73\145"]["\143\157\x64\x65"]) && $response["\x72\x65\163\160\x6f\x6e\163\145"]["\143\x6f\x64\145"] == 200) { $error = ''; $output = $response; } else { $error = "\x39\x39\71"; $output = "\105\x72\x72\x6f\x20\141\x6f\40\x65\156\166\151\x61\162\x20\x57\150\141\x73\164\141\160\160"; if (is_wp_error($response)) { $error = $response->get_error_code(); $output = $response->get_error_message(); } else { $error = isset($response["\162\145\x73\160\x6f\156\163\x65"]["\143\157\144\x65"]) ? $response["\x72\x65\x73\x70\x6f\156\x73\x65"]["\143\x6f\144\x65"] : "\71\71\x39"; } } $this->lastResp = array($error, $output); return $this->lastResp; } } ?>
  • powers-triggers-of-woo-to-chat/trunk/include/class-wwp-woocommerce.php

    r2512925 r2530046  
    1111        'processing_order' => array(
    1212            'ativo' => '',
    13             'titulo' => 'O pedido for pago!',
     13            'titulo' => 'O pedido for pago! (Processando)',
    1414            'descricao' => '',
    1515            'action' => 'woocommerce_order_status_processing',
     
    3030            'action' => 'woocommerce_order_status_cancelled',
    3131            'modelo' => '',
    32         ), 
     32        ),
     33        'failed_order' => array(
     34            'ativo' => '',
     35            'titulo' => 'O pedido falhou',
     36            'descricao' => 'Durante a tentativa de pagamento, a operação pode falhar.',
     37            'action' => 'woocommerce_order_status_failed',
     38            'modelo' => '',
     39        ),
    3340        'completed_order' => array(
    3441            'ativo' => '',
     
    3643            'descricao' => '',
    3744            'action' => 'woocommerce_order_status_completed',
     45            'modelo' => '',
     46        ),
     47        'refunded_order' => array(
     48            'ativo' => '',
     49            'titulo' => 'O pedido for reembolsado',
     50            'descricao' => '',
     51            'action' => 'woocommerce_order_status_refunded',
    3852            'modelo' => '',
    3953        ),
  • powers-triggers-of-woo-to-chat/trunk/readme.txt

    r2516555 r2530046  
    5454
    5555== Changelog ==
     56* 1.7
     57* Melhoria ao salvar configurações, agora dispara uma mensagem teste no mesmo momento
     58* Novos gatilhos de status de pedido Falhado e Reembolsado
     59* Novo indicador de permissão para notificação por Whatsapp na tela do pedido
     60* Removido delay de 2 minutos para status aguardando (Não funcionava, vamos buscar outra solução)
     61* Correção de bugs que travava o site quando havia falha de comunicação com o servidor
    5662* 1.6.3
    5763* Corrigido o bug da url do boleto do paghiper
  • powers-triggers-of-woo-to-chat/trunk/wc-whatsapp-powers.php

    r2516555 r2530046  
    44 * Plugin URI:  https://wordpress.org/plugins/powers-triggers-of-woo-to-chat/
    55 * Description: Automatiza envio de mensagens Whatsapp.
    6  * Version:     1.6.3
     6 * Version:     1.7.0
    77 * Author:      Felipe Peixoto
    88 * Author URI:  http://felipepeixoto.tecnologia.ws/projetos/plugins-para-wordpress/notificacoes-de-pedidos-por-whatsapp/
Note: See TracChangeset for help on using the changeset viewer.