MasterpassCard.php
4.29 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
<?php
namespace Braintree;
/**
* Braintree MasterpassCard module
* Creates and manages Braintree MasterpassCards
*
* <b>== More information ==</b>
*
* 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 string $countryOfIssuance
* @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 string $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
*/
class MasterpassCard extends Base
{
/* 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;
}
/**
* 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);
}
/**
* 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($otherMasterpassCard)
{
return !($otherMasterpassCard instanceof self) ? false : $this->token === $otherMasterpassCard->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 MasterpassCard
*/
public static function factory($attributes)
{
$defaultAttributes = [
'bin' => '',
'expirationMonth' => '',
'expirationYear' => '',
'last4' => '',
];
$instance = new self();
$instance->_initialize(array_merge($defaultAttributes, $attributes));
return $instance;
}
}
class_alias('Braintree\MasterpassCard', 'Braintree_MasterpassCard');