Plugin Directory

Changeset 2533054


Ignore:
Timestamp:
05/17/2021 01:41:31 PM (5 years ago)
Author:
appmaxplataforma
Message:

Ajustando mensagens de retorno para o cliente final.

Location:
appmax-woocommerce/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • appmax-woocommerce/trunk/appmax-woocommerce.php

    r2529290 r2533054  
    33 * Plugin Name: AppMax WooCommerce
    44 * Description: Gateway de pagamento AppMax para WooCommerce.
    5  * Version: 2.0.37
     5 * Version: 2.0.38
    66 * License: GPLv2 or later
    77 * Author: AppMax Plataforma de Vendas Ltda
     
    2424    class AppMax_WC
    2525    {
    26         const VERSION = '2.0.37';
     26        const VERSION = '2.0.38';
    2727
    2828        /**
  • appmax-woocommerce/trunk/includes/class-awc-process-payment.php

    r2510313 r2533054  
    3636        if ( $this->awc_enable_debug() ) {
    3737            $log_content = "";
     38            $log_content .= "============================================================" . PHP_EOL;
    3839            $log_content .= sprintf( "* Appmax Credit Card - #%s - %s", $order->get_order_number(), AWC_Helper::awc_date_time_formatted( date( 'Y-m-d H:i:s' ) ) ) . PHP_EOL;
    3940            $log_content .= sprintf( "* Meta Data \"_appmax_type_payment\": %s", AWC_Payment_Type::AWC_CREDIT_CARD ) . PHP_EOL;
     
    4546        // Send post to endpoint customer
    4647        $response_customer = $awc_api->awc_post_customer();
     48
     49        $this->awc_verify_server( $response_customer );
    4750
    4851        $response_customer_body = $this->awc_verify_post_customer( $response_customer );
     
    140143        if ( $this->awc_enable_debug() ) {
    141144            $log_content = "";
     145            $log_content .= "============================================================" . PHP_EOL;
    142146            $log_content .= sprintf( "* Appmax Billet - #%s - %s", $order->get_order_number(), AWC_Helper::awc_date_time_formatted( date( 'Y-m-d H:i:s' ) ) ) . PHP_EOL;
    143147            $log_content .= sprintf( "* Meta Data \"_appmax_type_payment\": %s", AWC_Payment_Type::AWC_BILLET ) . PHP_EOL;
     
    149153        // Send post to endpoint customer
    150154        $response_customer = $awc_api->awc_post_customer();
     155
     156        $this->awc_verify_server( $response_customer );
    151157
    152158        $response_customer_body = $this->awc_verify_post_customer( $response_customer );
     
    240246    /**
    241247     * @param $response
    242      * @return array|mixed|object
    243      * @throws Exception
    244      */
    245     private function awc_verify_post_customer( $response )
    246     {
    247         if ( is_wp_error( $response ) ) {
    248             $message_exception = sprintf( "%s - %s", AWC_Errors_Api::AWC_ERROR_CUSTOMER, AWC_Errors_Api::AWC_MSG_001 );
    249             throw new \Exception( $message_exception );
    250         }
    251 
    252         if ( empty( $response["body"] ) ) {
    253             $message_exception = sprintf( "%s - %s", AWC_Errors_Api::AWC_ERROR_CUSTOMER, AWC_Errors_Api::AWC_MSG_002 );
    254             throw new \Exception( $message_exception );
    255         }
    256 
    257         $response_body = AWC_Helper::awc_decode_object( wp_remote_retrieve_body( $response ) );
    258 
    259         if ( ! $response_body->success and $response_body->text != "OK" ) {
    260             $message_exception = sprintf( "%s - %s", AWC_Errors_Api::AWC_ERROR_CUSTOMER, AWC_Errors_Api::AWC_MSG_003 );
    261 
    262             if ($response_body->data) {
    263                 foreach ($response_body->data as $item) {
    264                     $message_exception .= $item[0];
    265                 }
    266             }
    267 
    268             throw new \Exception( $message_exception );
    269         }
    270 
    271         return $response_body;
     248     * @return bool
     249     * @throws Exception
     250     */
     251    private function awc_verify_server( $response )
     252    {
     253        $this->awc_verify_errors_curl( $response );
     254
     255        $data = $response['headers']->getAll();
     256
     257        $log_content = "";
     258
     259        if (array_key_exists('cf-ray', $data) && $data['server'] == 'cloudflare') {
     260            $log_content .= sprintf( "%s", AWC_Errors_Api::AWC_MESSAGE_001 ) . PHP_EOL;
     261            $log_content .= sprintf( "%s - %s (Cloudflare)", $response['response']['code'], $response['response']['message'] ) . PHP_EOL;
     262            $this->awc_add_log( $log_content );
     263
     264            $message_exception = sprintf( "%s", AWC_Errors_Api::AWC_MESSAGE_001 );
     265            throw new \Exception( $message_exception );
     266        }
     267
     268        if ($data['server'] == 'nginx') {
     269            $log_content .= sprintf( "%s", AWC_Errors_Api::AWC_MESSAGE_002 ) . PHP_EOL;
     270            $log_content .= sprintf( "%s - %s (Nginx)", $response['response']['code'], $response['response']['message'] ) . PHP_EOL;
     271            $this->awc_add_log( $log_content );
     272
     273            $message_exception = sprintf( "%s", AWC_Errors_Api::AWC_MESSAGE_002 );
     274            throw new \Exception( $message_exception );
     275        }
     276
     277        return true;
     278    }
     279
     280    /**
     281     * @param $response_body
     282     * @return bool
     283     * @throws Exception
     284     */
     285    private function awc_verify_access_token( $response_body )
     286    {
     287        if ( ! $response_body->success and $response_body->text == AWC_Errors_Api::AWC_INVALID_ACCESS_TOKEN ) {
     288            $log_content = sprintf( "%s", AWC_Errors_Api::AWC_MESSAGE_004 ) . PHP_EOL;
     289            $this->awc_add_log( $log_content );
     290
     291            $message_exception = sprintf( "%s", AWC_Errors_Api::AWC_MESSAGE_004 );
     292            throw new \Exception( $message_exception );
     293        }
     294
     295        return true;
     296    }
     297
     298    /**
     299     * @param $response
     300     * @param $type
     301     * @return bool
     302     * @throws Exception
     303     */
     304    private function awc_verify_errors_curl($response, $type = null)
     305    {
     306        if (is_wp_error($response) && $response instanceof WP_Error) {
     307
     308            $log_content = "";
     309
     310            if (! $type) {
     311                $log_content .= sprintf( "%s", AWC_Errors_Api::AWC_MESSAGE_003 ) . PHP_EOL;
     312            }
     313
     314            if ($type) {
     315                $log_content .= sprintf( "%s - %s", $type, AWC_Errors_Api::AWC_MESSAGE_003 ) . PHP_EOL;
     316            }
     317
     318            $log_content .= sprintf( "Motivo: %s", $response->get_error_message() ) . PHP_EOL;
     319            $this->awc_add_log( $log_content );
     320
     321            $message_exception = sprintf( "%s", AWC_Errors_Api::AWC_MESSAGE_003 );
     322            throw new \Exception($message_exception);
     323        }
     324
     325        return true;
    272326    }
    273327
     
    277331     * @throws Exception
    278332     */
     333    private function awc_verify_post_customer( $response )
     334    {
     335        $this->awc_verify_errors_curl( $response, AWC_Errors_Api::AWC_MESSAGE_ERROR_CUSTOMER );
     336
     337        $response_body = AWC_Helper::awc_decode_object( wp_remote_retrieve_body( $response ) );
     338
     339        $this->awc_verify_access_token( $response_body );
     340
     341        if ( ! $response_body->success and $response_body->text == AWC_Errors_Api::AWC_VALIDATE_REQUEST ) {
     342
     343            $message_exception = sprintf( "%s", AWC_Errors_Api::AWC_MESSAGE_ERROR_CUSTOMER );
     344
     345            if ($response_body->data) {
     346                $message_exception .= "<ul>";
     347                foreach ($response_body->data as $item) {
     348                    $message_exception .= "<li>" . $item[0] . "</li>";
     349                }
     350                $message_exception .= "</ul>";
     351            }
     352
     353            throw new \Exception( $message_exception );
     354        }
     355
     356        return $response_body;
     357    }
     358
     359    /**
     360     * @param $response
     361     * @return array|mixed|object
     362     * @throws Exception
     363     */
    279364    private function awc_verify_post_order( $response )
    280365    {
    281         if ( is_wp_error( $response ) ) {
    282             $message_exception = sprintf( "%s - %s", AWC_Errors_Api::AWC_ERROR_ORDER, AWC_Errors_Api::AWC_MSG_001 );
    283             throw new \Exception( $message_exception );
    284         }
    285 
    286         if ( empty( $response["body"] ) ) {
    287             $message_exception = sprintf( "%s - %s", AWC_Errors_Api::AWC_ERROR_ORDER, AWC_Errors_Api::AWC_MSG_002 );
    288             throw new \Exception( $message_exception );
    289         }
     366        $this->awc_verify_errors_curl( $response, AWC_Errors_Api::AWC_MESSAGE_ERROR_ORDER );
    290367
    291368        $response_body = AWC_Helper::awc_decode_object( wp_remote_retrieve_body( $response ) );
    292369
    293         if ( ! $response_body->success and $response_body->text != "OK" ) {
    294             $message_exception = sprintf( "%s - %s", AWC_Errors_Api::AWC_ERROR_ORDER, AWC_Errors_Api::AWC_MSG_003 );
     370        $this->awc_verify_access_token( $response_body );
     371
     372        if ( ! $response_body->success and $response_body->text == AWC_Errors_Api::AWC_VALIDATE_REQUEST ) {
     373            $message_exception = sprintf( "%s", AWC_Errors_Api::AWC_MESSAGE_ERROR_ORDER );
    295374
    296375            if ($response_body->data) {
     376                $message_exception .= "<ul>";
    297377                foreach ($response_body->data as $item) {
    298                     $message_exception .= $item[0];
     378                    $message_exception .= "<li>" . $item[0] . "</li>";
    299379                }
     380                $message_exception .= "</ul>";
    300381            }
    301382
     
    312393     * @throws Exception
    313394     */
    314     private function awc_verify_post_payment( $response, $order )
     395    private function awc_verify_post_payment($response, $order )
    315396    {
    316397        $log_content = "";
    317398
    318         if ( is_wp_error( $response ) ) {
    319 
    320             $order->update_status( AWC_Order_Status::AWC_FAILED, AWC_Errors_Api::AWC_MSG_001 );
    321 
    322             if ( $this->awc_enable_debug() ) {
    323                 $log_content .= sprintf( "* Falha na transação %s ...", $order->get_order_number() ) . PHP_EOL;
    324                 $log_content .= sprintf( "* Motivo do cancelamento: %s.", AWC_Errors_Api::AWC_MSG_001 ) . PHP_EOL;
    325 
    326                 if ( $response->errors ) {
    327                     $message = $response->errors['http_request_failed'][0];
    328                     $log_content .= sprintf( "* Resposta de servidor: %s.", $message ) . PHP_EOL;
     399        if (is_wp_error($response) && $response instanceof WP_Error) {
     400
     401            $order->update_status( AWC_Order_Status::AWC_FAILED, AWC_Errors_Api::AWC_MESSAGE_ERROR_PAYMENT );
     402
     403            $log_content .= sprintf( "* Falha na transação %s ...", $order->get_order_number() ) . PHP_EOL;
     404            $log_content .= sprintf( "* Motivo do cancelamento: %s.", AWC_Errors_Api::AWC_MESSAGE_ERROR_PAYMENT ) . PHP_EOL;
     405            $log_content .= sprintf( "* Resposta de servidor: %s.", $response->get_error_message() ) . PHP_EOL;
     406            $this->awc_add_log( $log_content );
     407
     408            $message_exception = sprintf( "%s", AWC_Errors_Api::AWC_MESSAGE_ERROR_PAYMENT );
     409            throw new \Exception( $message_exception );
     410        }
     411
     412        $response_body = AWC_Helper::awc_decode_object( wp_remote_retrieve_body( $response ) );
     413
     414        $this->awc_verify_access_token( $response_body );
     415
     416        if ( ! $response_body->success and $response_body->text == AWC_Errors_Api::AWC_VALIDATE_REQUEST ) {
     417            $message_exception = sprintf( "%s", AWC_Errors_Api::AWC_MESSAGE_ERROR_PAYMENT );
     418
     419            if ($response_body->data) {
     420                $message_exception .= "<ul>";
     421                foreach ($response_body->data as $item) {
     422                    $message_exception .= "<li>" . $item[0] . "</li>";
    329423                }
    330 
    331                 $this->awc_add_log( $log_content );
    332             }
    333 
    334             $message_exception = sprintf( "%s - %s", AWC_Errors_Api::AWC_ERROR_PAYMENT, AWC_Errors_Api::AWC_MSG_001 );
    335             throw new \Exception( $message_exception );
    336         }
    337 
    338         if ( empty( $response["body"] ) ) {
    339 
    340             $order->update_status( AWC_Order_Status::AWC_FAILED, AWC_Errors_Api::AWC_MSG_002 );
    341 
    342             if ( $this->awc_enable_debug() ) {
    343                 $log_content .= sprintf( "* Falha na transação %s ...", $order->get_order_number() ) . PHP_EOL;
    344                 $log_content .= sprintf( "* Motivo do cancelamento: %s.", AWC_Errors_Api::AWC_MSG_002 ) . PHP_EOL;
    345                 $this->awc_add_log( $log_content );
    346             }
    347 
    348             $message_exception = sprintf( "%s - %s", AWC_Errors_Api::AWC_ERROR_PAYMENT, AWC_Errors_Api::AWC_MSG_002 );
    349             throw new \Exception( $message_exception );
    350         }
    351 
    352         $response_body = AWC_Helper::awc_decode_object( wp_remote_retrieve_body( $response ) );
     424                $message_exception .= "</ul>";
     425            }
     426
     427            throw new \Exception( $message_exception );
     428        }
    353429
    354430        if ( ! $response_body->success ) {
     
    362438            }
    363439
    364             $message_exception = sprintf( "%s - %s", AWC_Errors_Api::AWC_ERROR_PAYMENT, $response_body->text );
     440            $message_exception = sprintf( "%s - %s", AWC_Errors_Api::AWC_MESSAGE_ERROR_PAYMENT, $response_body->text );
    365441            throw new \Exception( $message_exception );
    366442        }
     
    385461            $log_content .= sprintf( "* Meta Datas inseridas: %s", AWC_Helper::awc_encode_object( $meta_data ) ) . PHP_EOL;
    386462            $log_content .= PHP_EOL;
     463            $log_content .= "============================================================";
    387464            $this->awc_add_log( $log_content );
    388465        }
     
    485562        return true;
    486563    }
    487 
    488 
    489564}
  • appmax-woocommerce/trunk/includes/class-awc-tracking-code.php

    r2510320 r2533054  
    6464            $order->add_order_note( sprintf( "Adicionado o código de rastreamento: %s", $tracking_code ), true );
    6565        }
    66 
    6766    }
    6867
     
    128127    private function validateResponse($response)
    129128    {
    130         if ( is_wp_error( $response ) ) {
    131             $message_exception = sprintf( "%s - %s", AWC_Errors_Api::AWC_ERROR_TRACKING, AWC_Errors_Api::AWC_MSG_001 );
    132             throw new \Exception( $message_exception );
    133         }
    134 
    135         if ( empty( $response["body"] ) ) {
    136             $message_exception = sprintf( "%s - %s", AWC_Errors_Api::AWC_ERROR_TRACKING, AWC_Errors_Api::AWC_MSG_002 );
    137             throw new \Exception( $message_exception );
    138         }
     129        $this->awc_verify_errors_curl( $response, AWC_Errors_Api::AWC_MESSAGE_ERROR_TRACKING );
    139130
    140131        $response_body = AWC_Helper::awc_decode_object( wp_remote_retrieve_body( $response ) );
     132
     133        $this->awc_verify_access_token( $response_body );
    141134
    142135        if ($response_body->success and $response_body->text == "Store delivery tracking code" ) {
     
    144137        }
    145138
    146         $message_exception = sprintf( "%s - %s", AWC_Errors_Api::AWC_ERROR_TRACKING, AWC_Errors_Api::AWC_MSG_003 );
     139        $message_exception = sprintf( "%s", AWC_Errors_Api::AWC_MESSAGE_ERROR_TRACKING );
    147140
    148141        if ($response_body->data) {
     
    170163        $this->gateway->log->add( $this->gateway->id, $message );
    171164    }
     165
     166    /**
     167     * @param $response
     168     * @param $type
     169     * @return bool
     170     * @throws Exception
     171     */
     172    private function awc_verify_errors_curl($response, $type = null)
     173    {
     174        if (is_wp_error($response) && $response instanceof WP_Error) {
     175
     176            $log_content = "";
     177
     178            if (! $type) {
     179                $log_content .= sprintf( "%s", AWC_Errors_Api::AWC_MESSAGE_003 ) . PHP_EOL;
     180            }
     181
     182            if ($type) {
     183                $log_content .= sprintf( "%s - %s", $type, AWC_Errors_Api::AWC_MESSAGE_003 ) . PHP_EOL;
     184            }
     185
     186            $log_content .= sprintf( "Motivo: %s", $response->get_error_message() );
     187            $this->awc_add_log( $log_content );
     188
     189            $message_exception = sprintf( "%s", AWC_Errors_Api::AWC_MESSAGE_003 );
     190            throw new \Exception($message_exception);
     191        }
     192
     193        return true;
     194    }
     195
     196    /**
     197     * @param $response_body
     198     * @return bool
     199     * @throws Exception
     200     */
     201    private function awc_verify_access_token( $response_body )
     202    {
     203        if ( ! $response_body->success and $response_body->text == AWC_Errors_Api::AWC_INVALID_ACCESS_TOKEN ) {
     204            $log_content = sprintf( "%s", AWC_Errors_Api::AWC_MESSAGE_004 ) . PHP_EOL;
     205            $this->awc_add_log( $log_content );
     206
     207            $message_exception = sprintf( "%s", AWC_Errors_Api::AWC_MESSAGE_004 );
     208            throw new \Exception( $message_exception );
     209        }
     210
     211        return true;
     212    }
     213
    172214}
  • appmax-woocommerce/trunk/includes/domain/class-awc-errors-api.php

    r2510313 r2533054  
    77class AWC_Errors_Api
    88{
    9     const AWC_ERROR_CUSTOMER = "Error[C]";
     9    const AWC_MESSAGE_001 = "Solicite a liberação de  IP.";
     10    const AWC_MESSAGE_002 = "Erro interno. Para mais informações entre em contato.";
     11    const AWC_MESSAGE_003 = "Há um problema de conexão com o gateway de pagamento. Desculpe pela inconveniência.";
     12    const AWC_MESSAGE_004 = "Chave de API inválida. Contate o gateway de pagamento.";
    1013
    11     const AWC_ERROR_ORDER    = "Error[O]";
     14    const AWC_MESSAGE_ERROR_CUSTOMER = "Erro no processamento de informações do cliente.";
     15    const AWC_MESSAGE_ERROR_ORDER = "Erro no processamento de informações do pedido.";
     16    const AWC_MESSAGE_ERROR_PAYMENT = "Erro no processamento de informações do pagamento.";
     17    const AWC_MESSAGE_ERROR_TRACKING = "Erro no processamento de informações do tracking.";
    1218
    13     const AWC_ERROR_PAYMENT  = "Error[P]";
    14 
    15     const AWC_ERROR_TRACKING  = "Error[T]";
    16 
    17     const AWC_MSG_001 = "Há um problema de conexão com o gateway de pagamento. Desculpe pela inconveniência.";
    18 
    19     const AWC_MSG_002 = "Nenhum dado foi obtido no retorno da resposta.";
    20 
    21     const AWC_MSG_003 = "Problemas ao realizar o processamento de informações.";
    22 
     19    const AWC_INVALID_ACCESS_TOKEN = "Invalid Access Token";
     20    const AWC_VALIDATE_REQUEST = "The given data failed to pass validation.";
    2321}
  • appmax-woocommerce/trunk/readme.txt

    r2529290 r2533054  
    44Requires at least: 4.0
    55Tested up to: 5.1
    6 Stable tag: 2.0.37
     6Stable tag: 2.0.38
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    117117== Changelog ==
    118118
     119= 2.0.38 =
     120
     121* Ajustando mensagens de retorno para o cliente final.
     122
    119123= 2.0.37 =
    120124
Note: See TracChangeset for help on using the changeset viewer.