commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
TransactionDraftModel.php
1<?php
2
3declare(strict_types=1);
10
19use DateTimeImmutable;
20use stdClass;
21
26{
31 protected $timestamp;
32
37 protected $type;
38
43 protected $amount;
44
49 protected $interactionId;
50
55 protected $state;
56
61 protected $custom;
62
63
67 public function __construct(
68 ?DateTimeImmutable $timestamp = null,
69 ?string $type = null,
70 ?Money $amount = null,
71 ?string $interactionId = null,
72 ?string $state = null,
74 ) {
75 $this->timestamp = $timestamp;
76 $this->type = $type;
77 $this->amount = $amount;
78 $this->interactionId = $interactionId;
79 $this->state = $state;
80 $this->custom = $custom;
81 }
82
89 public function getTimestamp()
90 {
91 if (is_null($this->timestamp)) {
93 $data = $this->raw(self::FIELD_TIMESTAMP);
94 if (is_null($data)) {
95 return null;
96 }
97 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
98 if (false === $data) {
99 return null;
100 }
101 $this->timestamp = $data;
102 }
103
104 return $this->timestamp;
105 }
106
113 public function getType()
114 {
115 if (is_null($this->type)) {
117 $data = $this->raw(self::FIELD_TYPE);
118 if (is_null($data)) {
119 return null;
120 }
121 $this->type = (string) $data;
122 }
123
124 return $this->type;
125 }
126
133 public function getAmount()
134 {
135 if (is_null($this->amount)) {
137 $data = $this->raw(self::FIELD_AMOUNT);
138 if (is_null($data)) {
139 return null;
140 }
141
142 $this->amount = MoneyModel::of($data);
143 }
144
145 return $this->amount;
146 }
147
155 public function getInteractionId()
156 {
157 if (is_null($this->interactionId)) {
159 $data = $this->raw(self::FIELD_INTERACTION_ID);
160 if (is_null($data)) {
161 return null;
162 }
163 $this->interactionId = (string) $data;
164 }
165
167 }
168
175 public function getState()
176 {
177 if (is_null($this->state)) {
179 $data = $this->raw(self::FIELD_STATE);
180 if (is_null($data)) {
181 return null;
182 }
183 $this->state = (string) $data;
184 }
185
186 return $this->state;
187 }
188
195 public function getCustom()
196 {
197 if (is_null($this->custom)) {
199 $data = $this->raw(self::FIELD_CUSTOM);
200 if (is_null($data)) {
201 return null;
202 }
203
204 $this->custom = CustomFieldsDraftModel::of($data);
205 }
206
207 return $this->custom;
208 }
209
210
214 public function setTimestamp(?DateTimeImmutable $timestamp): void
215 {
216 $this->timestamp = $timestamp;
217 }
218
222 public function setType(?string $type): void
223 {
224 $this->type = $type;
225 }
226
230 public function setAmount(?Money $amount): void
231 {
232 $this->amount = $amount;
233 }
234
238 public function setInteractionId(?string $interactionId): void
239 {
240 $this->interactionId = $interactionId;
241 }
242
246 public function setState(?string $state): void
247 {
248 $this->state = $state;
249 }
250
254 public function setCustom(?CustomFieldsDraft $custom): void
255 {
256 $this->custom = $custom;
257 }
258
259
260 #[\ReturnTypeWillChange]
261 public function jsonSerialize()
262 {
263 $data = $this->toArray();
264 if (isset($data[TransactionDraft::FIELD_TIMESTAMP]) && $data[TransactionDraft::FIELD_TIMESTAMP] instanceof \DateTimeImmutable) {
265 $data[TransactionDraft::FIELD_TIMESTAMP] = $data[TransactionDraft::FIELD_TIMESTAMP]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
266 }
267 return (object) $data;
268 }
269}
__construct(?DateTimeImmutable $timestamp=null, ?string $type=null, ?Money $amount=null, ?string $interactionId=null, ?string $state=null, ?CustomFieldsDraft $custom=null)