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