Paypal NVP REFUND API getting Error 10007 - paypal

I am trying to refund the amount using the paypal nvp. And I am getting the following error
[TIMESTAMP] => 2013 04 06T13 48 19
[CORRELATIONID] => aac23709cc94a
[ACK] => Failure [VERSION] => 51 0
[BUILD] => 5618210
[L_ERRORCODE0] => 10007
[L_SHORTMESSAGE0] => Permission denied
[L_LONGMESSAGE0] => You do not have permission to refund this transaction
[L_SEVERITYCODE0] => Error )
What is that I am doing wrong?
I have set the api keys of the emailid to which payment is made
Please let me know what is problem and how can I make refund work.
Code
$API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
$version = urlencode('51.0');
$API_UserName = 'example';
$API_Password = 'example';
$API_Signature = 'example';
$API_Endpoint = 'example';
$sandboxmode = 'example';
$methodName_ = 'RefundTransaction';
$transactionID = urlencode('example');
$refundType = urlencode('example');
if($partial) {
$amount = 'example';
$memo = 'Refunding the amount ';
$nvpStr_ = "&TRANSACTIONID=$transactionID&REFUNDTYPE=$refundType&CURRENCYCODE=$currencyID&AMT=$amount&NOTE=$memo";
} else {
$nvpStr_ = "&TRANSACTIONID=$transactionID&REFUNDTYPE=$refundType&CURRENCYCODE=$currencyID";
}
$currencyID = urlencode('CAD');
$API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
$version = urlencode('51.0');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// Turn off the server and peer verification (TrustManager Concept).
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
// Set the API operation, version, and API signature in the request.
$nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";
// Set the request as a POST FIELD for curl.
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
// Get response from the server.
$httpResponse = curl_exec($ch);

Related

How to access data from onesignal additional data object in cordova ionic app

I want to access data i have assigned to the data variable of feilds array to be sent in onesignal message.
function sendMessage($received)
{
$content = array(
"en" => 'Current Data'
);
$data = $received;
$fields = array(
'app_id' => "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
'included_segments' => array('All'),
'contents' => $content,
'data' => $data, // => This is the data i want to access on
client side.
);
$response['feilds'] = $fields;
$fields = json_encode($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
"https://onesignal.com/api/v1/notifications");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:
application/json; charset=utf-8',
'Authorization:Basic
Nzg0YmM2NzUtZWYyMC00NDZmLWE1ODItZDExZTU3OTXXXXXX'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response['resp'] = curl_exec($ch);
curl_close($ch);
return $response;
}
I need help that how i can access the data variable there on client side in ionic app.
Below is what i am trying.
this.oneSignal.startInit('XXXXXXX-32ae-4025-b26b-
XXXXXXXXXX','XXXXXXXXX');
this.oneSignal.handleNotificationReceived().subscribe((jsonData) => {
if(jsonData.payload.additionalData)
{
this.myService.NotirefreshData(jsonData.payload.additionalData);
let ten = JSON.stringify(jsonData.payload.additionalData);
this.storage.set('current',ten);
this.presentAlert('From Server',ten);
this.storage.get('past').then((pri) => {
this.presentAlert('From Storage',JSON.parse(pri));
});
}
How should be the below statement to access the data variable to array feild received from server?
(jsonData.payload.additionalData.??????????????)
I have tried
(jsonData.payload.additionalData.feilds)
(jsonData.payload.additionalData.current) // as current is the name of an array
You don't need that subscribe() call. Simply pass in the handler into the function.
window.plugins.OneSignal
.startInit("YOUR_APP_ID")
.handleNotificationReceived(function(notificationData) {
alert("Notification Data Received:\n" + JSON.stringify(notificationData));
console.log('Notification Data Received: ' + JSON.stringify(notificationData));
})
.endInit();

PayPal PayFlow API Error

We are using PayFlow PayPal API for recurring payments, it gives us an issue.
We are sending amount $29 to the API but on PayPal log it is showing $1 only. When we asked PayPal support for this they said you are sending $1.
Please help us. Below is the code we have setup:
<?php
$payflow_partner = 'PayPal';
$payflow_vender = 'xxxxxxxxxxxxx';
$payflow_user = 'xxxxxxxxxxxx';
$payflow_pwd = 'XXXXXXXXX';
$payflow_url = 'https://pilot-payflowpro.paypal.com';
$first_name = 'First Name';
$last_name = 'Last Name';
$profile_name = $first_name.$last_name;
$plan_amount = 29.00;
$card_number = '4111111111111111';
$expiry_month = '05';
$expiry_year = '21';
$expiry = $expiry_month.$expiry_year;
$user_email = 'test#example.com';
$start_date = '01202017';
$post_list = 'TRXTYPE=R&TENDER=C&PARTNER='.$payflow_partner.'&VENDOR='.$payflow_vender.'&USER='.$payflow_user.'&PWD='.$payflow_pwd.'&ACTION=A&PROFILENAME='.$profile_name.'&AMT='.$plan_amount.'&CURRENCY=USD&ACCT='.$card_number.'&EXPDATE='.$expiry.'&START='.$start_date.'&PAYPERIOD=MONT&TERM=0&EMAIL='.$user_email.'&OPTIONALTRX=A&OPTIONALTRXAMT='.$plan_amount.'&COMMENT1=First-time-customer&STREET=sector-7-malviya-nagar&ZIP=302017&CITY=jaipur&STATE=rajasthan&COUNTRY=india&FIRSTNAME='.$first_name.'&MIDDLENAME='.$last_name.'&LASTNAME='.$last_name;
$headers = array();
$headers[] = "Content-Type: text/namevalue"; //or maybe text/xml
$headers[] = "X-VPS-Timeout: 3000";
$headers[] = "X-VPS-VIT-OS-Name: Linux"; // Name of your OS
$headers[] = "X-VPS-VIT-OS-Version: RHEL 4"; // OS Version
$headers[] = "X-VPS-VIT-Client-Type: PHP/cURL"; // What you are using
$headers[] = "X-VPS-VIT-Client-Version: 0.01"; // For your info
$headers[] = "X-VPS-VIT-Client-Architecture: x86"; // For your info
$headers[] = "X-VPS-VIT-Client-Certification-Id:13fda2433fc2123d8b191d2d011b7fdc";
$headers[] = "X-VPS-VIT-Integration-Product: MyApplication"; // For your info, would populate with application name
$headers[] = "X-VPS-VIT-Integration-Version: 0.01"; // Application version
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $payflow_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 1); // tells curl to include headers in response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 45); // times out after 45 secs
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // this line makes it work under https
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_list); //adding POST data
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); //verifies ssl certificate
curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE); //forces closure of connection when done
curl_setopt($ch, CURLOPT_POST, 1); //data sent as POST
$result = curl_exec($ch);
$headers = curl_getinfo($ch);
curl_close($ch);
echo $result;
In your post data you are sending these two values:
AMT='.$plan_amount
OPTIONALTRXAMT='.$plan_amount
PayPal's documentation states that OPTIONALTRXAMT should only be used when OPTIONALTRX=S, which it is not in your case.
The documentation also states that Amount is ignored when OPTIONALTRX=A, which is what you are doing.
Note: Do not specify an amount when OPTIONALTRX=A. The amount is ignored.
So, remove the Optional parameters.

Paypal PDT - SSL connect error

I use this code to process Paypal payment data transfer (PDT):
$url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
$tx_token = $_GET['tx'];
$auth_token = "my_token";
$fields = array(
'cmd' => '_notify-synch',
'tx' => $tx_token,
'at' => $auth_token,
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($fields));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$res = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo 'Curl error: ' . curl_error($ch);
echo "status: " . $status;
curl_close($ch);
And I'm getting:
Curl error: SSL connect error
status: 0
I tried to make the API in Postman with the same URL: www.sandbox.paypal.com with the same parameters (cmd, at, tx) and I got success response. What I did wrong?
PayPal has upgraded to TLS 1.2 for its sandbox API endpoints. You can find out more about the upgrade and when it will affect production at the TLS 1.2 and HTTP/1.1 Upgrade Microsite.
You will need OpenSSL to be 1.0.1c or higher and a recent version of libcurl.
As far as your specific code, you probably want to do the following:
curl_setopt($ch, CURLOPT_SSLVERSION, 6); // CURL_SSLLVERSION_TLSv1_2 = 6
Also, you probably should leave the CURLOPT_SSL_VERIFYHOST to be 2 to verify the SSL certificate for the endpoint.
You can find out more at the PayPal TLS update repository for specific language environment requirements.

How to get canceled payments detail

I am using PayPal classic API and fetching all PayPal transaction detail using following code.
$info = 'USER=api_username&PWD=api_password&SIGNATURE=api_sgnature&VERSION=94&METHOD=GetTransactionDetails&TRANSACTIONID='.$value;
$curl = curl_init('https://api-3t.paypal.com/nvp');
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POSTFIELDS, $info);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_POST, 1);
$result = curl_exec($curl);
$str = $result;
parse_str($result, $result);
foreach($result as $key => $value){
echo $key.' => '.$value."<BR>";
}
Following output, I am getting for created and canceled payments or transactions.
ADDRESSOWNER => PayPal
ADDRESSSTATUS => None
TIMESTAMP => 2015-06-26T05:10:54Z
CORRELATIONID => 4dad1aa370757
ACK => Failure
VERSION => 94
BUILD => 17103657
L_ERRORCODE0 => 10004
L_SHORTMESSAGE0 => Transaction refused because of an invalid argument. See additional error messages for details.
L_LONGMESSAGE0 => The transaction id is not valid
L_SEVERITYCODE0 => Error
PENDINGREASON => None
REASONCODE => None
L_TAXABLE0 => true
As you can see from response that neither I am getting transaction id nor email of cancelled transaction so there is no way to recognize this transaction.
What can be the error or is there any alternative?

Paypal error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure(35)

Hello i'm using paypal class in my e-commerce but when i put the code in my serverhost the paypal show me the mensage:
SetExpressCheckout failed: error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure(35)
this is my class:
class MyPayPal {
function PPHttpPost($methodName_, $nvpStr_, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode) {
// Set up your API credentials, PayPal end point, and API version.
$API_UserName = urlencode($PayPalApiUsername);
$API_Password = urlencode($PayPalApiPassword);
$API_Signature = urlencode($PayPalApiSignature);
$paypalmode = ($PayPalMode=='sandbox') ? '.sandbox' : '';
$API_Endpoint = "https://api-3t".$paypalmode.".paypal.com/nvp";
$version = urlencode('109.0');
// Set the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// Turn off the server and peer verification (TrustManager Concept).
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
// Set the API operation, version, and API signature in the request.
$nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";
// Set the request as a POST FIELD for curl.
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
// Get response from the server.
$httpResponse = curl_exec($ch);
if(!$httpResponse) {
exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')');
}
// Extract the response details.
$httpResponseAr = explode("&", $httpResponse);
$httpParsedResponseAr = array();
foreach ($httpResponseAr as $i => $value) {
$tmpAr = explode("=", $value);
if(sizeof($tmpAr) > 1) {
$httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
}
}
if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
}
return $httpParsedResponseAr;
}
}
Any idea how can i solve this problem?
Thanks a lot.