-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubscription.php
More file actions
105 lines (87 loc) · 2.84 KB
/
Subscription.php
File metadata and controls
105 lines (87 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
* 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
*/
declare(strict_types=1);
namespace D3\KlicktippPhpClient\Entities;
use Assert\Assert;
use D3\KlicktippPhpClient\Exceptions\CommunicationException;
use D3\KlicktippPhpClient\Exceptions\MissingEndpointException;
use D3\KlicktippPhpClient\Resources\SubscriptionProcess;
class Subscription extends Entity
{
private ?SubscriptionProcess $endpoint;
public function __construct(array $elements = [], ?SubscriptionProcess $endpoint = null)
{
$this->endpoint = $endpoint;
parent::__construct($elements);
}
private function getEndpoint(): SubscriptionProcess
{
Assert::lazy()
->setExceptionClass(MissingEndpointException::class)
->that($this->endpoint)
->isInstanceOf(SubscriptionProcess::class)
->verifyNow();
return $this->endpoint;
}
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;
}
}