Changeset 2589822
- Timestamp:
- 08/27/2021 12:09:21 PM (4 years ago)
- Location:
- appmax-woocommerce/trunk
- Files:
-
- 6 added
- 11 edited
-
appmax-woocommerce.php (modified) (8 diffs)
-
assets/js/my-scripts/awc_pix.js (added)
-
assets/js/my-scripts/awc_pix.min.js (added)
-
includes/class-awc-api.php (modified) (2 diffs)
-
includes/class-awc-form-payment.php (modified) (1 diff)
-
includes/class-awc-gateway-billet.php (modified) (1 diff)
-
includes/class-awc-gateway-credit-card.php (modified) (1 diff)
-
includes/class-awc-gateway-pix.php (added)
-
includes/class-awc-post-payment.php (modified) (1 diff)
-
includes/class-awc-process-payment.php (modified) (3 diffs)
-
includes/class-awc-search-gateway.php (modified) (1 diff)
-
includes/domain/class-awc-payment-type.php (modified) (1 diff)
-
includes/domain/class-awc-suffix-api.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
templates/views/pix (added)
-
templates/views/pix/form-appmax.php (added)
-
templates/views/pix/pix-payment.php (added)
Legend:
- Unmodified
- Added
- Removed
-
appmax-woocommerce/trunk/appmax-woocommerce.php
r2578312 r2589822 3 3 * Plugin Name: AppMax WooCommerce 4 4 * Description: Gateway de pagamento AppMax para WooCommerce. 5 * Version: 2.0.4 15 * Version: 2.0.42 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.4 1';26 const VERSION = '2.0.42'; 27 27 28 28 /** … … 59 59 add_action( 'wp_ajax_woocommerce_correios_add_tracking_code', array( $this, 'awc_send_correios_to_appmax' ), 1); 60 60 61 add_action( 'wp_ajax_update_order_status', array($this, 'awc_update_order_status')); 62 add_action( 'wp_ajax_nopriv_update_order_status', array($this, 'awc_update_order_status')); 63 61 64 add_action( 'woocommerce_order_details_after_order_table', array( $this, 'awc_show_link_billet' ) ); 65 add_action( 'woocommerce_order_details_after_order_table', array( $this, 'awc_show_pix_qrcode' ) ); 62 66 } else { 63 67 add_action( 'admin_notices', array( $this, 'awc_woocommerce_not_installed' ) ); … … 65 69 } 66 70 71 public function awc_update_order_status(){ 72 73 if ( isset($_POST['order_id']) && $_POST['order_id'] > 0 ) { 74 $order = wc_get_order($_POST['order_id']); 75 $order->update_status( AWC_Order_Status::AWC_COMPLETED ); 76 die(); 77 } 78 } 79 67 80 public function awc_send_to_appmax() 68 81 { … … 87 100 $methods[] = 'AWC_Gateway_Credit_Card'; 88 101 $methods[] = 'AWC_Gateway_Billet'; 102 $methods[] = 'AWC_Gateway_Pix'; 89 103 return $methods; 90 104 } … … 124 138 125 139 /** 140 * Add pix template when the payment is by pix 141 * 142 * @param $order 143 */ 144 public function awc_show_pix_qrcode( $order ) 145 { 146 if ( $order->get_meta( '_appmax_type_payment' ) == AWC_Payment_Type::AWC_PIX ) { 147 148 $pix_template = dirname( __FILE__ ) . '/templates/views/checkout/pix/pix-payment.php'; 149 150 if(file_exists($pix_template)){ 151 include $pix_template; 152 } 153 } 154 } 155 156 /** 126 157 * Include woocommerce-not-installed.php 127 158 */ … … 151 182 $this->awc_define( 'AWC_GATEWAY_ID_BILLET', 'appmax-billet' ); 152 183 $this->awc_define( 'AWC_GATEWAY_ID_CREDIT_CARD', 'appmax-credit-card' ); 184 $this->awc_define( 'AWC_GATEWAY_ID_PIX', 'appmax-pix' ); 153 185 $this->awc_define( 'AWC_APPMAX_WEB_HOOK', 'appmax-webhook' ); 154 155 186 $this->awc_define( 'AWC_URL_API_DOMAIN', 'https://admin.appmax.com.br/api/v3/' ); 156 187 $this->awc_define( 'AWC_HOST_DOMAIN', '' ); … … 178 209 include_once AWC_ABSPATH . '/includes/class-awc-gateway-billet.php'; 179 210 include_once AWC_ABSPATH . '/includes/class-awc-gateway-credit-card.php'; 211 include_once AWC_ABSPATH . '/includes/class-awc-gateway-pix.php'; 180 212 include_once AWC_ABSPATH . '/includes/class-awc-helper.php'; 181 213 include_once AWC_ABSPATH . '/includes/class-awc-interest.php'; -
appmax-woocommerce/trunk/includes/class-awc-api.php
r2578312 r2589822 141 141 } 142 142 143 if ( $information['type_payment'] == AWC_Payment_Type::AWC_PIX ) { 144 return $this->awc_payment_pix( $information['order_id'], $information['customer_id'], $information['post_payment'] ); 145 } 146 143 147 return $this->awc_payment_credit_card( $information['order_id'], $information['customer_id'], $information['post_payment'] ); 144 148 } … … 202 206 203 207 /** 208 * @param $order_id 209 * @param $customer_id 210 * @param $post_payment 211 * @return array|WP_Error 212 */ 213 private function awc_payment_pix( $order_id, $customer_id, $post_payment ) 214 { 215 $data = [ 216 "cart" => [ 217 "order_id" => $order_id, 218 ], 219 "customer" => [ 220 "customer_id" => $customer_id, 221 ], 222 "payment" => [ 223 "pix" => [ 224 "document_number" => $post_payment['cpf_pix'], 225 ], 226 ], 227 ]; 228 229 return $this->awc_post( $this->awc_get_full_url( AWC_Suffix_Api::AWC_SUFFIX_PAYMENT_PIX ), $data ); 230 } 231 232 /** 204 233 * @return array 205 234 */ -
appmax-woocommerce/trunk/includes/class-awc-form-payment.php
r2181704 r2589822 72 72 return "<script src=" . plugins_url( AWC_PLUGIN_ROOT_PATH . "/assets/js/my-scripts/awc_billet.min.js" ) . "></script>"; 73 73 } 74 75 public static function awc_display_script_payment_pix() 76 { 77 return "<script src=" . plugins_url( AWC_PLUGIN_ROOT_PATH . "/assets/js/my-scripts/awc_pix.min.js" ) . "></script>"; 78 } 74 79 } -
appmax-woocommerce/trunk/includes/class-awc-gateway-billet.php
r2283159 r2589822 165 165 166 166 AWC_Validation::awc_unset_variables_post( $_POST, AWC_Post_Payment::awc_get_structure_post_credit_card() ); 167 AWC_Validation::awc_unset_variables_post( $_POST, AWC_Post_Payment::awc_get_structure_post_pix() ); 167 168 168 169 list( $validation, $message ) = AWC_Validation::awc_validation_fields( $_POST, AWC_Post_Payment::awc_get_structure_post_billet() ); -
appmax-woocommerce/trunk/includes/class-awc-gateway-credit-card.php
r2413916 r2589822 243 243 244 244 AWC_Validation::awc_unset_variables_post( $_POST, AWC_Post_Payment::awc_get_structure_post_billet() ); 245 AWC_Validation::awc_unset_variables_post( $_POST, AWC_Post_Payment::awc_get_structure_post_pix() ); 245 246 246 247 list( $validation, $message ) = AWC_Validation::awc_validation_fields( $_POST, AWC_Post_Payment::awc_get_structure_post_credit_card() ); -
appmax-woocommerce/trunk/includes/class-awc-post-payment.php
r2127366 r2589822 14 14 'messages' => array( 15 15 AWC_Validation_Type::AWC_EMPTY => 'Necessário preencher o CPF para emissão da nota fiscal!', 16 AWC_Validation_Type::AWC_CPF => 'CPF inválido!', 17 ), 18 ), 19 ); 20 } 21 22 public static function awc_get_structure_post_pix() 23 { 24 return array( 25 'cpf_pix' => array( 26 'validation' => 'empty|cpf', 27 'messages' => array( 28 AWC_Validation_Type::AWC_EMPTY => 'Necessário preencher o CPF!', 16 29 AWC_Validation_Type::AWC_CPF => 'CPF inválido!', 17 30 ), -
appmax-woocommerce/trunk/includes/class-awc-process-payment.php
r2533270 r2589822 245 245 246 246 /** 247 * @param $order_id 248 * @return array 249 * @throws Exception 250 */ 251 public function awc_process_payment_pix( $order_id ) 252 { 253 $order = wc_get_order( $order_id ); 254 255 $order->add_meta_data( '_appmax_type_payment', AWC_Payment_Type::AWC_PIX ); 256 257 if ( $this->awc_enable_debug() ) { 258 $log_content = ""; 259 $log_content .= "============================================================" . PHP_EOL; 260 $log_content .= sprintf( "* Appmax Pix - #%s - %s", $order->get_order_number(), AWC_Helper::awc_date_time_formatted( date( 'Y-m-d H:i:s' ) ) ) . PHP_EOL; 261 $log_content .= sprintf( "* Meta Data \"_appmax_type_payment\": %s", AWC_Payment_Type::AWC_PIX ) . PHP_EOL; 262 $this->awc_add_log( $log_content ); 263 } 264 265 $awc_api = new AWC_Api( $this->gateway, $order ); 266 267 // Send post to endpoint customer 268 $response_customer = $awc_api->awc_post_customer(); 269 270 $this->awc_verify_server( $response_customer ); 271 272 $response_customer_body = $this->awc_verify_post_customer( $response_customer ); 273 274 if ( $this->awc_enable_debug() ) { 275 $log_content = ""; 276 $log_content .= "* Informações do endpoint \"/customer\"" . PHP_EOL; 277 $log_content .= sprintf( "* Response Json: %s", AWC_Helper::awc_encode_object( $response_customer_body->data ) ) . PHP_EOL; 278 $log_content .= PHP_EOL; 279 $this->awc_add_log( $log_content ); 280 } 281 282 $interest_total = 0; 283 284 // Send post to endpoint order 285 $response_order = $awc_api->awc_post_order( $response_customer_body->data->id, $interest_total ); 286 287 $response_order_body = $this->awc_verify_post_order( $response_order ); 288 289 $order->add_order_note( sprintf( "Appmax Order ID: %s", $response_order_body->data->id ), true ); 290 291 $order->add_meta_data( '_appmax_order_id', $response_order_body->data->id ); 292 293 $order->add_meta_data( '_appmax_tracking_code','' ); 294 295 update_post_meta( $order->get_order_number(),'appmax_tracking_code', '' ); 296 297 update_post_meta( $order->get_order_number(),'appmax_order_id', $response_order_body->data->id ); 298 299 if ( $this->awc_enable_debug() ) { 300 $log_content = ""; 301 $log_content .= "* Informações do endpoint \"/order\"" . PHP_EOL; 302 $log_content .= sprintf( "* Response Json: %s", AWC_Helper::awc_encode_object( $response_order_body->data ) ) . PHP_EOL; 303 $log_content .= PHP_EOL; 304 $this->awc_add_log( $log_content ); 305 } 306 307 $post_payment = AWC_Process_Payment::awc_make_post_payment_pix(); 308 309 $information = array( 310 'order_id' => $response_order_body->data->id, 311 'customer_id' => $response_customer_body->data->id, 312 'post_payment' => $post_payment, 313 'type_payment' => AWC_Payment_Type::AWC_PIX, 314 ); 315 316 // Send post to endpoint payment 317 $response_payment = $awc_api->awc_post_payment( $information ); 318 319 $response_payment_body = $this->awc_verify_post_payment( $response_payment, $order ); 320 321 $order->update_status( AWC_Order_Status::AWC_PENDING ); 322 323 $order->add_order_note( sprintf( "Pay Reference: %s", $response_payment_body->data->pay_reference ), true ); 324 $order->add_meta_data( '_appmax_pay_reference', $response_payment_body->data->pay_reference ); 325 326 update_post_meta( $order->get_order_number(),'appmax_pay_reference', $response_payment_body->data->pay_reference ); 327 328 if ( $this->awc_enable_debug() ) { 329 $log_content = ""; 330 $log_content .= "* Informações do endpoint \"/payment/pix\"" . PHP_EOL; 331 $log_content .= sprintf( "* Response Json: %s", AWC_Helper::awc_encode_object( $response_payment_body ) ) . PHP_EOL; 332 $this->awc_add_log( $log_content ); 333 } 334 335 $post_payment['pay_reference'] = $response_payment_body->data->pay_reference; 336 $post_payment['pix_qrcode'] = $response_payment_body->data->pix_qrcode; 337 $post_payment['pix_emv'] = $response_payment_body->data->pix_emv; 338 $post_payment['pix_expiration_date'] = $response_payment_body->data->pix_expiration_date; 339 $post_payment['order_id'] = $response_order_body->data->id; 340 341 $this->awc_save_order_meta_fields( $order->get_order_number(), [ 342 'type_payment' => AWC_Payment_Type::AWC_PIX, 343 'post_payment' => $post_payment, 344 ] ); 345 346 WC()->cart->empty_cart(); 347 348 return array( 349 'result' => 'success', 350 'redirect' => $this->gateway->get_return_url( $order ), 351 ); 352 } 353 354 /** 247 355 * @param $response 248 356 * @return bool … … 409 517 throw new \Exception( $message_exception ); 410 518 } 519 411 520 412 521 $response_body = AWC_Helper::awc_decode_object( wp_remote_retrieve_body( $response ) ); 522 413 523 414 524 $this->awc_verify_access_token( $response_body ); … … 507 617 508 618 /** 619 * @return array 620 */ 621 private static function awc_make_post_payment_pix() 622 { 623 return array( 624 'cpf_pix' => AWC_Helper::awc_cpf_unformatted( AWC_Helper::awc_clear_input( $_POST['cpf_pix'] ) ), 625 ); 626 } 627 628 /** 509 629 * @return bool 510 630 */ -
appmax-woocommerce/trunk/includes/class-awc-search-gateway.php
r2178552 r2589822 35 35 return unserialize( $result->option_value ); 36 36 } 37 38 public static function awc_get_gateway_pix() 39 { 40 global $wpdb; 41 42 $gateway = 'woocommerce_appmax-pix_settings'; 43 44 $sql = 'select option_value from %s where option_name = \'%s\' limit 1'; 45 $stmt = sprintf( $sql, $wpdb->options, $gateway); 46 $result = $wpdb->get_row( $stmt, OBJECT ); 47 48 return unserialize( $result->option_value ); 49 } 37 50 } -
appmax-woocommerce/trunk/includes/domain/class-awc-payment-type.php
r2127366 r2589822 10 10 11 11 const AWC_CREDIT_CARD = 'CreditCard'; 12 13 const AWC_PIX = 'Pix'; 12 14 } -
appmax-woocommerce/trunk/includes/domain/class-awc-suffix-api.php
r2510313 r2589822 14 14 15 15 const AWC_SUFFIX_PAYMENT_CREDIT_CARD = "payment/credit-card/"; 16 17 const AWC_SUFFIX_PAYMENT_PIX = "payment/pix/"; 16 18 17 19 const AWC_SUFFIX_PAYMENT_INSTALLMENTS = "payment/installments/"; -
appmax-woocommerce/trunk/readme.txt
r2578312 r2589822 4 4 Requires at least: 4.0 5 5 Tested up to: 5.1 6 Stable tag: 2.0.4 16 Stable tag: 2.0.42 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 115 115 Logs de transações de Boleto: **appmax-billet-{DATA-ATUAL}-{HASH}** 116 116 117 Logs de transações de Pix: **appmax-pix-{DATA-ATUAL}-{HASH}** 118 117 119 == Changelog == 120 121 = 2.0.42 = 122 123 * Adicionado opção de pagamento via Pix com notificação em caso de pedido aprovado. 118 124 119 125 = 2.0.41 =
Note: See TracChangeset
for help on using the changeset viewer.