Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paypal NVP API - Keep getting error 81002

Tags:

php

paypal

I am new to PayPal API, and I'm having trouble calling SetExpressCheckout using CURL in PHP. I have set everything correctly, as far as I'm concerned, but I kept getting an 81002 error "Method Specified is not Supported".

The code snippet is below. I got the CA Root certificates file from here.

<?php

$paypal_data = array(
    'USER' => urlencode('andree_1272823561_biz_api1.gmail.com'),
    'PWD' => urlencode('1272823576'),
    'SIGNATURE' => urlencode('Am1t0wiu2tv7VwZ5ebdeY9zv1GF6Ad0PFz-qTGFFf7vbWU6ee4bxy8KL'),
    'VERSION' => urlencode('52.0'),
    'PAYMENTACTION' => urlencode('Sale'),
    'METHOD' => urlencode('SetExpressCheckout'),
    'AMT' => urlencode('52.00'),
    'RETURNURL' => urlencode('get_express_checkout_details.php'),
    'CANCELURL' => urlencode('index.php')
);

$url = 'https://api-3t.sandbox.paypal.com/nvp?' . http_build_query($paypal_data);
$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');

$result = curl_exec($curl);
curl_close($curl);
parse_str($result, $result);
?>

<pre>Data sent: <?php print_r($paypal_data); ?></pre>
<pre>Result: <?php print_r($result); ?></pre>

When I run the code, the output is the following:

Data sent: Array
(
    [USER] => andree_1272823561_biz_api1.gmail.com
    [PWD] => 1272823576
    [SIGNATURE] => Am1t0wiu2tv7VwZ5ebdeY9zv1GF6Ad0PFz-qTGFFf7vbWU6ee4bxy8KL
    [VERSION] => 52.0
    [PAYMENTACTION] => Sale
    [METHOD] => SetExpressCheckout
    [AMT] => 52.00
    [RETURNURL] => get_express_checkout_details.php
    [CANCELURL] => index.php
)

Result: Array
(
    [ACK] => Failure
    [L_ERRORCODE0] => 81002
    [L_SHORTMESSAGE0] => Unspecified Method
    [L_LONGMESSAGE0] => Method Specified is not Supported
    [L_SEVERITYCODE0] => Error
)

Anyone knows what could be the problem?

Regards, Andree.

like image 892
Andree Avatar asked May 03 '10 13:05

Andree


3 Answers

The problem is when you use urlencode + http_build_query. You will end up with double encoding and PayPal will reject some of the info.

like image 110
Tomas Avatar answered Nov 16 '22 03:11

Tomas


I had this problem and in the end discovered that it was a problem with getting the parameters transmitted at all. I was using the following kind of code to pass the parameters (as shown in various examples on the net for PayPal):

   http.set_form_data({"q" => "ruby", "lang" => "en"}, ';')

When I changed this to:

   http.form_data = {"q" => "ruby", "lang" => "en"}

it stopped giving me the unknown method error (and moved onto other errors :-)

The Ruby code below worked for me (I have removed the return URLs though). The username etc are standard sandbox ones.

# http://www.ensta-paristech.fr/~diam/ruby/online/ruby-doc-stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html
# https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECGettingStarted

require 'net/https'
require 'uri'

uri = URI('https://api-3t.sandbox.paypal.com/nvp')

request_object = Net::HTTP::Post.new(uri.path)

request_object.form_data = {
'USER'=>'sdk-three_api1.sdk.com', # Sandbox value. See e_howto_api_ECGettingStarted
'PWD'=>'QFZCWN5HZM8VBG7Q',  # Sandbox value. See e_howto_api_ECGettingStarted
'SIGNATURE'=>'A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU',  # Sandbox value. See e_howto_api_ECGettingStarted
'METHOD'=>'SetExpressCheckout',
'VERSION'=>'88.0',
'PAYMENTREQUEST_0_PAYMENTACTION'=>'Sale',
'PAYMENTREQUEST_0_AMT'=>'23.00',  # Must have exactly two decimals for cents. See e_howto_api_ECGettingStarted above.
'PAYMENTREQUEST_0_CURRENCYCODE'=>'USD',
'cancelUrl'=>'http://www.add your own URL here',
'returnUrl'=>'http://www.add your own URL here'
}

http = Net::HTTP.new(uri.host,uri.port)
# HACK: The following two lines turn off secure certificate checking!!
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
response = http.request(request_object)
like image 30
Anonymous Coward Avatar answered Nov 16 '22 05:11

Anonymous Coward


I am not using the PHP API, but I ran into the same 81002 error using the Callback API (java) and I got this when some of the parameters were either missing or badly formated.

I don't know if you solved the issue, but my advice would be checking which of the parameters are requred for the SetExpressCheckout (API Reference). And than if you have set those, check if the limitations part of the description of the parameter is satisfied.

Sadly but they sometimes throw inappropriate errors (or errors that the developer can't quite understand). On the other side I usually get most of my responses answered on their forum. If in "trouble" you can also write a private message to the paypal team member on shift (or to a person that has already solved your problem).

Hope that helped!
Despot

like image 2
despot Avatar answered Nov 16 '22 03:11

despot