1
|
|
|
<?php |
2
|
|
|
namespace Loevgaard\Dandomain\Api\Endpoint; |
3
|
|
|
|
4
|
|
|
use Assert\Assert; |
5
|
|
|
|
6
|
|
|
class Customer extends Endpoint |
7
|
|
|
{ |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @see https://shoppartner.dandomain.dk/dokumentation/api-documentation/customer/#GetCustomer_GET |
11
|
|
|
* |
12
|
|
|
* @param int $customerId |
13
|
|
|
* @return array |
14
|
|
|
*/ |
15
|
3 |
|
public function getCustomer(int $customerId) : array |
16
|
|
|
{ |
17
|
3 |
|
Assert::that($customerId)->greaterThan(0, 'The $customerId has to be positive'); |
18
|
|
|
|
19
|
2 |
|
return (array)$this->master->doRequest( |
20
|
2 |
|
'GET', |
21
|
2 |
|
sprintf('/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}/%d', $customerId) |
22
|
|
|
); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @see https://shoppartner.dandomain.dk/dokumentation/api-documentation/customer/#GetCustomerByEmail_GET |
27
|
|
|
* |
28
|
|
|
* @param string $email |
29
|
|
|
* @return array |
30
|
|
|
*/ |
31
|
|
|
public function getCustomerByEmail(string $email) : array |
32
|
|
|
{ |
33
|
|
|
Assert::that($email)->email(); |
34
|
|
|
|
35
|
|
|
return (array)$this->master->doRequest( |
36
|
|
|
'GET', |
37
|
|
|
sprintf('/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}/GetCustomerByEmail?email=%s', rawurlencode($email)) |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @see https://shoppartner.dandomain.dk/dokumentation/api-documentation/customer/#General_Online_Reference |
43
|
|
|
* |
44
|
|
|
* @param \DateTimeInterface $date |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
|
|
public function getCustomersCreatedSince(\DateTimeInterface $date) : array |
48
|
|
|
{ |
49
|
|
|
return (array)$this->master->doRequest( |
50
|
|
|
'GET', |
51
|
|
|
sprintf('/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}/CreatedSince?date=%s', $date->format('Y-m-d\TH:i:s')) |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @see https://shoppartner.dandomain.dk/dokumentation/api-documentation/customer/#CreateCustomer_POST |
57
|
|
|
* |
58
|
|
|
* @param array|\stdClass $customer |
59
|
|
|
* @return array |
60
|
|
|
*/ |
61
|
|
|
public function createCustomer($customer) : array |
62
|
|
|
{ |
63
|
|
|
return (array)$this->master->doRequest('POST', '/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}', $customer); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @see https://shoppartner.dandomain.dk/dokumentation/api-documentation/customer/#UpdateCustomer_PUT |
68
|
|
|
* |
69
|
|
|
* @param int $customerId |
70
|
|
|
* @param array|\stdClass $customer |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
|
|
public function updateCustomer(int $customerId, $customer) : array |
74
|
|
|
{ |
75
|
|
|
Assert::that($customerId)->greaterThan(0, 'The $customerId has to be positive'); |
76
|
|
|
|
77
|
|
|
return (array)$this->master->doRequest( |
78
|
|
|
'PUT', |
79
|
|
|
sprintf('/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}/%d', $customerId), |
80
|
|
|
$customer |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @see https://shoppartner.dandomain.dk/dokumentation/api-documentation/customer/#DeleteCustomer_DELETE |
86
|
|
|
* |
87
|
|
|
* @param int $customerId |
88
|
|
|
* @return boolean |
89
|
|
|
*/ |
90
|
|
|
public function deleteCustomer(int $customerId) : bool |
91
|
|
|
{ |
92
|
|
|
Assert::that($customerId)->greaterThan(0, 'The $customerId has to be positive'); |
93
|
|
|
|
94
|
|
|
return (bool)$this->master->doRequest( |
95
|
|
|
'DELETE', |
96
|
|
|
sprintf( |
97
|
|
|
'/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}/%d', |
98
|
|
|
$customerId |
99
|
|
|
) |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @see https://shoppartner.dandomain.dk/dokumentation/api-documentation/customer/#GetCustomerGroups_GET |
105
|
|
|
* |
106
|
|
|
* @return array |
107
|
|
|
*/ |
108
|
|
|
public function getCustomerGroups() : array |
109
|
|
|
{ |
110
|
|
|
return (array)$this->master->doRequest( |
111
|
|
|
'GET', |
112
|
|
|
'/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}/CustomerGroup' |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @see https://shoppartner.dandomain.dk/dokumentation/api-documentation/customer/#UpdateCustomerDiscountPOST |
118
|
|
|
* |
119
|
|
|
* @param int $customerId |
120
|
|
|
* @param array|\stdClass $customerDiscount |
121
|
|
|
* @return array |
122
|
|
|
*/ |
123
|
|
|
public function updateCustomerDiscount(int $customerId, $customerDiscount) : array |
124
|
|
|
{ |
125
|
|
|
Assert::that($customerId)->greaterThan(0, 'The $customerId has to be positive'); |
126
|
|
|
|
127
|
|
|
return (array)$this->master->doRequest( |
128
|
|
|
'POST', |
129
|
|
|
sprintf('/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}/UpdateCustomerDiscount/%d', $customerId), |
130
|
|
|
$customerDiscount |
131
|
|
|
); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @see https://shoppartner.dandomain.dk/dokumentation/api-documentation/customer/#GetCustomerDiscountGET |
136
|
|
|
* |
137
|
|
|
* @param int $customerId |
138
|
|
|
* @return array |
139
|
|
|
*/ |
140
|
|
|
public function getCustomerDiscount(int $customerId) : array |
141
|
|
|
{ |
142
|
|
|
Assert::that($customerId)->greaterThan(0, 'The $customerId has to be positive'); |
143
|
|
|
|
144
|
|
|
return (array)$this->master->doRequest( |
145
|
|
|
'GET', |
146
|
|
|
sprintf( |
147
|
|
|
'/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}/GetCustomerDiscount/%d', |
148
|
|
|
$customerId |
149
|
|
|
) |
150
|
|
|
); |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|