I'm trying to do an NVP pay request via cURL to the Paypal servers, but i always end up getting ERRORCODE0=81002, which basically means there's something wrong with my method.
But I just cant seem to find the problem:
//The request parameters
$request_params = array(
'METHOD' => 'PAY',
'VERSION' => '85.0',
'USER' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'PWD' => 'xxxxxxxxxxxxxxxx',
'SIGNATURE' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'CURRENCYCODE' => 'USD',
'RETURNURL' => 'https://localhost',
'CANCELURL' => 'https://localhost'
);
$endpoint = 'https://api-3t.sandbox.paypal.com/nvp?';
//Building the NVP string
$request = http_build_query($request_params);
//cURL settings
$curl_options = array(
CURLOPT_URL => $endpoint,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $request,
CURLOPT_VERBOSE => 1,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_TIMEOUT => 30,
);
$ch = curl_init();
curl_setopt_array($ch, $curl_options);
$response = curl_exec($ch);
curl_close($ch);
where did you get this sample from?
I never saw the value "PAY" for "METHOD"
These need to be valid paypal actions. For example most recently I used DoDirectPayment (and I think that is the most used method for payments with paypal pro)
all the operations are available in this table on their site: http://rvyu.com/rcuu
Update: so the main question is: what do you want to do? because I don't think you are making a payment since you are not sending some basic fields (like the amount or card number); after that look for the value that matches the action you need to take
Related
So I have the following CURL command in PHP, if I send it https://webhook.site I can extract all the required data in JSON format.
Instead of using webhook.site, I would like to create my own PHP webhook client.
The code below is the CURL command that works 100% when using webhook.site:
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://webhook.site/832090f1-f54f-4847-8c0d-5ec9208541a1',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('SmsSid' => 'SMe8723661742d423fbf3fa9f7bbede050','SmsStatus' => 'sent','MessageStatus' => 'sent','ChannelToAddress' => '+1788123XXXX','To' => 'whatsapp:+15196978899','ChannelPrefix' => 'whatsapp','MessageSid' => 'SMe8723661742d423fbf3fa9f7bbede050','AccountSid' => 'AC306a09582e77715b0eb72df90de4c590','StructuredMessage' => 'false','From' => 'whatsapp:+154xxxxxx','MediaUrl0' => 'https://api.twilio.com/2010-04-01/Accounts/werwersdsdg72df90de4c590/Messages/wweugryuwyr7762b11ea/Media/wjeruwiy6243742
'),
CURLOPT_HTTPHEADER => array(
'user-agent: TwilioProxy/1.1',
'host: Postman'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
I then tried to use PHP to create a basic webhook just to pull the data:
<?php
if($json = json_decode(file_get_contents("php://input"), true)){
$data = $json;
$fp = file_put_contents( 'request.log', $data );
}
print_r($data);
?>
But I keep coming with a blank request.log file - what am I doing wrong??? Thanks in advance
Twilio developer evangelist here.
By default, curl will make a POST request with the Content-Type header application/x-www-form-urlencoded. This is actually the same content type that Twilio uses when it sends a webhook request.
Your PHP to receive the request is trying to json_decode the data, which won't work with form encoded data. Instead, you can access $_POST to get an associative array of the parameters sent to your script. You can then write them to a log file however you like.
When using either dynamically created JWT tokens, or even hard-copying the one provided from the App Marketplace for my app, my API requests always fail due to an ‘invalid access token’.
I am currently working on the Meetings endpoint, specifically trying to create a meeting. The endpoint is: https://eu01api-www4local.zoom.us/v2/users/me/meetings (using the GDPR compliant EU base URL).
My cURL request looks like this:
$body = json_encode($body);
$arr = [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => $this->timeout,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTPHEADER => [
"authorization: Bearer " . $this->generate_JWT(),
"content-type: application/json"
],
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $body
];
$ch = curl_init();
curl_setopt_array($ch, $arr);
$response = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
(CURLOPT_SSL_VERIFYPEER is set to false here, as I'm testing from localhost.)
The generate_JWT function looks like this:
private function generate_JWT()
{
$payload = [
"iss" => self::ZOOM_API_SECRET,
"exp" => time() + $this->timeout,
];
return JWT::encode($payload, self::ZOOM_API_KEY, 'HS256');
}
... using the Firebase\JWT\JWT class for encoding.
The 'app' itself is activated and live on the account, set as JWT type, with no intent to publish, and is 'Account level'.
Any help appreciated.
The endpoint described in the Documentation for GDPR compliant EU users is not, in fact, operable - at least for this type of work. The original .us base URL must be used.
I try to authenticate with LinkedIn API with OAuth2. Code:
if ((isset($_GET["code"])) AND (isset($_GET["state"]))) {
$code = $_GET["code"];
$state = $_GET["state"];
$curl_request = curl_init();
curl_setopt_array($curl_request, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => "https://www.linkedin.com/uas/oauth2/accessToken",
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
grant_type => "authorization_code",
code => "$code",
redirect_uri => "SECRET",
client_id => "SECRET",
client_secret => "SECRET"
)
));
$curl_result = curl_exec($curl_request);
var_dump($curl_result);
}
I got this message:
string(153) "{"error_description":"missing required parameters,
includes an invalid parameter value, parameter more than once. :
client_id","error":"invalid_request"}"
Could you help m?
You need to add the following header in your cURL POST call to ensure that the values you are passing in the body of your POST are interpreted correctly:
Content-Type: application/x-www-form-urlencoded
For additional info, see https://www.rfc-editor.org/rfc/rfc6749#section-4.1.3 for the actual OAuth 2.0 RFC spec.
Use: http_build_query
curl_setopt_array($curl, array(
CURLOPT_HTTPHEADER => array('Content-Type: application/x-www-form-urlencoded'),
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://www.linkedin.com/uas/oauth2/accessToken',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => http_build_query (array(
client_id => "secret",
client_secret => "secret",
grant_type => "authorization_code",
redirect_uri => "url",
code => $code
)),
));
I am weirded out by this, but I just had the same problem and when I just moved client id and secret to beginning of the POST array and everything worked. I don't even.
I am trying to charge the customer using eway payment method. I am implementing the procedure through curl and here is the code to the function.
public function testing_direct() {
$url = 'https://api.sandbox.ewaypayments.com/DirectPayment.json'; // PROD
$postData = array(
'Method' => 'TokenPayment',
'TransactionType' => 'Recurring',
'TokenCustomerID' => '918549937032',
'TotalAmount' => '1995',
'InvoiceNumber' => '123',
'InvoiceDescription' => 'testing'
);
$ch = curl_init($url);
$api_authentication = base64_encode('####;****');
curl_setopt_array($ch, array(
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json','Authorization:####'
),
CURLOPT_POSTFIELDS => json_encode($postData)
));
$response = curl_exec($ch);
// Check for errors
if ($response === FALSE) {
die(curl_error($ch));
}
$responseData = json_decode($response, TRUE);
print_r($responseData);
die;
}
This code doesnot print anything at all...Nothing in the error log either...any ideas that why it is not working??
Thanks
There are a few things that need to be fix to get that script working, particularly around the authentication which is the most immediate cause of a problem.
There needs to be a check of the HTTP status of the request since curl_exec only returns FALSE if there is an error - e.g. a 404 (page not found) or 401 (unauthorized) is still treated as a successful request.
// Check for errors
if ($response === FALSE) {
die(curl_error($ch));
}
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($code != 200) {
die('HTTP error: '.$code);
}
The actual authentication appears to suffer from 2 main issues: there is a semicolon instead of a colon between the username (API key) and password, and the Basic part of the authentication is missing:
$api_authentication = base64_encode('####:****');
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json','Authorization: Basic '.$api_authentication
),
This could be simplified by just using CURLOPT_USERPWD:
CURLOPT_USERPWD => '####:****',
Apart from that, note that the $postData array needs some extra nesting: TokenCustomerID should be a child of Customer and TotalAmount and the Invoice fields should be children of Payment:
$postData = array(
'Method' => 'TokenPayment',
'TransactionType' => 'Recurring',
'Customer' => array(
'TokenCustomerID' => '911058757297',
),
'Payment' => array(
'TotalAmount' => '1900',
'InvoiceNumber' => '123',
'InvoiceDescription' => 'testing',
),
);
Check out the example in the documentation for a complete example request.
Good luck!
Do any of you know a way to get datas from a database of a website? I already studied and made a program that POST data using json. It gets the shipment status of a certain tracking number and if it's shipped, it will be changed to delivered. And I already done that.
Now what I'm trying to do is get all the datas, or the row of that tracking number and then encode it to JSON. But I don't know what to do.
This is how I did the first program: on getting a specific tracking number and update the status to delivered.
<?php
$url='https://sample.com.ph';
$apikey='apikey';
$method ='SendPackageStatus';
$data = array(
'package' => array(
'tracking_number' => '735898532',
'package_status' => 'delivered',
'failed_reason' => '',
'updated_at' => '2014-01-01 07:02:14'
)
);
$check=json_encode($data);
$postdata = "&data=$check&apikey=$apikey&method=$method";
$ch = curl_init();
curl_setopt_array(
$ch,
array(
CURLOPT_URL => $url.'/webservice/',
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_VERBOSE => true,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $postdata,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADER => array('Content-type: application/x-www-form-urlencoded',
)
)
);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
Why not use mysql?... you can store json string on db (as..strings). I dont follow what you are trying to do.