OrderRequest::setEmailTemplate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Create an Order
5
 * https://docs.wegift.io/#9d98f03c-bd13-44e8-b208-e9cd108249cf
6
 */
7
8
namespace AllDigitalRewards\WeGift\Entity;
9
10
use Exception;
11
12
class OrderRequest extends AbstractEntity
13
{
14
    /**
15
     * Face value of the e-gift you wish to order in major units. This must be a string containing a decimal
16
     * representation of the amount. Based on your discounts we will calculate the amount to place an authorisation on
17
     *
18
     * Note 1: Even though JSON supports decimal point numbers, our request payload validation will throw an error
19
     * if the value is passed as number 7.50 rather than "7.50".
20
     * Note 2: When ordering Select products, amount must be a whole decimal, for example 10.00.
21
     *
22
     * @var string
23
     * @required
24
     */
25
    protected string $amount;
26
    /**
27
     * Currency code as defined by ISO 4217. It must match the currency code of the product
28
     *
29
     * @var string
30
     * @required
31
     */
32
    protected string $currency_code;
33
    /**
34
     * Recipients email address the product and product information.
35
     * For this to work email must be selected as the delivery_method
36
     *
37
     * @var string
38
     */
39
    protected string $delivery_email;
40
    /**
41
     *    This is the delivery format for the product which is an enumerated value of either url-instant or url-wrap
42
     *
43
     * url-instant means you will receive a URL to a page with the product details
44
     * url-wrap means you will receive a URL with the WeGift Wrap experience. For url-wrap the chosen product must have
45
     * Wrap support. You can check this using the product details method here.
46
     *
47
     * Note 1: when your account has breakage enabled, the accepted values are url-instant and url-wrap.
48
     * Note 2: when ordering Select products, the only accepted value is url-instant.
49
     *
50
     * @var string
51
     * @required
52
     */
53
    protected string $delivery_format = 'url-instant';
54
    /**
55
     * Enum: direct or email delivery method for the product.
56
     * direct means you will receive the product details in the response.
57
     * email means that WeGift will email the product directly to the recipient with our WeGift email template.
58
     *
59
     * @var string
60
     * @required
61
     */
62
    protected string $delivery_method = 'direct';
63
    protected string $description;
64
    protected string $email_template;
65
    protected string $idempotency_key;
66
    protected string $external_ref;
67
    protected string $notification_email;
68
    /**
69
     * The code of the product (specific gift card brand, e.g. tTV) you are ordering,
70
     * or Select template identifier (e.g. ST-ABC123DE).
71
     *
72
     * @var string
73
     * @required
74
     */
75
    protected string $product_code;
76
    protected string $quantity;
77
    protected string $stock_lock_token;
78
    protected string $url_expiry_period;
79
80
    public function __construct(
81
        string $product_code,
82
        string $amount,
83
        string $currency_code,
84
        string $delivery_method = 'direct'
85
    ) {
86
        $this->product_code = $product_code;
87
        $this->amount = $amount;
88
        $this->currency_code = $currency_code;
89
        $this->delivery_method = $delivery_method;
90
    }
91
92
    /**
93
     * @return string
94
     */
95
    public function getAmount(): string
96
    {
97
        return $this->amount;
98
    }
99
100
    /**
101
     * @param string $amount
102
     */
103
    public function setAmount(string $amount): void
104
    {
105
        $this->amount = $amount;
106
    }
107
108
    /**
109
     * @return string
110
     */
111
    public function getCurrencyCode(): string
112
    {
113
        return $this->currency_code;
114
    }
115
116
    /**
117
     * @param string $currency_code
118
     */
119
    public function setCurrencyCode(string $currency_code): void
120
    {
121
        $this->currency_code = $currency_code;
122
    }
123
124
    /**
125
     * @return string
126
     */
127
    public function getDeliveryEmail(): string
128
    {
129
        return $this->delivery_email;
130
    }
131
132
    /**
133
     * @param string $delivery_email
134
     */
135
    public function setDeliveryEmail(string $delivery_email): void
136
    {
137
        $this->delivery_email = $delivery_email;
138
    }
139
140
    /**
141
     * @return string
142
     */
143
    public function getDeliveryFormat(): string
144
    {
145
        return $this->delivery_format;
146
    }
147
148
    /**
149
     * @param string $delivery_format
150
     */
151
    public function setDeliveryFormat(string $delivery_format): void
152
    {
153
        $this->delivery_format = $delivery_format;
154
    }
155
156
    /**
157
     * @return string
158
     */
159
    public function getDeliveryMethod(): string
160
    {
161
        return $this->delivery_method;
162
    }
163
164
    /**
165
     * @param string $delivery_method
166
     * @throws Exception
167
     */
168
    public function setDeliveryMethod(string $delivery_method): void
169
    {
170
        if (!in_array($delivery_method, ['direct', 'instant'])) {
171
            throw new Exception('Invalid delivery method: ' . $delivery_method);
172
        }
173
174
        $this->delivery_method = $delivery_method;
175
    }
176
177
    /**
178
     * direct means you will receive the product details in the response
179
     *
180
     * @return void
181
     * @throws Exception
182
     */
183
    public function setDeliveryMethodToDirect(): void
184
    {
185
        $this->setDeliveryMethod('direct');
186
    }
187
188
    /**
189
     * email means that WeGift will email the product directly to the recipient with our WeGift email template.
190
     *
191
     * @return void
192
     * @throws Exception
193
     */
194
    public function setDeliveryMethodToEmail(): void
195
    {
196
        $this->setDeliveryMethod('email');
197
    }
198
199
    /**
200
     * @return string
201
     */
202
    public function getDescription(): string
203
    {
204
        return $this->description;
205
    }
206
207
    /**
208
     * @param string $description
209
     */
210
    public function setDescription(string $description): void
211
    {
212
        $this->description = $description;
213
    }
214
215
    /**
216
     * @return string
217
     */
218
    public function getEmailTemplate(): string
219
    {
220
        return $this->email_template;
221
    }
222
223
    /**
224
     * @param string $email_template
225
     */
226
    public function setEmailTemplate(string $email_template): void
227
    {
228
        $this->email_template = $email_template;
229
    }
230
231
    /**
232
     * @return string
233
     */
234
    public function getIdempotencyKey(): string
235
    {
236
        return $this->idempotency_key;
237
    }
238
239
    /**
240
     * @param string $idempotency_key
241
     */
242
    public function setIdempotencyKey(string $idempotency_key): void
243
    {
244
        $this->idempotency_key = $idempotency_key;
245
    }
246
247
    /**
248
     * @return string
249
     */
250
    public function getExternalRef(): string
251
    {
252
        return $this->external_ref;
253
    }
254
255
    /**
256
     * @param string $external_ref
257
     */
258
    public function setExternalRef(string $external_ref): void
259
    {
260
        $this->external_ref = $external_ref;
261
    }
262
263
    /**
264
     * @return string
265
     */
266
    public function getNotificationEmail(): string
267
    {
268
        return $this->notification_email;
269
    }
270
271
    /**
272
     * @param string $notification_email
273
     */
274
    public function setNotificationEmail(string $notification_email): void
275
    {
276
        $this->notification_email = $notification_email;
277
    }
278
279
    /**
280
     * @return string
281
     */
282
    public function getProductCode(): string
283
    {
284
        return $this->product_code;
285
    }
286
287
    /**
288
     * @param string $product_code
289
     */
290
    public function setProductCode(string $product_code): void
291
    {
292
        $this->product_code = $product_code;
293
    }
294
295
    /**
296
     * @return string
297
     */
298
    public function getQuantity(): string
299
    {
300
        return $this->quantity;
301
    }
302
303
    /**
304
     * @param string $quantity
305
     */
306
    public function setQuantity(string $quantity): void
307
    {
308
        $this->quantity = $quantity;
309
    }
310
311
    /**
312
     * @return string
313
     */
314
    public function getStockLockToken(): string
315
    {
316
        return $this->stock_lock_token;
317
    }
318
319
    /**
320
     * @param string $stock_lock_token
321
     */
322
    public function setStockLockToken(string $stock_lock_token): void
323
    {
324
        $this->stock_lock_token = $stock_lock_token;
325
    }
326
327
    /**
328
     * @return string
329
     */
330
    public function getUrlExpiryPeriod(): string
331
    {
332
        return $this->url_expiry_period;
333
    }
334
335
    /**
336
     * @param string $url_expiry_period
337
     */
338
    public function setUrlExpiryPeriod(string $url_expiry_period): void
339
    {
340
        $this->url_expiry_period = $url_expiry_period;
341
    }
342
}
343