<?php
// Your vendor ID and API key.
// Example only: Your API key should be stored in a suitable secret store.
$vendor_id = "your vendor id";
$api_key = "your api key";
$api_version = "1.0";
// The UAT endpoint for reporting a sale
$url = "https://uat-api.coverplatform.net/sale";
// The headers including the content type and your authentication details
$headers = array(
"Content-Type: application/json",
"X-CoverPlatform-Vendor-ID: " . $vendor_id,
"X-CoverPlatform-API-Key: " . $api_key,
"X-CoverPlatform-API-Version: " . $api_version,
);
// The sale request data
$sale_request_data = array(
"purchase_reference" => "ABC1234",
"purchaser_name" => "Jane Smith",
"purchase_title" => "Family Fun Summer Festival",
"protection_end_date" => "2024-08-18",
"currency_code" => "GBP",
"sold" => true,
"products" => array(
array(
"product_type" => "ticket",
"product_title" => "Adult Weekend",
"product_price" => 95.00
),
array(
"product_type" => "ticket",
"product_title" => "Adult Weekend",
"product_price" => 95.00
),
array(
"product_type" => "ticket",
"product_title" => "Child 8-15yrs Weekend",
"product_price" => 49.00
),
array(
"product_type" => "accommodation",
"product_title" => "Camping pitch (live-in vehicle under 5.5m)",
"product_price" => 29.00
)
)
);
$ch = curl_init();
// Make the POST request, converting sale_request_data to JSON
$options = array(
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($sale_request_data),
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
);
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
$errors = curl_error($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Print the response status code and content
echo $status_code . "\n";
echo $response;
curl_close($ch);