I am trying to implement paypal refund using php curl.
This is my code.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.paypal.com/v1/oauth2/token");
//curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Accept-Language: en_US'
));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$secret);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
$result = curl_exec($ch);
$json = json_decode($result);
$access_token=$json->access_token;
curl_close($ch);
$ch=curl_init();
$headers=array('Content-Type: application/json','Authorization: Bearer '.$access_token);
curl_setopt($ch,CRULOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_URL, "https://api.paypal.com/v1/payments/sale/".$paypal_transaction_id."/refund");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{}");
$result = curl_exec($ch);
$result_array=json_decode($result,true);
I got the access token successfully.
But, the following error occurs in refund.
"Authentication failed due to invalid authentication credentials or a
missing Authorization header."
What's wrong with my code?
Or
My PayPal account is a business account and there is no problem with receiving money (using php paypal api).
Look at https://developer.paypal.com/docs/platforms/get-started/ it says you need to fill out the PayPal Marketplaces and Platforms form to be approved.
Is this the problem?
Haha, I found the error.
It's just spell error.(curl_setopt($ch,CRULOPT_HTTPHEADER,$headers);)
not CRULOPT_HTTPHEADER , is CURLOPT_HTTPHEADER
and I have change code more simply.(using API v2)
$ch=curl_init();
$headers=array('Content-Type: application/json','Authorization: Basic '.base64_encode($clientId.':'.$secret));
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
$refund_url="https://api.paypal.com/v2/payments/captures/".$order['paypal_txn_id']."/refund";
curl_setopt($ch, CURLOPT_URL, $refund_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{}");
$result = curl_exec($ch);
$result_array=json_decode($result,true);
curl_close($ch);
Related
First I send a POST request with a login and a password (admin authorization) and get some fields.
Next, I need to send GET request to API (check that client email exists), but I receive CURL error: The requested URL returned error: 401
In Postman GET request is working, what I am doing wrong?
This is my GET Request:
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_URL, "www.myurl.com/clients?email=a#a.a");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_USERPWD, "myusername:mypassword");
$result = curl_exec($ch);
You have to pass query string in case GET.
try below updated code.
$qry_str = "?email=a#a.a"
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_URL, 'www.myurl.com/clients.php',$qry_str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_USERPWD, "myusername:mypassword");
$result = curl_exec($ch);
I am trying to login to saleforce api. when I try to login with postman, I can successfully generate the token. But when I tried to login with php CURL .
it is showing
{"ErrorCode":"invalid_client","Error":"Client identifier is
required"}.
$header = [
"Authorization: Basic example_encoded_data",
"Content-Type: application/json",
];
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_HEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
$result = curl_exec($ch);
Use in order to avoid certificate validation:
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
We set up a PayPal express checkout about 2 weeks ago which worked perfectly until a couple of days ago it didn't.
On PayPal the transactions is ok but when I try to log in with cURL to check the transaction the inital merchant/client login fails but cURL shows no error.
I know that PayPal is upgrading to TLS 1.2 and HTTP/1.1 but I did the test check were our server/site passed.
This is how I initated the communication with paypal (this worked until now):
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://paypal.com/v1/oauth2/token');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, 'CLIENT_ID:SECRET');
curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials');
$result = curl_exec($ch);
Now if I print out $result its empty, if I print out curl_errno its 0 and curl_error also empty
so because of TLS 1.2 I modified the code like this
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://paypal.com/v1/oauth2/token');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, 'CLIENT_ID:SECRET');
curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials');
$result = curl_exec($ch);
but it fails exactly the same as the previous code.
What could be the problem?
or is it possible that if the login is ok the result is empty?
I am getting {"int_err_code":"Authentication Failed","msg":"Wrong grant type"} trying to get access_token and organizer_key. I use GoToWebinar API.
Here is my curl:
$http_headers=array(
'Accept:application/json',
'Content-Type:application/x-www-form-urlencoded'
);
$URL = 'https://api.citrixonline.com/oauth/access_token?grant_type=authorization_code'
.'&code='.$response_key
.'&client_id='.$consumer_key;
// send curl post request
$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_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $http_headers);
$response = curl_exec($ch);
curl_close($ch);
I'm trying to intigrate First data Payment Getway in my site
Config file for FirstData Payment Gateway
define("FDAPI_URL","https://ws.merchanttest.firstdataglobalgateway.com/fdggwsapi/services/order.wsdl");
define("FD_USERPWD","WSXXXXXXXX._.1:XXXXXXXX");
define("FD_SSLCERT", "/home/flagcases/domains/usaflagcases.com/public_html/certificate/WSXXXXXXXX._.1.pem");
define("FD_SSLKEY","/home/flagcases/domains/usaflagcases.com/public_html/certificate/WSXXXXXXXX._.1.key");
define("FD_SSLKEYPASSWD", "ckp_XXXXXXXX");
$ch = curl_init(FDAPI_URL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, FD_USERPWD);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSLCERT, FD_SSLCERT);
curl_setopt($ch, CURLOPT_SSLKEY, FD_SSLKEY);
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, FD_SSLKEYPASSWD);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
if ($result === false)
{
echo curl_error($ch);
}
Alway I got Curl Error
unable to use client certificate (no key found or wrong pass phrase?) Curl Error
Please try to add WSXXXXXXXX..1.p12 might be help you... Where you added WSXXXXXXXX..1.pem and WSXXXXXXXX._.1.key