What I am trying to do is I would like to verify transaction ID of Paypal payments. But paypal sends me back a:
{"name":"INVALID_RESOURCE_ID","message":"Requested resource ID was not found.","information_link":"https:\/\/developer.paypal.com\/docs\/api\/payments\/#errors"}
my current code right now is this:
$curl = curl_init("https://api.sandbox.paypal.com/v1/payments/payment/<transaction_id>");
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . '<changed this to my access token>',
'Accept: application/json',
'Content-Type: application/json'
));
$response = curl_exec($curl);
$result = json_decode($response);
You're using the wrong endpoint of Paypal API. Based on your description of what you want to do, you should be using /v1/checkout/orders/ as per the documentation because it gives you all the details of a certain transaction.
Do it like this:
$curl = curl_init("https://api.sandbox.paypal.com/v1/checkout/orders/<transaction_id>");
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . '<access_token>',
'Accept: application/json',
'Content-Type: application/json'
));
$response = curl_exec($curl);
$result = json_decode($response);
Source: https://developer.paypal.com/docs/api/orders/v1/
Related
I am trying to clear Trash using php and drive api v3. Code excutes with no error but trash in drive is not deleted. Here is my code please help me to fix this. Thanks For your time.
if($_POST['trash']) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/drive/v3/files/trash?key='.$token.'");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'Authorization: Bearer ' . $token
));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
};
I believe your goal and current situation as follows.
You want to use "Files: emptyTrash" in Drive API v3 using curl of php.
Your access token of $token can be used for using this API.
In order to achieve your goal, how about the following modification?
From:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/drive/v3/files/trash?key='.$token.'");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'Authorization: Bearer ' . $token
));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
To:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/drive/v3/files/trash");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
Note:
At "Files: emptyTrash", no values are returned.
If $token in your script is the API key which is not the access token, please retrieve the access token and use it. Please be careful this.
Reference:
Files: emptyTrash
I'm trying to fetch Subscription details by its Subscription ID, but i'm unable to get it. It raised this error: {"name":"INVALID_RESOURCE_ID","message":"INVALID_RESOURCE_ID","information_link":"https://developer.paypal.com/docs/api/orders/v1/#error-INVALID_RESOURCE_ID","debug_id":"9fc43dc5ea630"}
Below is my code:
$accessToken='A21AAEk8KaihyonOUmmnSsx_2MLCXocZIMHjRxJreQtQ8Tck7fpxC_Q17u-OPRlnAdYWHRRwbiz-hLfBlbOJj_7SwOYVDoOaw';
$curl = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G");
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $accessToken,
'Accept: application/json',
'Content-Type: application/json'
));
$response = curl_exec($curl);
$result = json_decode($response);
print_r($response);
[![Error Screenshot][1]][1]
[1]: https://i.stack.imgur.com/xcvlW.png
I'm creating the authentication and getting an access token fine but the problem arises when I try to send a request. I'm creating the headers using PHP
<?php
define("POST", "POST");
**$environment=' https://api-crt.cert.havail.sabre.com';**
$userId='XXXXXXX';
$domain='AA';
$Group='XXXXXXXXXX';
$formatVersion='V1';
$clientSecret=base64_encode('XXXXXXXXXXX');
$client_id=base64_encode($formatVersion.":".$userId.":".$Group.":".$domain);
$bulid_credential=base64_encode($client_id.":".$clientSecret);
######################## Step 1: Get Token #############################
**$ch =curl_init("https://api-crt.cert.havail.sabre.com/v2/auth/token");**
$vars ="grant_type=client_credentials";
$header =array(
'Authorization: Basic '.$bulid_credential,
'Accept: */*',
'Content-Type: application/x-www-form-urlencoded'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res= curl_exec($ch);
$result=json_decode($res);
$token=$result->access_token;
########################## Step 2: Call the REST API###################
**$url="https://api.test.sabre.com/v3.3.0/shop/flights?mode=live";**
$header = array(
'Authorization: Bearer'. $token,
'Content-Type: application/json'
);
$calltype='POST';
$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $calltype);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonrequest);//Request
array_push($header, 'Content-Type: application/json');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result=curl_exec($ch);
$result1=json_decode($result);
curl_close($ch);
?>
The Sabre Response :
{"status":"Incomplete","type":"Application","errorCode":"ERR.2SG.PROVIDER_ERROR","timeStamp":"2017-10-11T06:02:08.658-05:00","message":"Error occurred while invoking service rest:readMetadata:1.13.7.SNAPSHOT"}
1) Did you ensure that $token is a string and not an object?
I use this:
$result=json_decode($res, TRUE);
$token=$result['access_token'];
Instead of this:
$result=json_decode($res);
$token=$result->access_token;
2) Did you ensure that the content of $jsonrequest is valid?
Maybe it's not the PHP code that is incorrect, but your JSON query.
Error
{"message":"Unexpected token '","body":"{'type':'A','name':'tarunDhiman','data':'166.62.81.221','ttl':3600}"}
Code
$data = "{'type':'A','name':'tarunDhiman','data':'166.62.81.221','ttl':3600}";
$url = "https://api.godaddy.com/v1/domains/{domain}/records";
$headers = array(
'Content-Type: application/json',
'Accept : application/json',
'Authorization : sso-key {key}:{token}' );
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
curl_close($curl);
print $response ;
exit;
The issue is solved by the help of #Slaiv206 And below the working code.
$data = '[{ "type":"A", "name":"tarunDhiman", "data":"255.255.255.0", "ttl":3600 }]';
$url = "https://api.godaddy.com/v1/domains/{domain}/records";
$headers = array(
'Content-Type: application/json',
'Accept : application/json',
'Authorization : sso-key {key}:{secret}' );
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
curl_close($curl);
print $response ;
exit;
I think the header Authorization string is:
Authorization: sso-key {KEY}:{SECRET}
and not:
Authorization : sso-key {key}:{token}
and in the json string use double quotes instead single quotes:
'{ "type":"A", "name":"tarunDhiman", "data":"166.62.81.221", "ttl":3600 }'
I get response after successful android paypal payment. The response was below.
{
"response": {
"state": "approved",
"id": "PAY-6PU626847B294842SKPEWXHY",
"create_time": "2014-07-18T18:46:55Z",
"intent": "sale"
},
"client": {
"platform": "Android",
"paypal_sdk_version": "2.11.0",
"product_name": "PayPal-Android-SDK",
"environment": "mock"
},
"response_type": "payment"
}
{
"short_description": "Pay List Payment",
"amount": "100",
"intent": "sale",
"currency_code": "USD"
}
then I use the PAY-6PU626847B294842SKPEWXHY pay key and get the transaction details using PHP curl GET request with the following code.
$accessToken='<Access Token>';
$curl = curl_init("https://api.sandbox.paypal.com/v1/payments/payment/PAY-6PU626847B294842SKPEWXHY");
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $accessToken,
'Accept: application/json',
'Content-Type: application/json'
));
$response = curl_exec($curl);
print_r($response);
exit;
After hit this i get the following response not get the transaction detail.
{"name":"INVALID_RESOURCE_ID","message":"The requested resource ID was not found","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#INVALID_RESOURCE_ID","debug_id":"ddc1e3a55f10e"}
anybody have idea thanks in advance.
The following works for me.
1. MAKE CURL POST TO GET ACCESS TOKEN
$uri = 'https://api.sandbox.paypal.com/v1/oauth2/token';
//for live production use $uri = 'https://api.paypal.com/v1/oauth2/token';
$clientId = '<YOUR-CLIENT-ID-HERE>';
$secret = '<YOUR-SECRET-HERE>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSLVERSION , 6); //NEW ADDITION
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);
$access_token = '';
if(empty($result))die("Error: No response.");
else
{
$json = json_decode($result);
$access_token = $json->access_token;
}
curl_close($ch);
2. MAKE CURL POST TO GET TRANSACTION DETAILS LIKE payment status,amount, date etc.
$url = "https://api.sandbox.paypal.com/v2/payments/captures/<YOUR-PAYMENT-ID-HERE>";
$accessToken=$access_token;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $accessToken,
'Accept: application/json',
'Content-Type: application/json'
));
$response = curl_exec($curl);
print_r($response);
exit;
3. MAKE CURL POST TO GET MORE TRANSACTION DETAILS (This give more detailed response than step 2. so you can us this instead of step 2
$url = "https://api.sandbox.paypal.com/v2/checkout/orders/<YOUR-order-ID-HERE>";
$accessToken=$access_token;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $accessToken,
'Accept: application/json',
'Content-Type: application/json'
));
$response = curl_exec($curl);
print_r($response);
exit;