1
|
|
|
<?php |
2
|
|
|
namespace Kerox\Messenger\Model\Message\Attachment\Template; |
3
|
|
|
|
4
|
|
|
use Kerox\Messenger\Model\Message\Attachment\Template; |
5
|
|
|
use Kerox\Messenger\Model\Message\Attachment\Template\Receipt\Address; |
6
|
|
|
use Kerox\Messenger\Model\Message\Attachment\Template\Receipt\Summary; |
7
|
|
|
|
8
|
|
|
class Receipt extends Template |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
protected $recipientName; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $orderNumber; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $currency; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $paymentMethod; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $timestamp; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $orderUrl; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var \Kerox\Messenger\Model\Message\Attachment\Template\Element\ReceiptElement[] |
43
|
|
|
*/ |
44
|
|
|
protected $elements; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var null|\Kerox\Messenger\Model\Message\Attachment\Template\Receipt\Address |
48
|
|
|
*/ |
49
|
|
|
protected $address; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var \Kerox\Messenger\Model\Message\Attachment\Template\Receipt\Summary |
53
|
|
|
*/ |
54
|
|
|
protected $summary; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var null|\Kerox\Messenger\Model\Message\Attachment\Template\Receipt\Adjustment[] |
58
|
|
|
*/ |
59
|
|
|
protected $adjustments; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Receipt constructor. |
63
|
|
|
* |
64
|
|
|
* @param string $recipientName |
65
|
|
|
* @param string $orderNumber |
66
|
|
|
* @param string $currency |
67
|
|
|
* @param string $paymentMethod |
68
|
|
|
* @param \Kerox\Messenger\Model\Message\Attachment\Template\Element\ReceiptElement[] $elements |
69
|
|
|
* @param \Kerox\Messenger\Model\Message\Attachment\Template\Receipt\Summary $summary |
70
|
|
|
*/ |
71
|
|
|
public function __construct( |
72
|
|
|
string $recipientName, |
73
|
|
|
string $orderNumber, |
74
|
|
|
string $currency, |
75
|
|
|
string $paymentMethod, |
76
|
|
|
array $elements, |
77
|
|
|
Summary $summary |
78
|
|
|
) { |
79
|
|
|
parent::__construct(); |
80
|
|
|
|
81
|
|
|
$this->isValidArray($elements, 100); |
82
|
|
|
|
83
|
|
|
$this->recipientName = $recipientName; |
84
|
|
|
$this->orderNumber = $orderNumber; |
85
|
|
|
$this->currency = $currency; |
86
|
|
|
$this->paymentMethod = $paymentMethod; |
87
|
|
|
$this->elements = $elements; |
88
|
|
|
$this->summary = $summary; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param string $timestamp |
93
|
|
|
* @return Receipt |
94
|
|
|
*/ |
95
|
|
|
public function setTimestamp(string $timestamp): Receipt |
96
|
|
|
{ |
97
|
|
|
$this->timestamp = $timestamp; |
98
|
|
|
|
99
|
|
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param string $orderUrl |
104
|
|
|
* @return Receipt |
105
|
|
|
*/ |
106
|
|
|
public function setOrderUrl(string $orderUrl): Receipt |
107
|
|
|
{ |
108
|
|
|
$this->isValidUrl($orderUrl); |
109
|
|
|
$this->orderUrl = $orderUrl; |
110
|
|
|
|
111
|
|
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param \Kerox\Messenger\Model\Message\Attachment\Template\Receipt\Address $address |
116
|
|
|
* @return Receipt |
117
|
|
|
*/ |
118
|
|
|
public function setAddress(Address $address): Receipt |
119
|
|
|
{ |
120
|
|
|
$this->address = $address; |
121
|
|
|
|
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param \Kerox\Messenger\Model\Message\Attachment\Template\Receipt\Adjustment[] $adjustments |
127
|
|
|
* @return Receipt |
128
|
|
|
*/ |
129
|
|
|
public function setAdjustments(array $adjustments): Receipt |
130
|
|
|
{ |
131
|
|
|
$this->adjustments = $adjustments; |
132
|
|
|
|
133
|
|
|
return $this; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @return array |
138
|
|
|
*/ |
139
|
|
|
public function jsonSerialize(): array |
140
|
|
|
{ |
141
|
|
|
$payload = [ |
142
|
|
|
'template_type' => Template::TYPE_RECEIPT, |
143
|
|
|
'recipient_name' => $this->recipientName, |
144
|
|
|
'order_number' => $this->orderNumber, |
145
|
|
|
'currency' => $this->currency, |
146
|
|
|
'payment_method' => $this->paymentMethod, |
147
|
|
|
'order_url' => $this->orderUrl, |
148
|
|
|
'timestamp' => $this->timestamp, |
149
|
|
|
'elements' => $this->elements, |
150
|
|
|
'address' => $this->address, |
151
|
|
|
'summary' => $this->summary, |
152
|
|
|
'adjustments' => $this->adjustments, |
153
|
|
|
]; |
154
|
|
|
|
155
|
|
|
$json = parent::jsonSerialize(); |
156
|
|
|
$json += [ |
157
|
|
|
'payload' => array_filter($payload), |
158
|
|
|
]; |
159
|
|
|
|
160
|
|
|
return $json; |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|