|
1
|
|
|
<?php |
|
2
|
|
|
// phpcs:disable Generic.Files.LineLength |
|
3
|
|
|
namespace Commercetools\Core\Builder\Request; |
|
4
|
|
|
|
|
5
|
|
|
use Commercetools\Core\Request\Customers\CustomerByEmailTokenGetRequest; |
|
6
|
|
|
use Commercetools\Core\Request\Customers\CustomerByIdGetRequest; |
|
7
|
|
|
use Commercetools\Core\Request\Customers\CustomerByKeyGetRequest; |
|
8
|
|
|
use Commercetools\Core\Request\Customers\CustomerByTokenGetRequest; |
|
9
|
|
|
use Commercetools\Core\Request\Customers\CustomerCreateRequest; |
|
10
|
|
|
use Commercetools\Core\Model\Customer\CustomerDraft; |
|
11
|
|
|
use Commercetools\Core\Request\Customers\CustomerDeleteByKeyRequest; |
|
12
|
|
|
use Commercetools\Core\Model\Customer\Customer; |
|
13
|
|
|
use Commercetools\Core\Request\Customers\CustomerDeleteRequest; |
|
14
|
|
|
use Commercetools\Core\Request\Customers\CustomerEmailConfirmRequest; |
|
15
|
|
|
use Commercetools\Core\Request\Customers\CustomerEmailTokenRequest; |
|
16
|
|
|
use Commercetools\Core\Request\Customers\CustomerLoginRequest; |
|
17
|
|
|
use Commercetools\Core\Request\Customers\CustomerPasswordChangeRequest; |
|
18
|
|
|
use Commercetools\Core\Request\Customers\CustomerPasswordResetRequest; |
|
19
|
|
|
use Commercetools\Core\Request\Customers\CustomerPasswordTokenRequest; |
|
20
|
|
|
use Commercetools\Core\Request\Customers\CustomerQueryRequest; |
|
21
|
|
|
use Commercetools\Core\Request\Customers\CustomerUpdateByKeyRequest; |
|
22
|
|
|
use Commercetools\Core\Request\Customers\CustomerUpdateRequest; |
|
23
|
|
|
|
|
24
|
|
|
class CustomerRequestBuilder |
|
25
|
|
|
{ |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#get-customer-by-email-token |
|
29
|
|
|
* @param string $token |
|
30
|
|
|
* @return CustomerByEmailTokenGetRequest |
|
31
|
|
|
*/ |
|
32
|
2 |
|
public function getByEmailToken($token) |
|
33
|
|
|
{ |
|
34
|
2 |
|
$request = CustomerByEmailTokenGetRequest::ofToken($token); |
|
35
|
2 |
|
return $request; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#get-customer-by-id |
|
40
|
|
|
* @param string $id |
|
41
|
|
|
* @return CustomerByIdGetRequest |
|
42
|
|
|
*/ |
|
43
|
3 |
|
public function getById($id) |
|
44
|
|
|
{ |
|
45
|
3 |
|
$request = CustomerByIdGetRequest::ofId($id); |
|
46
|
3 |
|
return $request; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#get-customer-by-key |
|
51
|
|
|
* @param string $key |
|
52
|
|
|
* @return CustomerByKeyGetRequest |
|
53
|
|
|
*/ |
|
54
|
3 |
|
public function getByKey($key) |
|
55
|
|
|
{ |
|
56
|
3 |
|
$request = CustomerByKeyGetRequest::ofKey($key); |
|
57
|
3 |
|
return $request; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#get-customer-by-password-token |
|
62
|
|
|
* @param string $tokenValue |
|
63
|
|
|
* @return CustomerByTokenGetRequest |
|
64
|
|
|
*/ |
|
65
|
3 |
|
public function getByPasswordToken($tokenValue) |
|
66
|
|
|
{ |
|
67
|
3 |
|
$request = CustomerByTokenGetRequest::ofToken($tokenValue); |
|
68
|
3 |
|
return $request; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#create-customer-sign-up |
|
73
|
|
|
* @param CustomerDraft $customer |
|
74
|
|
|
* @return CustomerCreateRequest |
|
75
|
|
|
*/ |
|
76
|
1 |
|
public function create(CustomerDraft $customer) |
|
77
|
|
|
{ |
|
78
|
1 |
|
$request = CustomerCreateRequest::ofDraft($customer); |
|
79
|
1 |
|
return $request; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#delete-customer-by-key |
|
84
|
|
|
* @param Customer $customer |
|
85
|
|
|
* @return CustomerDeleteByKeyRequest |
|
86
|
|
|
*/ |
|
87
|
1 |
|
public function deleteByKey(Customer $customer) |
|
88
|
|
|
{ |
|
89
|
1 |
|
$request = CustomerDeleteByKeyRequest::ofKeyAndVersion($customer->getKey(), $customer->getVersion()); |
|
90
|
1 |
|
return $request; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#delete-customer |
|
95
|
|
|
* @param Customer $customer |
|
96
|
|
|
* @return CustomerDeleteRequest |
|
97
|
|
|
*/ |
|
98
|
1 |
|
public function delete(Customer $customer) |
|
99
|
|
|
{ |
|
100
|
1 |
|
$request = CustomerDeleteRequest::ofIdAndVersion($customer->getId(), $customer->getVersion()); |
|
101
|
1 |
|
return $request; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#verify-customers-email |
|
106
|
|
|
* @param string $tokenValue |
|
107
|
|
|
* @return CustomerEmailConfirmRequest |
|
108
|
|
|
*/ |
|
109
|
2 |
|
public function confirmEmail($tokenValue) |
|
110
|
|
|
{ |
|
111
|
2 |
|
$request = CustomerEmailConfirmRequest::ofToken($tokenValue); |
|
112
|
2 |
|
return $request; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#create-a-token-for-verifying-the-customers-email |
|
117
|
|
|
* @param Customer $customer |
|
118
|
|
|
* @param int $ttlMinutes |
|
119
|
|
|
* @return CustomerEmailTokenRequest |
|
120
|
|
|
*/ |
|
121
|
2 |
|
public function createEmailVerificationToken(Customer $customer, $ttlMinutes) |
|
122
|
|
|
{ |
|
123
|
2 |
|
$request = CustomerEmailTokenRequest::ofIdVersionAndTtl($customer->getId(), $customer->getVersion(), $ttlMinutes); |
|
124
|
2 |
|
return $request; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#authenticate-customer-sign-in |
|
129
|
|
|
* @param string $email |
|
130
|
|
|
* @param string $password |
|
131
|
|
|
* @param bool $updateProductData |
|
132
|
|
|
* @param string $anonymousCartId |
|
133
|
|
|
* @return CustomerLoginRequest |
|
134
|
|
|
*/ |
|
135
|
7 |
|
public function login($email, $password, $updateProductData = false, $anonymousCartId = null) |
|
136
|
|
|
{ |
|
137
|
7 |
|
$request = CustomerLoginRequest::ofEmailPasswordAndUpdateProductData( |
|
138
|
7 |
|
$email, |
|
139
|
7 |
|
$password, |
|
140
|
7 |
|
$updateProductData, |
|
141
|
7 |
|
$anonymousCartId |
|
142
|
|
|
); |
|
143
|
7 |
|
return $request; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#change-customers-password |
|
148
|
|
|
* @param Customer $customer |
|
149
|
|
|
* @param string $currentPassword |
|
150
|
|
|
* @param string $newPassword |
|
151
|
|
|
* @return CustomerPasswordChangeRequest |
|
152
|
|
|
*/ |
|
153
|
2 |
|
public function changePassword(Customer $customer, $currentPassword, $newPassword) |
|
154
|
|
|
{ |
|
155
|
2 |
|
$request = CustomerPasswordChangeRequest::ofIdVersionAndPasswords( |
|
156
|
2 |
|
$customer->getId(), |
|
157
|
2 |
|
$customer->getVersion(), |
|
158
|
2 |
|
$currentPassword, |
|
159
|
2 |
|
$newPassword |
|
160
|
|
|
); |
|
161
|
2 |
|
return $request; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#customers-password-reset |
|
166
|
|
|
* @param string $tokenValue |
|
167
|
|
|
* @param string $newPassword |
|
168
|
|
|
* @return CustomerPasswordResetRequest |
|
169
|
|
|
*/ |
|
170
|
3 |
|
public function resetPassword($tokenValue, $newPassword) |
|
171
|
|
|
{ |
|
172
|
3 |
|
$request = CustomerPasswordResetRequest::ofTokenAndPassword($tokenValue, $newPassword); |
|
173
|
3 |
|
return $request; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#create-a-token-for-resetting-the-customers-password |
|
178
|
|
|
* @param string $email |
|
179
|
|
|
* @return CustomerPasswordTokenRequest |
|
180
|
|
|
*/ |
|
181
|
4 |
|
public function createResetPasswordToken($email) |
|
182
|
|
|
{ |
|
183
|
4 |
|
$request = CustomerPasswordTokenRequest::ofEmail($email); |
|
184
|
4 |
|
return $request; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#get-customer-by-id |
|
189
|
|
|
* |
|
190
|
|
|
* @return CustomerQueryRequest |
|
191
|
|
|
*/ |
|
192
|
3 |
|
public function query() |
|
193
|
|
|
{ |
|
194
|
3 |
|
$request = CustomerQueryRequest::of(); |
|
195
|
3 |
|
return $request; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#update-customer-by-key |
|
200
|
|
|
* @param Customer $customer |
|
201
|
|
|
* @return CustomerUpdateByKeyRequest |
|
202
|
|
|
*/ |
|
203
|
2 |
|
public function updateByKey(Customer $customer) |
|
204
|
|
|
{ |
|
205
|
2 |
|
$request = CustomerUpdateByKeyRequest::ofKeyAndVersion($customer->getKey(), $customer->getVersion()); |
|
206
|
2 |
|
return $request; |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* @link https://docs.commercetools.com/http-api-projects-customers.html#update-customer |
|
211
|
|
|
* @param Customer $customer |
|
212
|
|
|
* @return CustomerUpdateRequest |
|
213
|
|
|
*/ |
|
214
|
39 |
|
public function update(Customer $customer) |
|
215
|
|
|
{ |
|
216
|
39 |
|
$request = CustomerUpdateRequest::ofIdAndVersion($customer->getId(), $customer->getVersion()); |
|
217
|
39 |
|
return $request; |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* @return CustomerRequestBuilder |
|
222
|
|
|
*/ |
|
223
|
|
|
public function of() |
|
224
|
|
|
{ |
|
225
|
|
|
return new self(); |
|
226
|
|
|
} |
|
227
|
|
|
} |
|
228
|
|
|
|