如何处理WooCommerce中的Inicis付款网关弹出窗口

时间:2020-11-04 03:16:22

标签: php woocommerce hook-woocommerce

在WooCommerce结帐页面上,我正在使用inicis付款网关API接受付款。在“下订单”按钮上单击事件时,inicis付款会弹出一个表格,用户可以在其中填写付款信息。付款成功/失败后,icis付款网关会将发布变量返回给定的返回URL。问题是,返回URL没有结帐单ID来完成付款。这是我的自定义inicis付款插件文件。

<?php
add_action('plugins_loaded', 'init_inicis_class');
function init_inicis_class(){
class WC_Inicis extends WC_Payment_Gateway {

    public function __construct(){
    $this->id = 'inicis';
    .
    .
    $this->init_form_fields();
    $this->init_settings();
    $this->signkey = $this->testmode ? $this->get_option( 'test_signkey' ) : $this->get_option( 'live_signkey' );
    // Action hook to saves settings
    add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
    // custom thank you page
    add_action( 'woocommerce_thankyou_' . $this->id, array( $this, 'thankyou' ) );
    // Custom JavaScript
    add_action( 'wp_enqueue_scripts', array( $this, 'inicis_scripts' ) );
    }
    
    // admin options
    public function init_form_fields(){
    // admin options
    }
    
    public function payment_fields(){
    // Include inicis library file
    require_once plugin_dir_path(__FILE__).'includes/inicis/libs/INIStdPayUtil.php';
    $SignatureUtil = new INIStdPayUtil();
    $return_url = $plugin_url.'inicis-handler.php';
    .
    .
    .
    // Some hidden input fileds required for inicis payment gateway
    echo '<input type="text" name="sgnvalue" value="' . $this->signkey . '" />';
    echo '<input type="text" name="version" value="1.0" />';
    echo '<input type="text" name="goodname" value="' . $product_name . '" />';
    echo '<input type="text" name="price" value="' . $product_price . '" />';
    echo '<input type="text" name="currency" value="WON" />';
    echo '<input type="text" name="buyername" id="iBuyerName" value="" />';
    echo '<input type="text" name="buyeremail" id="iBuyerEmail" value="" />';
    echo '<input type="text" name="signature" value="' . $signature . '" />';
    echo '<input type="text" name="returnUrl" value="' . $return_url . '" />';
    }

    // JS files for inicis PG
    public function inicis_scripts(){
    wp_enqueue_script( 'inicis_process', 'https://stgstdpay.inicis.com/stdjs/INIStdPay.js' );
    // custom JS
    wp_register_script( 'inicis_js', plugins_url( 'js/cfpg-inicis.js', __FILE__ ), array( 'jquery', 'inicis_process' ), null, true );
    wp_enqueue_script( 'inicis_js' );
    add_action( 'wp_footer', function(){
    ?>
    <script type="text/javascript">
    // This function popus up payment gateway form
    function inicisPayment(){
    INIStdPay.pay('checkoutFormID');
    }
    </script>
    <?php
    });
    }
    // process payment
    public function process_payment( $order_id ){
    // Include inicis library files
    require_once plugin_dir_path(__FILE__).'includes/inicis/libs/INIStdPayUtil.php';
    require_once plugin_dir_path(__FILE__).'includes/inicis/libs/HttpClient.php';
    $util = new INIStdPayUtil();
    if(strcmp("0000", $_REQUEST["resultCode"]) == 0) {
        // update database
    } else {
        // show error
    }
    }   

    // Custom thank you page with instructions
    public function thankyou() {
        if ( $this->instructions ){
        echo wpautop( wptexturize( $this->instructions ) );
        }
    }
    
} // End: Class WC_Inicis
} // End: function init_inicis_class
?>

这是“ inicis-handler.php”页面

<?php
// Include inicis library files
    require_once plugin_dir_path(__FILE__).'includes/inicis/libs/INIStdPayUtil.php';
    require_once plugin_dir_path(__FILE__).'includes/inicis/libs/HttpClient.php';
    $util = new INIStdPayUtil();
    if(strcmp("0000", $_REQUEST["resultCode"]) == 0) {
        // update database
    } else {
        // show error
    }
?>

情况1::如果通过“下订单”按钮提交的结帐表单提交,则将触发“ process_payment”方法,但不会显示incis付款网关的弹出窗口。
案例2:如果在“下订单”按钮单击事件中,显示inicis弹出窗口,它将返回付款成功/失败变量以返回URL(inicis-handler.php),其中“ order_id”不存在可用来完成付款。

在这种情况下,我们应该如何处理通过inicis付款网关弹出表单返回的变量?

0 个答案:

没有答案