commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
MyTransactionDraftModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
19 use DateTimeImmutable;
20 use stdClass;
21 
26 {
31  protected $timestamp;
32 
37  protected $type;
38 
43  protected $amount;
44 
49  protected $interactionId;
50 
55  protected $custom;
56 
57 
61  public function __construct(
62  ?DateTimeImmutable $timestamp = null,
63  ?string $type = null,
64  ?Money $amount = null,
65  ?string $interactionId = null,
67  ) {
68  $this->timestamp = $timestamp;
69  $this->type = $type;
70  $this->amount = $amount;
71  $this->interactionId = $interactionId;
72  $this->custom = $custom;
73  }
74 
81  public function getTimestamp()
82  {
83  if (is_null($this->timestamp)) {
85  $data = $this->raw(self::FIELD_TIMESTAMP);
86  if (is_null($data)) {
87  return null;
88  }
89  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
90  if (false === $data) {
91  return null;
92  }
93  $this->timestamp = $data;
94  }
95 
96  return $this->timestamp;
97  }
98 
106  public function getType()
107  {
108  if (is_null($this->type)) {
110  $data = $this->raw(self::FIELD_TYPE);
111  if (is_null($data)) {
112  return null;
113  }
114  $this->type = (string) $data;
115  }
116 
117  return $this->type;
118  }
119 
126  public function getAmount()
127  {
128  if (is_null($this->amount)) {
130  $data = $this->raw(self::FIELD_AMOUNT);
131  if (is_null($data)) {
132  return null;
133  }
134 
135  $this->amount = MoneyModel::of($data);
136  }
137 
138  return $this->amount;
139  }
140 
148  public function getInteractionId()
149  {
150  if (is_null($this->interactionId)) {
152  $data = $this->raw(self::FIELD_INTERACTION_ID);
153  if (is_null($data)) {
154  return null;
155  }
156  $this->interactionId = (string) $data;
157  }
158 
159  return $this->interactionId;
160  }
161 
168  public function getCustom()
169  {
170  if (is_null($this->custom)) {
172  $data = $this->raw(self::FIELD_CUSTOM);
173  if (is_null($data)) {
174  return null;
175  }
176 
177  $this->custom = CustomFieldsDraftModel::of($data);
178  }
179 
180  return $this->custom;
181  }
182 
183 
187  public function setTimestamp(?DateTimeImmutable $timestamp): void
188  {
189  $this->timestamp = $timestamp;
190  }
191 
195  public function setType(?string $type): void
196  {
197  $this->type = $type;
198  }
199 
203  public function setAmount(?Money $amount): void
204  {
205  $this->amount = $amount;
206  }
207 
211  public function setInteractionId(?string $interactionId): void
212  {
213  $this->interactionId = $interactionId;
214  }
215 
219  public function setCustom(?CustomFieldsDraft $custom): void
220  {
221  $this->custom = $custom;
222  }
223 
224 
225  #[\ReturnTypeWillChange]
226  public function jsonSerialize()
227  {
228  $data = $this->toArray();
229  if (isset($data[MyTransactionDraft::FIELD_TIMESTAMP]) && $data[MyTransactionDraft::FIELD_TIMESTAMP] instanceof \DateTimeImmutable) {
230  $data[MyTransactionDraft::FIELD_TIMESTAMP] = $data[MyTransactionDraft::FIELD_TIMESTAMP]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
231  }
232  return (object) $data;
233  }
234 }
__construct(?DateTimeImmutable $timestamp=null, ?string $type=null, ?Money $amount=null, ?string $interactionId=null, ?CustomFieldsDraft $custom=null)