|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Moip\Tests\Resource; |
|
4
|
|
|
|
|
5
|
|
|
use Moip\Tests\TestCase; |
|
6
|
|
|
|
|
7
|
|
|
class PaymentTest extends TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
//todo: credit card hash |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* MoipTest creating a credit card payment, passing all credit card data. |
|
13
|
|
|
*/ |
|
14
|
|
|
public function testCreditCardPCI() |
|
15
|
|
|
{ |
|
16
|
|
|
$this->mockHttpSession($this->body_order); |
|
17
|
|
|
$order = $this->createOrder()->create(); |
|
18
|
|
|
$this->mockHttpSession($this->body_cc_pay_pci); |
|
19
|
|
|
$cc = '5555666677778884'; |
|
20
|
|
|
$payment = $order->payments()->setCreditCard(5, 2018, $cc, 123, $this->createCustomer())->execute(); |
|
|
|
|
|
|
21
|
|
|
$this->assertNotEmpty($payment->getFundingInstrument()->creditCard); |
|
22
|
|
|
$first6 = $payment->getFundingInstrument()->creditCard->first6; |
|
23
|
|
|
$last4 = $payment->getFundingInstrument()->creditCard->last4; |
|
24
|
|
|
$this->assertEquals($first6, substr($cc, 0, 6)); |
|
25
|
|
|
$this->assertEquals($last4, substr($cc, -4)); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* MoipTest creating a billet payment. |
|
30
|
|
|
*/ |
|
31
|
|
View Code Duplication |
public function testBillet() |
|
|
|
|
|
|
32
|
|
|
{ |
|
33
|
|
|
$this->mockHttpSession($this->body_order); |
|
34
|
|
|
$order = $this->createOrder()->create(); |
|
35
|
|
|
$this->mockHttpSession($this->body_billet_pay); |
|
36
|
|
|
$payment = $order->payments()->setBoleto(new \DateTime('today +1day'), 'http://dev.moip.com.br/images/logo-header-moip.png')->execute(); |
|
|
|
|
|
|
37
|
|
|
$this->assertNotEmpty($payment->getFundingInstrument()->boleto); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
View Code Duplication |
public function testCreditCardPCIStore() |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
|
|
$this->mockHttpSession($this->body_order); |
|
43
|
|
|
$order = $this->createOrder()->create(); |
|
44
|
|
|
$cc = '5555666677778884'; |
|
45
|
|
|
$this->mockHttpSession($this->body_cc_pay_pci_store); |
|
46
|
|
|
$payment = $order->payments()->setCreditCard(5, 2018, $cc, 123, $this->createCustomer(), false)->execute(); |
|
|
|
|
|
|
47
|
|
|
$this->assertFalse($payment->getFundingInstrument()->creditCard->store); |
|
48
|
|
|
$this->assertNotEmpty($payment->getId()); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
View Code Duplication |
public function testShouldCreateEscrowPaymentWithCreditCard() |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
$this->mockHttpSession($this->body_order); |
|
54
|
|
|
$order = $this->createOrder()->create(); |
|
55
|
|
|
$cc = '5555666677778884'; |
|
56
|
|
|
$this->mockHttpSession($this->body_cc_pay_pci_escrow); |
|
57
|
|
|
$payment = $order->payments() |
|
|
|
|
|
|
58
|
|
|
->setCreditCard(5, 2018, $cc, 123, $this->createCustomer(), false) |
|
59
|
|
|
->setEscrow('teste de descricao') |
|
60
|
|
|
->execute(); |
|
61
|
|
|
$this->assertEquals('teste de descricao', $payment->getEscrow()->description); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* MoipTest creating a credit card multipayment, passing all credit card data. |
|
66
|
|
|
*/ |
|
67
|
|
|
public function testMultipaymentCreditCardPCI() |
|
68
|
|
|
{ |
|
69
|
|
|
$this->mockHttpSession($this->body_multiorder); |
|
|
|
|
|
|
70
|
|
|
$order = $this->createMultiorder()->create(); |
|
71
|
|
|
$this->mockHttpSession($this->body_cc_multipay); |
|
|
|
|
|
|
72
|
|
|
$cc = '4012001037141112'; |
|
73
|
|
|
$payment = $order->multipayments()->setCreditCard(5, 2018, $cc, 123, $this->createCustomer())->execute(); |
|
74
|
|
|
|
|
75
|
|
|
$first6 = $payment->getPayments()[0]->fundingInstrument->creditCard->first6; |
|
76
|
|
|
$last4 = $payment->getPayments()[0]->fundingInstrument->creditCard->last4; |
|
77
|
|
|
$this->assertEquals($first6, substr($cc, 0, 6)); |
|
78
|
|
|
$this->assertEquals($last4, substr($cc, -4)); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* MoipTest creating a billet multipayment. |
|
83
|
|
|
*/ |
|
84
|
|
View Code Duplication |
public function testMultipaymentBillet() |
|
|
|
|
|
|
85
|
|
|
{ |
|
86
|
|
|
$this->mockHttpSession($this->body_multiorder); |
|
87
|
|
|
$order = $this->createMultiorder()->create(); |
|
88
|
|
|
$this->mockHttpSession($this->body_billet_multipay); |
|
|
|
|
|
|
89
|
|
|
$payment = $order->multipayments()->setBoleto(new \DateTime('today +1day'), 'http://dev.moip.com.br/images/logo-header-moip.png')->execute(); |
|
90
|
|
|
$this->assertNotEmpty($payment->getFundingInstrument()->boleto); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
View Code Duplication |
public function testCapturePreAuthorizedPayment() |
|
|
|
|
|
|
94
|
|
|
{ |
|
95
|
|
|
$this->mockHttpSession($this->body_order); |
|
96
|
|
|
$order = $this->createOrder()->create(); |
|
97
|
|
|
$this->mockHttpSession($this->body_cc_delay_capture); |
|
|
|
|
|
|
98
|
|
|
$payment = $order->payments() |
|
|
|
|
|
|
99
|
|
|
->setCreditCard(5, 2018, '5555666677778884', 123, $this->createCustomer(), false) |
|
100
|
|
|
->setDelayCapture(true) |
|
101
|
|
|
->execute(); |
|
102
|
|
|
|
|
103
|
|
|
$this->mockHttpSession($this->body_capture_pay); |
|
|
|
|
|
|
104
|
|
|
$captured_payment = $payment->capture(); |
|
105
|
|
|
|
|
106
|
|
|
$this->assertEquals('AUTHORIZED', $captured_payment->getStatus()); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
View Code Duplication |
public function testCapturePreAuthorizedMultiPayment() |
|
|
|
|
|
|
110
|
|
|
{ |
|
111
|
|
|
$this->mockHttpSession($this->body_multiorder); |
|
112
|
|
|
$order = $this->createMultiorder()->create(); |
|
113
|
|
|
$this->mockHttpSession($this->body_cc_multipay); |
|
114
|
|
|
$payment = $order->multipayments() |
|
115
|
|
|
->setCreditCard(5, 2018, '4012001037141112', 123, $this->createCustomer()) |
|
116
|
|
|
->setDelayCapture(true) |
|
117
|
|
|
->execute(); |
|
118
|
|
|
|
|
119
|
|
|
$this->mockHttpSession($this->body_capture_multipay); |
|
|
|
|
|
|
120
|
|
|
$captured_payment = $payment->capture(); |
|
121
|
|
|
|
|
122
|
|
|
$this->assertEquals('AUTHORIZED', $captured_payment->getStatus()); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
View Code Duplication |
public function testCancelPreAuthorizedMultiPayment() |
|
|
|
|
|
|
126
|
|
|
{ |
|
127
|
|
|
$this->mockHttpSession($this->body_multiorder); |
|
128
|
|
|
$order = $this->createMultiorder()->create(); |
|
129
|
|
|
$this->mockHttpSession($this->body_cc_multipay); |
|
130
|
|
|
$payment = $order->multipayments() |
|
131
|
|
|
->setCreditCard(5, 2018, '4012001037141112', 123, $this->createCustomer()) |
|
132
|
|
|
->setDelayCapture(true) |
|
133
|
|
|
->execute(); |
|
134
|
|
|
|
|
135
|
|
|
$this->mockHttpSession($this->body_cancel_multipay); |
|
|
|
|
|
|
136
|
|
|
$cancelled_payment = $payment->cancel(); |
|
137
|
|
|
|
|
138
|
|
|
$this->assertEquals('CANCELLED', $cancelled_payment->getStatus()); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
View Code Duplication |
public function testCancelPreAuthorizedPayment() |
|
|
|
|
|
|
142
|
|
|
{ |
|
143
|
|
|
$this->mockHttpSession($this->body_order); |
|
144
|
|
|
$order = $this->createOrder()->create(); |
|
145
|
|
|
$this->mockHttpSession($this->body_cc_delay_capture); |
|
146
|
|
|
$payment = $order->payments() |
|
|
|
|
|
|
147
|
|
|
->setCreditCard(5, 2018, '5555666677778884', 123, $this->createCustomer(), false) |
|
148
|
|
|
->setDelayCapture(true) |
|
149
|
|
|
->execute(); |
|
150
|
|
|
|
|
151
|
|
|
$this->mockHttpSession($this->body_cancel_pay); |
|
|
|
|
|
|
152
|
|
|
$cancelled_payment = $payment->cancel(); |
|
153
|
|
|
|
|
154
|
|
|
$this->assertEquals('CANCELLED', $cancelled_payment->getStatus()); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
public function testGetPayment() |
|
158
|
|
|
{ |
|
159
|
|
|
$this->mockHttpSession($this->body_order); |
|
160
|
|
|
$order = $this->createOrder()->create(); |
|
161
|
|
|
$this->mockHttpSession($this->body_cc_pay_pci); |
|
162
|
|
|
$payment = $order->payments()->setCreditCard(5, 2018, '5555666677778884', 123, $this->createCustomer())->execute(); |
|
|
|
|
|
|
163
|
|
|
|
|
164
|
|
|
$this->mockHttpSession($this->body_get_pay); |
|
|
|
|
|
|
165
|
|
|
$payment_get = $this->moip->payments()->get($payment->getId()); |
|
166
|
|
|
|
|
167
|
|
|
$this->assertEquals($payment_get->getAmount()->total, 102470); |
|
168
|
|
|
$this->assertEquals($payment_get->getFundingInstrument()->method, 'CREDIT_CARD'); |
|
169
|
|
|
$this->assertEquals($payment_get->getInstallmentCount(), 1); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
public function testGetMultiPayment() |
|
173
|
|
|
{ |
|
174
|
|
|
$this->mockHttpSession($this->body_multiorder); |
|
175
|
|
|
$order = $this->createMultiorder()->create(); |
|
176
|
|
|
$this->mockHttpSession($this->body_cc_multipay); |
|
177
|
|
|
$payment = $order->multipayments()->setCreditCard(5, 2018, '4012001037141112', 123, $this->createCustomer())->execute(); |
|
178
|
|
|
|
|
179
|
|
|
$this->mockHttpSession($this->body_get_multipay); |
|
|
|
|
|
|
180
|
|
|
$payment_get = $this->moip->payments()->get($payment->getId()); |
|
181
|
|
|
|
|
182
|
|
|
$this->assertEquals($payment_get->getAmount()->total, 77000); |
|
183
|
|
|
$this->assertNotNull($payment_get->getPayments()); |
|
184
|
|
|
} |
|
185
|
|
|
} |
|
186
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: