diff --git a/changes.md b/changes.md index fa719b9fb3a..d7c97786492 100644 --- a/changes.md +++ b/changes.md @@ -218,6 +218,7 @@ - added type `RecurringOrderCustomTypeRemovedMessage` - added type `RecurringOrderCustomTypeSetMessage` - added type `RecurringOrderDeletedMessage` +- added type `RecurringOrderExpiresAtSetMessage` - added type `RecurringOrderKeySetMessage` - added type `RecurringOrderScheduleSetMessage` - added type `RecurringOrderStartsAtSetMessage` @@ -267,6 +268,7 @@ - added type `RecurringOrderCustomTypeRemovedMessagePayload` - added type `RecurringOrderCustomTypeSetMessagePayload` - added type `RecurringOrderDeletedMessagePayload` +- added type `RecurringOrderExpiresAtSetMessagePayload` - added type `RecurringOrderKeySetMessagePayload` - added type `RecurringOrderScheduleSetMessagePayload` - added type `RecurringOrderStartsAtSetMessagePayload` @@ -348,6 +350,7 @@ - added type `SkipConfigurationDraft` - added type `RecurringOrderSetCustomFieldAction` - added type `RecurringOrderSetCustomTypeAction` +- added type `RecurringOrderSetExpiresAtAction` - added type `RecurringOrderSetKeyAction` - added type `RecurringOrderSetOrderSkipConfigurationAction` - added type `RecurringOrderSetScheduleAction` diff --git a/lib/commercetools-api/docs/RequestBuilder.md b/lib/commercetools-api/docs/RequestBuilder.md index 6a19370c3bb..63cb321010c 100644 --- a/lib/commercetools-api/docs/RequestBuilder.md +++ b/lib/commercetools-api/docs/RequestBuilder.md @@ -10858,10 +10858,11 @@ $request = $builder ## `withProjectKey("projectKey")->recurringOrders()->post(null)` Creates a Recurring Order in the Project. -The Cart is validated to ensure that it is convertible to an [Order](ctp:api:type:Order). If validation fails, an error is returned. - Produces the [RecurringOrderCreated](ctp:api:type:RecurringOrderCreatedMessage) message. +The Cart is validated to ensure that it is convertible to an [Order](ctp:api:type:Order). If the validation fails, an error is returned. +If the expiration date has been reached when the [Recurring Order](ctp:api:type:RecurringOrder) is processed, its [RecurringOrderState](ctp:api:type:RecurringOrderState) will be updated to `Expired`, and no Order will be created. + If a server-side problem occurs, indicated by a 500 Internal Server Error HTTP response, the Recurring Order creation may still successfully complete after the error is returned. If you receive this error, you should verify the status of the Recurring Order by querying a unique identifier supplied during the creation request, such as the key. diff --git a/lib/commercetools-api/src/Models/Common/BaseResource.php b/lib/commercetools-api/src/Models/Common/BaseResource.php index 0362e99f314..0afdfb47f20 100644 --- a/lib/commercetools-api/src/Models/Common/BaseResource.php +++ b/lib/commercetools-api/src/Models/Common/BaseResource.php @@ -228,6 +228,7 @@ use Commercetools\Api\Models\Message\RecurringOrderCustomTypeRemovedMessage; use Commercetools\Api\Models\Message\RecurringOrderCustomTypeSetMessage; use Commercetools\Api\Models\Message\RecurringOrderDeletedMessage; +use Commercetools\Api\Models\Message\RecurringOrderExpiresAtSetMessage; use Commercetools\Api\Models\Message\RecurringOrderKeySetMessage; use Commercetools\Api\Models\Message\RecurringOrderScheduleSetMessage; use Commercetools\Api\Models\Message\RecurringOrderStartsAtSetMessage; diff --git a/lib/commercetools-api/src/Models/Common/BaseResourceBuilder.php b/lib/commercetools-api/src/Models/Common/BaseResourceBuilder.php index 7f9b96e0c44..4d33b2896f7 100644 --- a/lib/commercetools-api/src/Models/Common/BaseResourceBuilder.php +++ b/lib/commercetools-api/src/Models/Common/BaseResourceBuilder.php @@ -448,6 +448,8 @@ use Commercetools\Api\Models\Message\RecurringOrderCustomTypeSetMessageBuilder; use Commercetools\Api\Models\Message\RecurringOrderDeletedMessage; use Commercetools\Api\Models\Message\RecurringOrderDeletedMessageBuilder; +use Commercetools\Api\Models\Message\RecurringOrderExpiresAtSetMessage; +use Commercetools\Api\Models\Message\RecurringOrderExpiresAtSetMessageBuilder; use Commercetools\Api\Models\Message\RecurringOrderKeySetMessage; use Commercetools\Api\Models\Message\RecurringOrderKeySetMessageBuilder; use Commercetools\Api\Models\Message\RecurringOrderScheduleSetMessage; diff --git a/lib/commercetools-api/src/Models/Common/BaseResourceModel.php b/lib/commercetools-api/src/Models/Common/BaseResourceModel.php index 81f5b200cc3..5587c3633a2 100644 --- a/lib/commercetools-api/src/Models/Common/BaseResourceModel.php +++ b/lib/commercetools-api/src/Models/Common/BaseResourceModel.php @@ -448,6 +448,8 @@ use Commercetools\Api\Models\Message\RecurringOrderCustomTypeSetMessageModel; use Commercetools\Api\Models\Message\RecurringOrderDeletedMessage; use Commercetools\Api\Models\Message\RecurringOrderDeletedMessageModel; +use Commercetools\Api\Models\Message\RecurringOrderExpiresAtSetMessage; +use Commercetools\Api\Models\Message\RecurringOrderExpiresAtSetMessageModel; use Commercetools\Api\Models\Message\RecurringOrderKeySetMessage; use Commercetools\Api\Models\Message\RecurringOrderKeySetMessageModel; use Commercetools\Api\Models\Message\RecurringOrderScheduleSetMessage; diff --git a/lib/commercetools-api/src/Models/Message/MessageModel.php b/lib/commercetools-api/src/Models/Message/MessageModel.php index 515001c4fd1..9b4466c09e2 100644 --- a/lib/commercetools-api/src/Models/Message/MessageModel.php +++ b/lib/commercetools-api/src/Models/Message/MessageModel.php @@ -352,6 +352,7 @@ final class MessageModel extends JsonObjectModel implements Message 'RecurringOrderCustomTypeRemoved' => RecurringOrderCustomTypeRemovedMessageModel::class, 'RecurringOrderCustomTypeSet' => RecurringOrderCustomTypeSetMessageModel::class, 'RecurringOrderDeleted' => RecurringOrderDeletedMessageModel::class, + 'RecurringOrderExpiresAtSet' => RecurringOrderExpiresAtSetMessageModel::class, 'RecurringOrderKeySet' => RecurringOrderKeySetMessageModel::class, 'RecurringOrderScheduleSet' => RecurringOrderScheduleSetMessageModel::class, 'RecurringOrderStartsAtSet' => RecurringOrderStartsAtSetMessageModel::class, diff --git a/lib/commercetools-api/src/Models/Message/MessagePayloadModel.php b/lib/commercetools-api/src/Models/Message/MessagePayloadModel.php index 65a4ff1e327..b999b683f21 100644 --- a/lib/commercetools-api/src/Models/Message/MessagePayloadModel.php +++ b/lib/commercetools-api/src/Models/Message/MessagePayloadModel.php @@ -283,6 +283,7 @@ final class MessagePayloadModel extends JsonObjectModel implements MessagePayloa 'RecurringOrderCustomTypeRemoved' => RecurringOrderCustomTypeRemovedMessagePayloadModel::class, 'RecurringOrderCustomTypeSet' => RecurringOrderCustomTypeSetMessagePayloadModel::class, 'RecurringOrderDeleted' => RecurringOrderDeletedMessagePayloadModel::class, + 'RecurringOrderExpiresAtSet' => RecurringOrderExpiresAtSetMessagePayloadModel::class, 'RecurringOrderKeySet' => RecurringOrderKeySetMessagePayloadModel::class, 'RecurringOrderScheduleSet' => RecurringOrderScheduleSetMessagePayloadModel::class, 'RecurringOrderStartsAtSet' => RecurringOrderStartsAtSetMessagePayloadModel::class, diff --git a/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessage.php b/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessage.php new file mode 100644 index 00000000000..5e57cd10ddf --- /dev/null +++ b/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessage.php @@ -0,0 +1,45 @@ +Expiration date and time of the Recurring Order after the Set Expires At update action.

+ * + + * @return null|DateTimeImmutable + */ + public function getNewExpiresAt(); + + /** + *

Expiration date and time of the Recurring Order before the Set Expires At update action.

+ * + + * @return null|DateTimeImmutable + */ + public function getOldExpiresAt(); + + /** + * @param ?DateTimeImmutable $newExpiresAt + */ + public function setNewExpiresAt(?DateTimeImmutable $newExpiresAt): void; + + /** + * @param ?DateTimeImmutable $oldExpiresAt + */ + public function setOldExpiresAt(?DateTimeImmutable $oldExpiresAt): void; +} diff --git a/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessageBuilder.php b/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessageBuilder.php new file mode 100644 index 00000000000..f14c8acc487 --- /dev/null +++ b/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessageBuilder.php @@ -0,0 +1,433 @@ + + */ +final class RecurringOrderExpiresAtSetMessageBuilder implements Builder +{ + /** + + * @var ?string + */ + private $id; + + /** + + * @var ?int + */ + private $version; + + /** + + * @var ?DateTimeImmutable + */ + private $createdAt; + + /** + + * @var ?DateTimeImmutable + */ + private $lastModifiedAt; + + /** + + * @var null|LastModifiedBy|LastModifiedByBuilder + */ + private $lastModifiedBy; + + /** + + * @var null|CreatedBy|CreatedByBuilder + */ + private $createdBy; + + /** + + * @var ?int + */ + private $sequenceNumber; + + /** + + * @var null|Reference|ReferenceBuilder + */ + private $resource; + + /** + + * @var ?int + */ + private $resourceVersion; + + /** + + * @var null|UserProvidedIdentifiers|UserProvidedIdentifiersBuilder + */ + private $resourceUserProvidedIdentifiers; + + /** + + * @var ?DateTimeImmutable + */ + private $newExpiresAt; + + /** + + * @var ?DateTimeImmutable + */ + private $oldExpiresAt; + + /** + *

Unique identifier of the Message. Can be used to track which Messages have been processed.

+ * + + * @return null|string + */ + public function getId() + { + return $this->id; + } + + /** + *

Version of a resource. In case of Messages, this is always 1.

+ * + + * @return null|int + */ + public function getVersion() + { + return $this->version; + } + + /** + *

Date and time (UTC) the Message was generated.

+ * + + * @return null|DateTimeImmutable + */ + public function getCreatedAt() + { + return $this->createdAt; + } + + /** + *

Value of createdAt.

+ * + + * @return null|DateTimeImmutable + */ + public function getLastModifiedAt() + { + return $this->lastModifiedAt; + } + + /** + *

IDs and references that last modified the Message.

+ * + + * @return null|LastModifiedBy + */ + public function getLastModifiedBy() + { + return $this->lastModifiedBy instanceof LastModifiedByBuilder ? $this->lastModifiedBy->build() : $this->lastModifiedBy; + } + + /** + *

IDs and references that created the Message.

+ * + + * @return null|CreatedBy + */ + public function getCreatedBy() + { + return $this->createdBy instanceof CreatedByBuilder ? $this->createdBy->build() : $this->createdBy; + } + + /** + *

Message number in relation to other Messages for a given resource. The sequenceNumber of the next Message for the resource is the successor of the sequenceNumber of the current Message. Meaning, the sequenceNumber of the next Message equals the sequenceNumber of the current Message + 1. + * sequenceNumber can be used to ensure that Messages are processed in the correct order for a particular resource.

+ * + + * @return null|int + */ + public function getSequenceNumber() + { + return $this->sequenceNumber; + } + + /** + *

Reference to the resource on which the change or action was performed.

+ * + + * @return null|Reference + */ + public function getResource() + { + return $this->resource instanceof ReferenceBuilder ? $this->resource->build() : $this->resource; + } + + /** + *

Version of the resource on which the change or action was performed.

+ * + + * @return null|int + */ + public function getResourceVersion() + { + return $this->resourceVersion; + } + + /** + *

User-provided identifiers of the resource, such as key or externalId. Only present if the resource has such identifiers.

+ * + + * @return null|UserProvidedIdentifiers + */ + public function getResourceUserProvidedIdentifiers() + { + return $this->resourceUserProvidedIdentifiers instanceof UserProvidedIdentifiersBuilder ? $this->resourceUserProvidedIdentifiers->build() : $this->resourceUserProvidedIdentifiers; + } + + /** + *

Expiration date and time of the Recurring Order after the Set Expires At update action.

+ * + + * @return null|DateTimeImmutable + */ + public function getNewExpiresAt() + { + return $this->newExpiresAt; + } + + /** + *

Expiration date and time of the Recurring Order before the Set Expires At update action.

+ * + + * @return null|DateTimeImmutable + */ + public function getOldExpiresAt() + { + return $this->oldExpiresAt; + } + + /** + * @param ?string $id + * @return $this + */ + public function withId(?string $id) + { + $this->id = $id; + + return $this; + } + + /** + * @param ?int $version + * @return $this + */ + public function withVersion(?int $version) + { + $this->version = $version; + + return $this; + } + + /** + * @param ?DateTimeImmutable $createdAt + * @return $this + */ + public function withCreatedAt(?DateTimeImmutable $createdAt) + { + $this->createdAt = $createdAt; + + return $this; + } + + /** + * @param ?DateTimeImmutable $lastModifiedAt + * @return $this + */ + public function withLastModifiedAt(?DateTimeImmutable $lastModifiedAt) + { + $this->lastModifiedAt = $lastModifiedAt; + + return $this; + } + + /** + * @param ?LastModifiedBy $lastModifiedBy + * @return $this + */ + public function withLastModifiedBy(?LastModifiedBy $lastModifiedBy) + { + $this->lastModifiedBy = $lastModifiedBy; + + return $this; + } + + /** + * @param ?CreatedBy $createdBy + * @return $this + */ + public function withCreatedBy(?CreatedBy $createdBy) + { + $this->createdBy = $createdBy; + + return $this; + } + + /** + * @param ?int $sequenceNumber + * @return $this + */ + public function withSequenceNumber(?int $sequenceNumber) + { + $this->sequenceNumber = $sequenceNumber; + + return $this; + } + + /** + * @param ?Reference $resource + * @return $this + */ + public function withResource(?Reference $resource) + { + $this->resource = $resource; + + return $this; + } + + /** + * @param ?int $resourceVersion + * @return $this + */ + public function withResourceVersion(?int $resourceVersion) + { + $this->resourceVersion = $resourceVersion; + + return $this; + } + + /** + * @param ?UserProvidedIdentifiers $resourceUserProvidedIdentifiers + * @return $this + */ + public function withResourceUserProvidedIdentifiers(?UserProvidedIdentifiers $resourceUserProvidedIdentifiers) + { + $this->resourceUserProvidedIdentifiers = $resourceUserProvidedIdentifiers; + + return $this; + } + + /** + * @param ?DateTimeImmutable $newExpiresAt + * @return $this + */ + public function withNewExpiresAt(?DateTimeImmutable $newExpiresAt) + { + $this->newExpiresAt = $newExpiresAt; + + return $this; + } + + /** + * @param ?DateTimeImmutable $oldExpiresAt + * @return $this + */ + public function withOldExpiresAt(?DateTimeImmutable $oldExpiresAt) + { + $this->oldExpiresAt = $oldExpiresAt; + + return $this; + } + + /** + * @deprecated use withLastModifiedBy() instead + * @return $this + */ + public function withLastModifiedByBuilder(?LastModifiedByBuilder $lastModifiedBy) + { + $this->lastModifiedBy = $lastModifiedBy; + + return $this; + } + + /** + * @deprecated use withCreatedBy() instead + * @return $this + */ + public function withCreatedByBuilder(?CreatedByBuilder $createdBy) + { + $this->createdBy = $createdBy; + + return $this; + } + + /** + * @deprecated use withResource() instead + * @return $this + */ + public function withResourceBuilder(?ReferenceBuilder $resource) + { + $this->resource = $resource; + + return $this; + } + + /** + * @deprecated use withResourceUserProvidedIdentifiers() instead + * @return $this + */ + public function withResourceUserProvidedIdentifiersBuilder(?UserProvidedIdentifiersBuilder $resourceUserProvidedIdentifiers) + { + $this->resourceUserProvidedIdentifiers = $resourceUserProvidedIdentifiers; + + return $this; + } + + public function build(): RecurringOrderExpiresAtSetMessage + { + return new RecurringOrderExpiresAtSetMessageModel( + $this->id, + $this->version, + $this->createdAt, + $this->lastModifiedAt, + $this->lastModifiedBy instanceof LastModifiedByBuilder ? $this->lastModifiedBy->build() : $this->lastModifiedBy, + $this->createdBy instanceof CreatedByBuilder ? $this->createdBy->build() : $this->createdBy, + $this->sequenceNumber, + $this->resource instanceof ReferenceBuilder ? $this->resource->build() : $this->resource, + $this->resourceVersion, + $this->resourceUserProvidedIdentifiers instanceof UserProvidedIdentifiersBuilder ? $this->resourceUserProvidedIdentifiers->build() : $this->resourceUserProvidedIdentifiers, + $this->newExpiresAt, + $this->oldExpiresAt + ); + } + + public static function of(): RecurringOrderExpiresAtSetMessageBuilder + { + return new self(); + } +} diff --git a/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessageCollection.php b/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessageCollection.php new file mode 100644 index 00000000000..1249e9ebff4 --- /dev/null +++ b/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessageCollection.php @@ -0,0 +1,56 @@ + + * @method RecurringOrderExpiresAtSetMessage current() + * @method RecurringOrderExpiresAtSetMessage end() + * @method RecurringOrderExpiresAtSetMessage at($offset) + */ +class RecurringOrderExpiresAtSetMessageCollection extends MessageCollection +{ + /** + * @psalm-assert RecurringOrderExpiresAtSetMessage $value + * @psalm-param RecurringOrderExpiresAtSetMessage|stdClass $value + * @throws InvalidArgumentException + * + * @return RecurringOrderExpiresAtSetMessageCollection + */ + public function add($value) + { + if (!$value instanceof RecurringOrderExpiresAtSetMessage) { + throw new InvalidArgumentException(); + } + $this->store($value); + + return $this; + } + + /** + * @psalm-return callable(int):?RecurringOrderExpiresAtSetMessage + */ + protected function mapper() + { + return function (?int $index): ?RecurringOrderExpiresAtSetMessage { + $data = $this->get($index); + if ($data instanceof stdClass) { + /** @var RecurringOrderExpiresAtSetMessage $data */ + $data = RecurringOrderExpiresAtSetMessageModel::of($data); + $this->set($data, $index); + } + + return $data; + }; + } +} diff --git a/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessageModel.php b/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessageModel.php new file mode 100644 index 00000000000..404e19d8621 --- /dev/null +++ b/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessageModel.php @@ -0,0 +1,542 @@ +id = $id; + $this->version = $version; + $this->createdAt = $createdAt; + $this->lastModifiedAt = $lastModifiedAt; + $this->lastModifiedBy = $lastModifiedBy; + $this->createdBy = $createdBy; + $this->sequenceNumber = $sequenceNumber; + $this->resource = $resource; + $this->resourceVersion = $resourceVersion; + $this->resourceUserProvidedIdentifiers = $resourceUserProvidedIdentifiers; + $this->newExpiresAt = $newExpiresAt; + $this->oldExpiresAt = $oldExpiresAt; + $this->type = $type ?? self::DISCRIMINATOR_VALUE; + } + + /** + *

Unique identifier of the Message. Can be used to track which Messages have been processed.

+ * + * + * @return null|string + */ + public function getId() + { + if (is_null($this->id)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_ID); + if (is_null($data)) { + return null; + } + $this->id = (string) $data; + } + + return $this->id; + } + + /** + *

Version of a resource. In case of Messages, this is always 1.

+ * + * + * @return null|int + */ + public function getVersion() + { + if (is_null($this->version)) { + /** @psalm-var ?int $data */ + $data = $this->raw(self::FIELD_VERSION); + if (is_null($data)) { + return null; + } + $this->version = (int) $data; + } + + return $this->version; + } + + /** + *

Date and time (UTC) the Message was generated.

+ * + * + * @return null|DateTimeImmutable + */ + public function getCreatedAt() + { + if (is_null($this->createdAt)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_CREATED_AT); + if (is_null($data)) { + return null; + } + $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data); + if (false === $data) { + return null; + } + $this->createdAt = $data; + } + + return $this->createdAt; + } + + /** + *

Value of createdAt.

+ * + * + * @return null|DateTimeImmutable + */ + public function getLastModifiedAt() + { + if (is_null($this->lastModifiedAt)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_LAST_MODIFIED_AT); + if (is_null($data)) { + return null; + } + $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data); + if (false === $data) { + return null; + } + $this->lastModifiedAt = $data; + } + + return $this->lastModifiedAt; + } + + /** + *

IDs and references that last modified the Message.

+ * + * + * @return null|LastModifiedBy + */ + public function getLastModifiedBy() + { + if (is_null($this->lastModifiedBy)) { + /** @psalm-var stdClass|array|null $data */ + $data = $this->raw(self::FIELD_LAST_MODIFIED_BY); + if (is_null($data)) { + return null; + } + + $this->lastModifiedBy = LastModifiedByModel::of($data); + } + + return $this->lastModifiedBy; + } + + /** + *

IDs and references that created the Message.

+ * + * + * @return null|CreatedBy + */ + public function getCreatedBy() + { + if (is_null($this->createdBy)) { + /** @psalm-var stdClass|array|null $data */ + $data = $this->raw(self::FIELD_CREATED_BY); + if (is_null($data)) { + return null; + } + + $this->createdBy = CreatedByModel::of($data); + } + + return $this->createdBy; + } + + /** + *

Message number in relation to other Messages for a given resource. The sequenceNumber of the next Message for the resource is the successor of the sequenceNumber of the current Message. Meaning, the sequenceNumber of the next Message equals the sequenceNumber of the current Message + 1. + * sequenceNumber can be used to ensure that Messages are processed in the correct order for a particular resource.

+ * + * + * @return null|int + */ + public function getSequenceNumber() + { + if (is_null($this->sequenceNumber)) { + /** @psalm-var ?int $data */ + $data = $this->raw(self::FIELD_SEQUENCE_NUMBER); + if (is_null($data)) { + return null; + } + $this->sequenceNumber = (int) $data; + } + + return $this->sequenceNumber; + } + + /** + *

Reference to the resource on which the change or action was performed.

+ * + * + * @return null|Reference + */ + public function getResource() + { + if (is_null($this->resource)) { + /** @psalm-var stdClass|array|null $data */ + $data = $this->raw(self::FIELD_RESOURCE); + if (is_null($data)) { + return null; + } + $className = ReferenceModel::resolveDiscriminatorClass($data); + $this->resource = $className::of($data); + } + + return $this->resource; + } + + /** + *

Version of the resource on which the change or action was performed.

+ * + * + * @return null|int + */ + public function getResourceVersion() + { + if (is_null($this->resourceVersion)) { + /** @psalm-var ?int $data */ + $data = $this->raw(self::FIELD_RESOURCE_VERSION); + if (is_null($data)) { + return null; + } + $this->resourceVersion = (int) $data; + } + + return $this->resourceVersion; + } + + /** + *

Message Type of the Message.

+ * + * + * @return null|string + */ + public function getType() + { + if (is_null($this->type)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_TYPE); + if (is_null($data)) { + return null; + } + $this->type = (string) $data; + } + + return $this->type; + } + + /** + *

User-provided identifiers of the resource, such as key or externalId. Only present if the resource has such identifiers.

+ * + * + * @return null|UserProvidedIdentifiers + */ + public function getResourceUserProvidedIdentifiers() + { + if (is_null($this->resourceUserProvidedIdentifiers)) { + /** @psalm-var stdClass|array|null $data */ + $data = $this->raw(self::FIELD_RESOURCE_USER_PROVIDED_IDENTIFIERS); + if (is_null($data)) { + return null; + } + + $this->resourceUserProvidedIdentifiers = UserProvidedIdentifiersModel::of($data); + } + + return $this->resourceUserProvidedIdentifiers; + } + + /** + *

Expiration date and time of the Recurring Order after the Set Expires At update action.

+ * + * + * @return null|DateTimeImmutable + */ + public function getNewExpiresAt() + { + if (is_null($this->newExpiresAt)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_NEW_EXPIRES_AT); + if (is_null($data)) { + return null; + } + $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data); + if (false === $data) { + return null; + } + $this->newExpiresAt = $data; + } + + return $this->newExpiresAt; + } + + /** + *

Expiration date and time of the Recurring Order before the Set Expires At update action.

+ * + * + * @return null|DateTimeImmutable + */ + public function getOldExpiresAt() + { + if (is_null($this->oldExpiresAt)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_OLD_EXPIRES_AT); + if (is_null($data)) { + return null; + } + $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data); + if (false === $data) { + return null; + } + $this->oldExpiresAt = $data; + } + + return $this->oldExpiresAt; + } + + + /** + * @param ?string $id + */ + public function setId(?string $id): void + { + $this->id = $id; + } + + /** + * @param ?int $version + */ + public function setVersion(?int $version): void + { + $this->version = $version; + } + + /** + * @param ?DateTimeImmutable $createdAt + */ + public function setCreatedAt(?DateTimeImmutable $createdAt): void + { + $this->createdAt = $createdAt; + } + + /** + * @param ?DateTimeImmutable $lastModifiedAt + */ + public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void + { + $this->lastModifiedAt = $lastModifiedAt; + } + + /** + * @param ?LastModifiedBy $lastModifiedBy + */ + public function setLastModifiedBy(?LastModifiedBy $lastModifiedBy): void + { + $this->lastModifiedBy = $lastModifiedBy; + } + + /** + * @param ?CreatedBy $createdBy + */ + public function setCreatedBy(?CreatedBy $createdBy): void + { + $this->createdBy = $createdBy; + } + + /** + * @param ?int $sequenceNumber + */ + public function setSequenceNumber(?int $sequenceNumber): void + { + $this->sequenceNumber = $sequenceNumber; + } + + /** + * @param ?Reference $resource + */ + public function setResource(?Reference $resource): void + { + $this->resource = $resource; + } + + /** + * @param ?int $resourceVersion + */ + public function setResourceVersion(?int $resourceVersion): void + { + $this->resourceVersion = $resourceVersion; + } + + /** + * @param ?UserProvidedIdentifiers $resourceUserProvidedIdentifiers + */ + public function setResourceUserProvidedIdentifiers(?UserProvidedIdentifiers $resourceUserProvidedIdentifiers): void + { + $this->resourceUserProvidedIdentifiers = $resourceUserProvidedIdentifiers; + } + + /** + * @param ?DateTimeImmutable $newExpiresAt + */ + public function setNewExpiresAt(?DateTimeImmutable $newExpiresAt): void + { + $this->newExpiresAt = $newExpiresAt; + } + + /** + * @param ?DateTimeImmutable $oldExpiresAt + */ + public function setOldExpiresAt(?DateTimeImmutable $oldExpiresAt): void + { + $this->oldExpiresAt = $oldExpiresAt; + } + + + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + $data = $this->toArray(); + if (isset($data[Message::FIELD_CREATED_AT]) && $data[Message::FIELD_CREATED_AT] instanceof \DateTimeImmutable) { + $data[Message::FIELD_CREATED_AT] = $data[Message::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c'); + } + + if (isset($data[Message::FIELD_LAST_MODIFIED_AT]) && $data[Message::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) { + $data[Message::FIELD_LAST_MODIFIED_AT] = $data[Message::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c'); + } + + if (isset($data[RecurringOrderExpiresAtSetMessage::FIELD_NEW_EXPIRES_AT]) && $data[RecurringOrderExpiresAtSetMessage::FIELD_NEW_EXPIRES_AT] instanceof \DateTimeImmutable) { + $data[RecurringOrderExpiresAtSetMessage::FIELD_NEW_EXPIRES_AT] = $data[RecurringOrderExpiresAtSetMessage::FIELD_NEW_EXPIRES_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c'); + } + + if (isset($data[RecurringOrderExpiresAtSetMessage::FIELD_OLD_EXPIRES_AT]) && $data[RecurringOrderExpiresAtSetMessage::FIELD_OLD_EXPIRES_AT] instanceof \DateTimeImmutable) { + $data[RecurringOrderExpiresAtSetMessage::FIELD_OLD_EXPIRES_AT] = $data[RecurringOrderExpiresAtSetMessage::FIELD_OLD_EXPIRES_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c'); + } + return (object) $data; + } +} diff --git a/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessagePayload.php b/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessagePayload.php new file mode 100644 index 00000000000..3e522a3c131 --- /dev/null +++ b/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessagePayload.php @@ -0,0 +1,45 @@ +Expiration date and time of the Recurring Order after the Set Expires At update action.

+ * + + * @return null|DateTimeImmutable + */ + public function getNewExpiresAt(); + + /** + *

Expiration date and time of the Recurring Order before the Set Expires At update action.

+ * + + * @return null|DateTimeImmutable + */ + public function getOldExpiresAt(); + + /** + * @param ?DateTimeImmutable $newExpiresAt + */ + public function setNewExpiresAt(?DateTimeImmutable $newExpiresAt): void; + + /** + * @param ?DateTimeImmutable $oldExpiresAt + */ + public function setOldExpiresAt(?DateTimeImmutable $oldExpiresAt): void; +} diff --git a/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessagePayloadBuilder.php b/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessagePayloadBuilder.php new file mode 100644 index 00000000000..9b9cb9785a2 --- /dev/null +++ b/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessagePayloadBuilder.php @@ -0,0 +1,93 @@ + + */ +final class RecurringOrderExpiresAtSetMessagePayloadBuilder implements Builder +{ + /** + + * @var ?DateTimeImmutable + */ + private $newExpiresAt; + + /** + + * @var ?DateTimeImmutable + */ + private $oldExpiresAt; + + /** + *

Expiration date and time of the Recurring Order after the Set Expires At update action.

+ * + + * @return null|DateTimeImmutable + */ + public function getNewExpiresAt() + { + return $this->newExpiresAt; + } + + /** + *

Expiration date and time of the Recurring Order before the Set Expires At update action.

+ * + + * @return null|DateTimeImmutable + */ + public function getOldExpiresAt() + { + return $this->oldExpiresAt; + } + + /** + * @param ?DateTimeImmutable $newExpiresAt + * @return $this + */ + public function withNewExpiresAt(?DateTimeImmutable $newExpiresAt) + { + $this->newExpiresAt = $newExpiresAt; + + return $this; + } + + /** + * @param ?DateTimeImmutable $oldExpiresAt + * @return $this + */ + public function withOldExpiresAt(?DateTimeImmutable $oldExpiresAt) + { + $this->oldExpiresAt = $oldExpiresAt; + + return $this; + } + + + public function build(): RecurringOrderExpiresAtSetMessagePayload + { + return new RecurringOrderExpiresAtSetMessagePayloadModel( + $this->newExpiresAt, + $this->oldExpiresAt + ); + } + + public static function of(): RecurringOrderExpiresAtSetMessagePayloadBuilder + { + return new self(); + } +} diff --git a/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessagePayloadCollection.php b/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessagePayloadCollection.php new file mode 100644 index 00000000000..8bbd72dab35 --- /dev/null +++ b/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessagePayloadCollection.php @@ -0,0 +1,56 @@ + + * @method RecurringOrderExpiresAtSetMessagePayload current() + * @method RecurringOrderExpiresAtSetMessagePayload end() + * @method RecurringOrderExpiresAtSetMessagePayload at($offset) + */ +class RecurringOrderExpiresAtSetMessagePayloadCollection extends MessagePayloadCollection +{ + /** + * @psalm-assert RecurringOrderExpiresAtSetMessagePayload $value + * @psalm-param RecurringOrderExpiresAtSetMessagePayload|stdClass $value + * @throws InvalidArgumentException + * + * @return RecurringOrderExpiresAtSetMessagePayloadCollection + */ + public function add($value) + { + if (!$value instanceof RecurringOrderExpiresAtSetMessagePayload) { + throw new InvalidArgumentException(); + } + $this->store($value); + + return $this; + } + + /** + * @psalm-return callable(int):?RecurringOrderExpiresAtSetMessagePayload + */ + protected function mapper() + { + return function (?int $index): ?RecurringOrderExpiresAtSetMessagePayload { + $data = $this->get($index); + if ($data instanceof stdClass) { + /** @var RecurringOrderExpiresAtSetMessagePayload $data */ + $data = RecurringOrderExpiresAtSetMessagePayloadModel::of($data); + $this->set($data, $index); + } + + return $data; + }; + } +} diff --git a/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessagePayloadModel.php b/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessagePayloadModel.php new file mode 100644 index 00000000000..07e58f3ae0b --- /dev/null +++ b/lib/commercetools-api/src/Models/Message/RecurringOrderExpiresAtSetMessagePayloadModel.php @@ -0,0 +1,153 @@ +newExpiresAt = $newExpiresAt; + $this->oldExpiresAt = $oldExpiresAt; + $this->type = $type ?? self::DISCRIMINATOR_VALUE; + } + + /** + * + * @return null|string + */ + public function getType() + { + if (is_null($this->type)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_TYPE); + if (is_null($data)) { + return null; + } + $this->type = (string) $data; + } + + return $this->type; + } + + /** + *

Expiration date and time of the Recurring Order after the Set Expires At update action.

+ * + * + * @return null|DateTimeImmutable + */ + public function getNewExpiresAt() + { + if (is_null($this->newExpiresAt)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_NEW_EXPIRES_AT); + if (is_null($data)) { + return null; + } + $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data); + if (false === $data) { + return null; + } + $this->newExpiresAt = $data; + } + + return $this->newExpiresAt; + } + + /** + *

Expiration date and time of the Recurring Order before the Set Expires At update action.

+ * + * + * @return null|DateTimeImmutable + */ + public function getOldExpiresAt() + { + if (is_null($this->oldExpiresAt)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_OLD_EXPIRES_AT); + if (is_null($data)) { + return null; + } + $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data); + if (false === $data) { + return null; + } + $this->oldExpiresAt = $data; + } + + return $this->oldExpiresAt; + } + + + /** + * @param ?DateTimeImmutable $newExpiresAt + */ + public function setNewExpiresAt(?DateTimeImmutable $newExpiresAt): void + { + $this->newExpiresAt = $newExpiresAt; + } + + /** + * @param ?DateTimeImmutable $oldExpiresAt + */ + public function setOldExpiresAt(?DateTimeImmutable $oldExpiresAt): void + { + $this->oldExpiresAt = $oldExpiresAt; + } + + + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + $data = $this->toArray(); + if (isset($data[RecurringOrderExpiresAtSetMessagePayload::FIELD_NEW_EXPIRES_AT]) && $data[RecurringOrderExpiresAtSetMessagePayload::FIELD_NEW_EXPIRES_AT] instanceof \DateTimeImmutable) { + $data[RecurringOrderExpiresAtSetMessagePayload::FIELD_NEW_EXPIRES_AT] = $data[RecurringOrderExpiresAtSetMessagePayload::FIELD_NEW_EXPIRES_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c'); + } + + if (isset($data[RecurringOrderExpiresAtSetMessagePayload::FIELD_OLD_EXPIRES_AT]) && $data[RecurringOrderExpiresAtSetMessagePayload::FIELD_OLD_EXPIRES_AT] instanceof \DateTimeImmutable) { + $data[RecurringOrderExpiresAtSetMessagePayload::FIELD_OLD_EXPIRES_AT] = $data[RecurringOrderExpiresAtSetMessagePayload::FIELD_OLD_EXPIRES_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c'); + } + return (object) $data; + } +} diff --git a/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderDraft.php b/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderDraft.php index 3918a0d5242..7013e648332 100644 --- a/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderDraft.php +++ b/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderDraft.php @@ -21,6 +21,7 @@ interface RecurringOrderDraft extends JsonObject public const FIELD_CART = 'cart'; public const FIELD_CART_VERSION = 'cartVersion'; public const FIELD_STARTS_AT = 'startsAt'; + public const FIELD_EXPIRES_AT = 'expiresAt'; public const FIELD_STATE = 'state'; public const FIELD_CUSTOM = 'custom'; @@ -56,6 +57,14 @@ public function getCartVersion(); */ public function getStartsAt(); + /** + *

Date and time (UTC) when the RecurringOrder will expire.

+ * + + * @return null|DateTimeImmutable + */ + public function getExpiresAt(); + /** *

State for the RecurringOrder in a custom workflow.

* @@ -92,6 +101,11 @@ public function setCartVersion(?int $cartVersion): void; */ public function setStartsAt(?DateTimeImmutable $startsAt): void; + /** + * @param ?DateTimeImmutable $expiresAt + */ + public function setExpiresAt(?DateTimeImmutable $expiresAt): void; + /** * @param ?StateResourceIdentifier $state */ diff --git a/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderDraftBuilder.php b/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderDraftBuilder.php index 2fc1e4e4c80..be5772528f7 100644 --- a/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderDraftBuilder.php +++ b/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderDraftBuilder.php @@ -51,6 +51,12 @@ final class RecurringOrderDraftBuilder implements Builder */ private $startsAt; + /** + + * @var ?DateTimeImmutable + */ + private $expiresAt; + /** * @var null|StateResourceIdentifier|StateResourceIdentifierBuilder @@ -107,6 +113,17 @@ public function getStartsAt() return $this->startsAt; } + /** + *

Date and time (UTC) when the RecurringOrder will expire.

+ * + + * @return null|DateTimeImmutable + */ + public function getExpiresAt() + { + return $this->expiresAt; + } + /** *

State for the RecurringOrder in a custom workflow.

* @@ -173,6 +190,17 @@ public function withStartsAt(?DateTimeImmutable $startsAt) return $this; } + /** + * @param ?DateTimeImmutable $expiresAt + * @return $this + */ + public function withExpiresAt(?DateTimeImmutable $expiresAt) + { + $this->expiresAt = $expiresAt; + + return $this; + } + /** * @param ?StateResourceIdentifier $state * @return $this @@ -235,6 +263,7 @@ public function build(): RecurringOrderDraft $this->cart instanceof CartResourceIdentifierBuilder ? $this->cart->build() : $this->cart, $this->cartVersion, $this->startsAt, + $this->expiresAt, $this->state instanceof StateResourceIdentifierBuilder ? $this->state->build() : $this->state, $this->custom instanceof CustomFieldsDraftBuilder ? $this->custom->build() : $this->custom ); diff --git a/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderDraftModel.php b/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderDraftModel.php index 667f5fce76d..9d2548c5033 100644 --- a/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderDraftModel.php +++ b/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderDraftModel.php @@ -50,6 +50,12 @@ final class RecurringOrderDraftModel extends JsonObjectModel implements Recurrin */ protected $startsAt; + /** + * + * @var ?DateTimeImmutable + */ + protected $expiresAt; + /** * * @var ?StateResourceIdentifier @@ -71,6 +77,7 @@ public function __construct( ?CartResourceIdentifier $cart = null, ?int $cartVersion = null, ?DateTimeImmutable $startsAt = null, + ?DateTimeImmutable $expiresAt = null, ?StateResourceIdentifier $state = null, ?CustomFieldsDraft $custom = null ) { @@ -78,6 +85,7 @@ public function __construct( $this->cart = $cart; $this->cartVersion = $cartVersion; $this->startsAt = $startsAt; + $this->expiresAt = $expiresAt; $this->state = $state; $this->custom = $custom; } @@ -167,6 +175,30 @@ public function getStartsAt() return $this->startsAt; } + /** + *

Date and time (UTC) when the RecurringOrder will expire.

+ * + * + * @return null|DateTimeImmutable + */ + public function getExpiresAt() + { + if (is_null($this->expiresAt)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_EXPIRES_AT); + if (is_null($data)) { + return null; + } + $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data); + if (false === $data) { + return null; + } + $this->expiresAt = $data; + } + + return $this->expiresAt; + } + /** *

State for the RecurringOrder in a custom workflow.

* @@ -242,6 +274,14 @@ public function setStartsAt(?DateTimeImmutable $startsAt): void $this->startsAt = $startsAt; } + /** + * @param ?DateTimeImmutable $expiresAt + */ + public function setExpiresAt(?DateTimeImmutable $expiresAt): void + { + $this->expiresAt = $expiresAt; + } + /** * @param ?StateResourceIdentifier $state */ @@ -266,6 +306,10 @@ public function jsonSerialize() if (isset($data[RecurringOrderDraft::FIELD_STARTS_AT]) && $data[RecurringOrderDraft::FIELD_STARTS_AT] instanceof \DateTimeImmutable) { $data[RecurringOrderDraft::FIELD_STARTS_AT] = $data[RecurringOrderDraft::FIELD_STARTS_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c'); } + + if (isset($data[RecurringOrderDraft::FIELD_EXPIRES_AT]) && $data[RecurringOrderDraft::FIELD_EXPIRES_AT] instanceof \DateTimeImmutable) { + $data[RecurringOrderDraft::FIELD_EXPIRES_AT] = $data[RecurringOrderDraft::FIELD_EXPIRES_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c'); + } return (object) $data; } } diff --git a/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetExpiresAtAction.php b/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetExpiresAtAction.php new file mode 100644 index 00000000000..32a36eea09f --- /dev/null +++ b/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetExpiresAtAction.php @@ -0,0 +1,32 @@ +Date and time (UTC) the Recurring Order should expire. If empty, any existing value will be removed.

+ *

If the date or time is extended or removed when the RecurringOrderState is Expired, the state will be updated to Active.

+ * + + * @return null|DateTimeImmutable + */ + public function getExpiresAt(); + + /** + * @param ?DateTimeImmutable $expiresAt + */ + public function setExpiresAt(?DateTimeImmutable $expiresAt): void; +} diff --git a/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetExpiresAtActionBuilder.php b/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetExpiresAtActionBuilder.php new file mode 100644 index 00000000000..2a728cfb96e --- /dev/null +++ b/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetExpiresAtActionBuilder.php @@ -0,0 +1,65 @@ + + */ +final class RecurringOrderSetExpiresAtActionBuilder implements Builder +{ + /** + + * @var ?DateTimeImmutable + */ + private $expiresAt; + + /** + *

Date and time (UTC) the Recurring Order should expire. If empty, any existing value will be removed.

+ *

If the date or time is extended or removed when the RecurringOrderState is Expired, the state will be updated to Active.

+ * + + * @return null|DateTimeImmutable + */ + public function getExpiresAt() + { + return $this->expiresAt; + } + + /** + * @param ?DateTimeImmutable $expiresAt + * @return $this + */ + public function withExpiresAt(?DateTimeImmutable $expiresAt) + { + $this->expiresAt = $expiresAt; + + return $this; + } + + + public function build(): RecurringOrderSetExpiresAtAction + { + return new RecurringOrderSetExpiresAtActionModel( + $this->expiresAt + ); + } + + public static function of(): RecurringOrderSetExpiresAtActionBuilder + { + return new self(); + } +} diff --git a/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetExpiresAtActionCollection.php b/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetExpiresAtActionCollection.php new file mode 100644 index 00000000000..122440e31b4 --- /dev/null +++ b/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetExpiresAtActionCollection.php @@ -0,0 +1,56 @@ + + * @method RecurringOrderSetExpiresAtAction current() + * @method RecurringOrderSetExpiresAtAction end() + * @method RecurringOrderSetExpiresAtAction at($offset) + */ +class RecurringOrderSetExpiresAtActionCollection extends RecurringOrderUpdateActionCollection +{ + /** + * @psalm-assert RecurringOrderSetExpiresAtAction $value + * @psalm-param RecurringOrderSetExpiresAtAction|stdClass $value + * @throws InvalidArgumentException + * + * @return RecurringOrderSetExpiresAtActionCollection + */ + public function add($value) + { + if (!$value instanceof RecurringOrderSetExpiresAtAction) { + throw new InvalidArgumentException(); + } + $this->store($value); + + return $this; + } + + /** + * @psalm-return callable(int):?RecurringOrderSetExpiresAtAction + */ + protected function mapper() + { + return function (?int $index): ?RecurringOrderSetExpiresAtAction { + $data = $this->get($index); + if ($data instanceof stdClass) { + /** @var RecurringOrderSetExpiresAtAction $data */ + $data = RecurringOrderSetExpiresAtActionModel::of($data); + $this->set($data, $index); + } + + return $data; + }; + } +} diff --git a/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetExpiresAtActionModel.php b/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetExpiresAtActionModel.php new file mode 100644 index 00000000000..ba5919a4a7c --- /dev/null +++ b/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetExpiresAtActionModel.php @@ -0,0 +1,110 @@ +expiresAt = $expiresAt; + $this->action = $action ?? self::DISCRIMINATOR_VALUE; + } + + /** + * + * @return null|string + */ + public function getAction() + { + if (is_null($this->action)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_ACTION); + if (is_null($data)) { + return null; + } + $this->action = (string) $data; + } + + return $this->action; + } + + /** + *

Date and time (UTC) the Recurring Order should expire. If empty, any existing value will be removed.

+ *

If the date or time is extended or removed when the RecurringOrderState is Expired, the state will be updated to Active.

+ * + * + * @return null|DateTimeImmutable + */ + public function getExpiresAt() + { + if (is_null($this->expiresAt)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_EXPIRES_AT); + if (is_null($data)) { + return null; + } + $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data); + if (false === $data) { + return null; + } + $this->expiresAt = $data; + } + + return $this->expiresAt; + } + + + /** + * @param ?DateTimeImmutable $expiresAt + */ + public function setExpiresAt(?DateTimeImmutable $expiresAt): void + { + $this->expiresAt = $expiresAt; + } + + + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + $data = $this->toArray(); + if (isset($data[RecurringOrderSetExpiresAtAction::FIELD_EXPIRES_AT]) && $data[RecurringOrderSetExpiresAtAction::FIELD_EXPIRES_AT] instanceof \DateTimeImmutable) { + $data[RecurringOrderSetExpiresAtAction::FIELD_EXPIRES_AT] = $data[RecurringOrderSetExpiresAtAction::FIELD_EXPIRES_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c'); + } + return (object) $data; + } +} diff --git a/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetOrderSkipConfigurationAction.php b/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetOrderSkipConfigurationAction.php index fb276ab581f..5e720579ac2 100644 --- a/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetOrderSkipConfigurationAction.php +++ b/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetOrderSkipConfigurationAction.php @@ -26,7 +26,7 @@ interface RecurringOrderSetOrderSkipConfigurationAction extends RecurringOrderUp public function getSkipConfiguration(); /** - *

Date and time (UTC) the Recurring Order will resume and start to generate new orders.

+ *

Date and time (UTC) the Recurring Order will expire and stop generating new orders.

* * @return null|DateTimeImmutable diff --git a/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetOrderSkipConfigurationActionBuilder.php b/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetOrderSkipConfigurationActionBuilder.php index e711b0aa44a..0314389d3ab 100644 --- a/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetOrderSkipConfigurationActionBuilder.php +++ b/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetOrderSkipConfigurationActionBuilder.php @@ -45,7 +45,7 @@ public function getSkipConfiguration() } /** - *

Date and time (UTC) the Recurring Order will resume and start to generate new orders.

+ *

Date and time (UTC) the Recurring Order will expire and stop generating new orders.

* * @return null|DateTimeImmutable diff --git a/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetOrderSkipConfigurationActionModel.php b/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetOrderSkipConfigurationActionModel.php index 0d386111724..4e937074727 100644 --- a/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetOrderSkipConfigurationActionModel.php +++ b/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderSetOrderSkipConfigurationActionModel.php @@ -93,7 +93,7 @@ public function getSkipConfiguration() } /** - *

Date and time (UTC) the Recurring Order will resume and start to generate new orders.

+ *

Date and time (UTC) the Recurring Order will expire and stop generating new orders.

* * * @return null|DateTimeImmutable diff --git a/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderUpdateActionModel.php b/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderUpdateActionModel.php index 7837dcfb268..74b45498ef0 100644 --- a/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderUpdateActionModel.php +++ b/lib/commercetools-api/src/Models/RecurringOrder/RecurringOrderUpdateActionModel.php @@ -33,6 +33,7 @@ final class RecurringOrderUpdateActionModel extends JsonObjectModel implements R private static $discriminatorClasses = [ 'setCustomField' => RecurringOrderSetCustomFieldActionModel::class, 'setCustomType' => RecurringOrderSetCustomTypeActionModel::class, + 'setExpiresAt' => RecurringOrderSetExpiresAtActionModel::class, 'setKey' => RecurringOrderSetKeyActionModel::class, 'setOrderSkipConfiguration' => RecurringOrderSetOrderSkipConfigurationActionModel::class, 'setRecurringOrderState' => RecurringOrderSetStateActionModel::class, diff --git a/references.txt b/references.txt index e8b30a6e0a2..48f8663bcb0 100644 --- a/references.txt +++ b/references.txt @@ -478,3 +478,4 @@ a80637ece283fffff6a7d554d5645743a15f8c5d 09f7ffec9d7cad1549201cafbf8da0170de93a9a 379c828b5abfaddb82b32374ff94f92260fb4daf 2259b69b970dc8d2e038f59fa7bcdd55fd859da2 +ae6bd28bc66a9ad876c323a54026e34e4f26c475