i am using credit card with paypal payment code from below site-
http://code.tutsplus.com/tutorials/how-to-process-credit-cards-with-paypal-payments-pro-using-php--net-25397
and got my api credentials from here-
https://www.paypal.com/uk/cgi-bin/webscr?cmd=_profile-api-signature
and i am entering my API usaername, API password and signature but it is returning "ACK=Failure".I followed its comments but did not get proper solution, my code is-
includes/config.php
// Set sandbox (test mode) to true/false.
$sandbox = TRUE;
// Set PayPal API version and credentials.
$api_version = '85.0';
$api_endpoint = $sandbox ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp';
$api_username = $sandbox ? 'SANDBOX_USERNAME_GOES_HERE' : 'LIVE_USERNAME_GOES_HERE';
$api_password = $sandbox ? 'SANDBOX_PASSWORD_GOES_HERE' : 'LIVE_PASSWORD_GOES_HERE';
$api_signature = $sandbox ? 'SANDBOX_SIGNATURE_GOES_HERE' : 'LIVE_SIGNATURE_GOES_HERE';
process-credit-card.php
// Include config file
require_once('includes/config.php');
// Store request params in an array
$request_params = array
(
'METHOD' => 'DoDirectPayment',
'USER' => $api_username,
'PWD' => $api_password,
'SIGNATURE' => $api_signature,
'VERSION' => $api_version,
'PAYMENTACTION' => 'Sale',
'IPADDRESS' => $_SERVER['REMOTE_ADDR'],
'CREDITCARDTYPE' => 'MasterCard',
'ACCT' => '5522340006063638',
'EXPDATE' => '022013',
'CVV2' => '456',
'FIRSTNAME' => 'Tester',
'LASTNAME' => 'Testerson',
'STREET' => '707 W. Bay Drive',
'CITY' => 'Largo',
'STATE' => 'FL',
'COUNTRYCODE' => 'US',
'ZIP' => '33770',
'AMT' => '100.00',
'CURRENCYCODE' => 'USD',
'DESC' => 'Testing Payments Pro'
);
// Loop through $request_params array to generate the NVP string.
$nvp_string = '';
foreach($request_params as $var=>$val)
{
$nvp_string .= '&'.$var.'='.urlencode($val);
}
// Send NVP string to PayPal and store response
$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);
var_dump($result);
// Parse the API response
$nvp_response_array = parse_str($result);
// Function to convert NTP string to an array
function NVPToArray($NVPString)
{
$proArray = array();
while(strlen($NVPString))
{
// name
$keypos= strpos($NVPString,'=');
$keyval = substr($NVPString,0,$keypos);
// value
$valuepos = strpos($NVPString,'&') ? strpos($NVPString,'&'): strlen($NVPString);
$valval = substr($NVPString,$keypos+1,$valuepos-$keypos-1);
// decoding the respose
$proArray[$keyval] = urldecode($valval);
$NVPString = substr($NVPString,$valuepos+1,strlen($NVPString));
}
return $proArray;
}
Error
ACK=Failure
L_SHORTMESSAGE0=Security error
L_LONGMESSAGE0=Security header is not valid
How to solve this error?
Quite simple Google search came up with this:
http://www.prestashop.com/forums/topic/125029-security-header-is-not-valid-read-first/
Which says:
[...] your credentials are incorrect or [...] you are using
SandBox credentials with production mode (or production credentials
with sandbox mode). If you are in production, you have to check
INACTIVE for SandBox mode (be sure to fill the configuration form with
your production credentials and not your sandbox credentials).
And adds:
If the problem is not coming from the test mode that means your credentials are incorrect.
So I would start there.
Also instead of creating that query string manually with foreach construct, try looking into http-build-query() function: http://php.net/manual/en/function.http-build-query.php
Related
I am trying to implement "DoDirectPayment" method in my website.
I have paypal sandbox account and I have paypal api into.
When I have set the currency as 'USD' then my code return success message.
But when I set 'HKD' currency then it return "This transaction cannot be processed due to an unsupported currency" message.
Here I have attached my code. Please check and give me some solution.
$api_version = '78.0';
$api_endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
$api_username = 'platfo_1255077030_biz_api1.gmail.com';
$api_password = '1255077037';
$api_signature = 'Abg0gYcQyxQvnf2HDJkKtA-p6pqhA1k-KTYE0Gcy1diujFio4io5Vqjf';
$creditcardtype = 'VISA';
$cardno = '4854897648835021';
$expdate = '112020';
$cvv = '176';
$PRICE = '50.00';
$currency_code = 'HKD';
$request_params = array(
'USER' => $api_username,
'PWD' => $api_password,
'SIGNATURE' => $api_signature,
'VERSION' => $api_version,
'PAYMENTACTION' => 'SALE',
'CREDITCARDTYPE' => $creditcardtype,
'ACCT' => $cardno,
'EXPDATE' => $expdate,
'CVV2' => $cvv,
'AMT' => $PRICE,
'CURRENCYCODE' => $currency_code,
'FIRSTNAME'=>'James',
'LASTNAME'=>'Smith',
'STREET'=>'FirstStreet',
'CITY'=>'SanJose',
'STATE'=>'CA',
'COUNTRYCODE'=>'US',
'ZIP'=>95131
);
$request_params['METHOD'] = 'DoDirectPayment';
$nvp_string = '';
foreach($request_params as $var=>$val)
{
$nvp_string .= '&'.$var.'='.urlencode($val);
}
$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);
$response = NVPToArray($result);
echo '<pre>';
print_r($response);
echo '</pre>';
function NVPToArray($NVPString)
{
$proArray = array();
while(strlen($NVPString))
{
$keypos= strpos($NVPString,'=');
$keyval = substr($NVPString,0,$keypos);
$valuepos = strpos($NVPString,'&') ? strpos($NVPString,'&'): strlen($NVPString);
$valval = substr($NVPString,$keypos+1,$valuepos-$keypos-1);
$proArray[$keyval] = urldecode($valval);
$NVPString = substr($NVPString,$valuepos+1,strlen($NVPString));
}
return $proArray;
}
Here is the output message
http://i.imgur.com/JMMG4I3.png
Thanks in advance
Refer to https://developer.paypal.com/docs/classic/api/currency_codes/?mark=currency , in "Multi-currency support for direct credit card products" part, if your sandbox account country is USD, the supported currencies are AUD, CAD, EUR, GBP, JPY, USD, so HKD is not supported.
Hi I want to test payment in paypal test account but I am facing error
ACK: "Failure"
AMT: "100.00"
BUILD: "9915774"
CORRELATIONID: "39d5ad29e8411"
CURRENCYCODE: "USD"
L_ERRORCODE0: "10501"
L_LONGMESSAGE0: "This transaction cannot be processed due to an invalid merchant configuration."
L_SEVERITYCODE0: "Error"
L_SHORTMESSAGE0: "Invalid Configuration"
TIMESTAMP: "2014-03-18T07:29:45Z"
VERSION: "85.0"
my config.php file is
$sandbox = TRUE;
// Set PayPal API version and credentials.
$api_version = '85.0';
$api_endpoint = $sandbox ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp';
$api_username = $sandbox ? 'shafiq2626-facilitator#hotmail.com' : 'shafiq2626-facilitator#hotmail.com';
$api_password = $sandbox ? 'XXXXXX' : 'XXXXX';
$api_signature = $sandbox ? 'XXXXXXXXXXXXXXXXXXXXXXxx' : 'XXXXXXXXXXXXXXXXXXXXXXXXXXxxx';
my dodirect method is
<?php
// Include config file
require_once('includes/config.php');
// Store request params in an array
$request_params = array
(
'METHOD' => 'DoDirectPayment',
'USER' => $api_username,
'PWD' => $api_password,
'SIGNATURE' => $api_signature,
'VERSION' => $api_version,
'PAYMENTACTION' => 'Sale',
'IPADDRESS' => $_SERVER['REMOTE_ADDR'],
'CREDITCARDTYPE' => $_REQUEST['cardtype'],
'ACCT' => $_REQUEST['pay_cardnumber'],
'EXPDATE' => $_REQUEST['crd_month'].$_REQUEST['crd_year'],
'CVV2' => $_REQUEST['security_code'],
'FIRSTNAME' => $_REQUEST['vpb_fname'],
'LASTNAME' => $_REQUEST['vpb_lname'],
'STREET' => $_REQUEST['street'],
'CITY' => $_REQUEST['city'],
'STATE' => $_REQUEST['state'],
'COUNTRYCODE' => 'US',
'ZIP' => $_REQUEST['zip'],
'AMT' => '100.00',
'CURRENCYCODE' => 'USD',
'DESC' => 'Testing Payments Pro'
);
// Loop through $request_params array to generate the NVP string.
$nvp_string = '';
foreach($request_params as $var=>$val)
{
$nvp_string .= '&'.$var.'='.urlencode($val);
}
// Send NVP string to PayPal and store response
$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);
// Parse the API response
$result_array = NVPToArray($result);
print_r($result_array);
// Function to convert NTP string to an array
function NVPToArray($NVPString)
{
$proArray = array();
while(strlen($NVPString))
{
// name
$keypos= strpos($NVPString,'=');
$keyval = substr($NVPString,0,$keypos);
// value
$valuepos = strpos($NVPString,'&') ? strpos($NVPString,'&'): strlen($NVPString);
$valval = substr($NVPString,$keypos+1,$valuepos-$keypos-1);
// decoding the respose
$proArray[$keyval] = urldecode($valval);
$NVPString = substr($NVPString,$valuepos+1,strlen($NVPString));
}
return json_encode($proArray);
}
What can be the problem and how this will fix please.
That particular error has to do with not having Pro enabled on your account. Facilitator accounts do not have Pro enabled by default so you'd either need to enable it on that account or create a separate account inside your developer portal that has Pro enabled on it. To enable pro on an existing business sandbox account follow the directions below.
Login to developer.paypal.com
Click the Applications Tab
Click Sandbox Accounts on the left menu
Click the arrow to the left of your facilitator account to expand the options
Click the Profile link
Click "Upgrade to Pro" next to your Business account type
I have built a IPN Listener and tested it with the IPN Simulator in sandbox and it works fine, however when I add the "NOTIFYURL" parameter and set it to my IPN Listener I do not get any notifications from my listener, but payment still goes through.
Is there something else I have to do to get this to work?
Here's my codes
My IPN Listener (for the purposes of testing it simply Imports the entire result into a SQL Table)
include "dbconnect.php";
$request = "cmd=_notify-validate";
foreach ($_POST as $varname => $varvalue){
$email .= "$varname: $varvalue\n";
if(function_exists('get_magic_quotes_gpc') and get_magic_quotes_gpc()){
$varvalue = urlencode(stripslashes($varvalue));
}
else {
$value = urlencode($value);
}
$request .= "&$varname=$varvalue";
}
mysql_query("INSERT INTO `test` (`nvps`) VALUES ('".$email."')");
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,"https://www.sandbox.paypal.com/cgi-bin/webscr");
//curl_setopt($ch,CURLOPT_URL,"https://www.paypal.com");
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$request);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$result = curl_exec($ch);
curl_close($ch);
The portion of my payment processing script that interacts with paypal:
// Store request params in an array
$request_params = array
(
'METHOD' => 'DoDirectPayment',
'USER' => $api_username,
'PWD' => $api_password,
'SIGNATURE' => $api_signature,
'VERSION' => $api_version,
'PAYMENTACTION' => 'Sale',
'IPADDRESS' => $_SERVER['REMOTE_ADDR'],
'CREDITCARDTYPE' => 'Visa',
'ACCT' => '4887864152287206',
'EXPDATE' => '072018',
'CVV2' => '123',
'FIRSTNAME' => 'Tester',
'LASTNAME' => 'Testerson',
'STREET' => '707 W. Bay Drive',
'CITY' => 'Largo',
'STATE' => 'FL',
'COUNTRYCODE' => 'US',
'ZIP' => '33770',
'AMT' => '100.00',
'CURRENCYCODE' => 'USD',
'NOTIFYURL' => 'http://www.mysite.com/ipnlistener.php',
'DESC' => 'Testing Payments Pro'
);
// Loop through $request_params array to generate the NVP string.
$nvp_string = '';
foreach($request_params as $var=>$val)
{
$nvp_string .= '&'.$var.'='.urlencode($val);
}
// Send NVP string to PayPal and store response
$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);
echo $result.'<br /><br />';
mysql_query("INSERT INTO `test` (`nvps`) VALUES ('".$result."')");
Why aren't I getting my notifications?
Can you take a look at the PHP IPN script over at https://github.com/paypal/ipn-code-samples/blob/master/IPN_PHP.txt?
Leave USE_SANDBOX and USE_DEBUG enabled and create an empty file called 'ipn.txt' in the same directory (writable by the webserver).
This will log all steps of the IPN process (receiving it, posting it back, verifying the results, etc). Should anything, that should make it clear.
the purpose of the ipn listener is for paypal to pass back payment info so you can process it, it will not send you any notifications as such unless you add things like a log file, where each payment status is logged or send email to yourself about processed payments (whether they failed or not)
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
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!