forked from voucherifyio/voucherify-php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VoucherBuilder.php
128 lines (106 loc) · 4.24 KB
/
VoucherBuilder.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
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
<?php
namespace Voucherify {
class VoucherBuilder {
private $_voucher;
public function __construct() {
$this->_voucher = (object)[
"code_config" => (object)[]
];
}
public function setCode($code) {
$this->_voucher->code = $code;
return $this;
}
public function setCodeLength($length) {
$this->_voucher->code_config->length = $length;
return $this;
}
public function setCodeCharset($charset) {
$this->_voucher->code_config->charset = $charset;
return $this;
}
public function setCodePrefix($prefix) {
$this->_voucher->code_config->prefix = $prefix;
return $this;
}
public function setCodePostfix($postfix) {
$this->_voucher->code_config->postfix = $postfix;
return $this;
}
public function setCodePattern($pattern) {
$this->_voucher->code_config->pattern = $pattern;
return $this;
}
public function setCampaign($campaign) {
$this->_voucher->campaign = $campaign;
return $this;
}
public function setCategory($category) {
$this->_voucher->category = $category;
return $this;
}
public function setAmountDiscount($amount_off) {
$this->_voucher->type = "DISCOUNT_VOUCHER";
$this->_voucher->discount = (object) [
"type" => "AMOUNT",
"amount_off" => $amount_off * 100
];
return $this;
}
public function setPercentDiscount($percent_off) {
$this->_voucher->type = "DISCOUNT_VOUCHER";
$this->_voucher->discount = (object) [
"type" => "PERCENT",
"percent_off" => $percent_off
];
return $this;
}
public function setUnitDiscount($unit_off, $unit_type) {
$this->_voucher->type = "DISCOUNT_VOUCHER";
$this->_voucher->discount = (object) [
"type" => "UNIT",
"unit_off" => $unit_off,
"unit_type" => $unit_type
];
return $this;
}
public function setGiftAmount($amount) {
$this->_voucher->type = "GIFT_VOUCHER";
$this->_voucher->gift = (object) [
"amount" => $amount * 100
];
return $this;
}
public function setStartDate($start_date) {
if ($start_date instanceof \DateTime) {
$start_date = $start_date->format(\DateTime::ISO8601);
}
$this->_voucher->start_date = $start_date;
return $this;
}
public function setExpirationDate($expiration_date) {
if ($expiration_date instanceof \DateTime) {
$expiration_date = $expiration_date->format(\DateTime::ISO8601);
}
$this->_voucher->expiration_date = $expiration_date;
return $this;
}
public function setRedemptionLimit($redemption_limit) {
$this->_voucher->redemption = (object) [
"quantity" => $redemption_limit
];
return $this;
}
public function setActive($active) {
$this->_voucher->active = $active;
return $this;
}
public function build() {
if (isset($this->_voucher->code)) {
unset($this->_voucher->code_config);
}
return $this->_voucher;
}
}
}
?>