I have access_token, corelation id and amount. Please provide solution in CURL php. GIT Url https://github.com/paypal/PayPal-iOS-SDK/blob/master/docs/future_payments_server.md
curl 'https://api.paypal.com/v1/payments/payment' \
-H "Content-Type: application/json" \
-H "PayPal-Client-Metadata-Id: c2edbd6e97b14ff2b19ddb8eec9d264c" \
-H "Authorization: Bearer WfXdnxmyJtdF4q59ofxuQuAAk6eEV-Njm6puht3Nk3w" \
-d '{
"intent":"authorize",
"payer":{
"payment_method":"paypal"
},
"transactions":[
{
"amount":{
"currency":"USD",
"total":"1.88"
},
"description":"future of sauces"
}
]
}'
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payment");
curl_setopt($ch, CURLOPT_HEADER, "Content-Type: application/json");
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HEADER, "PayPal-Client-Metadata-Id: 10aab1a2e941462096ca8aba539784f3");
curl_setopt($ch, CURLOPT_HEADER, "Authorization: Bearer A103.Ekl88t1fnvoypD1F7HZDt3X-jzmxm6rxMxW6QtI79iIJdgDaDiIO8luWS-C1D-0z.h2YAz4LujULmTjQXcPjF8_ImbV0");
curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{
"intent":"authorize",
"payer":{
"payment_method":"paypal"
},
"transactions":[
{
"amount":{
"currency":"USD",
"total":"1.88"
},
"description":"future of sauces"
}
]
}');
**using curl Php**
$result1 = curl_exec($ch);
$information = curl_getinfo($ch);
curl_close($ch);
print_r($result1);
print_r($information);die;
Return curl info 1Array ( [url] => https://api.sandbox.paypal.com/v1/payments/payment [content_type] => application/json [http_code] => 401 [header_size] => 520 [request_size] => 514 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 1.542536 [namelookup_time] => 0.341438 [connect_time] => 0.628821 [pretransfer_time] => 1.237494 [size_upload] => 363 [size_download] => 0 [speed_download] => 0 [speed_upload] => 235 [download_content_length] => 0 [upload_content_length] => 363 [starttransfer_time] => 1.542478 [redirect_time] => 0 [redirect_url] => [primary_ip] => 173.0.82.78 [certinfo] => Array ( )
[primary_port] => 443
[local_ip] => 115.112.59.164
[local_port] => 58225
[request_header] => POST /v1/payments/payment HTTP/1.1
Host: api.sandbox.paypal.com Accept: / Content-Length: 363 Content-Type: application/x-www-form-urlencoded
At the very least, this code has problems with the HTTP headers you want to send.
CURLOPT_HEADER
, when set to true
, will cause the HTTP response headers to be included in the cURL response.
To send HTTP headers, you need to use CURLOPT_HTTPHEADER
and pass an array of headers.
It would look like this:
$headers = array(
'Content-Type: application/json',
'PayPal-Client-Metadata-Id: 10aab1a2e941462096ca8aba539784f3',
'Authorization: Bearer A103.Ekl88t1fnvoypD1F7HZDt3X-jzmxm6rxMxW6QtI79iIJdgDaDiIO8luWS-C1D-0z.h2YAz4LujULmTjQXcPjF8_ImbV0',
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
You'll also need to call curl_setopt($ch, CURLOPT_POST, 1);
to actually send a POST request.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.