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
<?php
namespace Test\Unit;
require_once dirname(__DIR__) . '/Setup.php';
use Test\Setup;
use Braintree;
class PaymentMethodTest extends Setup
{
public function testCreate_throwsIfInvalidKey()
{
$this->setExpectedException('InvalidArgumentException', 'invalid keys: invalidKey');
Braintree\PaymentMethod::create(['invalidKey' => 'foo']);
}
public function testCreateSignature()
{
$expected = [
'billingAddressId',
'cardholderName',
'cvv',
'deviceData',
'expirationDate',
'expirationMonth',
'expirationYear',
'number',
'paymentMethodNonce',
'token',
['options' => [
'failOnDuplicatePaymentMethod',
'makeDefault',
'verificationMerchantAccountId',
'verifyCard',
'verificationAmount',
'usBankAccountVerificationMethod',
['paypal' => [
'payee_email',
'payeeEmail',
'order_id',
'orderId',
'custom_field',
'customField',
'description',
'amount',
['shipping' =>
[
'firstName', 'lastName', 'company', 'countryName',
'countryCodeAlpha2', 'countryCodeAlpha3', 'countryCodeNumeric',
'extendedAddress', 'locality', 'postalCode', 'region',
'streetAddress'],
],
]],
]],
['billingAddress' => Braintree\AddressGateway::createSignature()],
'customerId',
'paypalRefreshToken',
'paypalVaultWithoutUpgrade'
];
$this->assertEquals($expected, Braintree\PaymentMethodGateway::createSignature());
}
public function testErrorsOnFindWithBlankArgument()
{
$this->setExpectedException('InvalidArgumentException');
Braintree\PaymentMethod::find('');
}
public function testErrorsOnFindWithWhitespaceArgument()
{
$this->setExpectedException('InvalidArgumentException');
Braintree\PaymentMethod::find(' ');
}
public function testErrorsOnFindWithWhitespaceCharacterArgument()
{
$this->setExpectedException('InvalidArgumentException');
Braintree\PaymentMethod::find('\t');
}
public function testDeleteWithRevokeAllGrantsAsTrue()
{
$paymentMethodGateway = $this->mockPaymentMethodGatewayDoDelete();
$expectedURL = "/payment_methods/any/some_token?revoke_all_grants=1";
$paymentMethodGateway->expects($this->once())->method('_doDelete')->with($this->equalTo($expectedURL));
$paymentMethodGateway->delete("some_token", ['revokeAllGrants' => true]);
}
public function testDeleteWithRevokeAllGrantsAsFalse()
{
$paymentMethodGateway = $this->mockPaymentMethodGatewayDoDelete();
$expectedURL = "/payment_methods/any/some_token?revoke_all_grants=0";
$paymentMethodGateway->expects($this->once())->method('_doDelete')->with($this->equalTo($expectedURL));
$paymentMethodGateway->delete("some_token", ['revokeAllGrants' => false]);
}
public function testDeleteWithoutRevokeAllGrantsOption()
{
$paymentMethodGateway = $this->mockPaymentMethodGatewayDoDelete();
$expectedURL = "/payment_methods/any/some_token";
$paymentMethodGateway->expects($this->once())->method('_doDelete')->with($this->equalTo($expectedURL));
$paymentMethodGateway->delete("some_token");
}
public function testDeleteWithInvalidOption()
{
$paymentMethodGateway = $this->mockPaymentMethodGatewayDoDelete();
$this->setExpectedException('InvalidArgumentException');
$paymentMethodGateway->expects($this->never())->method('_doDelete');
$paymentMethodGateway->delete("some_token", ['invalidKey' => false]);
}
private function mockPaymentMethodGatewayDoDelete()
{
return $this->getMockBuilder('Braintree\PaymentMethodGateway')
->setConstructorArgs(array(Braintree\Configuration::gateway()))
->setMethods(array('_doDelete'))
->getMock();
}
}