Changeset 2533054
- Timestamp:
- 05/17/2021 01:41:31 PM (5 years ago)
- Location:
- appmax-woocommerce/trunk
- Files:
-
- 5 edited
-
appmax-woocommerce.php (modified) (2 diffs)
-
includes/class-awc-process-payment.php (modified) (10 diffs)
-
includes/class-awc-tracking-code.php (modified) (4 diffs)
-
includes/domain/class-awc-errors-api.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
appmax-woocommerce/trunk/appmax-woocommerce.php
r2529290 r2533054 3 3 * Plugin Name: AppMax WooCommerce 4 4 * Description: Gateway de pagamento AppMax para WooCommerce. 5 * Version: 2.0.3 75 * Version: 2.0.38 6 6 * License: GPLv2 or later 7 7 * Author: AppMax Plataforma de Vendas Ltda … … 24 24 class AppMax_WC 25 25 { 26 const VERSION = '2.0.3 7';26 const VERSION = '2.0.38'; 27 27 28 28 /** -
appmax-woocommerce/trunk/includes/class-awc-process-payment.php
r2510313 r2533054 36 36 if ( $this->awc_enable_debug() ) { 37 37 $log_content = ""; 38 $log_content .= "============================================================" . PHP_EOL; 38 39 $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; 39 40 $log_content .= sprintf( "* Meta Data \"_appmax_type_payment\": %s", AWC_Payment_Type::AWC_CREDIT_CARD ) . PHP_EOL; … … 45 46 // Send post to endpoint customer 46 47 $response_customer = $awc_api->awc_post_customer(); 48 49 $this->awc_verify_server( $response_customer ); 47 50 48 51 $response_customer_body = $this->awc_verify_post_customer( $response_customer ); … … 140 143 if ( $this->awc_enable_debug() ) { 141 144 $log_content = ""; 145 $log_content .= "============================================================" . PHP_EOL; 142 146 $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; 143 147 $log_content .= sprintf( "* Meta Data \"_appmax_type_payment\": %s", AWC_Payment_Type::AWC_BILLET ) . PHP_EOL; … … 149 153 // Send post to endpoint customer 150 154 $response_customer = $awc_api->awc_post_customer(); 155 156 $this->awc_verify_server( $response_customer ); 151 157 152 158 $response_customer_body = $this->awc_verify_post_customer( $response_customer ); … … 240 246 /** 241 247 * @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; 272 326 } 273 327 … … 277 331 * @throws Exception 278 332 */ 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 */ 279 364 private function awc_verify_post_order( $response ) 280 365 { 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 ); 290 367 291 368 $response_body = AWC_Helper::awc_decode_object( wp_remote_retrieve_body( $response ) ); 292 369 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 ); 295 374 296 375 if ($response_body->data) { 376 $message_exception .= "<ul>"; 297 377 foreach ($response_body->data as $item) { 298 $message_exception .= $item[0];378 $message_exception .= "<li>" . $item[0] . "</li>"; 299 379 } 380 $message_exception .= "</ul>"; 300 381 } 301 382 … … 312 393 * @throws Exception 313 394 */ 314 private function awc_verify_post_payment( $response, $order )395 private function awc_verify_post_payment($response, $order ) 315 396 { 316 397 $log_content = ""; 317 398 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>"; 329 423 } 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 } 353 429 354 430 if ( ! $response_body->success ) { … … 362 438 } 363 439 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 ); 365 441 throw new \Exception( $message_exception ); 366 442 } … … 385 461 $log_content .= sprintf( "* Meta Datas inseridas: %s", AWC_Helper::awc_encode_object( $meta_data ) ) . PHP_EOL; 386 462 $log_content .= PHP_EOL; 463 $log_content .= "============================================================"; 387 464 $this->awc_add_log( $log_content ); 388 465 } … … 485 562 return true; 486 563 } 487 488 489 564 } -
appmax-woocommerce/trunk/includes/class-awc-tracking-code.php
r2510320 r2533054 64 64 $order->add_order_note( sprintf( "Adicionado o código de rastreamento: %s", $tracking_code ), true ); 65 65 } 66 67 66 } 68 67 … … 128 127 private function validateResponse($response) 129 128 { 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 ); 139 130 140 131 $response_body = AWC_Helper::awc_decode_object( wp_remote_retrieve_body( $response ) ); 132 133 $this->awc_verify_access_token( $response_body ); 141 134 142 135 if ($response_body->success and $response_body->text == "Store delivery tracking code" ) { … … 144 137 } 145 138 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 ); 147 140 148 141 if ($response_body->data) { … … 170 163 $this->gateway->log->add( $this->gateway->id, $message ); 171 164 } 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 172 214 } -
appmax-woocommerce/trunk/includes/domain/class-awc-errors-api.php
r2510313 r2533054 7 7 class AWC_Errors_Api 8 8 { 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."; 10 13 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."; 12 18 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."; 23 21 } -
appmax-woocommerce/trunk/readme.txt
r2529290 r2533054 4 4 Requires at least: 4.0 5 5 Tested up to: 5.1 6 Stable tag: 2.0.3 76 Stable tag: 2.0.38 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 117 117 == Changelog == 118 118 119 = 2.0.38 = 120 121 * Ajustando mensagens de retorno para o cliente final. 122 119 123 = 2.0.37 = 120 124
Note: See TracChangeset
for help on using the changeset viewer.