Android Question national electronic payments system

PABLO2013

Well-Known Member
Licensed User
Longtime User
national electronic payments system (SINPE)
I would like to know how this php code could be implemented to make electronic payments through the cell phone with a link to bank accounts, I do not know what this is called but here is an example of the php code, any help or support, thanks
PHP1:
<?php
/*
         GitHub Plugin URI: Pending
*/

if ( ! defined( 'ABSPATH' ) )
    exit;

add_action( 'plugins_loaded', 'sp_sinpe_init', 0 );

function sp_sinpe_init() {

    if ( ! class_exists( 'WC_Payment_Gateway' ) ) return;

    /**
     * SINPE SMS Payment Gateway.
     *
     * Facilitates a SINPE Bank Transfer Payment Gateway. Based on code by Mike Pepper.
     *
     * @class       sp_sinpe_Gateway
     * @extends     WC_Payment_Gateway
     * @version     1.0.0
     * @package     WooCommerce/Classes/Payment
     */
    class sp_sinpe_Gateway extends WC_Payment_Gateway {

        /**
         * Array of locales
         *
         * [USER=57375]@var[/USER] array
         */
        public $locale;

        /**
         * Constructor for the gateway.
         */
        public function __construct() {

            $this->id                 = 'sp_sinpe_gateway';
            $this->icon               = apply_filters( 'sp_sinpe_gateway', '/wp-content/plugins/wc-SINPE-payment-gateway/assets/images/sinpe-sms.png' );
            $this->has_fields         = true;
            $this->method_title       = __( 'SINPE SMS', 'sp_sinpe_gateway' );
            $this->method_description = __( 'Pagos fáciles a Vendedores vía SINPE SMS. Con un Click.', 'sp_sinpe_gateway' );

            // Load the settings.
            $this->init_form_fields();
            $this->init_settings();

            // Define user set variables.
            $this->title        = $this->get_option( 'title' );
            $this->description  = $this->get_option( 'description' );
            $this->instructions = $this->get_option( 'instructions' );

            $this->BANCs = array(
                'USA' => [
                    'numero_sms' => '2276',
                    'nombre_largo' =>     'BANC USA',
                    'nombre_corto' => 'USA',
                    'icono' => '/wp-content/plugins/wc-SINPE-payment-gateway/assets/images/BANC-USA-icon.png'
                ],

            );
            
            $this->secret = '111111111111111111111111';

            // SINPE account fields shown on the thanks page and in emails.
            $this->sinpe_details = get_option(
                'sp_sinpe_details',
                array(
                    array(
                        'sinpe_mobile'   => $this->get_option( 'sinpe_mobile' ),
                        'sinpe_name'      => $this->get_option( 'sinpe_mobile' ),
                        'clave'      => $this->get_option( 'clave' )
                    ),
                )
            );

            // Actions.
            add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
            add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'save_account_details' ) );   
            add_action( 'woocommerce_thankyou_' . $this->id,  array( $this, 'thankyou_page' ));


            // Customer Emails.
            add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
        
        }
        /**
         * Initialise Gateway Settings Form Fields.
         */
        public function init_form_fields() {

            $this->form_fields = array(
                'enabled'         => array(
                    'title'   => __( 'Enable/Disable', 'sp_sinpe_gateway' ),
                    'type'    => 'checkbox',
                    'label'   => __( 'Enable  SINPE Móvil', 'sp_sinpe_gateway' ),
                    'default' => 'no',
                ),
                'title'           => array(
                    'title'       => __( 'Title', 'sp_sinpe_gateway' ),
                    'type'        => 'text',
                    'description' => __( 'This controls the title which the user sees during checkout.', 'sp_sinpe_gateway' ),
                    'default'     => __( 'PAY Fácil SINPE Móvil', 'sp_sinpe_gateway' ),
                    'desc_tip'    => true,
                ),

                
            );

        }

        /**
         * Save account details table.
         */
        public function save_account_details() {

            $accounts = array();

            // phpcs:disable WordPress.Security.NonceVerification.Missing -- Nonce verification already handled in WC_Admin_Settings::save()
            if ( isset( $_POST['sinpe_mobile'] ) && isset( $_POST['sinpe_name'] ) ) {

                $sinpe_details = array(
                    'sinpe_mobile'   => wc_clean( wp_unslash( $_POST['sinpe_mobile'] ) ),
                    'sinpe_name' => wc_clean( wp_unslash( $_POST['sinpe_name'] ) )
                );
            }
            // phpcs:enable

            update_option( 'sp_sinpe_details', $accounts );
        }

        /**
         * Output for the order received page.
         *
         * @param int $order_id Order ID.
         */
        public function thankyou_page( $order_id ) {

            if ( $this->instructions ) {
                echo wp_kses_post( wpautop( wptexturize( wp_kses_post( $this->instructions ) ) ) );
            }
            $this->receipt_sinpe_details( $order_id );

        }

        /**
         * Add content to the WC emails.
         *
         * @param WC_Order $order Order object.
         * @param bool     $sent_to_admin Sent to admin.
         * @param bool     $plain_text Email format: plain text or HTML.
         */
        public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {

            if ( ! $sent_to_admin && 'sp_sinpe_gateway' === $order->get_payment_method() && $order->has_status( 'on-hold' ) ) {
                if ( $this->instructions ) {
                    echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL );
                }
                $this->receipt_sinpe_details( $order->get_id() );
            }

        }

        /**
         * Get SINPE details and place into a list format.
         *
         * @param int $order_id Order ID.
         */
        private function receipt_sinpe_details( $order_id = '' ) {

            // Get order and store in $order.
            $order = wc_get_order( $order_id );
            $no_celular_sinpe = $this->get_option( 'sinpe_mobile' );
            $total = (float) $order->get_total();

                        
            echo '<h2>Procede con el PAY Vía Sinpe Móvil (SMS):</h2>';
            echo '<hr><p>';
            echo 'Titular de cuenta_______:<strong> ' .  $this->get_option( 'sinpe_name' )  . '</strong> <br>';
            echo 'Teléfono a Transferir___: <strong>'. $no_celular_sinpe .'</strong> <br>';
            echo 'Monto___________________: <strong>'. wc_price($order->get_total()) .'</strong> <br>';
            echo '<h4>Haga click en el BANC de su elección para pagar con SMS</h4>';
            echo '<div class="sinpe-sms-buttons">';

            foreach ($this->BANCs as $key => $BANC) {
                echo '<a class="sinpe-button button sinpe-'.$key.'" href="sms://'. $BANC['numero_sms'] .'?&body=PASE%20'. $total .'%20'.  $no_celular_sinpe .'">'.$BANC['nombre_largo'].'</a>';
            }
            $key = implode('-', str_split(substr(strtolower(md5(microtime().rand(1000, 9999))), 0, 30), 6));
            echo $key;
            echo '</div><hr>';
        }

        
        // /* WC Vendors Pro - My Custom Field */
        // public static function email_sinpe_details( ){
        //     if ( class_exists( 'WCVendors_Pro' ) ){
        //         $key = '_wcv_custom_settings_no_sinpe';
        //         $value = get_user_meta( get_current_user_id(), $key, true );
        //         // Bank Name
        //         WCVendors_Pro_Form_Helper::input( array( 
        //             'id'                 => $key,
        //             'label'             => __( 'No. Celular Asociado a SINPE', 'wcvendors-pro' ),
        //             'placeholder'             => __( 'Ejemplo: 88794294', 'wcvendors-pro' ),
        //             'desc_tip'             => 'true',
        //             'description'             => __( 'El Número de Tel que asociaste a servicio SINPE Móvil', 'wcvendors-pro' ),
        //             'type'                 => 'text',
        //             'value'                => $value,
        //             )
        //         );

        //         $key = '_wcv_custom_settings_sinpe_titular';
        //         $value = get_user_meta( get_current_user_id(), $key, true );
        //         // Bank Name
        //         WCVendors_Pro_Form_Helper::input( array( 
        //             'id'                 => $key,
        //             'label'             => __( 'Nombre Completo del titular de la Línea Celular', 'wcvendors-pro' ),
        //             'placeholder'             => __( '', 'wcvendors-pro' ),
        //             'desc_tip'             => 'true',
        //             'description'             => __( 'El nombre del titular del número celular y la cuenta bancaria', 'wcvendors-pro' ),
        //             'type'                 => 'text',
        //             'value'                => $value,
        //             )
        //         );
        //     }
        // }

        /**
         * Process the payment and return the result.
         * Sets the order on-hold until the vendor confirms the payment by clicking on the confirmation button sent in an email.
         *
         * @param int $order_id Order ID.
         * @return array
         */
        public function process_payment( $order_id ) {

            $order = wc_get_order( $order_id );

            if ( $order->get_total() > 0 ) {
                // Mark as on-hold (we're awaiting the payment).
                $order->update_status( apply_filters( 'woocommerce_bacs_process_payment_order_status', 'on-hold', $order ), __( 'Esperando Transferencia SINPE', 'sp_sinpe_gateway' ) );
            } else {
                // Free orders
                $order->payment_complete();
            }

            // Remove cart.
            WC()->cart->empty_cart();

            // Return thankyou redirect.
            return array(
                'result'   => 'success',
                'redirect' => $this->get_return_url( $order ),
            );

        }
        


    } // End of Class


    /**
     * Add SINPE Gateway to WC
     **/
    function sp_sinpe_add_gateway( $methods ) {

        $methods[] = 'sp_sinpe_Gateway';
        return $methods;

    }
    add_filter('woocommerce_payment_gateways', 'sp_sinpe_add_gateway' );


    /**
    * Add Settings link to the plugin entry in the plugins menu
    **/
    function sp_sinpe_plugin_action_links( $links, $file ) {

        static $this_plugin;

        if ( ! $this_plugin ) {

            $this_plugin = plugin_basename( __FILE__ );

        }

        if ( $file == $this_plugin ) {

            $settings_link = '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=wc-settings&tab=checkout&section=sp_sinpe_add_gateway">Configuración</a>';
            array_unshift($links, $settings_link);

        }

        return $links;

    }
    add_filter( 'plugin_action_links', 'sp_sinpe_plugin_action_links', 10, 2 );

    function sp_sinpe_confirma_pago_html(){
        
        $order_number = $_GET['orden'];
        $token =         $_GET['token'];



        echo "<p>No. de Orden:" . $order_number . '</p>';
        echo "<p>No. de Orden:" . $_GET['token'] . '</p>';
    }

    add_shortcode('sp_sinpe_confirma_pay', 'sp_sinpe_confirma_pay_html');


}

class sp_sinpe_Expedited_Order_Email extends WC_Email {


} // end \WC_Expedited_Order_Email class

/**
 *  Add a custom email to the list of emails WooCommerce should load
 *
 * @since 0.1
 * @param array $email_classes available email classes
 * @return array filtered available email classes
 */
function add_expedited_order_woocommerce_email( $email_classes ) {

    // include our custom email class
    require( 'includes/class-wc-expedited-order-email.php' );

    // add the email class to the list of email classes that WooCommerce loads
    $email_classes['WC_Expedited_Order_Email'] = new sp_sinpe_Expedited_Order_Email();

    return $email_classes;

}
add_filter( 'woocommerce_email_classes', 'add_expedited_order_woocommerce_email' );

PHP2:
<?php
/*
    Plugin Name:  SINPE Payment Gateway

     License URI:       https://opensource.org/licenses/MIT
     GitHub Plugin URI: Pending
*/

if ( ! defined( 'ABSPATH' ) )
    exit;

add_action( 'plugins_loaded', 'wc_sinpe_init', 0 );

function wc_sinpecr_init() {

    if ( ! class_exists( 'WC_Payment_Gateway' ) ) return;

    /**
     * SINPE SMS Payment Gateway.
     *
     * @extends     WC_Payment_Gateway
     * @version     1.0.0
     * @package     WooCommerce/Classes/Payment
     */
    class wc_sinpe_gateway extends WC_Payment_Gateway {

        /**
         * Array of locales
         *
         * [USER=57375]@var[/USER] array
         */
        public $locale;

        /**
         * Constructor for the gateway.
         */
        public function __construct() {

            $this->id                 = 'wc_sinpe_gateway';
            $this->icon               = apply_filters( 'wc_sinpe_gateway', '/wp-content/plugins/wc-sinpe-payment-gateway/assets/images/sinpe-sms.png' );
            $this->has_fields         = true;
            $this->method_title       = __( 'SINPE SMS', 'wc_sinpe_gateway' );
            $this->method_description = __( 'Pagos fáciles a Vendedores vía SINPE SMS. Con un Click.', 'wc_sinpe_gateway' );

            // Load the settings.
            $this->init_form_fields();
            $this->init_settings();

            // Define user set variables.
            $this->title        = $this->get_option( 'title' );
            $this->description  = $this->get_option( 'description' );
            $this->instructions = $this->get_option( 'instructions' );

            $this->bancos = array(
                'bcr' => [
                    'numero_sms' => 'xxx',
                    'nombre_largo' =>     'xxxx',
                    'nombre_corto' => 'xxx',
                    'icono' => '/wp-content/plugins/wc-sinpe-payment-gateway/assets/images/xxxx-icon.png'
                ],

            );
            
            $this->secret = 'xxxx';

            // sinpe account fields shown on the thanks page and in emails.
            $this->sinpe_details = get_option(
                'wc_sinpecr_details',
                array(
                    array(
                        'sinpe_mobile'   => $this->get_option( 'sinpe_mobile' ),
                        'sinpe_name'      => $this->get_option( 'sinpe_mobile' ),
                        'clave'      => $this->get_option( 'clave' )
                    ),
                )
            );

            // Actions.
            add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
            add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'save_account_details' ) );   
            add_action( 'woocommerce_thankyou_' . $this->id,  array( $this, 'thankyou_page' ));


            // Customer Emails.
            add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
        
        }
        /**
         * Initialise Gateway Settings Form Fields.
         */
        public function init_form_fields() {

            $this->form_fields = array(
                'enabled'         => array(
                    'title'   => __( 'Enable/Disable', 'wc_sinpe_gateway' ),
                    'type'    => 'checkbox',
                    'label'   => __( 'Enable Pago Fácil SINPE Móvil', 'wc_sinpe_gateway' ),
                    'default' => 'no',
                ),
                'title'           => array(
                    'title'       => __( 'Title', 'wc_sinpe_gateway' ),
                    'type'        => 'text',
                    'description' => __( 'This controls the title which the user sees during checkout.', 'wc_sinpe_gateway' ),
                    'default'     => __( 'Pago Fácil SINPE Móvil', 'wc_sinpe_gateway' ),
                    'desc_tip'    => true,
                ),
                'description'     => array(
                    'title'       => __( 'Description', 'wc_sinpe_gateway' ),
                    'type'        => 'textarea',
                    'description' => __( 'What users see in the checkout ', 'wc_sinpe_gateway' ),
                    'default'     => __( 'Pague directamente a cada comercio, con un click!', 'wc_sinpe_gateway' ),
                    'desc_tip'    => true,
                ),
                'instructions'    => array(
                    'title'       => __( 'Instructions', 'wc_sinpe_gateway' ),
                    'type'        => 'textarea',
                    'description' => 'Instrucciones para el Cliente',
                    'default'     => __( 'Haga click en el botón de <strong>SU banc</strong> para pagarle a comercio mediante SINPE Móvil. ( Mensaje SMS ) <br>
                    Al hacer click, se abrirá automáticamente una plantilla para enviar un SMS al No. SINPE del banc de SU elección.', 'woocommerce' ),
                    'desc_tip'    => true,
                ),
                'sinpe_mobile'    => array(
                    'title'       => __( 'Tel. Receptor SINPE', 'wc_sinpe_gateway' ),
                    'type'        => 'text',
                    'description' => 'Número de Teléfono asociado a SINPE Móvil. No importa de que banc. Sin espacios. Ejemplo: 12345678',
                    'default'     => __( 'Sin Configurar', 'wc_sinpe_gateway' ),
                    'desc_tip'    => true,
                ),

            );

        }

        /**
         * Save account details table.
         */
        public function save_account_details() {

            $accounts = array();

            // phpcs:disable WordPress.Security.NonceVerification.Missing -- Nonce verification already handled in WC_Admin_Settings::save()
            if ( isset( $_POST['sinpe_mobile'] ) && isset( $_POST['sinpe_name'] ) ) {

                $sinpe_details = array(
                    'sinpe_mobile'   => wc_clean( wp_unslash( $_POST['sinpe_mobile'] ) ),
                    'sinpe_name' => wc_clean( wp_unslash( $_POST['sinpe_name'] ) )
                );
            }
            // phpcs:enable

            update_option( 'wc_sinpecr_details', $accounts );
        }

        /**
         * Output for the order received page.
         *
         * @param int $order_id Order ID.
         */
        public function thankyou_page( $order_id ) {

            if ( $this->instructions ) {
                echo wp_kses_post( wpautop( wptexturize( wp_kses_post( $this->instructions ) ) ) );
            }
            $this->receipt_sinpe_details( $order_id );

        }

        /**
         * Add content to the WC emails.
         *
         * @param WC_Order $order Order object.
         * @param bool     $sent_to_admin Sent to admin.
         * @param bool     $plain_text Email format: plain text or HTML.
         */
        public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {

            if ( ! $sent_to_admin && 'wc_sinpe_gateway' === $order->get_payment_method() && $order->has_status( 'on-hold' ) ) {
                // Not necesARY FOR EAIL
                // if ( $this->instructions ) {
                //     echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL );
                // }
                $this->receipt_sinpe_details( $order->get_id() );
            }

        }

        /**
         * Get SINPE details and place into a list format.
         *
         * @param int $order_id Order ID.
         */
        private function receipt_sinpe_details( $order_id = '' ) {

            // Get order and store in $order.
            $order = wc_get_order( $order_id );
            $no_celular_sinpe = $this->get_option( 'sinpe_mobile' );
            $total = (float) $order->get_total();

                        
            echo '<h2>Procede con el Pago Vía Sinpe Móvil (SMS):</h2>';
            echo '<hr><p>';
            echo 'Titular de cuenta_______:<strong> ' .  $this->get_option( 'sinpe_name' )  . '</strong> <br>';
            echo 'Teléfono a Transferir___: <strong>'. $no_celular_sinpe .'</strong> <br>';
            echo 'Monto___________________: <strong>'. wc_price($order->get_total()) .'</strong> <br>';
            echo '<h4>Haga click en el banc de su elección para pagar con SMS</h4>';
            echo '<div class="sinpe-sms-buttons">';

            foreach ($this->bancos as $key => $banc) {
                echo '<a class="sinpe-button button sinpe-'.$key.'" href="sms://'. $banc['numero_sms'] .'?&body=PASE%20'. $total .'%20'.  $no_celular_sinpe .'">'.$banc['nombre_largo'].'</a>';
            }
            $key = implode('-', str_split(substr(strtolower(md5(microtime().rand(1000, 9999))), 0, 30), 6));
            echo $key;
            echo '</div><hr>';
        }

        


        /**
         * Process the payment and return the result.
         * Sets the order on-hold until the vendor confirms the payment by clicking on the confirmation button sent in an email.
         *
         * @param int $order_id Order ID.
         * @return array
         */
        public function process_payment( $order_id ) {

            $order = wc_get_order( $order_id );

            if ( $order->get_total() > 0 ) {
                // Mark as on-hold (we're awaiting the payment).
                $order->update_status( apply_filters( 'woocommerce_bacs_process_payment_order_status', 'on-hold', $order ), __( 'Esperando Transferencia SINPE', 'wc_sinpe_gateway' ) );
            } else {
                // Free orders
                $order->payment_complete();
            }

            // Remove cart.
            WC()->cart->empty_cart();

            // Return thankyou redirect.
            return array(
                'result'   => 'success',
                'redirect' => $this->get_return_url( $order ),
            );

        }
        


    } // End of Class


    /**
     * Add sinpe Gateway to WC
     **/
    function wc_sinpecr_add_gateway( $methods ) {

        $methods[] = 'wc_sinpe_gateway';
        return $methods;

    }
    add_filter('woocommerce_payment_gateways', 'wc_sinpecr_add_gateway' );


    /**
    * Add Settings link to the plugin entry in the plugins menu
    **/
    function wc_sinpecr_plugin_action_links( $links, $file ) {

        static $this_plugin;

        if ( ! $this_plugin ) {

            $this_plugin = plugin_basename( __FILE__ );

        }

        if ( $file == $this_plugin ) {

            $settings_link = '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=wc-settings&tab=checkout&section=wc_sinpecr_add_gateway">Configuración</a>';
            array_unshift($links, $settings_link);

        }

        return $links;

    }
    add_filter( 'plugin_action_links', 'wc_sinpecr_plugin_action_links', 10, 2 );

    
    /**
     * Shortcode: wc_sinpecr_confirma_pago
     * Used by the Vendor to confirm the order has been paid via SINPE.
     * TODO
     */
    
    function wc_sinpecr_confirma_pago_html(){
        
        $order_number = $_GET['orden'];
        $token =         $_GET['token'];

        echo "<p>No. de Orden:" . $order_number . '</p>';
        echo "<p>No. de Orden:" . $_GET['token'] . '</p>';
    }

    add_shortcode('wc_sinpecr_confirma_pago', 'wc_sinpecr_confirma_pago_html');
 
Top