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
<?php
namespace Test\Integration;
require_once dirname(__DIR__) . '/Setup.php';
use Test;
use Test\Braintree\CreditCardNumbers\CardTypeIndicators;
use Test\Setup;
use Braintree;
class VisaCheckoutCardTest extends Setup
{
public function testCreateWithVisaCheckoutCardNonce()
{
$customer = Braintree\Customer::createNoValidate();
$result = Braintree\PaymentMethod::create([
'customerId' => $customer->id,
'paymentMethodNonce' => Braintree\Test\Nonces::$visaCheckoutDiscover,
]);
$this->assertTrue($result->success);
$visaCheckoutCard = $result->paymentMethod;
$this->assertNotNull($visaCheckoutCard->token);
$this->assertSame(Braintree\CreditCard::DISCOVER, $visaCheckoutCard->cardType);
$this->assertTrue($visaCheckoutCard->default);
$this->assertContains('discover', $visaCheckoutCard->imageUrl);
$this->assertTrue(intval($visaCheckoutCard->expirationMonth) > 0);
$this->assertTrue(intval($visaCheckoutCard->expirationYear) > 0);
$this->assertSame($customer->id, $visaCheckoutCard->customerId);
$this->assertSame('abc123', $visaCheckoutCard->callId);
$this->assertSame($visaCheckoutCard->last4, '1117');
$this->assertSame($visaCheckoutCard->maskedNumber, '601111******1117');
$this->assertNotNull($visaCheckoutCard->billingAddress);
$this->assertNotNull($visaCheckoutCard->bin);
$this->assertNotNull($visaCheckoutCard->callId);
$this->assertNotNull($visaCheckoutCard->cardType);
$this->assertNotNull($visaCheckoutCard->cardholderName);
$this->assertNotNull($visaCheckoutCard->commercial);
$this->assertNotNull($visaCheckoutCard->countryOfIssuance);
$this->assertNotNull($visaCheckoutCard->createdAt);
$this->assertNotNull($visaCheckoutCard->customerId);
$this->assertNotNull($visaCheckoutCard->customerLocation);
$this->assertNotNull($visaCheckoutCard->debit);
$this->assertNotNull($visaCheckoutCard->default);
$this->assertNotNull($visaCheckoutCard->durbinRegulated);
$this->assertNotNull($visaCheckoutCard->expirationDate);
$this->assertNotNull($visaCheckoutCard->expirationMonth);
$this->assertNotNull($visaCheckoutCard->expirationYear);
$this->assertNotNull($visaCheckoutCard->expired);
$this->assertNotNull($visaCheckoutCard->healthcare);
$this->assertNotNull($visaCheckoutCard->imageUrl);
$this->assertNotNull($visaCheckoutCard->issuingBank);
$this->assertNotNull($visaCheckoutCard->last4);
$this->assertNotNull($visaCheckoutCard->maskedNumber);
$this->assertNotNull($visaCheckoutCard->payroll);
$this->assertNotNull($visaCheckoutCard->prepaid);
$this->assertNotNull($visaCheckoutCard->productId);
$this->assertNotNull($visaCheckoutCard->subscriptions);
$this->assertNotNull($visaCheckoutCard->token);
$this->assertNotNull($visaCheckoutCard->uniqueNumberIdentifier);
$this->assertNotNull($visaCheckoutCard->updatedAt);
}
public function testCreateWithVisaCheckoutCardNonceWithVerification()
{
$customer = Braintree\Customer::createNoValidate();
$result = Braintree\PaymentMethod::create([
'customerId' => $customer->id,
'paymentMethodNonce' => Braintree\Test\Nonces::$visaCheckoutDiscover,
'options' => [
'verifyCard' => true
]
]);
$this->assertTrue($result->success);
$visaCheckoutCard = $result->paymentMethod;
$verification = $visaCheckoutCard->verification;
$this->assertNotNull($verification);
$this->assertNotNull($verification->status);
}
public function testTransactionSearchWithVisaCheckout()
{
$transaction = Braintree\Transaction::saleNoValidate([
'amount' => Braintree\Test\TransactionAmounts::$authorize,
'paymentMethodNonce' => Braintree\Test\Nonces::$visaCheckoutDiscover,
]);
$collection = Braintree\Transaction::search([
Braintree\TransactionSearch::id()->is($transaction->id),
Braintree\TransactionSearch::paymentInstrumentType()->is(Braintree\PaymentInstrumentType::VISA_CHECKOUT_CARD)
]);
$this->assertEquals($transaction->paymentInstrumentType, Braintree\PaymentInstrumentType::VISA_CHECKOUT_CARD);
$this->assertEquals($transaction->id, $collection->firstItem()->id);
}
public function testCreateCustomerWithVisaCheckoutCard()
{
$nonce = Braintree\Test\Nonces::$visaCheckoutDiscover;
$result = Braintree\Customer::create([
'paymentMethodNonce' => $nonce
]);
$this->assertTrue($result->success);
$customer = $result->customer;
$this->assertNotNull($customer->visaCheckoutCards[0]);
$this->assertNotNull($customer->paymentMethods[0]);
}
public function testCreateTransactionWithVisaCheckoutNonceAndVault()
{
$result = Braintree\Transaction::sale([
'amount' => '47.00',
'paymentMethodNonce' => Braintree\Test\Nonces::$visaCheckoutAmEx,
'options' => [
'storeInVault' => true
]
]);
$this->assertTrue($result->success);
$transaction = $result->transaction;
$this->assertEquals('47.00', $transaction->amount);
$visaCheckoutCardDetails = $transaction->visaCheckoutCardDetails;
$this->assertSame(Braintree\CreditCard::AMEX, $visaCheckoutCardDetails->cardType);
$this->assertNotNull($visaCheckoutCardDetails->bin);
$this->assertNotNull($visaCheckoutCardDetails->callId);
$this->assertNotNull($visaCheckoutCardDetails->cardType);
$this->assertNotNull($visaCheckoutCardDetails->cardholderName);
$this->assertNotNull($visaCheckoutCardDetails->commercial);
$this->assertNotNull($visaCheckoutCardDetails->countryOfIssuance);
$this->assertNotNull($visaCheckoutCardDetails->customerLocation);
$this->assertNotNull($visaCheckoutCardDetails->debit);
$this->assertNotNull($visaCheckoutCardDetails->durbinRegulated);
$this->assertNotNull($visaCheckoutCardDetails->expirationDate);
$this->assertNotNull($visaCheckoutCardDetails->expirationMonth);
$this->assertNotNull($visaCheckoutCardDetails->expirationYear);
$this->assertNotNull($visaCheckoutCardDetails->healthcare);
$this->assertNotNull($visaCheckoutCardDetails->imageUrl);
$this->assertNotNull($visaCheckoutCardDetails->issuingBank);
$this->assertNotNull($visaCheckoutCardDetails->last4);
$this->assertNotNull($visaCheckoutCardDetails->maskedNumber);
$this->assertNotNull($visaCheckoutCardDetails->payroll);
$this->assertNotNull($visaCheckoutCardDetails->prepaid);
$this->assertNotNull($visaCheckoutCardDetails->productId);
$this->assertNotNull($visaCheckoutCardDetails->token);
}
}