Refund Cover Integration Guide

Appendix 1: Example code

Example JSON request

The order of the fields is not important.

This example shows a booking for two adult and one child ticket, plus a camping pass.

 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
{
    "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": [
        {
            "product_type": "ticket",
            "title": "Adult Weekend",
            "price": 95.00
        },
        {
            "product_type": "ticket",
            "title": "Adult Weekend",
            "price": 95.00
        },
        {
            "product_type": "ticket",
            "title": "Child 8-15yrs Weekend",
            "price": 49.00
        },
        {
            "product_type": "accommodation",
            "title": "Camping pitch (live-in vehicle under 5.5m)",
            "price": 29.00
        }
    ]
}

Example curl command

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
curl -X POST https://uat-api.coverplatform.net/sale \
-H "Content-Type: application/json" \
-H "X-CoverPlatform-Vendor-ID: <your vendor ID>" \
-H "X-CoverPlatform-API-Key: <your api key>" \
-H "X-CoverPlatform-API-Version: 1.0" \
-d '{
    "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": [
        {
            "product_type": "ticket",
            "product_title": "Adult Weekend",
            "product_price": 95.00
        }
    ]
}'

Example Python code

 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import requests
import json

# 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>'

# 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 = {
    'Content-Type': 'application/json',
    'X-CoverPlatform-Vendor-ID': vendor_id,
    'X-CoverPlatform-API-Key': api_key,
    'X-CoverPlatform-API-Version': '1.0'
}

# The sale request data
sale_request_data = {
    "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": [
        {
            "product_type": "ticket",
            "product_title": "Adult Weekend",
            "product_price": 95.00
        },
        {
            "product_type": "ticket",
            "product_title": "Adult Weekend",
            "product_price": 95.00
        },
        {
            "product_type": "ticket",
            "product_title": "Child 8-15yrs Weekend",
            "product_price": 49.00
        },
        {
            "product_type": "accommodation",
            "product_title": "Camping pitch (live-in vehicle under 5.5m)",
            "product_price": 29.00
        }
    ]
}

# Make the POST request, converting sale_request_data to JSON
response = requests.post(
    url,
    headers=headers,
    data=json.dumps(sale_request_data)
)

# Print the response status code and content
print(f'Status Code: {response.status_code}')
print('Response:', response.json())

Example Ruby code

 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require "uri"
require "json"
require "net/http"

# 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
uri = URI.parse("https://uat-api.coverplatform.net/sale")

# The headers including the content type and your authentication details
headers = {
    "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 = {
    purchase_reference: "ABC12345",
    purchaser_name: "Jane Smith",
    purchase_title: "Family Fun Summer Festival",
    protection_end_date: "2024-08-18",
    currency_code: "GBP",
    sold: true,
    products: [
        {
            product_type: "ticket",
            product_title: "Adult Weekend",
            product_price: 95.00
        },
        {
            product_type: "ticket",
            product_title: "Adult Weekend",
            product_price: 95.00
        },
        {
            product_type: "ticket",
            product_title: "Child 8-15yrs Weekend",
            product_price: 49.00
        },
        {
            product_type: "accommodation",
            product_title: "Camping pitch (live-in vehicle under 5.5m)",
            product_price: 29.00
        }
    ]
}

# Make the POST request, converting sale_request_data to JSON
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri, headers)
request.body = sale_request_data.to_json

begin
    response = http.request(request)

    # Print the response status code and content
    puts response.code

    if response.is_a?(Net::HTTPSuccess)
        puts response.body
    else
        puts "Error: #{response.body}"
    end
    rescue StandardError => e
        puts "An error occurred: #{e.message}"
end

Example Node.js code

 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const axios = require('axios').default

// Your vendor ID and API key.
// Example only: Your API key should be stored in a suitable secret store.
const vendorId = '<your vendor ID>'
const apiKey = '<your api key>'
const apiVersion = '1.0'

// The UAT endpoint for reporting a sale
const url = 'https://uat-api.coverplatform.net/sale'

// The headers including the content type and your authentication details
const headers = {
    'Content-Type': 'application/json',
    'X-CoverPlatform-Vendor-ID': vendorId,
    'X-CoverPlatform-API-Key': apiKey,
    'X-CoverPlatform-API-Version': apiVersion,
}

// The sale request data
const saleRequestData = {
    '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': [
        {
            'product_type': 'ticket',
            'product_title': 'Adult Weekend',
            'product_price': 95.00
        },
        {
            'product_type': 'ticket',
            'product_title': 'Adult Weekend',
            'product_price': 95.00
        },
        {
            'product_type': 'ticket',
            'product_title': 'Child 8-15yrs Weekend',
            'product_price': 49.00
        },
        {
            'product_type': 'accommodation',
            'product_title': 'Camping pitch (live-in vehicle under 5.5m)',
            'product_price': 29.00
        }
    ]
}

// Make the POST request, converting sale_request_data to JSON
axios.post(
    url,
    saleRequestData,
    {headers: headers},
).then(function (response) {
    // Print the response status code and content
    console.log(response.status);
    console.log(response.data)
}).catch(function (error) {
    // Print the error status code and details
    if (error.response) {
        console.log(error.response.data);
    } else if (error.request) {
        console.log(error.request);
    } else {
        console.log('Error', error.message)
    }
});

Example C# code

  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
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace HttpClientApp
{
    public class Product
    {
        public string ProductType { get; set; }
        public string ProductTitle { get; set; }
        public decimal ProductPrice { get; set; }
    }

    public class Transaction
    {
        public string PurchaseReference { get; set; }
        public string PurchaserName { get; set; }
        public string PurchaseTitle { get; set; }
        public string ProtectionEndDate { get; set; }
        public string CurrencyCode { get; set; }
        public bool Sold { get; set; }
        public List<Product> Products { get; set; }
    }

    class Program
    {
        static async Task Main(string[] args)
        {
            // Your vendor ID and API key.
            // Example only: Your API key should be stored in a suitable secret store.
            const string vendorId = "<your vendor ID>";
            const string apiKey = "<your api key>";
            const string apiVersion = "1.0";

            // The UAT endpoint for reporting a sale
            const string url = "https://uat-api.coverplatform.net/";

            var products = new List<Product>()
            {
                new Product { ProductType = "ticket", ProductTitle = "Adult Weekend", ProductPrice = 95.00m },
                new Product { ProductType = "ticket", ProductTitle = "Adult Weekend", ProductPrice = 95.00m },
                new Product { ProductType = "ticket", ProductTitle = "Child 8-15yrs Weekend", ProductPrice = 49.00m },
                new Product { ProductType = "accommodation", ProductTitle = "Camping pitch (live-in vehicle under 5.5m)", ProductPrice = 29.00m }
            };

            // The sale request data
            var saleRequestData = new Transaction
            {
                PurchaseReference = "ABC1234",
                PurchaserName = "Jane Smith",
                PurchaseTitle = "Family Fun Summer Festival",
                ProtectionEndDate = DateTime.Parse("2024-08-18").ToString("yyyy-MM-dd"),
                CurrencyCode = "GBP",
                Sold = true,
                Products = products
            };

            var serializeOptions = new JsonSerializerOptions
            {
                PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
                WriteIndented = true
            };

            try
            {
                var client = new HttpClient();
                client.BaseAddress = new Uri(url);

                // The headers including the content type and your authentication details
                client.DefaultRequestHeaders.Add("X-CoverPlatform-Vendor-ID", vendorId);
                client.DefaultRequestHeaders.Add("X-CoverPlatform-API-Key", apiKey);
                client.DefaultRequestHeaders.Add("X-CoverPlatform-API-Version", apiVersion);

                // Convert saleRequestData to json
                var content = new StringContent(JsonSerializer.Serialize(saleRequestData, serializeOptions));
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                // Make the POST request
                var response = await client.PostAsync("/sale", content);

                // Print the response status code
                Console.WriteLine((int)response.StatusCode);

                // Print the content
                var responseBody = await response.Content.ReadAsStringAsync();
                Console.WriteLine(responseBody);
            }
            catch (HttpRequestException e)
            {
                Console.WriteLine($"Request error: {e.Message}");
            }
            catch (TaskCanceledException e)
            {
                Console.WriteLine(e.CancellationToken.IsCancellationRequested
                    ? "Request was canceled."
                    : "Request timed out.");
            }
            catch (Exception e)
            {
                Console.WriteLine($"An error occurred: {e.Message}");
            }
        }
    }
}

Example PHP code

 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?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);

Example Java code

  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
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Arrays;
import java.util.List;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;

public class App
{
    @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
    public static class Product {
        private String productType;
        private String productTitle;
        private double productPrice;

        public Product(String productType, String productTitle, double productPrice) {
            this.productType = productType;
            this.productTitle = productTitle;
            this.productPrice = productPrice;
        }

        public String getProductType() {
            return productType;
        }

        public void setProductType(String productType) {
            this.productType = productType;
        }

        public String getProductTitle() {
            return productTitle;
        }

        public void setProductTitle(String productTitle) {
            this.productTitle = productTitle;
        }

        public double getProductPrice() {
            return productPrice;
        }

        public void setProductPrice(double productPrice) {
            this.productPrice = productPrice;
        }
    }

    @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
    public static class SaleData {
        private String purchaseReference;
        private String purchaserName;
        private String purchaseTitle;
        private String protectionEndDate;
        private String currencyCode;
        private boolean sold;
        private List<Product> products;

        public SaleData(String purchaseReference, String purchaserName, String purchaseTitle,
                        String protectionEndDate, String currencyCode, boolean sold, List<Product> products) {
            this.purchaseReference = purchaseReference;
            this.purchaserName = purchaserName;
            this.purchaseTitle = purchaseTitle;
            this.protectionEndDate = protectionEndDate;
            this.currencyCode = currencyCode;
            this.sold = sold;
            this.products = products;
        }

        public String getPurchaseReference() {
            return purchaseReference;
        }

        public void setPurchaseReference(String purchaseReference) {
            this.purchaseReference = purchaseReference;
        }

        public String getPurchaserName() {
            return purchaserName;
        }

        public void setPurchaserName(String purchaserName) {
            this.purchaserName = purchaserName;
        }

        public String getPurchaseTitle() {
            return purchaseTitle;
        }

        public void setPurchaseTitle(String purchaseTitle) {
            this.purchaseTitle = purchaseTitle;
        }

        public String getProtectionEndDate() {
            return protectionEndDate;
        }

        public void setProtectionEndDate(String protectionEndDate) {
            this.protectionEndDate = protectionEndDate;
        }

        public String getCurrencyCode() {
            return currencyCode;
        }

        public void setCurrencyCode(String currencyCode) {
            this.currencyCode = currencyCode;
        }

        public boolean isSold() {
            return sold;
        }

        public void setSold(boolean sold) {
            this.sold = sold;
        }

        public List<Product> getProducts() {
            return products;
        }

        public void setProducts(List<Product> products) {
            this.products = products;
        }
    }

    // Your vendor ID and API key.
    // Example only: Your API key should be stored in a suitable secret store.
    private static final String VENDOR_ID = "<your vendor ID>";
    private static final String API_KEY = "<your api key >";
    private static final String API_VERSION = "1.0";

    // The UAT endpoint for reporting a sale
    private static final String URL = "https://uat-api.coverplatform.net/sale";

    public static void reportSale(SaleData saleData) throws IOException {
        ObjectMapper mapper = new ObjectMapper(); // Example JSON mapper

        // Convert sale data to JSON
        String jsonData = mapper.writeValueAsString(saleData);

        URL url = new URL(URL);

        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");

        // The headers including the content type and your authentication details
        connection.setRequestProperty("Content-Type", "application/json");
        connection.setRequestProperty("X-CoverPlatform-Vendor-ID", VENDOR_ID);
        connection.setRequestProperty("X-CoverPlatform-API-Key", API_KEY);
        connection.setRequestProperty("X-CoverPlatform-API-Version", API_VERSION);

        // Make the POST request
        connection.setDoOutput(true);
        connection.getOutputStream().write(jsonData.getBytes());

        int statusCode = connection.getResponseCode();

        BufferedReader reader = new BufferedReader(new InputStreamReader(
                statusCode >= 200 && statusCode < 300 ? connection.getInputStream() : connection.getErrorStream()));
        String line;
        StringBuilder response = new StringBuilder();
        while ((line = reader.readLine()) != null) {
            response.append(line);
        }
        reader.close();

        // Output the response status code and content

        System.out.println("Status Code: " + statusCode);

        if (statusCode >= 300) {
            System.out.println("Error: " + response.toString());
        }

        connection.disconnect();
    }

    public static void main( String[] args )
    {
        List<Product> products = Arrays.asList(
            new Product("ticket", "Adult Weekend", 95.00),
            new Product("ticket", "Adult Weekend", 95.00),
            new Product("ticket", "Child 8-15yrs Weekend", 49.00),
            new Product("accommodation", "Camping pitch (live-in vehicle under 5.5m)", 29.00)
        );

        // The sale request data
        SaleData saleData = new SaleData(
                "ABC12345",
                "Jane Smith",
                "Family Fun Summer Festival",
                "2024-08-18",
                "GBP",
                true,
                products
        );

        try {
            reportSale(saleData);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}