• Hello,

    I am using WooCommerce PayPal Express Checkout Gateway 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 ) {

    // creating a copy of the Express_Checkout_Gateway object
    $Custom_Express_Checkout_Gateway = clone $Express_Checkout_Gateway;

    // modify the cloned Express_Checkout_Gateway object
    $api_username = ‘SECOND PAYPAL ACCOUNT USENAME’;
    $api_password = ‘SECOND PAYPAL ACCOUNT PASSWORD’;
    $api_signature = ‘SECOND PAYPAL ACCOUNT SIGNATURE’;
    set_express_checkout_gateway_api_credentials( $Custom_Express_Checkout_Gateway, $api_username, $api_password, $api_signature );
    set_express_checkout_gateway_id( $Custom_Express_Checkout_Gateway, ‘express_checkout_custom’ );
    $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;
    }

    function set_express_checkout_gateway_id( $Express_Checkout_Gateway, $id = false ) {
    if( get_class( $Express_Checkout_Gateway ) != ‘Express_Checkout_Gateway’ || !$id ) {
    return;
    }
    $Express_Checkout_Gateway->id = $id;
    }

    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 Contributor Hannah S.L.

    (@fernashes)

    Automattic Happiness Engineer

    Hey there,

    We don’t offer customization support, but someone else might be able to answer and help you out with this.

Viewing 1 replies (of 1 total)

The topic ‘Multiple PayPal Accounts’ is closed to new replies.