|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Kerox\Messenger\Model\Message\Attachment\Template\Element; |
|
6
|
|
|
|
|
7
|
|
|
class ReceiptElement extends AbstractElement |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @var int|null |
|
11
|
|
|
*/ |
|
12
|
|
|
protected $quantity; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var float|null |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $price; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var string|null |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $currency; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Element constructor. |
|
26
|
|
|
* |
|
27
|
|
|
* @throws \Kerox\Messenger\Exception\MessengerException |
|
28
|
|
|
*/ |
|
29
|
6 |
|
public function __construct(string $title, float $price) |
|
30
|
|
|
{ |
|
31
|
6 |
|
parent::__construct($title); |
|
32
|
|
|
|
|
33
|
6 |
|
$this->price = $price; |
|
34
|
6 |
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @throws \Kerox\Messenger\Exception\MessengerException |
|
38
|
|
|
* |
|
39
|
|
|
* @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\ReceiptElement |
|
40
|
|
|
*/ |
|
41
|
6 |
|
public static function create(string $title, float $price): self |
|
42
|
|
|
{ |
|
43
|
6 |
|
return new self($title, $price); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @throws \Kerox\Messenger\Exception\MessengerException |
|
48
|
|
|
* |
|
49
|
|
|
* @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\ReceiptElement |
|
50
|
|
|
*/ |
|
51
|
6 |
|
public function setSubtitle(string $subtitle): self |
|
52
|
|
|
{ |
|
53
|
6 |
|
parent::setSubtitle($subtitle); |
|
54
|
|
|
|
|
55
|
6 |
|
return $this; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @throws \Kerox\Messenger\Exception\MessengerException |
|
60
|
|
|
* |
|
61
|
|
|
* @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\ReceiptElement |
|
62
|
|
|
*/ |
|
63
|
6 |
|
public function setImageUrl(string $imageUrl): self |
|
64
|
|
|
{ |
|
65
|
6 |
|
parent::setImageUrl($imageUrl); |
|
66
|
|
|
|
|
67
|
6 |
|
return $this; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return ReceiptElement |
|
72
|
|
|
*/ |
|
73
|
6 |
|
public function setQuantity(int $quantity): self |
|
74
|
|
|
{ |
|
75
|
6 |
|
$this->quantity = $quantity; |
|
76
|
|
|
|
|
77
|
6 |
|
return $this; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @throws \Kerox\Messenger\Exception\MessengerException |
|
82
|
|
|
* |
|
83
|
|
|
* @return ReceiptElement |
|
84
|
|
|
*/ |
|
85
|
6 |
|
public function setCurrency(string $currency): self |
|
86
|
|
|
{ |
|
87
|
6 |
|
$this->isValidCurrency($currency); |
|
88
|
|
|
|
|
89
|
6 |
|
$this->currency = $currency; |
|
90
|
|
|
|
|
91
|
6 |
|
return $this; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
5 |
|
public function toArray(): array |
|
95
|
|
|
{ |
|
96
|
5 |
|
$array = parent::toArray(); |
|
97
|
|
|
$array += [ |
|
98
|
5 |
|
'subtitle' => $this->subtitle, |
|
99
|
5 |
|
'quantity' => $this->quantity, |
|
100
|
5 |
|
'price' => $this->price, |
|
101
|
5 |
|
'currency' => $this->currency, |
|
102
|
5 |
|
'image_url' => $this->imageUrl, |
|
103
|
|
|
]; |
|
104
|
|
|
|
|
105
|
5 |
|
return array_filter($array); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|