-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubscriptionProcess.php
More file actions
142 lines (128 loc) · 3.82 KB
/
Copy pathSubscriptionProcess.php
File metadata and controls
142 lines (128 loc) · 3.82 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?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\Resources;
use D3\KlicktippPhpClient\Entities\Subscription as SubscriptionEntity;
use D3\KlicktippPhpClient\Entities\SubscriptionList;
use D3\KlicktippPhpClient\Exceptions\CommunicationException;
use D3\KlicktippPhpClient\Exceptions\ResponseContentException;
use GuzzleHttp\RequestOptions;
class SubscriptionProcess extends Model
{
public const LISTID = 'listid';
public const NAME = 'name';
public const PENDINGURL = 'pendingurl';
public const THANKYOUURL = 'thankyouurl';
public const USE_SINGLE_OPTIN = 'usesingleoptin';
public const RESEND_CONFIRMATION_EMAIL = 'resendconfirmationemail';
public const USE_CHANGE_EMAIL = 'usechangeemail';
public const PARAM_EMAIL = 'email';
/**
* @throws CommunicationException
* @throws ResponseContentException
*/
public function index(): SubscriptionList
{
$data = $this->connection->requestAndParse(
'GET',
'list.json'
);
return new SubscriptionList($data);
}
/**
* @throws CommunicationException
* @throws ResponseContentException
*/
public function get(string $listId): array
{
return $this->connection->requestAndParse(
'GET',
'list/'.urlencode(trim($listId)).'.json'
);
}
/**
* @throws CommunicationException
*/
public function getEntity(string $listId): SubscriptionEntity
{
return new SubscriptionEntity($this->get($listId), $this);
}
/**
* @throws CommunicationException
* @throws ResponseContentException
*/
public function create(?string $name): SubscriptionEntity
{
$data = $this->connection->requestAndParse(
'POST',
'list.json',
[
RequestOptions::FORM_PARAMS => array_filter([
self::NAME => trim($name ?? ''),
]),
]
);
return new SubscriptionEntity($data);
}
/**
* @throws CommunicationException
* @throws ResponseContentException
*/
public function update(string $listId, ?string $name): bool
{
return (bool) current(
$this->connection->requestAndParse(
'PUT',
'list/'.urlencode(trim($listId)).'.json',
[
RequestOptions::FORM_PARAMS => array_filter([
self::NAME => trim($name ?? ''),
]),
]
)
);
}
/**
* @throws CommunicationException
* @throws ResponseContentException
*/
public function redirect(string $listId, string $email): string
{
return current(
$this->connection->requestAndParse(
'POST',
'list/redirect.json',
[
RequestOptions::FORM_PARAMS => [
self::LISTID => trim($listId),
self::PARAM_EMAIL => trim($email),
],
]
)
);
}
/**
* @throws CommunicationException
* @throws ResponseContentException
*/
public function delete(string $listId): bool
{
return (bool) current(
$this->connection->requestAndParse(
'DELETE',
'list/'.urlencode(trim($listId)).'.json'
)
);
}
}