将Paytabs Express结帐添加到WooCommerce结帐页面

时间:2018-12-03 14:02:51

标签: php wordpress woocommerce e-commerce

我正试图在woocommerce结帐页面上添加paytabs express结帐选项,我想将其添加为仅在某些国家/地区可用的付款选项。

这是我到目前为止所获得的     

/**
 * Plugin Name: Paytabs Express Checkout
 * Description: Add the Paytabs Express Checkout Option.
 * Author: 
 * Version: 1.0
 */

@session_start();
//load plugin function when woocommerce loaded
add_action('plugins_loaded', 'woocommerce_paytabs_express_checkout_init', 0);

// Paytabs Express checkout function
function woocommerce_paytabs_express_checkout_init() {
    // Extend WooCommerce payment options class
    class WC_Gateway_Paytabs_express_checkout extends WC_Payment_Gateway{

        public function __construct(){
            $pluginpath          =   WC()->plugin_url();
            $pluginpath          =   explode('plugins', $pluginpath);
            $this->id            =   'paytabs_ec';
            $this->icon          =   apply_filters( 'woocommerce_paytabs_icon', $pluginpath[0] . 'plugins/Paytabs-ExpressCheckout/icons/paytabs.png' );
            $this->medthod_title =   'PayTabs Express Checkout';
            $this->description   =   'Integrate PayTabs Express Checkout Option';
            $this->has_fields    =   false;
            // Init admin panel fields under woocommerce settings page 
            $this->init_form_fields();
            $this->init_settings();

            $this->title            = $this->settings['title'];
            }

            /**
            * Initialize Gateway Settings Form Fields
            */
        public function init_form_fields() {
            $this->form_fields = array(
                    'enabled'   => array(
                        'title'   => __('Enable/Disable', 'PayTabs Express Checkout'),
                        'type'    => 'checkbox',
                        'label'   => __('Enable PayTabs Express Checkout .', 'PayTabs'),
                        'default' => 'no'),

                    'title'     => array(
                        'title'       => __('Title:', 'Credit Card payments powered by PayTabs.'),
                        'type'        => 'text',
                        'description' => __('PayTabs Express Checkout.', 'PayTabs'),
                        'default'     => __('PayTabs', 'PayTabs')),

                    'description' => array(
                        'title'       => __('Description:', 'PayTabs'),
                        'type'        => 'textarea',
                        'description' => __('Making any changes to the above may result in suspension or termination of your PayTabs Merchant Account.', 'PayTabs'),
                        'default'     => __('Pay securely by Credit or Debit card through PayTabs Secure Servers.', 'PayTabs')),
                );
        }

        public function process_payment( $order_id ) {

            $order = wc_get_order( $order_id );

            // Mark as on-hold (we're awaiting the payment)
            $order->update_status( 'on-hold', __( 'Awaiting payment', 'PayTabs' ) );

            // Reduce stock levels
            $order->reduce_order_stock();

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

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

    } // End WC_Gateway_Paytabs_express_checkout Class

    /**
     * Add the Gateway to WooCommerce
     **/
    function woocommerce_add_paytabs_creditcard_wc_gateway($methods) {
        $methods[] = 'WC_Gateway_Paytabs_express_checkout';
        return $methods;
    }
    add_filter('woocommerce_payment_gateways', 'woocommerce_add_paytabs_creditcard_wc_gateway' );
}

它添加了Paytabs付款选项,但现在我需要它来运行快速结帐脚本(此处为https://dev.paytabs.com/wp-content/uploads/paytabs-express-checkout-v3-documentation-v3.6.pdf的详细信息)

0 个答案:

没有答案