Support » Plugin: PayPal Express Checkout for WooCommerce » Multiple PayPal Accounts

  • Resolved willwong89

    (@willwong89)


    Hello,

    I am using the WooCommerce PayPal Express Checkout plugin v1.1.7 for an online store. I was wondering if it is possible to extend the plugin so that I can set up multiple PayPay Express gateways with different PayPal accounts.

    I am able clone the “Express_Checkout_Gateway” object from $woocommerce->payment_gateways->payment_gateways, modify the api username/password/signature and gateway ID, and add the cloned “Express_Checkout_Gateway” object back to $woocommerce->payment_gateways->payment_gateways with something like this:

    function custom_express_checkout_gateway() {

    global $woocommerce;

    // get all payment gateways
    $payment_gateways = $woocommerce->payment_gateways->payment_gateways;

    // find the Express_Checkout_Gateway object
    $Express_Checkout_Gateway = false;
    foreach( $payment_gateways as $payment_gateway ) {
    if( get_class( $payment_gateway ) == ‘Express_Checkout_Gateway’ ) {
    $Express_Checkout_Gateway = $payment_gateway;
    }
    }

    if( $Express_Checkout_Gateway !== false ) {

    $custom_gateway_configs = array(
    ‘custom_1’ => array(
    ‘id’ => ‘express_checkout_custom_1’,
    ‘title’ => ‘PayPal Express Custom 1’,
    ‘api_username’ => ‘USERNAME #1’,
    ‘api_password’ => ‘PASSWORD #1’,
    ‘api_signature’ => ‘SIGNATURE #1’,
    ),
    ‘custom_2’ => array(
    ‘id’ => ‘express_checkout_custom_2’,
    ‘title’ => ‘PayPal Express Custom 2’,
    ‘api_username’ => ‘USERNAME #2’,
    ‘api_password’ => ‘PASSWORD #2’,
    ‘api_signature’ => ‘SIGNATURE #2’,
    )
    );

    foreach( $custom_gateway_configs as $custom_gateway_config ) {

    $Custom_Express_Checkout_Gateway = clone $Express_Checkout_Gateway;
    $custom_gateway_id = $custom_gateway_config[‘id’];
    $api_username = $custom_gateway_config[‘api_username’];
    $api_password = $custom_gateway_config[‘api_password’];
    $api_signature = $custom_gateway_config[‘api_signature’];

    // update the API Credentials
    set_express_checkout_gateway_api_credentials( $Custom_Express_Checkout_Gateway, $api_username, $api_password, $api_signature );

    // update the ID to be unique so that woocommerce will display it as a separate gateway.
    $Custom_Express_Checkout_Gateway->id = $custom_gateway_config[‘id’];

    // update the title
    $Custom_Express_Checkout_Gateway->title = $custom_gateway_config[‘title’];

    // add the Custom_Express_Checkout_Gateway to the woocommerce payment gateways array
    $woocommerce->payment_gateways->payment_gateways[] = $Custom_Express_Checkout_Gateway;

    }
    }

    }
    }
    add_action( ‘init’, ‘custom_express_checkout_gateway’ );

    function set_express_checkout_gateway_api_credentials( $Express_Checkout_Gateway, $api_username = false, $api_password = false, $api_signature = false ) {

    if( get_class( $Express_Checkout_Gateway ) != ‘Express_Checkout_Gateway’ || !$api_username || !$api_password || !$api_signature ) {
    return;
    }
    $Express_Checkout_Gateway->settings[‘sandbox_api_username’] = $api_username;
    $Express_Checkout_Gateway->settings[‘sandbox_api_password’] = $api_password;
    $Express_Checkout_Gateway->settings[‘sandbox_api_signature’] = $api_signature;
    $Express_Checkout_Gateway->api_username = $api_username;
    $Express_Checkout_Gateway->api_password = $api_password;
    $Express_Checkout_Gateway->api_signature = $api_signature;
    }

    Everything seems to be working fine except I am not sure what to do modify the plugin “process_payment” function. It’d just return a “express checkout false” error message if the user checks out with my custom “Express_Checkout_Gateway” selected. I’d probably need to extend the “process_payment” function so that it will know and process my custom gateways?

    Any advice would be greatly appreciated!

    Thanks.

Viewing 1 replies (of 1 total)
  • Plugin Author wpgateways

    (@wpgateways)

    I could not help you with above customisation, because I am little bit behind with other supports ticket. it will take few days to resolved your issues.

    Sorry!

Viewing 1 replies (of 1 total)
  • The topic ‘Multiple PayPal Accounts’ is closed to new replies.