Plugin Directory

Changeset 2589822


Ignore:
Timestamp:
08/27/2021 12:09:21 PM (4 years ago)
Author:
appmaxplataforma
Message:

Subindo novo método de pagamento pix ao plugin.

Location:
appmax-woocommerce/trunk
Files:
6 added
11 edited

Legend:

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

    r2578312 r2589822  
    33 * Plugin Name: AppMax WooCommerce
    44 * Description: Gateway de pagamento AppMax para WooCommerce.
    5  * Version: 2.0.41
     5 * Version: 2.0.42
    66 * License: GPLv2 or later
    77 * Author: AppMax Plataforma de Vendas Ltda
     
    2424    class AppMax_WC
    2525    {
    26         const VERSION = '2.0.41';
     26        const VERSION = '2.0.42';
    2727
    2828        /**
     
    5959                add_action( 'wp_ajax_woocommerce_correios_add_tracking_code',  array( $this, 'awc_send_correios_to_appmax' ), 1);
    6060
     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
    6164                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' ) );
    6266            } else {
    6367                add_action( 'admin_notices', array( $this, 'awc_woocommerce_not_installed' ) );
     
    6569        }
    6670
     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
    6780        public function awc_send_to_appmax()
    6881        {
     
    87100            $methods[] = 'AWC_Gateway_Credit_Card';
    88101            $methods[] = 'AWC_Gateway_Billet';
     102            $methods[] = 'AWC_Gateway_Pix';
    89103            return $methods;
    90104        }
     
    124138
    125139        /**
     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        /**
    126157         * Include woocommerce-not-installed.php
    127158         */
     
    151182            $this->awc_define( 'AWC_GATEWAY_ID_BILLET', 'appmax-billet' );
    152183            $this->awc_define( 'AWC_GATEWAY_ID_CREDIT_CARD', 'appmax-credit-card' );
     184            $this->awc_define( 'AWC_GATEWAY_ID_PIX', 'appmax-pix' );
    153185            $this->awc_define( 'AWC_APPMAX_WEB_HOOK', 'appmax-webhook' );
    154 
    155186            $this->awc_define( 'AWC_URL_API_DOMAIN', 'https://admin.appmax.com.br/api/v3/' );
    156187            $this->awc_define( 'AWC_HOST_DOMAIN', '' );
     
    178209            include_once AWC_ABSPATH . '/includes/class-awc-gateway-billet.php';
    179210            include_once AWC_ABSPATH . '/includes/class-awc-gateway-credit-card.php';
     211            include_once AWC_ABSPATH . '/includes/class-awc-gateway-pix.php';
    180212            include_once AWC_ABSPATH . '/includes/class-awc-helper.php';
    181213            include_once AWC_ABSPATH . '/includes/class-awc-interest.php';
  • appmax-woocommerce/trunk/includes/class-awc-api.php

    r2578312 r2589822  
    141141        }
    142142
     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
    143147        return $this->awc_payment_credit_card( $information['order_id'], $information['customer_id'], $information['post_payment'] );
    144148    }
     
    202206
    203207    /**
     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    /**
    204233     * @return array
    205234     */
  • appmax-woocommerce/trunk/includes/class-awc-form-payment.php

    r2181704 r2589822  
    7272        return "<script src=" . plugins_url( AWC_PLUGIN_ROOT_PATH . "/assets/js/my-scripts/awc_billet.min.js" ) . "></script>";
    7373    }
     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    }
    7479}
  • appmax-woocommerce/trunk/includes/class-awc-gateway-billet.php

    r2283159 r2589822  
    165165
    166166        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() );
    167168
    168169        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  
    243243
    244244            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() );
    245246
    246247            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  
    1414                'messages' => array(
    1515                    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!',
    1629                    AWC_Validation_Type::AWC_CPF   => 'CPF inválido!',
    1730                ),
  • appmax-woocommerce/trunk/includes/class-awc-process-payment.php

    r2533270 r2589822  
    245245
    246246    /**
     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    /**
    247355     * @param $response
    248356     * @return bool
     
    409517            throw new \Exception( $message_exception );
    410518        }
     519       
    411520
    412521        $response_body = AWC_Helper::awc_decode_object( wp_remote_retrieve_body( $response ) );
     522
    413523
    414524        $this->awc_verify_access_token( $response_body );
     
    507617
    508618    /**
     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    /**
    509629     * @return bool
    510630     */
  • appmax-woocommerce/trunk/includes/class-awc-search-gateway.php

    r2178552 r2589822  
    3535        return unserialize( $result->option_value );
    3636    }
     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    }
    3750}
  • appmax-woocommerce/trunk/includes/domain/class-awc-payment-type.php

    r2127366 r2589822  
    1010
    1111    const AWC_CREDIT_CARD = 'CreditCard';
     12
     13    const AWC_PIX = 'Pix';
    1214}
  • appmax-woocommerce/trunk/includes/domain/class-awc-suffix-api.php

    r2510313 r2589822  
    1414
    1515    const AWC_SUFFIX_PAYMENT_CREDIT_CARD = "payment/credit-card/";
     16   
     17    const AWC_SUFFIX_PAYMENT_PIX = "payment/pix/";
    1618
    1719    const AWC_SUFFIX_PAYMENT_INSTALLMENTS = "payment/installments/";
  • appmax-woocommerce/trunk/readme.txt

    r2578312 r2589822  
    44Requires at least: 4.0
    55Tested up to: 5.1
    6 Stable tag: 2.0.41
     6Stable tag: 2.0.42
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    115115Logs de transações de Boleto: **appmax-billet-{DATA-ATUAL}-{HASH}**
    116116
     117Logs de transações de Pix: **appmax-pix-{DATA-ATUAL}-{HASH}**
     118
    117119== Changelog ==
     120
     121= 2.0.42 =
     122
     123* Adicionado opção de pagamento via Pix com notificação em caso de pedido aprovado.
    118124
    119125= 2.0.41 =
Note: See TracChangeset for help on using the changeset viewer.