Completed
Push — master ( eb575e...c103e9 )
by Romain
13s
created

ReceiptTemplate::setAdjustments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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\Template;
9
use Kerox\Messenger\Model\Message\Attachment\Template\Receipt\Summary;
10
11
class ReceiptTemplate extends Template
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 null|\Kerox\Messenger\Model\Common\Address
50
     */
51
    protected $address;
52
53
    /**
54
     * @var \Kerox\Messenger\Model\Message\Attachment\Template\Receipt\Summary
55
     */
56
    protected $summary;
57
58
    /**
59
     * @var null|\Kerox\Messenger\Model\Message\Attachment\Template\Receipt\Adjustment[]
60
     */
61
    protected $adjustments;
62
63
    /**
64
     * Receipt constructor.
65
     *
66
     * @param string                                                                      $recipientName
67
     * @param string                                                                      $orderNumber
68
     * @param string                                                                      $currency
69
     * @param string                                                                      $paymentMethod
70
     * @param \Kerox\Messenger\Model\Message\Attachment\Template\Element\ReceiptElement[] $elements
71
     * @param \Kerox\Messenger\Model\Message\Attachment\Template\Receipt\Summary          $summary
72
     *
73
     * @throws \InvalidArgumentException
74
     */
75
    public function __construct(
76
        string $recipientName,
77
        string $orderNumber,
78
        string $currency,
79
        string $paymentMethod,
80
        array $elements,
81
        Summary $summary
82
    ) {
83
        parent::__construct();
84
85
        $this->isValidArray($elements, 100);
86
87
        $this->recipientName = $recipientName;
88
        $this->orderNumber = $orderNumber;
89
        $this->currency = $currency;
90
        $this->paymentMethod = $paymentMethod;
91
        $this->elements = $elements;
92
        $this->summary = $summary;
93
    }
94
95
    /**
96
     * @param string                                                             $recipientName
97
     * @param string                                                             $orderNumber
98
     * @param string                                                             $currency
99
     * @param string                                                             $paymentMethod
100
     * @param array                                                              $elements
101
     * @param \Kerox\Messenger\Model\Message\Attachment\Template\Receipt\Summary $summary
102
     *
103
     * @throws \InvalidArgumentException
104
     *
105
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\ReceiptTemplate
106
     */
107
    public static function create(
108
        string $recipientName,
109
        string $orderNumber,
110
        string $currency,
111
        string $paymentMethod,
112
        array $elements,
113
        Summary $summary
114
    ): self {
115
        return new self($recipientName, $orderNumber, $currency, $paymentMethod, $elements, $summary);
116
    }
117
118
    /**
119
     * @param string $timestamp
120
     *
121
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\ReceiptTemplate
122
     */
123
    public function setTimestamp(string $timestamp): self
124
    {
125
        $this->timestamp = $timestamp;
126
127
        return $this;
128
    }
129
130
    /**
131
     * @param string $orderUrl
132
     *
133
     * @throws \InvalidArgumentException
134
     *
135
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\ReceiptTemplate
136
     */
137
    public function setOrderUrl(string $orderUrl): self
138
    {
139
        $this->isValidUrl($orderUrl);
140
141
        $this->orderUrl = $orderUrl;
142
143
        return $this;
144
    }
145
146
    /**
147
     * @param \Kerox\Messenger\Model\Common\Address $address
148
     *
149
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\ReceiptTemplate
150
     */
151
    public function setAddress(Address $address): self
152
    {
153
        $this->address = $address;
154
155
        return $this;
156
    }
157
158
    /**
159
     * @param \Kerox\Messenger\Model\Message\Attachment\Template\Receipt\Adjustment[] $adjustments
160
     *
161
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\ReceiptTemplate
162
     */
163
    public function setAdjustments(array $adjustments): self
164
    {
165
        $this->adjustments = $adjustments;
166
167
        return $this;
168
    }
169
170
    /**
171
     * @return array
172
     */
173
    public function toArray(): array
174
    {
175
        $array = parent::toArray();
176
        $array += [
177
            'payload' => [
178
                'template_type'  => Template::TYPE_RECEIPT,
179
                'recipient_name' => $this->recipientName,
180
                'order_number'   => $this->orderNumber,
181
                'currency'       => $this->currency,
182
                'payment_method' => $this->paymentMethod,
183
                'order_url'      => $this->orderUrl,
184
                'timestamp'      => $this->timestamp,
185
                'elements'       => $this->elements,
186
                'address'        => $this->address,
187
                'summary'        => $this->summary,
188
                'adjustments'    => $this->adjustments,
189
            ],
190
        ];
191
192
        return $this->arrayFilter($array);
193
    }
194
}
195