-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathexample-POST.php
46 lines (39 loc) · 1.21 KB
/
example-POST.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
use Ebay\DigitalSignature\Signature;
require 'vendor/autoload.php';
$signature = new Signature("example-config.json");
$endpoint = 'https://api.sandbox.ebay.com/sell/fulfillment/v1/order/14-00032-43825/issue_refund';
const USER_TOKEN = '<token>';
$headers = [
'Authorization' => 'Bearer ' . USER_TOKEN,
'Accept' => 'application/json',
'Content-Type' => 'application/json'
];
$body = '{
"orderLevelRefundAmount": {
"currency": "USD",
"value": 10.39
},
"reasonForRefund": "ITEM_NOT_AS_DESCRIBED",
"comment": "public API test_order_partial_refund"
}';
$headers = $signature->generateSignatureHeaders($headers, $endpoint, "POST", $body);
//Making a call
$ch = curl_init($endpoint);
if (!empty($body)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
}
curl_setopt($ch, CURLOPT_HTTPHEADER, curlifyHeaders($headers));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo "response: \n" . $response;
//Header array conversion
function curlifyHeaders($headers): array
{
$new_headers = [];
foreach ($headers as $header_name => $header_value) {
$new_headers[] = $header_name . ': ' . $header_value;
}
return $new_headers;
}