Laravel Paypal SandBox to Live

silhouette photography of standing woman

My project works perfectly in mode ‘sandbox’ but when I go to put it in mode ‘live’ (I did it correctly as indicated in the instructions in PayPal-PHP-SDK, my credentials are correct and I put mode ‘live’ instead of mode ‘sandbox’).
It gives me the following error:

PayPal  Exception  PayPalConnectionException
Got Http response code 401 when accessing https://api.sandbox.paypal.com/v1/oauth2/token.

Looking for this error notice that it happened to others but it was the following error:

PayPal  Exception  PayPalConnectionException
Got Http response code 401 when accessing https://api.paypal.com/v1/oauth2/token.

Why does my error say sandbox if I have mode ‘live’? So I started looking because if I had mode ‘live’ I kept getting api.sandbox.paypal.com instead of api.paypal.com error.

and get to vendor paypal rest-api-sdk-php lib PayPal Handler OauthHandler.php (Which I have never modified) has a _getEndPoint method.

 private static function _getEndpoint($config)
{
    if (isset($config['oauth.EndPoint'])) {
        $baseEndpoint = $config['oauth.EndPoint'];
    } elseif (isset($config['service.EndPoint'])) {
        $baseEndpoint = $config['service.EndPoint'];
    } elseif (isset($config['mode'])) {
        switch (strtoupper($config['mode'])) {
            case 'SANDBOX':
                $baseEndpoint = PayPalConstants::REST_SANDBOX_ENDPOINT;
                break;
            case 'LIVE':
                $baseEndpoint = PayPalConstants::REST_LIVE_ENDPOINT;
                break;
            default:
                throw new PayPalConfigurationException('The mode config parameter must be set to either sandbox/live');
        }
    } else {
        // Defaulting to Sandbox
        $baseEndpoint = PayPalConstants::REST_SANDBOX_ENDPOINT;
    }

    $baseEndpoint = rtrim(trim($baseEndpoint), '/') . "/v1/oauth2/token";

    return $baseEndpoint;
}

I noticed that the config always arrives empty in that part, when it arrives empty it goes to the case by default
which is sandbox. That’s why sandobox works for me even though nothing is coming either.
Any idea why this can happen. I really have no idea, any help is welcome.

asked 2 hours ago
PandicornGhostPandicornGhost

133 bronze badges

1 Answer

I think you need mode ‘production’ for that SDK’s config

But you are using a deprecated v1 SDK that is no longer maintained

You should be using the v2 Checkout-PHP-SDK, documented here: https://developer.paypal.com/docs/checkout/reference/server-integration/


By the way, the best UI approval flow to pair it with is here: https://developer.paypal.com/demo/checkout/#/pattern/server

answered 1 hour ago
Preston PHXPreston PHX

8,2533 gold badges14 silver badges31 bronze badges

Latest posts