* @link https://www.oxidmodule.com */ declare(strict_types=1); namespace D3\KlicktippPhpClient\Entities; use D3\KlicktippPhpClient\Exceptions\CommunicationException; use D3\KlicktippPhpClient\Exceptions\MissingEndpointException; use D3\KlicktippPhpClient\Resources\SubscriptionProcess; class Subscription extends Entity { use EndpointTrait; private ?SubscriptionProcess $endpoint; public function __construct(array $elements = [], ?SubscriptionProcess $endpoint = null) { $this->endpoint = $endpoint; parent::__construct($elements); } public function getListId(): ?string { return $this->getStringOrNullValue($this->get(SubscriptionProcess::LISTID)); } public function getName(): ?string { return $this->getStringOrNullValue($this->get(SubscriptionProcess::NAME)); } public function setName(string $name): void { $this->set(SubscriptionProcess::NAME, $name); } public function getPendingUrl(): ?string { return $this->getStringOrNullValue($this->get(SubscriptionProcess::PENDINGURL)); } public function getThankyouUrl(): ?string { return $this->getStringOrNullValue($this->get(SubscriptionProcess::THANKYOUURL)); } public function useSingleOptin(): ?bool { return $this->getBooleanOrNullValue($this->get(SubscriptionProcess::USE_SINGLE_OPTIN)); } public function useDoubleOptin(): ?bool { return is_null($soi = $this->useSingleOptin()) ? null : !$soi; } public function resendConfirmationEmail(): ?bool { return $this->getBooleanOrNullValue($this->get(SubscriptionProcess::RESEND_CONFIRMATION_EMAIL)); } public function useChangeEmail(): ?bool { return $this->getBooleanOrNullValue($this->get(SubscriptionProcess::USE_CHANGE_EMAIL)); } /** * @return null|bool * @throws CommunicationException * @throws MissingEndpointException */ public function persist(): ?bool { return !is_null($this->getListId()) ? $this->getEndpoint()->update( $this->getListId(), $this->getName() ?? '' ) : null; } }