Etisalat付款整数Woocommerce

时间:2018-12-03 05:36:11

标签: php woocommerce

我正在尝试为Woocommerce创建自定义付款网关,该程序允许客户重定向到Etisalat付款网关。到目前为止,在工作了许多天之后,我陷入了内部服务器错误的境地。让我向您介绍一些代码。

这是我的构造类。

/* Etisalat Payment Gateway Class */

class ETISALAT_Payment_GATEWAY extends WC_Payment_Gateway {



// Setup our Gateway's id, description and other values

function __construct() {



    // The global ID for this Payment method

    $this->id = "etisalat-payment-gateway";



    // The Title shown on the top of the Payment Gateways Page next to all the other Payment Gateways

    $this->method_title = __( "ETISALAT Payment gateway", 'etisalat-payment-gateway' );



    // The description for this Payment Gateway, shown on the actual Payment options page on the backend

    $this->method_description = __( "ETISALAT Payment Gateway Plug-in for WooCommerce", 'etisalat-payment-gateway' );



    // The title to be used for the vertical tabs that can be ordered top to bottom

    $this->title = __( "ETISALAT Payment gateway", 'etisalat-payment-gateway' );



    // If you want to show an image next to the gateway's name on the frontend, enter a URL to an image.

    $this->icon = null;



    // Bool. Can be set to true if you want payment fields to show on the checkout 

    // if doing a direct integration, which we are doing in this case

    $this->has_fields = false;



    // Supports the default credit card form

    // $this->supports = array( 'default_credit_card_form' );



    // This basically defines your settings which are then loaded with init_settings()

    $this->init_form_fields();



    // After init_settings() is called, you can get the settings and load them into variables, e.g:

    // $this->title = $this->get_option( 'title' );

    $this->init_settings();



    // Turn these settings into variables we can use

    foreach ( $this->settings as $setting_key => $value ) {

        $this->$setting_key = $value;

    }



    // Lets check for SSL

    add_action( 'admin_notices', array( $this,  'do_ssl_check' ) );



    // Save settings

    if ( is_admin() ) {

        // Versions over 2.0

        // Save our administration options. Since we are not going to be doing anything special

        // we have not defined 'process_admin_options' in this class so the method in the parent

        // class will be used instead

        add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );

    }       

} // End __construct()

到目前为止,这是我的付款整数的构造,然后我为woocommerce设置页面添加了表格以对商家帐户详细信息进行整数化。

// Build the administration fields for this specific Gateway

public function init_form_fields() {

    $this->form_fields = array(

        'enabled' => array(

            'title'     => __( 'Enable / Disable', 'etisalat-payment-gateway' ),

            'label'     => __( 'Enable ETISALAT payment gateway', 'etisalat-payment-gateway' ),

            'type'      => 'checkbox',

            'default'   => 'no',

        ),

        'title' => array(

            'title'     => __( 'Title', 'etisalat-payment-gateway' ),

            'type'      => 'text',

            'desc_tip'  => __( 'Payment title the customer will see during the checkout process.', 'etisalat-payment-gateway' ),

            'default'   => __( 'ETISALAT Payment Gateway', 'etisalat-payment-gateway' ),

        ),

        'description' => array(

            'title'     => __( 'Description', 'setisalat-payment-gateway' ),

            'type'      => 'textarea',

            'desc_tip'  => __( 'Payment description the customer will see during the checkout process.', 'etisalat-payment-gateway' ),

            'default'   => __( 'Pay securely using your credit card.', 'etisalat-payment-gateway' ),

            'css'       => 'max-width:350px;'

        ),

        'api_login' => array(

            'title'     => __( 'ETISALAT Username', 'etisalat-payment-gateway' ),

            'type'      => 'text',

            'desc_tip'  => __( 'This is the Username Login provided by Etisalat when you signed up for an account.', 'etisalat-payment-gateway' ),

        ),

        'etisalat_password' => array(

            'title'     => __( 'ETISALAT Password', 'etisalat-payment-gateway' ),

            'type'      => 'password',

            'desc_tip'  => __( 'This is the password provided by Etisalat when you signed up for an account.', 'etisalat-payment-gateway' ),

        ),

        'environment' => array(

            'title'     => __( 'ETISALAT Test Mode', 'etisalat-payment-gateway' ),

            'label'     => __( 'Enable Test Mode', 'etisalat-payment-gateway' ),

            'type'      => 'checkbox',

            'description' => __( 'Place the payment gateway in test mode.', 'etisalat-payment-gateway' ),

            'default'   => 'no',

        )

    );      

}

这是我的付款处理功能,在这里我可能会做一些错误或使用错误的方式重定向它,因为我有从Authorize.NET付款整数中进行制作的想法,也许他们只是将其用于直接付款,但在我情况下,我希望它可以重定向到Etisalat门户。

// Submit payment and handle response

public function process_payment( $order_id ) {

    global $woocommerce;



    // Get this Order's information so that we know

    // who to charge and how much

    $customer_order = new WC_Order( $order_id );



    // Are we testing right now or is it a real transaction

    $environment = ( $this->environment == "yes" ) ? 'TRUE' : 'FALSE';



    // Decide which URL to post to

    $environment_url = ( "FALSE" == $environment ) 

                       ? 'https://demo-ipg.comtrust.ae'

                       : 'https://demo-ipg.comtrust.ae';



    // This is where the fun stuff begins

    $payload = array(

        // Authorize.net Credentials and API Info

        "x_password"            => $this->etisalat_password,

        "x_login"               => $this->api_login,

        "x_version"             => "3.1",



        // Order total

        "x_amount"              => $customer_order->order_total,



        // Credit Card Information

        // "x_card_num"             => str_replace( array(' ', '-' ), '', $_POST['etisalat_card-number'] ),

    //  "x_card_code"           => ( isset( $_POST['etisalat_card-cvc'] ) ) ? $_POST['etisalat_card-cvc'] : '',

    //  "x_exp_date"            => str_replace( array( '/', ' '), '', $_POST['etisalat_card-expiry'] ),



        "x_type"                => 'AUTH_CAPTURE',

        "x_invoice_num"         => str_replace( "#", "", $customer_order->get_order_number() ),

        "x_test_request"        => $environment,

        "x_delim_char"          => '|',

        "x_encap_char"          => '',

        "x_delim_data"          => "TRUE",

        "x_relay_response"      => "FALSE",

        "x_method"              => "CC",



        // Billing Information

        "x_first_name"          => $customer_order->billing_first_name,

        "x_last_name"           => $customer_order->billing_last_name,

        "x_address"             => $customer_order->billing_address_1,

        "x_city"                => $customer_order->billing_city,

        "x_state"               => $customer_order->billing_state,

        "x_zip"                 => $customer_order->billing_postcode,

        "x_country"             => $customer_order->billing_country,

        "x_phone"               => $customer_order->billing_phone,

        "x_email"               => $customer_order->billing_email,



        // Shipping Information

        "x_ship_to_first_name"  => $customer_order->shipping_first_name,

        "x_ship_to_last_name"   => $customer_order->shipping_last_name,

        "x_ship_to_company"     => $customer_order->shipping_company,

        "x_ship_to_address"     => $customer_order->shipping_address_1,

        "x_ship_to_city"        => $customer_order->shipping_city,

        "x_ship_to_country"     => $customer_order->shipping_country,

        "x_ship_to_state"       => $customer_order->shipping_state,

        "x_ship_to_zip"         => $customer_order->shipping_postcode,



        // Some Customer Information

        "x_cust_id"             => $customer_order->user_id,

        "x_customer_ip"         => $_SERVER['REMOTE_ADDR'],



    );

0 个答案:

没有答案