2

I've been trying to create a Paypal adaptive payments API call to the sandbox all day now without success. I've read dozends of tutorials, SE threads etc but nothing I tried worked. I keep getting the "Authentication failed. API credentials are incorrect." error message.

The following is the code I'm using:

$baseurl = 'https://svcs.sandbox.paypal.com/AdaptivePayments/Pay'; 

define('PAYPAL_API_USER', '<snip>');
define('PAYPAL_API_PWD', '<snip>');
define('PAYPAL_API_SIGNATURE', '<snip>');
define('PAYPAL_API_APPLICATION_ID', 'APP-80W284485P519543T');

$returnurl = "<snip>";
$cancelurl = "<snip>";

$data = array(
    "actionType" => "PAY",
    "currencyCode" => "USD",
    "receiverList" => array(
        "receiver" => array(
            array(
                "amount" => "1.00",
                "email" => "<snip>"
            ),
        )
    ),
    "returnUrl" => $returnurl,
    "cancelUrl" => $cancelurl,
    "requestEnvelope" => array(
        "errorLangauge" => "en_US",
        "detailLevel" => "ReturnAll",
    )
);

$headers = array(
    "X-PAYPAL-SECURITY-USERID: ".PAYPAL_API_USER,
    "X-PAYPAL-SECURITY-PASSWORD: ".PAYPAL_API_PWD,
    "X-PAYPAL-SECURITY-SIGNATURE: ".PAYPAL_API_SIGNATURE,
    "X-PAYPAL-SECURITY-REQUEST-DATA-FORMAT: JSON",
    "X-PAYPAL-SECURITY-RESPONSE-DATA-FORMAT: JSON",
    "X-PAYPAL-SECURITY-APPLICATION-ID: ".PAYPAL_API_APPLICATION_ID,
);

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $baseurl);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt ($ch, CURLOPT_POSTFIELDS, json_encode($data)); 
curl_setopt ($ch, CURLOPT_HEADER, $headers);
print_r(curl_exec($ch));

I created several test accounts under "Sandbox Test Accounts" on developer.paypal.com. I tried using their username + password + signature (from the API Credentials tab) in the code above. Always getting "Authentication failed. API credentials are incorrect."

Edit 1:

On this page: https://developer.paypal.com/docs/classic/adaptive-payments/gs_AdaptivePayments/ they have a similar curl command. I run this command:

curl -s --insecure -H "X-PAYPAL-SECURITY-USERID: caller_1312486258_biz_api1.gmail.com" -H "X-PAYPAL-SECURITY-PASSWORD: 1312486294" -H "X-PAYPAL-SECURITY-SIGNATURE: AbtI7HV1xB428VygBUcIhARzxch4AL65.T18CTeylixNNxDZUu0iO87e" -H "X-PAYPAL-REQUEST-DATA-FORMAT: JSON" -H "X-PAYPAL-RESPONSE-DATA-FORMAT: JSON" -H "X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T" https://svcs.sandbox.paypal.com/AdaptivePayments/Pay -d "{\"actionType\":\"PAY\", \"currencyCode\":\"USD\", \"receiverList\":{\"receiver\":[{\"amount\":\"1.00\",\"email\":\"[email protected]\"}]}, \"returnUrl\":\"http://www.example.com/success.html\", \"cancelUrl\":\"http://www.example.com/failure.html\", \"requestEnvelope\":{\"errorLanguage\":\"en_US\", \"detailLevel\":\"ReturnAll\"}}"

in a terminal window and got a payment created success response. So next I switched the userid/password/signature in this command with the ones from the original question, and guess what, that worked too!

Finally I used the userid/password/signature from the example in the PHP curl code from my original question and again got the "Authentication failed. API credentials are incorrect." message.

To sum things up both userid/password/signature combinations (mine and Paypal's) generate a success response if run via terminal, but both produce authentication failure errors when run via my PHP CURL code. So there is definitely something wrong in my original code, question is WHAT??

Edit 2:

Still can't get it to work, but I'm thinking it's something to do with the headers bit. Here is why: take a look at the full response I'm getting:

HTTP/1.1 200 OK
Date: Tue, 13 Oct 2015 11:51:23 GMT
Server: Apache
X-EBAY-SOA-REQUEST-ID: 150610a6-a690-a488-6781-12e6ffa2f8dd!AdaptivePayments!10.72.134.120![]
X-PAYPAL-SERVICE-VERSION: 1.0.0
X-PAYPAL-SERVICE-NAME: {http://svcs.paypal.com/types/ap}AdaptivePayments
X-EBAY-SOA-RESPONSE-DATA-FORMAT: XML
X-PAYPAL-OPERATION-NAME: Pay
CACHE-CONTROL: no-cache
X-PAYPAL-ERROR-RESPONSE: TRUE
X-EBAY-SOA-MESSAGE-PROTOCOL: NONE
Set-Cookie: Apache=10.72.108.11.1444737084008373; path=/; expires=Thu, 05-Oct-45 11:51:24 GMT
Vary: Accept-Encoding
Paypal-Debug-Id: 32922591f3d33
Set-Cookie: X-PP-SILOVER=name%3DSANDBOX3.APIT.1%26silo_version%3D880%26app%3Dadaptivepaymentspartaweb_api3t%26TIME%3D1005591638; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT
Connection: close
Transfer-Encoding: chunked
Content-Type: text/xml;charset=UTF-8

<?xml version='1.0' encoding='UTF-8'?><ns3:FaultMessage xmlns:ns3="http://svcs.paypal.com/types/common" xmlns:ns2="http://svcs.paypal.com/types/ap"><responseEnvelope><timestamp>2015-10-13T04:51:24.021-07:00</timestamp><ack>Failure</ack><correlationId>e133487976d4b</correlationId><build>17820627</build></responseEnvelope><error><errorId>520003</errorId><domain>PLATFORM</domain><subdomain>Application</subdomain><severity>Error</severity><category>Application</category><message>Authentication failed. API credentials are incorrect.</message></error></ns3:FaultMessage>

It's XML why I specified JSON as the response data format. So if the response format line is ignored or not properly read I guess the same thing is messing the login details. Hope this is a good clue...

1 Answer 1

0

If you are 100% certain that the API Credentials for a business Sandbox account are correct then verify you have the correct App id. The APP Id needs to be the APP id from the application you submitted for Adaptive Payments. If you have not submitted an application yet here are the instructions:
How to Submit a Developer Application
If you have already applied for Adaptive Payments go to your list of applications, and click on your application to verify the correct App id.

7
  • but I'm only testing in sandbox... I'm using the global sandbox App id - APP-80W284485P519543T.
    – Liam Arbel
    Oct 12, 2015 at 22:37
  • You can test in sandbox but you need your own app id. The global app id will not work with your sandbox API Credentials. Oct 12, 2015 at 22:44
  • pp_MSI_Jenn that's just the thing. I CAN'T test in sandbox as I keep getting the authentication error. I want to be able to test just like the guy in this video: youtube.com/watch?v=rzRR1i-F_VA using the APP-80W284485P519543T sandbox App id
    – Liam Arbel
    Oct 12, 2015 at 23:06
  • You will need to use the test API Credentials that go along with the test APP and not your sandbox API Credentials. If you use your API credentials our server is looking for the Application that goes with your sandbox API Credentials. Here is a link to the Test Adaptive Payments API go to try it and use all the test credentials. Oct 13, 2015 at 15:30
  • pp_MSI_Jenn: on the developer.paypal.com dashboard, if I go to "My apps" and click on an app I get a credential pair of "Client ID" and "Secret", NOT the user ID/password/signature combination the adaptive API requires... More so, as I mentioned before the user ID/password/signature of the sandbox test account do work when sent using curl via SSH just like in the example you referred me to, but DON'T work when using PHP CURL as per my original post. I am now completely at loss!
    – Liam Arbel
    Oct 14, 2015 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.