CreditCard.php
10.1 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
<?php
namespace Braintree;
/**
* Braintree CreditCard module
* Creates and manages Braintree CreditCards
*
* <b>== More information ==</b>
*
* For more detailed information on CreditCards, see {@link https://developers.braintreepayments.com/reference/response/credit-card/php https://developers.braintreepayments.com/reference/response/credit-card/php}<br />
* For more detailed information on CreditCard verifications, see {@link https://developers.braintreepayments.com/reference/response/credit-card-verification/php https://developers.braintreepayments.com/reference/response/credit-card-verification/php}
*
* @package Braintree
* @category Resources
*
* @property-read \Braintree\Address $billingAddress
* @property-read string $bin
* @property-read string $cardType
* @property-read string $cardholderName
* @property-read string $commercial
* @property-read \DateTime $createdAt
* @property-read string $customerId
* @property-read string $customerLocation
* @property-read string $debit
* @property-read boolean $default
* @property-read string $durbinRegulated
* @property-read string $expirationDate
* @property-read string $expirationMonth
* @property-read string $expirationYear
* @property-read boolean $expired
* @property-read boolean $healthcare
* @property-read string $imageUrl
* @property-read string $issuingBank
* @property-read string $last4
* @property-read string $maskedNumber
* @property-read string $payroll
* @property-read string $prepaid
* @property-read string $productId
* @property-read \Braintree\Subscription[] $subscriptions
* @property-read string $token
* @property-read string $uniqueNumberIdentifier
* @property-read \DateTime $updatedAt
* @property-read \Braintree\CreditCardVerification|null $verification
*/
class CreditCard extends Base
{
// Card Type
const AMEX = 'American Express';
const CARTE_BLANCHE = 'Carte Blanche';
const CHINA_UNION_PAY = 'China UnionPay';
const DINERS_CLUB_INTERNATIONAL = 'Diners Club';
const DISCOVER = 'Discover';
const ELO = 'Elo';
const JCB = 'JCB';
const LASER = 'Laser';
const MAESTRO = 'Maestro';
const UK_MAESTRO = 'UK Maestro';
const MASTER_CARD = 'MasterCard';
const SOLO = 'Solo';
const SWITCH_TYPE = 'Switch';
const VISA = 'Visa';
const UNKNOWN = 'Unknown';
// Credit card origination location
const INTERNATIONAL = "international";
const US = "us";
const PREPAID_YES = 'Yes';
const PREPAID_NO = 'No';
const PREPAID_UNKNOWN = 'Unknown';
const PAYROLL_YES = 'Yes';
const PAYROLL_NO = 'No';
const PAYROLL_UNKNOWN = 'Unknown';
const HEALTHCARE_YES = 'Yes';
const HEALTHCARE_NO = 'No';
const HEALTHCARE_UNKNOWN = 'Unknown';
const DURBIN_REGULATED_YES = 'Yes';
const DURBIN_REGULATED_NO = 'No';
const DURBIN_REGULATED_UNKNOWN = 'Unknown';
const DEBIT_YES = 'Yes';
const DEBIT_NO = 'No';
const DEBIT_UNKNOWN = 'Unknown';
const COMMERCIAL_YES = 'Yes';
const COMMERCIAL_NO = 'No';
const COMMERCIAL_UNKNOWN = 'Unknown';
const COUNTRY_OF_ISSUANCE_UNKNOWN = "Unknown";
const ISSUING_BANK_UNKNOWN = "Unknown";
const PRODUCT_ID_UNKNOWN = "Unknown";
/* instance methods */
/**
* returns false if default is null or false
*
* @return boolean
*/
public function isDefault()
{
return $this->default;
}
/**
* checks whether the card is expired based on the current date
*
* @return boolean
*/
public function isExpired()
{
return $this->expired;
}
/**
* checks whether the card is associated with venmo sdk
*
* @return boolean
*/
public function isVenmoSdk()
{
return $this->venmoSdk;
}
/**
* sets instance properties from an array of values
*
* @access protected
* @param array $creditCardAttribs array of creditcard data
* @return void
*/
protected function _initialize($creditCardAttribs)
{
// set the attributes
$this->_attributes = $creditCardAttribs;
// map each address into its own object
$billingAddress = isset($creditCardAttribs['billingAddress']) ?
Address::factory($creditCardAttribs['billingAddress']) :
null;
$subscriptionArray = [];
if (isset($creditCardAttribs['subscriptions'])) {
foreach ($creditCardAttribs['subscriptions'] AS $subscription) {
$subscriptionArray[] = Subscription::factory($subscription);
}
}
$this->_set('subscriptions', $subscriptionArray);
$this->_set('billingAddress', $billingAddress);
$this->_set('expirationDate', $this->expirationMonth . '/' . $this->expirationYear);
$this->_set('maskedNumber', $this->bin . '******' . $this->last4);
if(isset($creditCardAttribs['verifications']) && count($creditCardAttribs['verifications']) > 0) {
$verifications = $creditCardAttribs['verifications'];
usort($verifications, [$this, '_compareCreatedAtOnVerifications']);
$this->_set('verification', CreditCardVerification::factory($verifications[0]));
}
}
private function _compareCreatedAtOnVerifications($verificationAttrib1, $verificationAttrib2)
{
return ($verificationAttrib2['createdAt'] < $verificationAttrib1['createdAt']) ? -1 : 1;
}
/**
* returns false if comparing object is not a CreditCard,
* or is a CreditCard with a different id
*
* @param object $otherCreditCard customer to compare against
* @return boolean
*/
public function isEqual($otherCreditCard)
{
return !($otherCreditCard instanceof self) ? false : $this->token === $otherCreditCard->token;
}
/**
* create a printable representation of the object as:
* ClassName[property=value, property=value]
* @return string
*/
public function __toString()
{
return __CLASS__ . '[' .
Util::attributesToString($this->_attributes) .']';
}
/**
* factory method: returns an instance of CreditCard
* to the requesting method, with populated properties
*
* @ignore
* @return CreditCard
*/
public static function factory($attributes)
{
$defaultAttributes = [
'bin' => '',
'expirationMonth' => '',
'expirationYear' => '',
'last4' => '',
];
$instance = new self();
$instance->_initialize(array_merge($defaultAttributes, $attributes));
return $instance;
}
// static methods redirecting to gateway
public static function create($attribs)
{
return Configuration::gateway()->creditCard()->create($attribs);
}
public static function createNoValidate($attribs)
{
return Configuration::gateway()->creditCard()->createNoValidate($attribs);
}
public static function createFromTransparentRedirect($queryString)
{
return Configuration::gateway()->creditCard()->createFromTransparentRedirect($queryString);
}
public static function createCreditCardUrl()
{
return Configuration::gateway()->creditCard()->createCreditCardUrl();
}
public static function expired()
{
return Configuration::gateway()->creditCard()->expired();
}
public static function fetchExpired($ids)
{
return Configuration::gateway()->creditCard()->fetchExpired($ids);
}
public static function expiringBetween($startDate, $endDate)
{
return Configuration::gateway()->creditCard()->expiringBetween($startDate, $endDate);
}
public static function fetchExpiring($startDate, $endDate, $ids)
{
return Configuration::gateway()->creditCard()->fetchExpiring($startDate, $endDate, $ids);
}
public static function find($token)
{
return Configuration::gateway()->creditCard()->find($token);
}
public static function fromNonce($nonce)
{
return Configuration::gateway()->creditCard()->fromNonce($nonce);
}
public static function credit($token, $transactionAttribs)
{
return Configuration::gateway()->creditCard()->credit($token, $transactionAttribs);
}
public static function creditNoValidate($token, $transactionAttribs)
{
return Configuration::gateway()->creditCard()->creditNoValidate($token, $transactionAttribs);
}
public static function sale($token, $transactionAttribs)
{
return Configuration::gateway()->creditCard()->sale($token, $transactionAttribs);
}
public static function saleNoValidate($token, $transactionAttribs)
{
return Configuration::gateway()->creditCard()->saleNoValidate($token, $transactionAttribs);
}
public static function update($token, $attributes)
{
return Configuration::gateway()->creditCard()->update($token, $attributes);
}
public static function updateNoValidate($token, $attributes)
{
return Configuration::gateway()->creditCard()->updateNoValidate($token, $attributes);
}
public static function updateCreditCardUrl()
{
return Configuration::gateway()->creditCard()->updateCreditCardUrl();
}
public static function updateFromTransparentRedirect($queryString)
{
return Configuration::gateway()->creditCard()->updateFromTransparentRedirect($queryString);
}
public static function delete($token)
{
return Configuration::gateway()->creditCard()->delete($token);
}
/** @return array */
public static function allCardTypes()
{
return [
CreditCard::AMEX,
CreditCard::CARTE_BLANCHE,
CreditCard::CHINA_UNION_PAY,
CreditCard::DINERS_CLUB_INTERNATIONAL,
CreditCard::DISCOVER,
CreditCard::ELO,
CreditCard::JCB,
CreditCard::LASER,
CreditCard::MAESTRO,
CreditCard::MASTER_CARD,
CreditCard::SOLO,
CreditCard::SWITCH_TYPE,
CreditCard::VISA,
CreditCard::UNKNOWN
];
}
}
class_alias('Braintree\CreditCard', 'Braintree_CreditCard');