|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Srmklive\Chargify\Traits\ChargifyAPI; |
|
4
|
|
|
|
|
5
|
|
|
trait Customers |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* Create customer. |
|
9
|
|
|
* |
|
10
|
|
|
* @param array $data |
|
11
|
|
|
* |
|
12
|
|
|
* @return array |
|
13
|
|
|
*/ |
|
14
|
|
|
public function customer_create(array $data): array |
|
15
|
|
|
{ |
|
16
|
|
|
$this->apiEndPoint = '/customers.json'; |
|
17
|
|
|
|
|
18
|
|
|
$this->verb = 'post'; |
|
19
|
|
|
|
|
20
|
|
|
$this->options['json'] = [ |
|
|
|
|
|
|
21
|
|
|
'customer' => $data, |
|
22
|
|
|
]; |
|
23
|
|
|
|
|
24
|
|
|
return $this->doChargifyRequest(); |
|
|
|
|
|
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Get customer details. |
|
29
|
|
|
* |
|
30
|
|
|
* @param int $customer_id |
|
31
|
|
|
* |
|
32
|
|
|
* @return array |
|
33
|
|
|
*/ |
|
34
|
|
|
public function customer_details(int $customer_id): array |
|
35
|
|
|
{ |
|
36
|
|
|
$this->apiEndPoint = "/customers/{$customer_id}.json"; |
|
37
|
|
|
|
|
38
|
|
|
$this->verb = 'get'; |
|
39
|
|
|
|
|
40
|
|
|
return $this->doChargifyRequest(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Get list of customers. |
|
45
|
|
|
* |
|
46
|
|
|
* @param string $direction |
|
47
|
|
|
* @param int $page |
|
48
|
|
|
* @param string $date_field |
|
49
|
|
|
* @param string $start_date |
|
50
|
|
|
* @param string $end_date |
|
51
|
|
|
* |
|
52
|
|
|
* @return array |
|
53
|
|
|
*/ |
|
54
|
|
|
public function customer_list(string $direction = 'desc', int $page = 50, string $date_field = 'created_at', string $start_date = '', string $end_date = ''): array |
|
55
|
|
|
{ |
|
56
|
|
|
$start_date_param = !empty($start_date) ? "&start_date={$start_date}" : ''; |
|
57
|
|
|
$end_date_param = !empty($end_date) ? "&end_date={$end_date}" : ''; |
|
58
|
|
|
|
|
59
|
|
|
$this->apiEndPoint = "/customers.json?direction={$direction}&page={$page}&date_field={$date_field}{$start_date_param}{$end_date_param}"; |
|
60
|
|
|
|
|
61
|
|
|
$this->verb = 'get'; |
|
62
|
|
|
|
|
63
|
|
|
return $this->doChargifyRequest(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Get list of customers through lookup reference field. |
|
68
|
|
|
* |
|
69
|
|
|
* @param string $reference |
|
70
|
|
|
* |
|
71
|
|
|
* @return array |
|
72
|
|
|
*/ |
|
73
|
|
|
public function customer_lookup(string $reference): array |
|
74
|
|
|
{ |
|
75
|
|
|
$this->apiEndPoint = "/customers/lookup.json?reference={$reference}"; |
|
76
|
|
|
|
|
77
|
|
|
$this->verb = 'get'; |
|
78
|
|
|
|
|
79
|
|
|
return $this->doChargifyRequest(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Get list of customer subscriptions. |
|
84
|
|
|
* |
|
85
|
|
|
* @param int $customer_id |
|
86
|
|
|
* |
|
87
|
|
|
* @return array |
|
88
|
|
|
*/ |
|
89
|
|
|
public function customer_subscriptions(int $customer_id): array |
|
90
|
|
|
{ |
|
91
|
|
|
$this->apiEndPoint = "/customers/{$customer_id}/subscriptions.json"; |
|
92
|
|
|
|
|
93
|
|
|
$this->verb = 'get'; |
|
94
|
|
|
|
|
95
|
|
|
return $this->doChargifyRequest(); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Search customers by parameter such as email, chargify id & organization. |
|
100
|
|
|
* |
|
101
|
|
|
* @param string $q |
|
102
|
|
|
* |
|
103
|
|
|
* @return array |
|
104
|
|
|
*/ |
|
105
|
|
|
public function customer_search(string $q): array |
|
106
|
|
|
{ |
|
107
|
|
|
$this->apiEndPoint = "/customers.json?q={$q}"; |
|
108
|
|
|
|
|
109
|
|
|
$this->verb = 'get'; |
|
110
|
|
|
|
|
111
|
|
|
return $this->doChargifyRequest(); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Get customer details. |
|
116
|
|
|
* |
|
117
|
|
|
* @param int $customer_id |
|
118
|
|
|
* @param array $data |
|
119
|
|
|
* |
|
120
|
|
|
* @return array |
|
121
|
|
|
*/ |
|
122
|
|
|
public function customer_update(int $customer_id, array $data): array |
|
123
|
|
|
{ |
|
124
|
|
|
$this->apiEndPoint = "/customers/{$customer_id}.json"; |
|
125
|
|
|
|
|
126
|
|
|
$this->verb = 'put'; |
|
127
|
|
|
|
|
128
|
|
|
$this->options['json'] = [ |
|
|
|
|
|
|
129
|
|
|
'customer' => $data, |
|
130
|
|
|
]; |
|
131
|
|
|
|
|
132
|
|
|
return $this->doChargifyRequest(); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Delete a customer. |
|
137
|
|
|
* |
|
138
|
|
|
* @param int $customer_id |
|
139
|
|
|
* |
|
140
|
|
|
* @return string |
|
141
|
|
|
*/ |
|
142
|
|
|
public function customer_delete(int $customer_id): string |
|
143
|
|
|
{ |
|
144
|
|
|
$this->apiEndPoint = "/customers/{$customer_id}.json"; |
|
145
|
|
|
|
|
146
|
|
|
$this->verb = 'delete'; |
|
147
|
|
|
|
|
148
|
|
|
return $this->doChargifyRequest(false); |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|