SamsungPayCardTest.php
8.55 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
<?php
namespace Test\Integration;
require_once dirname(__DIR__) . '/Setup.php';
use Test;
use Test\Braintree\CreditCardNumbers\CardTypeIndicators;
use Test\Setup;
use Braintree;
class SamsungPayCardTest extends Setup
{
    public function testCreateWithSamsungPayCardNonce()
    {
        $customer = Braintree\Customer::createNoValidate();
        $result = Braintree\PaymentMethod::create([
            'customerId' => $customer->id,
            'paymentMethodNonce' => Braintree\Test\Nonces::$samsungPayDiscover,
            'cardholderName' => 'Jenny Block',
            'billingAddress' => [
                'firstName' => 'Drew',
                'lastName' => 'Smith',
                'company' => 'Smith Co.',
                'streetAddress' => '1 E Main St',
                'extendedAddress' => 'Suite 101',
                'locality' => 'Chicago',
                'region' => 'IL',
                'postalCode' => '60622',
                'countryName' => 'Micronesia',
                'countryCodeAlpha2' => 'FM',
                'countryCodeAlpha3' => 'FSM',
                'countryCodeNumeric' => '583'
            ]
        ]);
        $this->assertTrue($result->success);
        $samsungPayCard = $result->paymentMethod;
        $this->assertNotNull($samsungPayCard->token);
        $this->assertSame(Braintree\CreditCard::DISCOVER, $samsungPayCard->cardType);
        $this->assertTrue($samsungPayCard->default);
        $this->assertContains('discover', $samsungPayCard->imageUrl);
        $this->assertTrue(intval($samsungPayCard->expirationMonth) > 0);
        $this->assertTrue(intval($samsungPayCard->expirationYear) > 0);
        $this->assertSame($customer->id, $samsungPayCard->customerId);
        $this->assertSame($samsungPayCard->last4, '1117');
        $this->assertSame($samsungPayCard->maskedNumber, '601111******1117');
        $this->assertNotNull($samsungPayCard->billingAddress);
        $this->assertNotNull($samsungPayCard->bin);
        $this->assertNotNull($samsungPayCard->cardholderName);
        $this->assertNotNull($samsungPayCard->cardType);
        $this->assertNotNull($samsungPayCard->commercial);
        $this->assertNotNull($samsungPayCard->countryOfIssuance);
        $this->assertNotNull($samsungPayCard->createdAt);
        $this->assertNotNull($samsungPayCard->customerId);
        $this->assertNotNull($samsungPayCard->customerLocation);
        $this->assertNotNull($samsungPayCard->debit);
        $this->assertNotNull($samsungPayCard->default);
        $this->assertNotNull($samsungPayCard->durbinRegulated);
        $this->assertNotNull($samsungPayCard->expirationDate);
        $this->assertNotNull($samsungPayCard->expirationMonth);
        $this->assertNotNull($samsungPayCard->expirationYear);
        $this->assertNotNull($samsungPayCard->expired);
        $this->assertNotNull($samsungPayCard->healthcare);
        $this->assertNotNull($samsungPayCard->imageUrl);
        $this->assertNotNull($samsungPayCard->issuingBank);
        $this->assertNotNull($samsungPayCard->last4);
        $this->assertNotNull($samsungPayCard->maskedNumber);
        $this->assertNotNull($samsungPayCard->payroll);
        $this->assertNotNull($samsungPayCard->prepaid);
        $this->assertNotNull($samsungPayCard->productId);
        $this->assertNotNull($samsungPayCard->sourceCardLast4);
        $this->assertNotNull($samsungPayCard->subscriptions);
        $this->assertNotNull($samsungPayCard->token);
        $this->assertNotNull($samsungPayCard->uniqueNumberIdentifier);
        $this->assertNotNull($samsungPayCard->updatedAt);
    }
    public function testCreateWithNameAndAddress()
    {
        $customer = Braintree\Customer::createNoValidate();
        $result = Braintree\PaymentMethod::create([
            'customerId' => $customer->id,
            'paymentMethodNonce' => Braintree\Test\Nonces::$samsungPayDiscover,
            'cardholderName' => 'Jenny Block',
            'billingAddress' => [
                'firstName' => 'Drew',
                'lastName' => 'Smith',
                'company' => 'Smith Co.',
                'streetAddress' => '1 E Main St',
                'extendedAddress' => 'Suite 101',
                'locality' => 'Chicago',
                'region' => 'IL',
                'postalCode' => '60622',
                'countryName' => 'Micronesia',
                'countryCodeAlpha2' => 'FM',
                'countryCodeAlpha3' => 'FSM',
                'countryCodeNumeric' => '583'
            ]
        ]);
        $this->assertTrue($result->success);
        $samsungPayCard = $result->paymentMethod;
        $this->assertEquals($samsungPayCard->cardholderName, 'Jenny Block');
        $address = $samsungPayCard->billingAddress;
        $this->assertEquals('Drew', $address->firstName);
        $this->assertEquals('Smith', $address->lastName);
        $this->assertEquals('Smith Co.', $address->company);
        $this->assertEquals('1 E Main St', $address->streetAddress);
        $this->assertEquals('Suite 101', $address->extendedAddress);
        $this->assertEquals('Chicago', $address->locality);
        $this->assertEquals('IL', $address->region);
        $this->assertEquals('60622', $address->postalCode);
        $this->assertEquals('Micronesia', $address->countryName);
        $this->assertEquals('FM', $address->countryCodeAlpha2);
        $this->assertEquals('FSM', $address->countryCodeAlpha3);
    }
    public function testTransactionSearchWithSamsungPay()
    {
        $transaction = Braintree\Transaction::saleNoValidate([
            'amount' => Braintree\Test\TransactionAmounts::$authorize,
            'paymentMethodNonce' => Braintree\Test\Nonces::$samsungPayDiscover,
        ]);
        $collection = Braintree\Transaction::search([
            Braintree\TransactionSearch::id()->is($transaction->id),
            Braintree\TransactionSearch::paymentInstrumentType()->is(Braintree\PaymentInstrumentType::SAMSUNG_PAY_CARD)
        ]);
        $this->assertEquals($transaction->paymentInstrumentType, Braintree\PaymentInstrumentType::SAMSUNG_PAY_CARD);
        $this->assertEquals($transaction->id, $collection->firstItem()->id);
    }
    public function testCreateCustomerWithSamsungPayCard()
    {
        $nonce = Braintree\Test\Nonces::$samsungPayDiscover;
        $result = Braintree\Customer::create([
            'paymentMethodNonce' => $nonce
        ]);
        $this->assertTrue($result->success);
        $customer = $result->customer;
        $this->assertNotNull($customer->samsungPayCards[0]);
        $this->assertNotNull($customer->paymentMethods[0]);
    }
    public function testCreateTransactionWithSamsungPayNonceAndVault()
    {
        $result = Braintree\Transaction::sale([
            'amount' => '47.00',
            'paymentMethodNonce' => Braintree\Test\Nonces::$samsungPayAmEx,
            'options' => [
                'storeInVault' => true
            ],
            'creditCard' => [
                'cardholderName' => 'Jenny Block'
            ]
        ]);
        $this->assertTrue($result->success);
        $transaction = $result->transaction;
        $this->assertEquals('47.00', $transaction->amount);
        $samsungPayCardDetails = $transaction->samsungPayCardDetails;
        $this->assertSame(Braintree\CreditCard::AMEX, $samsungPayCardDetails->cardType);
        $this->assertNotNull($samsungPayCardDetails->bin);
        $this->assertNotNull($samsungPayCardDetails->cardholderName);
        $this->assertNotNull($samsungPayCardDetails->cardType);
        $this->assertNotNull($samsungPayCardDetails->commercial);
        $this->assertNotNull($samsungPayCardDetails->countryOfIssuance);
        $this->assertNotNull($samsungPayCardDetails->customerLocation);
        $this->assertNotNull($samsungPayCardDetails->debit);
        $this->assertNotNull($samsungPayCardDetails->durbinRegulated);
        $this->assertNotNull($samsungPayCardDetails->expirationDate);
        $this->assertNotNull($samsungPayCardDetails->expirationMonth);
        $this->assertNotNull($samsungPayCardDetails->expirationYear);
        $this->assertNotNull($samsungPayCardDetails->healthcare);
        $this->assertNotNull($samsungPayCardDetails->imageUrl);
        $this->assertNotNull($samsungPayCardDetails->issuingBank);
        $this->assertNotNull($samsungPayCardDetails->last4);
        $this->assertNotNull($samsungPayCardDetails->maskedNumber);
        $this->assertNotNull($samsungPayCardDetails->payroll);
        $this->assertNotNull($samsungPayCardDetails->prepaid);
        $this->assertNotNull($samsungPayCardDetails->productId);
        $this->assertNotNull($samsungPayCardDetails->sourceCardLast4);
        $this->assertNotNull($samsungPayCardDetails->token);
    }
}