8
0
klicktipp-php-client/src/Entities/Subscription.php

96 Zeilen
2.5 KiB
PHP

2024-12-22 13:52:28 +01:00
<?php
2024-12-29 00:47:30 +01:00
/**
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
2025-01-05 15:20:56 +01:00
declare(strict_types=1);
2024-12-22 13:52:28 +01:00
namespace D3\KlicktippPhpClient\Entities;
2025-01-08 15:29:20 +01:00
use D3\KlicktippPhpClient\Exceptions\CommunicationException;
2025-01-17 11:14:11 +01:00
use D3\KlicktippPhpClient\Exceptions\MissingEndpointException;
2025-01-03 09:33:08 +01:00
use D3\KlicktippPhpClient\Resources\SubscriptionProcess;
2024-12-22 13:52:28 +01:00
class Subscription extends Entity
2024-12-22 13:52:28 +01:00
{
2025-01-17 11:14:11 +01:00
use EndpointTrait;
private ?SubscriptionProcess $endpoint;
public function __construct(array $elements = [], ?SubscriptionProcess $endpoint = null)
{
$this->endpoint = $endpoint;
parent::__construct($elements);
}
public function getListId(): ?string
2024-12-22 13:52:28 +01:00
{
return $this->getStringOrNullValue($this->get(SubscriptionProcess::LISTID));
2024-12-22 23:38:41 +01:00
}
public function getName(): ?string
2024-12-22 23:38:41 +01:00
{
return $this->getStringOrNullValue($this->get(SubscriptionProcess::NAME));
2024-12-22 23:38:41 +01:00
}
public function setName(string $name): void
{
$this->set(SubscriptionProcess::NAME, $name);
}
public function getPendingUrl(): ?string
2024-12-22 23:38:41 +01:00
{
return $this->getStringOrNullValue($this->get(SubscriptionProcess::PENDINGURL));
2024-12-22 23:38:41 +01:00
}
public function getThankyouUrl(): ?string
2024-12-22 23:38:41 +01:00
{
return $this->getStringOrNullValue($this->get(SubscriptionProcess::THANKYOUURL));
2024-12-22 23:38:41 +01:00
}
public function useSingleOptin(): ?bool
2024-12-22 23:38:41 +01:00
{
return $this->getBooleanOrNullValue($this->get(SubscriptionProcess::USE_SINGLE_OPTIN));
2024-12-22 23:38:41 +01:00
}
public function useDoubleOptin(): ?bool
2024-12-22 23:38:41 +01:00
{
return is_null($soi = $this->useSingleOptin()) ? null : !$soi;
2024-12-22 23:38:41 +01:00
}
public function resendConfirmationEmail(): ?bool
2024-12-22 23:38:41 +01:00
{
return $this->getBooleanOrNullValue($this->get(SubscriptionProcess::RESEND_CONFIRMATION_EMAIL));
2024-12-22 23:38:41 +01:00
}
public function useChangeEmail(): ?bool
2024-12-22 23:38:41 +01:00
{
return $this->getBooleanOrNullValue($this->get(SubscriptionProcess::USE_CHANGE_EMAIL));
2024-12-22 13:52:28 +01:00
}
/**
* @return null|bool
2025-01-08 15:29:20 +01:00
* @throws CommunicationException
2025-01-17 11:14:11 +01:00
* @throws MissingEndpointException
*/
public function persist(): ?bool
{
2025-01-16 14:17:55 +01:00
return !is_null($this->getListId()) ?
2025-01-17 11:14:11 +01:00
$this->getEndpoint()->update(
2025-01-16 14:17:55 +01:00
$this->getListId(),
$this->getName() ?? ''
) :
null;
}
2024-12-29 00:47:30 +01:00
}