1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests; |
4
|
|
|
|
5
|
|
|
use Ipag\Classes\Authentication; |
6
|
|
|
use Ipag\Classes\Endpoint; |
7
|
|
|
use Ipag\Classes\Enum\Method; |
8
|
|
|
use Ipag\Classes\Enum\PaymentStatus; |
9
|
|
|
use Ipag\Classes\Subscription; |
10
|
|
|
use Ipag\Classes\Transaction; |
11
|
|
|
use Ipag\Ipag; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
|
14
|
|
|
class PaymentTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var Transaction |
18
|
|
|
*/ |
19
|
|
|
private $transaction; |
20
|
|
|
private $ipag; |
21
|
|
|
|
22
|
|
|
public function __construct() |
23
|
|
|
{ |
24
|
|
|
parent::__construct(); |
25
|
|
|
$this->init(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function setUp() |
29
|
|
|
{ |
30
|
|
|
parent::setUp(); |
31
|
|
|
$this->init(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function init() |
35
|
|
|
{ |
36
|
|
|
$this->ipag = new Ipag(new Authentication(getenv('ID_IPAG'), getenv('API_KEY')), Endpoint::SANDBOX); |
37
|
|
|
|
38
|
|
|
$this->transaction = $this->ipag->transaction(); |
39
|
|
|
|
40
|
|
|
$cart = $this->ipag->cart( |
41
|
|
|
['APC Flotador Universal Perol 5 Litros', 55.9, 2, '000347'], |
42
|
|
|
['Aplicador de gel para pneus Cadillac', 10, 2, '001567'], |
43
|
|
|
['Escova Azul para Furo de Rodas Mandala', 35.9, 2, 'E01'], |
44
|
|
|
['Polidor de Corte LPD Hi Cut + Lincoln 1K (nova fórmula)', 148.9, 1, '002053'], |
45
|
|
|
['Lava Auto Shampoo Super Concentrado 1:300 Monster Cadillac 2L', 37.05, 2, '001646'], |
46
|
|
|
['Balde com Protetor de Areia Ultimate Filter GF', 60.9, 1, '001549'], |
47
|
|
|
['Balde com Protetor de Areia Ultimate Filter GF', 60.9, 1, '001549'], |
48
|
|
|
['Removedor de Piche Tar Remover Sonax 300ml', 54, 1, '000586'], |
49
|
|
|
['Boina de Espuma Super Macia Preta Waffle Mills 7.8\'', 60, 1, '001004'], |
50
|
|
|
['Cera de Carnaúba Cleaner Wax Cadillac 300gr', 79.9, 1, '000312'], |
51
|
|
|
['Cera de Carnaúba Lincoln 200g', 72.5, 1, '001051'], |
52
|
|
|
['Vonixx Cera de Carnaúba Super Protetora', 52, 1, '001455'], |
53
|
|
|
['Vonixx Revitalizador de Pneus 500ml', 32, 1, '001479'], |
54
|
|
|
['Boina de Espuma Médio Agressiva Dune Alcance 5\' ', 41.5, 1, '002333'], |
55
|
|
|
['Boina Lã S/Interface Corte Lincoln 6\' (listra Colorida)', 39, 1, '001891'], |
56
|
|
|
['Desinfetante BAC 500 Perol 5L', 66.9, 1, '001286'], |
57
|
|
|
['Escova Caixa de Roda Cadillac', 39.9, 1, '000544'], |
58
|
|
|
['Escova para Estofados (cerdas de silicone) Cadillac', 36.9, 1, '001488'], |
59
|
|
|
['Lavagem a Seco Affix Perol 5L', 216.9, 1, '000499'], |
60
|
|
|
['POLIDOR DE METAIS METAL-LAC CADILLAC 150G', 37.9, 1, '831676'], |
61
|
|
|
['Vonixx Restaurax 500ml', 32.9, 1, '001478'], |
62
|
|
|
['Revitalizador de Plásticos Doctor Shine Cadillac 500ml', 34.1, 1, '002020'], |
63
|
|
|
['Menzerna Selante Power Lock Ultimate Protection 1L', 251.9, 1, '001423'], |
64
|
|
|
['Pneu Visco Cadillac 5L', 43.6, 1, '000265'], |
65
|
|
|
['Metal Polish Optimum 227g', 83, 1, '001910'], |
66
|
|
|
['Nano Pro (Profiline) Perfect Finish Sonax - 400g', 109.9, 1, '000427'], |
67
|
|
|
['OXICLEAN – REMOVEDOR DE CHUVA ÁCIDA', 45.9, 1, '001513'], |
68
|
|
|
['Pasta Abrasiva 3M Cleaner Clay + Brinde Limpeza Final 3M 500ml', 86.9, 1, '000279'], |
69
|
|
|
['Shampoo automotivo Espumacar Cadillac 5L', 28, 1, '000266'], |
70
|
|
|
['Suporte c/ Velcro Ventilado 5\' p/ Roto 21 - Cadillac ou Kers', 56.9, 1, '001547'], |
71
|
|
|
['Toalha de Microfibra Cadillac 40x40 cm', 9.9, 1, '001554'], |
72
|
|
|
['Boina de Espuma Agressiva Azul Spider Scholl 6.5\'', 113.5, 1, 'BSA165'], |
73
|
|
|
['Ironlac Descontaminante de Superfícies Cadillac 5L', 113.9, 1, '001824'], |
74
|
|
|
['Lustrador Alto Brilho 2x1 Lincoln', 39.9, 1, '000086'], |
75
|
|
|
['Meguiars Espuma Aplicadora', 11.23, 1, '000558'], |
76
|
|
|
['Melamina Kers - Esponja Mágica', 11.9, 1, '001406'], |
77
|
|
|
['Escova Pneus Cadillac', 40.9, 1, '000573'], |
78
|
|
|
['Mini Politriz Roto Orbital Yes GFX-5802 220V + Kit Pincel Kers', 1100, 1, '002165'] |
79
|
|
|
); |
80
|
|
|
|
81
|
|
|
$this->transaction->getOrder() |
82
|
|
|
->setOrderId(date('mdHis')) |
83
|
|
|
->setCallbackUrl(getenv('CALLBACK_URL')) |
84
|
|
|
->setAmount(10.00) |
85
|
|
|
->setInstallments(1) |
86
|
|
|
->setVisitorId('9as7d8s9a7da9sd7sa9889a') |
87
|
|
|
->setAcquirerToken('1234567890') |
88
|
|
|
->setPayment($this->ipag->payment() |
89
|
|
|
->setMethod(Method::VISA) |
90
|
|
|
->setCreditCard($this->initCard()) |
91
|
|
|
)->setCustomer($this->initCustomer()) |
92
|
|
|
->setCart($cart); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function initCustomer() |
96
|
|
|
{ |
97
|
|
|
return $this->ipag->customer() |
98
|
|
|
->setName('Fulano da Silva') |
99
|
|
|
->setTaxpayerId('799.993.388-01') |
100
|
|
|
->setPhone('11', '98888-3333') |
101
|
|
|
->setEmail('[email protected]') |
102
|
|
|
->setBirthdate('1989-03-28') |
103
|
|
|
->setAddress($this->ipag->address() |
104
|
|
|
->setStreet('Rua Júlio Gonzalez') |
105
|
|
|
->setNumber('1000') |
106
|
|
|
->setNeighborhood('Barra Funda') |
107
|
|
|
->setCity('São Paulo') |
108
|
|
|
->setState('SP') |
109
|
|
|
->setZipCode('01156-060') |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function initCard() |
114
|
|
|
{ |
115
|
|
|
return $this->ipag->creditCard() |
116
|
|
|
->setNumber('4066553613548107') |
117
|
|
|
->setHolder('FULANO') |
118
|
|
|
->setExpiryMonth('10') |
119
|
|
|
->setExpiryYear('2025') |
120
|
|
|
->setCvc('123') |
121
|
|
|
->setSave(true); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function doPayment($capture = false) |
125
|
|
|
{ |
126
|
|
|
if ($capture) { |
127
|
|
|
$this->transaction->getOrder()->setCapture('c'); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
return $this->transaction->execute(); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function testExecutePaymentSuccessfully() |
134
|
|
|
{ |
135
|
|
|
$transaction = $this->doPayment(); |
136
|
|
|
|
137
|
|
|
$this->assertEquals(PaymentStatus::PRE_AUTHORIZED, $transaction->payment->status); |
138
|
|
|
$this->assertEquals(36, strlen($transaction->creditCard->token)); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function testExecutePaymentSuccessfullyWithAntifraud() |
142
|
|
|
{ |
143
|
|
|
$this->transaction->getOrder()->setAntifraud(1); |
144
|
|
|
$transaction = $this->transaction->execute(); |
145
|
|
|
|
146
|
|
|
$this->assertEquals(0.00, $transaction->antifraud->score); |
147
|
|
|
$this->assertEquals('approved', $transaction->antifraud->status); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public function testExecutePaymentWithCaptureSuccessfully() |
151
|
|
|
{ |
152
|
|
|
$transaction = $this->doPayment(true); |
153
|
|
|
|
154
|
|
|
$this->assertEquals(PaymentStatus::CAPTURED, $transaction->payment->status); |
155
|
|
|
$this->assertEquals(36, strlen($transaction->creditCard->token)); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function testExecuteSubscribePaymentSuccessfully() |
159
|
|
|
{ |
160
|
|
|
$subscription = new Subscription(); |
161
|
|
|
|
162
|
|
|
$subscription->setProfileId(time()) |
163
|
|
|
->setFrequency(1) |
164
|
|
|
->setInterval('month') |
165
|
|
|
->setStart(date('d/m/Y')); |
166
|
|
|
|
167
|
|
|
$this->transaction->getOrder()->setSubscription($subscription); |
168
|
|
|
|
169
|
|
|
$response = $this->doPayment(); |
170
|
|
|
|
171
|
|
|
$this->assertEquals(PaymentStatus::PRE_AUTHORIZED, $response->payment->status); |
172
|
|
|
$this->assertNotEmpty($response->creditCard->token); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
public function testSplitRuleWithPaymentInPercentage() |
176
|
|
|
{ |
177
|
|
|
$payment = $this->transaction->getOrder()->getPayment(); |
178
|
|
|
|
179
|
|
|
$payment->addSplitRule( |
180
|
|
|
$this->ipag->splitRule() |
181
|
|
|
->setSellerId('c66fabf44786459e81e3c65e339a4fc9') |
182
|
|
|
->setPercentage(10) |
183
|
|
|
->setChargeProcessingFee(0) |
184
|
|
|
->setLiable(1) |
185
|
|
|
); |
186
|
|
|
$payment->addSplitRule( |
187
|
|
|
$this->ipag->splitRule() |
188
|
|
|
->setSellerId('c66fabf44786459e81e3c65e339a4fc9') |
189
|
|
|
->setPercentage(15) |
190
|
|
|
->setChargeProcessingFee(0) |
191
|
|
|
->setLiable(1) |
192
|
|
|
); |
193
|
|
|
|
194
|
|
|
$response = $this->doPayment(); |
195
|
|
|
|
196
|
|
|
$this->assertEquals(PaymentStatus::PRE_AUTHORIZED, $response->payment->status); |
197
|
|
|
$this->assertNotEmpty($response->splitRules); |
198
|
|
|
$this->assertEquals(2, count($response->splitRules)); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
public function testSplitRuleWithPaymentInAmount() |
202
|
|
|
{ |
203
|
|
|
$payment = $this->transaction->getOrder()->getPayment(); |
204
|
|
|
$payment->addSplitRule( |
205
|
|
|
$this->ipag->splitRule() |
206
|
|
|
->setSellerId('c66fabf44786459e81e3c65e339a4fc9') |
207
|
|
|
->setAmount(1.00) |
208
|
|
|
->setChargeProcessingFee(0) |
209
|
|
|
->setLiable(1) |
210
|
|
|
); |
211
|
|
|
$payment->addSplitRule( |
212
|
|
|
$this->ipag->splitRule() |
213
|
|
|
->setSellerId('c66fabf44786459e81e3c65e339a4fc9') |
214
|
|
|
->setPercentage(15) |
215
|
|
|
->setChargeProcessingFee(1) |
216
|
|
|
->setLiable(1) |
217
|
|
|
); |
218
|
|
|
|
219
|
|
|
$response = $this->doPayment(); |
220
|
|
|
|
221
|
|
|
$this->assertEquals(PaymentStatus::PRE_AUTHORIZED, $response->payment->status); |
222
|
|
|
$this->assertNotEmpty($response->splitRules); |
223
|
|
|
$this->assertEquals(2, count($response->splitRules)); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
public function testReturnResponseErrorUnauthorized() |
227
|
|
|
{ |
228
|
|
|
$this->ipag = new Ipag(new Authentication('no_login_error', '123'), Endpoint::SANDBOX); |
229
|
|
|
|
230
|
|
|
$transaction = $this->ipag->transaction(); |
231
|
|
|
$transaction->getOrder() |
232
|
|
|
->setOrderId(date('mdHis')) |
233
|
|
|
->setCallbackUrl(getenv('CALLBACK_URL')) |
234
|
|
|
->setAmount(10.00) |
235
|
|
|
->setInstallments(1) |
236
|
|
|
->setPayment($this->ipag->payment() |
237
|
|
|
->setMethod(Method::VISA) |
238
|
|
|
); |
239
|
|
|
|
240
|
|
|
$response = $transaction->execute(); |
241
|
|
|
|
242
|
|
|
$this->assertEquals('401', $response->error); |
243
|
|
|
$this->assertEquals('Unauthorized', $response->errorMessage); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
public function testPaymentWithSplitHoldReceivables() |
247
|
|
|
{ |
248
|
|
|
$this->ipag = new Ipag(new Authentication('no_login_error', '123'), Endpoint::SANDBOX); |
249
|
|
|
|
250
|
|
|
$payment = $this->transaction->getOrder()->getPayment(); |
251
|
|
|
$payment->addSplitRule( |
252
|
|
|
$this->ipag->splitRule() |
253
|
|
|
->setSellerId('jabuticaba') |
254
|
|
|
->setAmount(1.00) |
255
|
|
|
->setChargeProcessingFee(0) |
256
|
|
|
->setHoldReceivables(1) |
257
|
|
|
); |
258
|
|
|
|
259
|
|
|
$response = $this->doPayment(); |
260
|
|
|
|
261
|
|
|
$this->assertEquals(1, $response->splitRules[0]->hold_receivables); |
262
|
|
|
} |
263
|
|
|
} |
264
|
|
|
|