diff --git a/.changeset/forty-ties-think.md b/.changeset/forty-ties-think.md new file mode 100644 index 000000000..6f552c988 --- /dev/null +++ b/.changeset/forty-ties-think.md @@ -0,0 +1,5 @@ +--- +"@rebilly/client-php": patch +--- + +Make Plan.id readOnly Rebilly/api-definitions#1651 diff --git a/.changeset/great-waves-cheer.md b/.changeset/great-waves-cheer.md new file mode 100644 index 000000000..c9b364032 --- /dev/null +++ b/.changeset/great-waves-cheer.md @@ -0,0 +1,5 @@ +--- +"@rebilly/client-php": patch +--- + +Make cashier request fields nullable Rebilly/api-definitions#1654 diff --git a/.changeset/hungry-goats-matter.md b/.changeset/hungry-goats-matter.md new file mode 100644 index 000000000..4c591f6db --- /dev/null +++ b/.changeset/hungry-goats-matter.md @@ -0,0 +1,5 @@ +--- +"@rebilly/client-php": patch +--- + +Add default values for cashier request Rebilly/api-definitions#1656 diff --git a/src/Api/CashierRequestsApi.php b/src/Api/CashierRequestsApi.php index c69fc48c2..dc51125cc 100644 --- a/src/Api/CashierRequestsApi.php +++ b/src/Api/CashierRequestsApi.php @@ -18,6 +18,7 @@ use GuzzleHttp\Utils; use Rebilly\Sdk\Collection; use Rebilly\Sdk\Model\CashierRequest; +use Rebilly\Sdk\Model\PostCashierRequest; use Rebilly\Sdk\Paginator; class CashierRequestsApi @@ -30,11 +31,11 @@ public function __construct(protected ?ClientInterface $client) * @return CashierRequest */ public function create( - CashierRequest $cashierRequest, + PostCashierRequest $postCashierRequest, ): CashierRequest { $uri = '/cashier-requests'; - $request = new Request('POST', $uri, body: Utils::jsonEncode($cashierRequest)); + $request = new Request('POST', $uri, body: Utils::jsonEncode($postCashierRequest)); $response = $this->client->send($request); $data = Utils::jsonDecode((string) $response->getBody(), true); diff --git a/src/Model/CashierRequest.php b/src/Model/CashierRequest.php index 542c8303a..4f6584bed 100644 --- a/src/Model/CashierRequest.php +++ b/src/Model/CashierRequest.php @@ -40,9 +40,6 @@ public function __construct(array $data = []) if (array_key_exists('customerId', $data)) { $this->setCustomerId($data['customerId']); } - if (array_key_exists('strategyId', $data)) { - $this->setStrategyId($data['strategyId']); - } if (array_key_exists('transactionId', $data)) { $this->setTransactionId($data['transactionId']); } @@ -64,9 +61,6 @@ public function __construct(array $data = []) if (array_key_exists('expirationTime', $data)) { $this->setExpirationTime($data['expirationTime']); } - if (array_key_exists('customPropertySetId', $data)) { - $this->setCustomPropertySetId($data['customPropertySetId']); - } if (array_key_exists('propertiesSchema', $data)) { $this->setPropertiesSchema($data['propertiesSchema']); } @@ -121,18 +115,6 @@ public function setCustomerId(string $customerId): static return $this; } - public function getStrategyId(): ?string - { - return $this->fields['strategyId'] ?? null; - } - - public function setStrategyId(null|string $strategyId): static - { - $this->fields['strategyId'] = $strategyId; - - return $this; - } - public function getTransactionId(): ?string { return $this->fields['transactionId'] ?? null; @@ -222,18 +204,6 @@ public function setExpirationTime(null|DateTimeImmutable|string $expirationTime) return $this; } - public function getCustomPropertySetId(): ?string - { - return $this->fields['customPropertySetId'] ?? null; - } - - public function setCustomPropertySetId(null|string $customPropertySetId): static - { - $this->fields['customPropertySetId'] = $customPropertySetId; - - return $this; - } - public function getPropertiesSchema(): ?object { return $this->fields['propertiesSchema'] ?? null; @@ -293,9 +263,6 @@ public function jsonSerialize(): array if (array_key_exists('customerId', $this->fields)) { $data['customerId'] = $this->fields['customerId']; } - if (array_key_exists('strategyId', $this->fields)) { - $data['strategyId'] = $this->fields['strategyId']; - } if (array_key_exists('transactionId', $this->fields)) { $data['transactionId'] = $this->fields['transactionId']; } @@ -317,9 +284,6 @@ public function jsonSerialize(): array if (array_key_exists('expirationTime', $this->fields)) { $data['expirationTime'] = $this->fields['expirationTime']?->format(DateTimeInterface::RFC3339); } - if (array_key_exists('customPropertySetId', $this->fields)) { - $data['customPropertySetId'] = $this->fields['customPropertySetId']; - } if (array_key_exists('propertiesSchema', $this->fields)) { $data['propertiesSchema'] = $this->fields['propertiesSchema']; } diff --git a/src/Model/FlexiblePlan.php b/src/Model/FlexiblePlan.php index adc03be7c..1ac5826a1 100644 --- a/src/Model/FlexiblePlan.php +++ b/src/Model/FlexiblePlan.php @@ -287,14 +287,14 @@ public function setLinks(null|array $links): static return $this; } - public function getRecurringInterval(): ?SubscriptionOrderPlanRecurringInterval + public function getRecurringInterval(): SubscriptionOrderPlanRecurringInterval { - return $this->fields['recurringInterval'] ?? null; + return $this->fields['recurringInterval']; } - public function setRecurringInterval(null|SubscriptionOrderPlanRecurringInterval|array $recurringInterval): static + public function setRecurringInterval(SubscriptionOrderPlanRecurringInterval|array $recurringInterval): static { - if ($recurringInterval !== null && !($recurringInterval instanceof SubscriptionOrderPlanRecurringInterval)) { + if (!($recurringInterval instanceof SubscriptionOrderPlanRecurringInterval)) { $recurringInterval = SubscriptionOrderPlanRecurringInterval::from($recurringInterval); } @@ -303,15 +303,15 @@ public function setRecurringInterval(null|SubscriptionOrderPlanRecurringInterval return $this; } - public function getTrial(): ?PlanTrial + public function getTrial(): TrialOnlyPlanTrial { - return $this->fields['trial'] ?? null; + return $this->fields['trial']; } - public function setTrial(null|PlanTrial|array $trial): static + public function setTrial(TrialOnlyPlanTrial|array $trial): static { - if ($trial !== null && !($trial instanceof PlanTrial)) { - $trial = PlanTrial::from($trial); + if (!($trial instanceof TrialOnlyPlanTrial)) { + $trial = TrialOnlyPlanTrial::from($trial); } $this->fields['trial'] = $trial; diff --git a/src/Model/OrderItemPlan.php b/src/Model/OrderItemPlan.php index 37938474d..4f0ad065c 100644 --- a/src/Model/OrderItemPlan.php +++ b/src/Model/OrderItemPlan.php @@ -287,14 +287,14 @@ public function setLinks(null|array $links): static return $this; } - public function getRecurringInterval(): ?SubscriptionOrderPlanRecurringInterval + public function getRecurringInterval(): SubscriptionOrderPlanRecurringInterval { - return $this->fields['recurringInterval'] ?? null; + return $this->fields['recurringInterval']; } - public function setRecurringInterval(null|SubscriptionOrderPlanRecurringInterval|array $recurringInterval): static + public function setRecurringInterval(SubscriptionOrderPlanRecurringInterval|array $recurringInterval): static { - if ($recurringInterval !== null && !($recurringInterval instanceof SubscriptionOrderPlanRecurringInterval)) { + if (!($recurringInterval instanceof SubscriptionOrderPlanRecurringInterval)) { $recurringInterval = SubscriptionOrderPlanRecurringInterval::from($recurringInterval); } @@ -303,15 +303,15 @@ public function setRecurringInterval(null|SubscriptionOrderPlanRecurringInterval return $this; } - public function getTrial(): ?PlanTrial + public function getTrial(): TrialOnlyPlanTrial { - return $this->fields['trial'] ?? null; + return $this->fields['trial']; } - public function setTrial(null|PlanTrial|array $trial): static + public function setTrial(TrialOnlyPlanTrial|array $trial): static { - if ($trial !== null && !($trial instanceof PlanTrial)) { - $trial = PlanTrial::from($trial); + if (!($trial instanceof TrialOnlyPlanTrial)) { + $trial = TrialOnlyPlanTrial::from($trial); } $this->fields['trial'] = $trial; diff --git a/src/Model/Plan.php b/src/Model/Plan.php index 0af62ad42..f99b6c690 100644 --- a/src/Model/Plan.php +++ b/src/Model/Plan.php @@ -98,13 +98,6 @@ public function getId(): ?string return $this->fields['id'] ?? null; } - public function setId(null|string $id): static - { - $this->fields['id'] = $id; - - return $this; - } - public function getName(): string { return $this->fields['name']; @@ -287,14 +280,14 @@ public function setLinks(null|array $links): static return $this; } - public function getRecurringInterval(): ?SubscriptionOrderPlanRecurringInterval + public function getRecurringInterval(): SubscriptionOrderPlanRecurringInterval { - return $this->fields['recurringInterval'] ?? null; + return $this->fields['recurringInterval']; } - public function setRecurringInterval(null|SubscriptionOrderPlanRecurringInterval|array $recurringInterval): static + public function setRecurringInterval(SubscriptionOrderPlanRecurringInterval|array $recurringInterval): static { - if ($recurringInterval !== null && !($recurringInterval instanceof SubscriptionOrderPlanRecurringInterval)) { + if (!($recurringInterval instanceof SubscriptionOrderPlanRecurringInterval)) { $recurringInterval = SubscriptionOrderPlanRecurringInterval::from($recurringInterval); } @@ -303,15 +296,15 @@ public function setRecurringInterval(null|SubscriptionOrderPlanRecurringInterval return $this; } - public function getTrial(): ?PlanTrial + public function getTrial(): TrialOnlyPlanTrial { - return $this->fields['trial'] ?? null; + return $this->fields['trial']; } - public function setTrial(null|PlanTrial|array $trial): static + public function setTrial(TrialOnlyPlanTrial|array $trial): static { - if ($trial !== null && !($trial instanceof PlanTrial)) { - $trial = PlanTrial::from($trial); + if (!($trial instanceof TrialOnlyPlanTrial)) { + $trial = TrialOnlyPlanTrial::from($trial); } $this->fields['trial'] = $trial; @@ -421,6 +414,13 @@ public function jsonSerialize(): array return $data; } + private function setId(null|string $id): static + { + $this->fields['id'] = $id; + + return $this; + } + private function setCurrencySign(null|string $currencySign): static { $this->fields['currencySign'] = $currencySign; diff --git a/src/Model/PostCashierRequest.php b/src/Model/PostCashierRequest.php new file mode 100644 index 000000000..d1aabbce7 --- /dev/null +++ b/src/Model/PostCashierRequest.php @@ -0,0 +1,220 @@ +setWebsiteId($data['websiteId']); + } + if (array_key_exists('customerId', $data)) { + $this->setCustomerId($data['customerId']); + } + if (array_key_exists('strategyId', $data)) { + $this->setStrategyId($data['strategyId']); + } + if (array_key_exists('currency', $data)) { + $this->setCurrency($data['currency']); + } + if (array_key_exists('amounts', $data)) { + $this->setAmounts($data['amounts']); + } + if (array_key_exists('customAmount', $data)) { + $this->setCustomAmount($data['customAmount']); + } + if (array_key_exists('redirectUrl', $data)) { + $this->setRedirectUrl($data['redirectUrl']); + } + if (array_key_exists('expirationTime', $data)) { + $this->setExpirationTime($data['expirationTime']); + } + if (array_key_exists('customPropertySetId', $data)) { + $this->setCustomPropertySetId($data['customPropertySetId']); + } + } + + public static function from(array $data = []): self + { + return new self($data); + } + + public function getWebsiteId(): string + { + return $this->fields['websiteId']; + } + + public function setWebsiteId(string $websiteId): static + { + $this->fields['websiteId'] = $websiteId; + + return $this; + } + + public function getCustomerId(): string + { + return $this->fields['customerId']; + } + + public function setCustomerId(string $customerId): static + { + $this->fields['customerId'] = $customerId; + + return $this; + } + + public function getStrategyId(): ?string + { + return $this->fields['strategyId'] ?? null; + } + + public function setStrategyId(null|string $strategyId): static + { + $this->fields['strategyId'] = $strategyId; + + return $this; + } + + public function getCurrency(): string + { + return $this->fields['currency']; + } + + public function setCurrency(string $currency): static + { + $this->fields['currency'] = $currency; + + return $this; + } + + /** + * @return null|float[] + */ + public function getAmounts(): ?array + { + return $this->fields['amounts'] ?? null; + } + + /** + * @param null|float[] $amounts + */ + public function setAmounts(null|array $amounts): static + { + $amounts = $amounts !== null ? array_map( + fn ($value) => $value, + $amounts, + ) : null; + + $this->fields['amounts'] = $amounts; + + return $this; + } + + public function getCustomAmount(): ?CashierRequestCustomAmount + { + return $this->fields['customAmount'] ?? null; + } + + public function setCustomAmount(null|CashierRequestCustomAmount|array $customAmount): static + { + if ($customAmount !== null && !($customAmount instanceof CashierRequestCustomAmount)) { + $customAmount = CashierRequestCustomAmount::from($customAmount); + } + + $this->fields['customAmount'] = $customAmount; + + return $this; + } + + public function getRedirectUrl(): ?string + { + return $this->fields['redirectUrl'] ?? null; + } + + public function setRedirectUrl(null|string $redirectUrl): static + { + $this->fields['redirectUrl'] = $redirectUrl; + + return $this; + } + + public function getExpirationTime(): ?DateTimeImmutable + { + return $this->fields['expirationTime'] ?? null; + } + + public function setExpirationTime(null|DateTimeImmutable|string $expirationTime): static + { + if ($expirationTime !== null && !($expirationTime instanceof DateTimeImmutable)) { + $expirationTime = new DateTimeImmutable($expirationTime); + } + + $this->fields['expirationTime'] = $expirationTime; + + return $this; + } + + public function getCustomPropertySetId(): ?string + { + return $this->fields['customPropertySetId'] ?? null; + } + + public function setCustomPropertySetId(null|string $customPropertySetId): static + { + $this->fields['customPropertySetId'] = $customPropertySetId; + + return $this; + } + + public function jsonSerialize(): array + { + $data = []; + if (array_key_exists('websiteId', $this->fields)) { + $data['websiteId'] = $this->fields['websiteId']; + } + if (array_key_exists('customerId', $this->fields)) { + $data['customerId'] = $this->fields['customerId']; + } + if (array_key_exists('strategyId', $this->fields)) { + $data['strategyId'] = $this->fields['strategyId']; + } + if (array_key_exists('currency', $this->fields)) { + $data['currency'] = $this->fields['currency']; + } + if (array_key_exists('amounts', $this->fields)) { + $data['amounts'] = $this->fields['amounts']; + } + if (array_key_exists('customAmount', $this->fields)) { + $data['customAmount'] = $this->fields['customAmount']?->jsonSerialize(); + } + if (array_key_exists('redirectUrl', $this->fields)) { + $data['redirectUrl'] = $this->fields['redirectUrl']; + } + if (array_key_exists('expirationTime', $this->fields)) { + $data['expirationTime'] = $this->fields['expirationTime']?->format(DateTimeInterface::RFC3339); + } + if (array_key_exists('customPropertySetId', $this->fields)) { + $data['customPropertySetId'] = $this->fields['customPropertySetId']; + } + + return $data; + } +} diff --git a/src/Model/PlanTrial.php b/src/Model/TrialOnlyPlanTrial.php similarity index 97% rename from src/Model/PlanTrial.php rename to src/Model/TrialOnlyPlanTrial.php index 32b40b298..c2afbe7ba 100644 --- a/src/Model/PlanTrial.php +++ b/src/Model/TrialOnlyPlanTrial.php @@ -15,7 +15,7 @@ use JsonSerializable; -class PlanTrial implements JsonSerializable +class TrialOnlyPlanTrial implements JsonSerializable { private array $fields = [];