Currently using PHP + cURL to test the NVP SetExpressCheckout Paypal feature (sandbox mode) on xampp,
no matter what I do, I receive the following error:
Error Code 10002 : Authentication/Authorization Failed. You do not have permission to make this API call.
$nvp = array(
'METHOD' => 'SetExpressCheckout',
'VERSION' => '98',
'USER' => $user,
'PWD' => $pwd,
'SIGNATURE' => $signature,
'RETURNURL' => $returnurl,
'CANCELURL' => $cancelurl,
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
'PAYMENTREQUEST_0_AMT' => '20.00',
'PAYMENTREQUEST_0_CURRENCYCODE' => $currency,
'REQCONFIRMSHIPPING' => '0',
'NOSHIPPING' => '1',
'ALLOWNOTE' => '0',
'LOCALECODE' => 'US'
'L_PAYMENTREQUEST_0_NAME0' = 'A product name';
'L_PAYMENTREQUEST_0_AMT0' = '20.00';
'L_PAYMENTREQUEST_0_QTY0' = '1';
'L_PAYMENTREQUEST_0_ITEMCATEGORY0' = 'Digital';
);
$request = 'https://api-3t.sandbox.paypal.com/nvp?' . http_build_query($nvp);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $request);
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = urldecode(curl_exec($curl));
curl_close($curl);
The weird thing is if I type curl request(the same as $request variable) in the browser I get the SUCCESS and token from the endpoint,
I don't know if it has something to do with the curl itself or if it's something else, I tried to completely
disable my firewall but the error persists...
Your array is malformed.
'L_PAYMENTREQUEST_0_NAME0' = 'A product name';
That's a good way to start debugging
Related
I'm trying to integrate Paypal express checkout integration with PayPal REST API.
JS file looks like this:
paypal.Button.render({
env: 'sandbox', // sandbox | production
commit: true,
payment: function() {
var CREATE_URL = 'createpayment';
return paypal.request.get(CREATE_URL)
.then(function(res) {
return res.paymentID;
});
},
onAuthorize: function(data, actions) {
var EXECUTE_URL = 'executepayment';
var data = {
paymentID: data.paymentID,
payerID: data.payerID
};
return paypal.request.post(EXECUTE_URL, data)
.then(function (res) {
window.alert('Payment Complete!');
});
}
}, '#paypal-button-container');
Now I can't figure out what should be in CREATE_URL and EXECUTE_URL url's php files. I have read a lot of their docs. I understand that in php I should make first request to get token, then I should make create-payment request and after execute-payment curl reuqest. But I have no-luck.
I also don't understand how should I pass payment value to CREATE_URL php file.
Several days ago I found here some good answer of my question with all examples, but it's about two days I can't find it.
Update: ALso I need to pass input amount to php file from payment request. And I can't do that using return paypal.request.get(CREATE_URL, data)
request.
Can anybody help me please.
Thank you.
Share some examples for server PHP code.
PHP Code in CREATE_URL:
<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp');
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(array(
'USER' => 'xxxxx',
'PWD' => 'xxxxx',
'SIGNATURE' => 'xxxxx',
'METHOD' => 'SetExpressCheckout',
'VERSION' => '108',
'LOCALECODE' => 'en_US',
'PAYMENTREQUEST_0_AMT' => 100,
'PAYMENTREQUEST_0_CURRENCYCODE' => 'USD',
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
'PAYMENTREQUEST_0_ITEMAMT' => 100,
'L_PAYMENTREQUEST_0_NAME0' => 'test name',
'L_PAYMENTREQUEST_0_DESC0' => 'test desc',
'L_PAYMENTREQUEST_0_QTY0' => 1,
'L_PAYMENTREQUEST_0_AMT0' => 100,
'CANCELURL' => 'http://localhost/cancel.html',
'RETURNURL' => 'http://localhost/success.html'
)));
$response = curl_exec($curl);
curl_close($curl);
$nvp = array();
if (preg_match_all('/(?<name>[^\=]+)\=(?<value>[^&]+)&?/', $response, $matches)) {
foreach ($matches['name'] as $offset => $name) {
$nvp[$name] = urldecode($matches['value'][$offset]);
}
}
if (isset($nvp['ACK']) && $nvp['ACK'] == 'Success') {
echo $nvp['TOKEN'];
} else {
//failed
}
?>
PHP Code in EXECUTE_URL:
<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp');
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(array(
'USER' => 'xxxxx',
'PWD' => 'xxxxx',
'SIGNATURE' => 'xxxxx',
'METHOD' => 'DoExpressCheckoutPayment',
'VERSION' => '108',
'LOCALECODE' => 'en_US',
'TOKEN' => $_POST['TOKEN'],
'PayerID' => $_POST['PAYERID'],
'PAYMENTREQUEST_0_AMT' => 100,
'PAYMENTREQUEST_0_CURRENCYCODE' => 'USD',
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
'PAYMENTREQUEST_0_ITEMAMT' => 100,
'L_PAYMENTREQUEST_0_NAME0' => 'test name',
'L_PAYMENTREQUEST_0_DESC0' => 'test desc',
'L_PAYMENTREQUEST_0_QTY0' => 1,
'L_PAYMENTREQUEST_0_AMT0' => 100,
)));
$response = curl_exec($curl);
curl_close($curl);
$nvp = array();
if (preg_match_all('/(?<name>[^\=]+)\=(?<value>[^&]+)&?/', $response, $matches)) {
foreach ($matches['name'] as $offset => $name) {
$nvp[$name] = urldecode($matches['value'][$offset]);
}
}
print_r($nvp);
Hi I implement PayPal DoDirectPayment in my website, I want to required expire date And CVV but payment taking without those with this warning "This transaction was approved. However, the Card Security Code provided had too few, too many, or invalid character types but, as per your account option settings, was not required in the approval process"
I'm using PHP.
My Code is
$api_endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
$request = array
(
'METHOD' => 'DoDirectPayment',
'USER' => 'sell3_api1.pay.com',
'PWD' => '75DQHCABLDFSDF',
'SIGNATURE' => 'AFcWxV21C7fd0asdasdCpasdsdAtxzafSFsaKZ3unSUBjX9r-',
'VERSION' => '55.0',
'PAYMENTACTION' => 'Sale',
'FIRSTNAME' => $current_user->user_login,
'LASTNAME' => '.',
'IPADDRESS' => $_SERVER['REMOTE_ADDR'],
'ACCT' => $acct,
'CREDITCARDTYPE'=>
'EXPDATE' => $month.$year,
'CVV2' => $cvv,
'AMT' => $amt,
'CURRENCYCODE' => 'USD',
);
$nvp_string = '';
foreach ($request as $key => $value) {
$nvp_string .= '&'.$key.'='.urlencode($value);
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_URL, $api_endpoint);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $nvp_string);
$result = curl_exec($curl);
curl_close($curl);
parse_str($result);
How can I solve It.
I develop a paypal pro in magento.
my paypal code look below:
$api_username = 'sdk-three_api1.sdk.com';
$api_password = 'QFZCWN5HZM8VBG7Q';
$api_signature = 'A.d9eRKfd1yVkRrtmMfCFLTqa6M9AyodL0SJkhYztxUi8W9pCXF6.4NI';
$api_version = '57.0';
$api_endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
$request_params = array
(
'METHOD' => 'DoDirectPayment',
'USER' => $api_username,
'PWD' => $api_password,
'SIGNATURE' => $api_signature,
'VERSION' => $api_version,
'PAYMENTACTION' => 'Sale',
'IPADDRESS' => $_SERVER['REMOTE_ADDR'],
'CREDITCARDTYPE' => $params['creditCardType'],
'ACCT' => $params['creditCardNumber'],
'EXPDATE' => $params['expDateMonth'].$params['expDateYear'],
'CVV2' => $params['cvv2Number'],
'FIRSTNAME' => 'Tester',
'LASTNAME' => 'Testerson',
'STREET' => '707 W. Bay Drive',
'CITY' => 'Largo',
'STATE' => 'FL',
'COUNTRYCODE' => 'US',
'ZIP' => '33770',
'AMT' => $plan_data['amount'],
'CURRENCYCODE' => 'USD',
'DESC' => 'Testing Payments Pro'
);
$nvp_string = '';
foreach($request_params as $var=>$val)
{
$nvp_string .= '&'.$var.'='.urlencode($val);
}
//var_dump($nvp_string); die;
$curl = curl_init();
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_URL, $api_endpoint);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $nvp_string);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSLVERSION, 3);
curl_setopt($curl, CURLOPT_SSL_CIPHER_LIST, 'SSLv3');
//curl_setopt($curl, CURLOPT_SSL_CIPHER_LIST, 'TLSv1');
$result = curl_exec($curl);
if (curl_errno($curl))
{
echo "CURL send a error during perform operation: ".curl_error($curl);
}
else
{
curl_close($curl);
}
// Parse the API response
$nvp_response_array = parse_str($result);
var_dump($result);
But i getting an error like
error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake
failure
And if i not added this two line
curl_setopt($curl, CURLOPT_SSLVERSION, 3);
curl_setopt($curl, CURLOPT_SSL_CIPHER_LIST, 'SSLv3');
then give me an error like
error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
Any help?
There was some updates to Sandbox recently, updates that will need to be applied on Live at a later time, this post will help you
I'm trying to authenticate using OAuth in OpenX (site does not render well in chrome. Use iexplore or safari.)
This is my piece of code
# Login
$url = "https://sso.openx.com/api/index/token";
$post = http_build_query( array( 'Access Token URL' => 'https://sso.openx.com/api/index/token',
'Authorize URL' => 'https://sso.openx.com/login/login',
'callbackUrl' => 'oob',
'Consumer Key' => $key,
'Consumer Secret' => $secret,
'OAuth Realm' => $realm,
'Request Token URL' => 'https://sso.openx.com/api/index/initiate',
'Signature Method' => 'HMAC-SHA1 ',
'Version' => '1.0a ') );
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($resource, CURLOPT_POSTFIELDS, $post);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$json_response = curl_exec($curl);
var_dump($json_response);
curl_close($curl);
$authObj = json_decode($json_response);
And, according to the linked documentation, I should be expecting an oauth_token and oauth_verifier:
1.Set the callbackUrl to oob (out-of-band), which tells the OAuth server that you are not redirecting a user. The OAuth Server returns the request token.
but instead I'm getting:
HTTP/1.1 400 Bad Request - Invalid Request: Missing parameters
Am I doing something obviously wrong here that I am missing? Am I misunderstanding something in the linked documentation?
Any sort of help is welcome, either aimed at the problem itself or to the way it's been presented; answers, hints, ideas, corrections, etc.
Thank you.
I am using openx too, here is my code. Hope it can help someone
$para = array (
'Access Token URL' => 'https://sso.openx.com/api/index/token',
'Authorize URL' => 'https://sso.openx.com/login/process',
'callbackUrl' => 'oob',
'Consumer Key' => $email,
'Consumer Secret' => $consumer_secret,
'OAuth Realm' => $sso_realm,
'Request Token URL' => 'https://sso.openx.com/api/index/initiate',
'Signature Method' => 'HMAC-SHA1',
'Version' => '1.0a'
);
$opt = array (
CURLOPT_URL => "https://sso.openx.com/login/process",
CURLOPT_COOKIEFILE => $cookieFile,
CURLOPT_COOKIEJAR => $cookieFile,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $para,
CURLOPT_VERBOSE => true,
CURLOPT_HEADER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERPWD => "{$authentication}",
CURLOPT_FOLLOWLOCATION => true
);
$c = curl_init();
curl_setopt_array($c, $opt);
$content = curl_exec($c);
$info = curl_getinfo($c);
$error = curl_error($c);
You need the "consumer_secret" and "sso_realm" from the email openx people sent to you.
Try passing the parameters like this
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
where $data will have $data='username='.$username.'&password='.$password.'';
Where does "$resource" come from?? Replace:
curl_setopt($resource, CURLOPT_POSTFIELDS, $post);
with
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
for a start.
I have registered on PayPal Sandbox, then I added Seller Preconfigured test account. As for ApplicationId, I used few ones found on Web. Finally, triggering Preapproval, I'm having error in response:
Array
(
[RESPONSEENVELOPE.TIMESTAMP] => 2011-12-26T19:39:54.500-08:00
[RESPONSEENVELOPE.ACK] => Failure
[RESPONSEENVELOPE.CORRELATIONID] => a052cd3abd4ea
[RESPONSEENVELOPE.BUILD] => 2279004
[ERROR(0).ERRORID] => 520003
[ERROR(0).DOMAIN] => PLATFORM
[ERROR(0).SUBDOMAIN] => Application
[ERROR(0).SEVERITY] => Error
[ERROR(0).CATEGORY] => Application
[ERROR(0).MESSAGE] => Authentication failed. API credentials are incorrect.
)
PHP code:
$URL = 'https://svcs.sandbox.paypal.com/AdaptivePayments/Preapproval'
.'?startingDate='.date('Y-m-d\Z')
.'&endingDate='.date('Y-m-d\Z', strtotime('+1 year'))
.'¤cyCode=USD'
.'&maxTotalAmountOfAllPayments=500.00'
.'&maxAmountPerPayment=200.00'
.'&maxNumberOfPayments=30'
.'&senderEmail=user#domain.com'
.'&cancelUrl=http://example.com/cancel'
.'&returnUrl=http://example.com'
.'&pinType=NOT_REQUIRED'
.'&requestEnvelope.errorLanguage=en_US';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER
, array(
'X-PAYPAL-SECURITY-USERID' => 'xxxx'
, 'X-PAYPAL-SECURITY-PASSWORD' => 'xxxx'
, 'X-PAYPAL-SECURITY-SIGNATURE' => 'xxxxxxxxxxxxxxxxxxxx'
, 'X-PAYPAL-APPLICATION-ID' => 'APP-80W284485P519543T'
, 'X-PAYPAL-REQUEST-DATA-FORMAT' => 'NV'
, 'X-PAYPAL-RESPONSE-DATA-FORMAT' => 'NV'
)
);
$response = curl_exec($ch);
$responseAr = explode('&', $response);
$parsedResponseAr = array();
foreach($responseAr as $i => $value) {
$tmpAr = explode('=', $value);
if(!empty($tmpAr))
$parsedResponseAr[strtoupper($tmpAr[0])] = urldecode($tmpAr[1]);
}
print_r($parsedResponseAr);
Could that be because of wrong App Ids? Do I have to register my App first to get App Id to use it in Sandbox?
Edit: I found the reason: the format of headers array was incorrect.
It should be:
array(
'X-PAYPAL-SECURITY-USERID: xxx'
, 'X-PAYPAL-SECURITY-PASSWORD: xxxx'
, 'X-PAYPAL-SECURITY-SIGNATURE: xxxxxxxx'
, 'X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T'
, 'X-PAYPAL-REQUEST-DATA-FORMAT: NV'
, 'X-PAYPAL-RESPONSE-DATA-FORMAT: NV'
)
[ERROR(0).MESSAGE] => Authentication failed. API credentials are incorrect.
bit of a give away!