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
67 protected $interfaceId;
68
69
73 public function __construct(
74 ?DateTimeImmutable $timestamp = null,
75 ?string $type = null,
76 ?Money $amount = null,
77 ?string $interactionId = null,
78 ?string $state = null,
80 ?string $interfaceId = null
81 ) {
82 $this->timestamp = $timestamp;
83 $this->type = $type;
84 $this->amount = $amount;
85 $this->interactionId = $interactionId;
86 $this->state = $state;
87 $this->custom = $custom;
88 $this->interfaceId = $interfaceId;
89 }
90
97 public function getTimestamp()
98 {
99 if (is_null($this->timestamp)) {
101 $data = $this->raw(self::FIELD_TIMESTAMP);
102 if (is_null($data)) {
103 return null;
104 }
105 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
106 if (false === $data) {
107 return null;
108 }
109 $this->timestamp = $data;
110 }
111
112 return $this->timestamp;
113 }
114
121 public function getType()
122 {
123 if (is_null($this->type)) {
125 $data = $this->raw(self::FIELD_TYPE);
126 if (is_null($data)) {
127 return null;
128 }
129 $this->type = (string) $data;
130 }
131
132 return $this->type;
133 }
134
141 public function getAmount()
142 {
143 if (is_null($this->amount)) {
145 $data = $this->raw(self::FIELD_AMOUNT);
146 if (is_null($data)) {
147 return null;
148 }
149
150 $this->amount = MoneyModel::of($data);
151 }
152
153 return $this->amount;
154 }
155
163 public function getInteractionId()
164 {
165 if (is_null($this->interactionId)) {
167 $data = $this->raw(self::FIELD_INTERACTION_ID);
168 if (is_null($data)) {
169 return null;
170 }
171 $this->interactionId = (string) $data;
172 }
173
175 }
176
183 public function getState()
184 {
185 if (is_null($this->state)) {
187 $data = $this->raw(self::FIELD_STATE);
188 if (is_null($data)) {
189 return null;
190 }
191 $this->state = (string) $data;
192 }
193
194 return $this->state;
195 }
196
203 public function getCustom()
204 {
205 if (is_null($this->custom)) {
207 $data = $this->raw(self::FIELD_CUSTOM);
208 if (is_null($data)) {
209 return null;
210 }
211
212 $this->custom = CustomFieldsDraftModel::of($data);
213 }
214
215 return $this->custom;
216 }
217
224 public function getInterfaceId()
225 {
226 if (is_null($this->interfaceId)) {
228 $data = $this->raw(self::FIELD_INTERFACE_ID);
229 if (is_null($data)) {
230 return null;
231 }
232 $this->interfaceId = (string) $data;
233 }
234
235 return $this->interfaceId;
236 }
237
238
242 public function setTimestamp(?DateTimeImmutable $timestamp): void
243 {
244 $this->timestamp = $timestamp;
245 }
246
250 public function setType(?string $type): void
251 {
252 $this->type = $type;
253 }
254
258 public function setAmount(?Money $amount): void
259 {
260 $this->amount = $amount;
261 }
262
266 public function setInteractionId(?string $interactionId): void
267 {
268 $this->interactionId = $interactionId;
269 }
270
274 public function setState(?string $state): void
275 {
276 $this->state = $state;
277 }
278
282 public function setCustom(?CustomFieldsDraft $custom): void
283 {
284 $this->custom = $custom;
285 }
286
290 public function setInterfaceId(?string $interfaceId): void
291 {
292 $this->interfaceId = $interfaceId;
293 }
294
295
296 #[\ReturnTypeWillChange]
297 public function jsonSerialize()
298 {
299 $data = $this->toArray();
300 if (isset($data[TransactionDraft::FIELD_TIMESTAMP]) && $data[TransactionDraft::FIELD_TIMESTAMP] instanceof \DateTimeImmutable) {
301 $data[TransactionDraft::FIELD_TIMESTAMP] = $data[TransactionDraft::FIELD_TIMESTAMP]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
302 }
303 return (object) $data;
304 }
305}
__construct(?DateTimeImmutable $timestamp=null, ?string $type=null, ?Money $amount=null, ?string $interactionId=null, ?string $state=null, ?CustomFieldsDraft $custom=null, ?string $interfaceId=null)