Customer.php
13.2 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
<?php
namespace Braintree;
/**
* Braintree Customer module
* Creates and manages Customers
*
* <b>== More information ==</b>
*
* For more detailed information on Customers, see {@link https://developers.braintreepayments.com/reference/response/customer/php https://developers.braintreepayments.com/reference/response/customer/php}
*
* @package Braintree
* @category Resources
*
* @property-read \Braintree\Address[] $addresses
* @property-read \Braintree\AndroidPayCard[] $androidPayCards
* @property-read \Braintree\AmexExpressCheckoutCard[] $amexExpressCheckoutCards
* @property-read \Braintree\ApplePayCard[] $applePayCards
* @property-read \Braintree\CoinbaseAccount[] $coinbaseAccounts
* @property-read string $company
* @property-read \DateTime $createdAt
* @property-read \Braintree\CreditCard[] $creditCards
* @property-read array $customFields custom fields passed with the request
* @property-read string $email
* @property-read string $fax
* @property-read string $firstName
* @property-read string $id
* @property-read string $lastName
* @property-read \Braintree\MasterpassCard[] $masterpassCards
* @property-read \Braintree\PaymentMethod[] $paymentMethods
* @property-read \Braintree\PayPalAccount[] $paypalAccounts
* @property-read string $phone
* @property-read \Braintree\SamsungPayCard[] $samsungPayCards
* @property-read \DateTime $updatedAt
* @property-read \Braintree\UsBankAccount[] $usBankAccounts
* @property-read \Braintree\VenmoAccount[] $venmoAccounts
* @property-read \Braintree\VisaCheckoutCard[] $visaCheckoutCards
* @property-read string $website
*/
class Customer extends Base
{
/**
*
* @return Customer[]
*/
public static function all()
{
return Configuration::gateway()->customer()->all();
}
/**
*
* @param string $query
* @param int[] $ids
* @return Customer|Customer[]
*/
public static function fetch($query, $ids)
{
return Configuration::gateway()->customer()->fetch($query, $ids);
}
/**
*
* @param array $attribs
* @return Result\Successful|Result\Error
*/
public static function create($attribs = [])
{
return Configuration::gateway()->customer()->create($attribs);
}
/**
*
* @param array $attribs
* @return Customer
*/
public static function createNoValidate($attribs = [])
{
return Configuration::gateway()->customer()->createNoValidate($attribs);
}
/**
* @deprecated since version 2.3.0
* @param string $queryString
* @return Result\Successful
*/
public static function createFromTransparentRedirect($queryString)
{
return Configuration::gateway()->customer()->createFromTransparentRedirect($queryString);
}
/**
* @deprecated since version 2.3.0
* @return string
*/
public static function createCustomerUrl()
{
return Configuration::gateway()->customer()->createCustomerUrl();
}
/**
*
* @throws Exception\NotFound
* @param string $id customer id
* @return Customer
*/
public static function find($id, $associationFilterId = null)
{
return Configuration::gateway()->customer()->find($id, $associationFilterId);
}
/**
*
* @param int $customerId
* @param array $transactionAttribs
* @return Result\Successful|Result\Error
*/
public static function credit($customerId, $transactionAttribs)
{
return Configuration::gateway()->customer()->credit($customerId, $transactionAttribs);
}
/**
*
* @throws Exception\ValidationError
* @param type $customerId
* @param type $transactionAttribs
* @return Transaction
*/
public static function creditNoValidate($customerId, $transactionAttribs)
{
return Configuration::gateway()->customer()->creditNoValidate($customerId, $transactionAttribs);
}
/**
*
* @throws Exception on invalid id or non-200 http response code
* @param int $customerId
* @return Result\Successful
*/
public static function delete($customerId)
{
return Configuration::gateway()->customer()->delete($customerId);
}
/**
*
* @param int $customerId
* @param array $transactionAttribs
* @return Transaction
*/
public static function sale($customerId, $transactionAttribs)
{
return Configuration::gateway()->customer()->sale($customerId, $transactionAttribs);
}
/**
*
* @param int $customerId
* @param array $transactionAttribs
* @return Transaction
*/
public static function saleNoValidate($customerId, $transactionAttribs)
{
return Configuration::gateway()->customer()->saleNoValidate($customerId, $transactionAttribs);
}
/**
*
* @throws InvalidArgumentException
* @param string $query
* @return ResourceCollection
*/
public static function search($query)
{
return Configuration::gateway()->customer()->search($query);
}
/**
*
* @throws Exception\Unexpected
* @param int $customerId
* @param array $attributes
* @return Result\Successful|Result\Error
*/
public static function update($customerId, $attributes)
{
return Configuration::gateway()->customer()->update($customerId, $attributes);
}
/**
*
* @throws Exception\Unexpected
* @param int $customerId
* @param array $attributes
* @return CustomerGateway
*/
public static function updateNoValidate($customerId, $attributes)
{
return Configuration::gateway()->customer()->updateNoValidate($customerId, $attributes);
}
/**
*
* @deprecated since version 2.3.0
* @return string
*/
public static function updateCustomerUrl()
{
return Configuration::gateway()->customer()->updateCustomerUrl();
}
/**
*
* @deprecated since version 2.3.0
* @param string $queryString
* @return Result\Successful|Result\Error
*/
public static function updateFromTransparentRedirect($queryString)
{
return Configuration::gateway()->customer()->updateFromTransparentRedirect($queryString);
}
/* instance methods */
/**
* sets instance properties from an array of values
*
* @ignore
* @access protected
* @param array $customerAttribs array of customer data
*/
protected function _initialize($customerAttribs)
{
$this->_attributes = $customerAttribs;
$addressArray = [];
if (isset($customerAttribs['addresses'])) {
foreach ($customerAttribs['addresses'] AS $address) {
$addressArray[] = Address::factory($address);
}
}
$this->_set('addresses', $addressArray);
$creditCardArray = [];
if (isset($customerAttribs['creditCards'])) {
foreach ($customerAttribs['creditCards'] AS $creditCard) {
$creditCardArray[] = CreditCard::factory($creditCard);
}
}
$this->_set('creditCards', $creditCardArray);
$coinbaseAccountArray = [];
if (isset($customerAttribs['coinbaseAccounts'])) {
foreach ($customerAttribs['coinbaseAccounts'] AS $coinbaseAccount) {
$coinbaseAccountArray[] = CoinbaseAccount::factory($coinbaseAccount);
}
}
$this->_set('coinbaseAccounts', $coinbaseAccountArray);
$paypalAccountArray = [];
if (isset($customerAttribs['paypalAccounts'])) {
foreach ($customerAttribs['paypalAccounts'] AS $paypalAccount) {
$paypalAccountArray[] = PayPalAccount::factory($paypalAccount);
}
}
$this->_set('paypalAccounts', $paypalAccountArray);
$applePayCardArray = [];
if (isset($customerAttribs['applePayCards'])) {
foreach ($customerAttribs['applePayCards'] AS $applePayCard) {
$applePayCardArray[] = ApplePayCard::factory($applePayCard);
}
}
$this->_set('applePayCards', $applePayCardArray);
$androidPayCardArray = [];
if (isset($customerAttribs['androidPayCards'])) {
foreach ($customerAttribs['androidPayCards'] AS $androidPayCard) {
$androidPayCardArray[] = AndroidPayCard::factory($androidPayCard);
}
}
$this->_set('androidPayCards', $androidPayCardArray);
$amexExpressCheckoutCardArray = [];
if (isset($customerAttribs['amexExpressCheckoutCards'])) {
foreach ($customerAttribs['amexExpressCheckoutCards'] AS $amexExpressCheckoutCard) {
$amexExpressCheckoutCardArray[] = AmexExpressCheckoutCard::factory($amexExpressCheckoutCard);
}
}
$this->_set('amexExpressCheckoutCards', $amexExpressCheckoutCardArray);
$venmoAccountArray = array();
if (isset($customerAttribs['venmoAccounts'])) {
foreach ($customerAttribs['venmoAccounts'] AS $venmoAccount) {
$venmoAccountArray[] = VenmoAccount::factory($venmoAccount);
}
}
$this->_set('venmoAccounts', $venmoAccountArray);
$visaCheckoutCardArray = [];
if (isset($customerAttribs['visaCheckoutCards'])) {
foreach ($customerAttribs['visaCheckoutCards'] AS $visaCheckoutCard) {
$visaCheckoutCardArray[] = VisaCheckoutCard::factory($visaCheckoutCard);
}
}
$this->_set('visaCheckoutCards', $visaCheckoutCardArray);
$masterpassCardArray = [];
if (isset($customerAttribs['masterpassCards'])) {
foreach ($customerAttribs['masterpassCards'] AS $masterpassCard) {
$masterpassCardArray[] = MasterpassCard::factory($masterpassCard);
}
}
$this->_set('masterpassCards', $masterpassCardArray);
$samsungPayCardArray = [];
if (isset($customerAttribs['samsungPayCards'])) {
foreach ($customerAttribs['samsungPayCards'] AS $samsungPayCard) {
$samsungPayCardArray[] = SamsungPayCard::factory($samsungPayCard);
}
}
$this->_set('samsungPayCards', $samsungPayCardArray);
$usBankAccountArray = array();
if (isset($customerAttribs['usBankAccounts'])) {
foreach ($customerAttribs['usBankAccounts'] AS $usBankAccount) {
$usBankAccountArray[] = UsBankAccount::factory($usBankAccount);
}
}
$this->_set('usBankAccounts', $usBankAccountArray);
$this->_set('paymentMethods', array_merge(
$this->creditCards,
$this->paypalAccounts,
$this->applePayCards,
$this->coinbaseAccounts,
$this->androidPayCards,
$this->amexExpressCheckoutCards,
$this->venmoAccounts,
$this->visaCheckoutCards,
$this->masterpassCards,
$this->samsungPayCards,
$this->usBankAccounts
));
}
/**
* returns a string representation of the customer
* @return string
*/
public function __toString()
{
return __CLASS__ . '[' .
Util::attributesToString($this->_attributes) .']';
}
/**
* returns false if comparing object is not a Customer,
* or is a Customer with a different id
*
* @param object $otherCust customer to compare against
* @return boolean
*/
public function isEqual($otherCust)
{
return !($otherCust instanceof Customer) ? false : $this->id === $otherCust->id;
}
/**
* returns an array containt all of the customer's payment methods
*
* @deprecated since version 3.1.0 - use the paymentMethods property directly
*
* @return array
*/
public function paymentMethods()
{
return $this->paymentMethods;
}
/**
* returns the customer's default payment method
*
* @return CreditCard|PayPalAccount
*/
public function defaultPaymentMethod()
{
$defaultPaymentMethods = array_filter($this->paymentMethods, 'Braintree\Customer::_defaultPaymentMethodFilter');
return current($defaultPaymentMethods);
}
public static function _defaultPaymentMethodFilter($paymentMethod)
{
return $paymentMethod->isDefault();
}
/* private class properties */
/**
* @access protected
* @var array registry of customer data
*/
protected $_attributes = [
'addresses' => '',
'company' => '',
'creditCards' => '',
'email' => '',
'fax' => '',
'firstName' => '',
'id' => '',
'lastName' => '',
'phone' => '',
'createdAt' => '',
'updatedAt' => '',
'website' => '',
];
/**
* factory method: returns an instance of Customer
* to the requesting method, with populated properties
*
* @ignore
* @param array $attributes
* @return Customer
*/
public static function factory($attributes)
{
$instance = new Customer();
$instance->_initialize($attributes);
return $instance;
}
}
class_alias('Braintree\Customer', 'Braintree_Customer');