0

On one of Paypal's API documentation pages there is the following 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\"}}"

Running this command via SSH yields a success response.

I'm try to have this exact command run via PHP CURL, but keep getting an error message that the API credentials are incorrect. Since that is obviously not the case (otherwise the above command would have yielded a similar response) I can't come to any conclusion other than there is something wrong with my code, yet a mistake that has been eluding me for several days now:

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

define('PAYPAL_API_USER', 'caller_1312486258_biz_api1.gmail.com');
define('PAYPAL_API_PWD', '1312486294');
define('PAYPAL_API_SIGNATURE', 'AbtI7HV1xB428VygBUcIhARzxch4AL65.T18CTeylixNNxDZUu0iO87e');
define('PAYPAL_API_APPLICATION_ID', 'APP-80W284485P519543T');

$returnurl = "http://www.returnurl.net";
$cancelurl = "http://www.cancelnurl.net";

$data = array(
    "actionType" => "PAY",
    "currencyCode" => "USD",
    "receiverList" => array(
        "receiver" => array(
            array(
                "amount" => "1.00",
                "email" => "[email protected]"
            ),
        )
    ),
    "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));

Can anyone spot anything wrong with this code?

Once again I must stress that this is strictly a PHP CURL issue, not a Paypal one.

3
  • 1
    You shouldn't be including your security keys/passwords.... this is a public forum.. Commented Oct 15, 2015 at 23:59
  • Darren these are public ones published on a Paypal documentation page: developer.paypal.com/docs/classic/adaptive-payments/…. I would of course never post my own Commented Oct 16, 2015 at 11:39
  • Just looking out my friend :-) Commented Oct 16, 2015 at 11:41

1 Answer 1

4

Hmm, try:

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

use CURLOPT_HTTPHEADER instead of CURLOPT_HEADER. CURLOPT_HEADER is just a flag, which you can use if you want to see the response's headers in output.

source: http://php.net/manual/ro/function.curl-setopt.php

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.