-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.php
79 lines (64 loc) · 2.21 KB
/
sample.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
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
<?php
// Use autoloader to include dependencies
require_once('vendor/autoload.php');
use Voucherify\VoucherifyClient;
use Voucherify\ClientException;
// Testing data
$apiID = "c70a6f00-cf91-4756-9df5-47628850002b";
$apiKey = "3266b9f8-e246-4f79-bdf0-833929b1380c";
$voucherCode = "Testing7fjWdr";
$trackingID = "my.custom.tracking.id";
// Create new VoucherifyClient instance
$voucherify = new VoucherifyClient($apiID, $apiKey);
// method: Get
try {
echo("Voucherify: GET" . PHP_EOL);
$result = $voucherify->get($voucherCode);
echo(json_encode($result) . PHP_EOL);
}
catch (ClientException $e) {
echo ("Error: " . $e->getMessage() . PHP_EOL);
}
// method: Redemption
try {
echo("Voucherify: REDEMPTION" . PHP_EOL);
$result = $voucherify->redemption($voucherCode);
echo(json_encode($result) . PHP_EOL);
}
catch (ClientException $e) {
echo ("Error: " . $e->getMessage() . PHP_EOL);
}
// method: Redeem (by Code)
try {
echo("Voucherify: REDEEM" . PHP_EOL);
$result = $voucherify->redeem($voucherCode, NULL);
echo(json_encode($result) . PHP_EOL);
}
catch (ClientException $e) {
echo ("Error: " . $e->getMessage() . PHP_EOL);
}
// method: Redeem (by Code with tracking provided)
try {
echo("Voucherify: REDEEM (with code)" . PHP_EOL);
$result = $voucherify->redeem($voucherCode, $trackingID);
echo(json_encode($result) . PHP_EOL);
}
catch (ClientException $e) {
echo("Error: " . $e->getMessage() . PHP_EOL);
}
// method: Redeem (with customer profile)
try {
echo("Voucherify: REDEEM (with customer profile)" . "\n");
$result = $voucherify->redeem([
"voucher" => $voucherCode,
"customer" => [
"id" => "alice.query",
"name" => "Alice Query"
]
], NULL);
echo(json_encode($result) . PHP_EOL);
}
catch (ClientException $e) {
echo("Error: " . $e->getMessage() . PHP_EOL);
}
?>