Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paypal: Client Authentication Failed

Trying to take my paypal REST api site live. It works well in sandbox mode, with verified transfers.

When I switch my sandbox for live client ID and secret, I get the error

{"error":"invalid_client","error_description":"Client Authentication failed"}   

I checked and made sure that my code should go live

$apiContext = new \PayPal\Rest\ApiContext(
 new \PayPal\Auth\OAuthTokenCredential(
  PP_CLIENT_ID ,     // ClientID
  PP_CLIENT_SECRET      // ClientSecret
 )
);

// setting mode to live
// https://github.com/paypal/PayPal-PHP-SDK/wiki/Going-Live

$apiContext->setConfig([
 'mode' => 'live',
]);

running this via wp_ajax

Any help would be appreciated! Thanks!

2/5/2019: Seems other people got this problem: https://github.com/paypal/PayPal-PHP-SDK/issues/435

Also the same question on StackOverflow that I missed ... that also had no answer. PayPal App works perfectly as Sandbox, Client Authentication failed on Live: list of steps to check?

like image 795
chi11ax Avatar asked Feb 04 '19 07:02

chi11ax


3 Answers

Try to change return new SandboxEnvironment($clientId, $clientSecret); to

return new ProductionEnvironment($clientId, $clientSecret); in your PayPalClient.php class

like image 112
Eugene Avatar answered Oct 09 '22 07:10

Eugene


https://developer.paypal.com/docs/api/overview/#api-requests

when using live credentials the url should be https://api.paypal.com instead https://api.sandbox.paypal.com

reference https://github.com/paypal/PayPal-PHP-SDK/issues/435#issuecomment-462133355

like image 40
user3512810 Avatar answered Oct 09 '22 06:10

user3512810


I was having a similar issue trying to generate the REST API token, following PayPal REST API docs for sandbox API works. Live should be the same. Make sure you're grabbing the REST API credentials and not grabbing the "NVP/SOAP API apps" secret.

Go here: https://developer.paypal.com/developer/applications/

At the top select Sandbox or Live

Click Create App under REST API apps, NOT NVP/SOAP API apps.

This will give you a Client ID and Secret, both look like a string of upper and lower case alphanumeric, some 40-50 chars in length.

With these credentials, run this curl command to get your access token so you can make calls to the REST API, substitute your client id and secret:

curl -v POST https://api.sandbox.paypal.com/v1/oauth2/token \
  -H "Accept: application/json" \
  -H "Accept-Language: en_US" \
  -u "CLIENT_ID:SECRET" \
  -d "grant_type=client_credentials"

This should return your token:

Sample response
{
    "scope": "https://uri.paypal.com/services/invoicing https://uri.paypal.com/services/disputes/read-buyer https://uri.paypal.com/services/payments/realtimepayment https://uri.paypal.com/services/disputes/update-seller https://uri.paypal.com/services/payments/payment/authcapture openid https://uri.paypal.com/services/disputes/read-seller https://uri.paypal.com/services/payments/refund https://api.paypal.com/v1/vault/credit-card https://api.paypal.com/v1/payments/.* https://uri.paypal.com/payments/payouts https://api.paypal.com/v1/vault/credit-card/.* https://uri.paypal.com/services/subscriptions https://uri.paypal.com/services/applications/webhooks",
    "access_token": "A21AAFEpH4PsADK7qSS7pSRsgzfENtu-Q1ysgEDVDESseMHBYXVJYE8ovjj68elIDy8nF26AwPhfXTIeWAZHSLIsQkSYz9ifg",
    "token_type": "Bearer",
    "app_id": "APP-80W284485P519543T",
    "expires_in": 31668,
    "nonce": "2020-04-03T15:35:36ZaYZlGvEkV4yVSz8g6bAKFoGSEzuy3CQcz3ljhibkOHg"
}

You don't typically integrate these things into your application, rather these are things you do once and then you embed the REST API token into your application.

I know this is kind of repeating the obvious but I hope this helps.

See further instructions here: https://developer.paypal.com/docs/platforms/get-started/#step-1-get-api-credentials

like image 35
John Avatar answered Oct 09 '22 08:10

John