|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Classes\Services; |
|
4
|
|
|
|
|
5
|
|
|
use Ipag\Classes\Authentication; |
|
6
|
|
|
use Ipag\Classes\Enum\Action; |
|
7
|
|
|
use Ipag\Classes\Enum\Method; |
|
8
|
|
|
use Ipag\Classes\Enum\Operation; |
|
9
|
|
|
use Ipag\Classes\Serializer\PaymentSerializer; |
|
10
|
|
|
use Ipag\Ipag; |
|
11
|
|
|
use PHPUnit\Framework\TestCase; |
|
12
|
|
|
|
|
13
|
|
|
class PaymentSerializerTest extends TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
private $ipag; |
|
16
|
|
|
private $transaction; |
|
17
|
|
|
|
|
18
|
|
|
public function setUp() |
|
19
|
|
|
{ |
|
20
|
|
|
parent::setUp(); |
|
21
|
|
|
|
|
22
|
|
|
$authentication = new Authentication('[email protected]'); |
|
23
|
|
|
|
|
24
|
|
|
$this->ipag = new Ipag($authentication); |
|
25
|
|
|
|
|
26
|
|
|
$this->transaction = $this->ipag->transaction(); |
|
27
|
|
|
|
|
28
|
|
|
$this->transaction->getOrder() |
|
29
|
|
|
->setOrderId('10000') |
|
30
|
|
|
->setCallbackUrl('https://minha_loja.com.br/ipag/callback') |
|
31
|
|
|
->setAmount(10.00) |
|
32
|
|
|
->setInstallments(1); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
private function creditCard() |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->ipag->creditCard() |
|
38
|
|
|
->setNumber('4066553613548107') |
|
39
|
|
|
->setHolder('FULANO') |
|
40
|
|
|
->setExpiryMonth('10') |
|
41
|
|
|
->setExpiryYear('2025') |
|
42
|
|
|
->setCvc('123') |
|
43
|
|
|
->setSave(true); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
private function cart() |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->ipag->cart() |
|
49
|
|
|
->addProduct($this->ipag->product() |
|
50
|
|
|
->setName('Produto 1') |
|
51
|
|
|
->setQuantity(2) |
|
52
|
|
|
->setUnitPrice(1.00) |
|
53
|
|
|
->setSku('G9F07GSD96FA8') |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
private function customer() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->ipag->customer() |
|
60
|
|
|
->setName('Fulano da Silva') |
|
61
|
|
|
->setTaxpayerId('799.993.388-01') |
|
62
|
|
|
->setPhone('11', '98888-3333') |
|
63
|
|
|
->setEmail('[email protected]') |
|
64
|
|
|
->setAddress($this->ipag->address() |
|
65
|
|
|
->setStreet('Rua Júlio Gonzalez') |
|
66
|
|
|
->setNumber('1000') |
|
67
|
|
|
->setNeighborhood('Barra Funda') |
|
68
|
|
|
->setCity('São Paulo') |
|
69
|
|
|
->setState('SP') |
|
70
|
|
|
->setZipCode('01156-060') |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
private function serializePayment($transaction, $action, $operation) |
|
|
|
|
|
|
75
|
|
|
{ |
|
76
|
|
|
return (new PaymentSerializer($transaction, Action::PAYMENT, Operation::PAYMENT))->serialize(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function testSerializeWithFullCreditCard() |
|
80
|
|
|
{ |
|
81
|
|
|
$this->ipag->getAuthentication()->setPartner('[email protected]'); |
|
82
|
|
|
|
|
83
|
|
|
$this->transaction->getOrder() |
|
84
|
|
|
->setPayment($this->ipag->payment() |
|
85
|
|
|
->setMethod(Method::VISA) |
|
86
|
|
|
->setCreditCard($this->creditCard() |
|
87
|
|
|
)->setInstructions('Instrução 1') |
|
88
|
|
|
->setInstructions('Instrução 2') |
|
89
|
|
|
->setInstructions('Instrução 3') |
|
90
|
|
|
->setSoftDescriptor('EMPRESA') |
|
91
|
|
|
)->setCustomer($this->customer()) |
|
92
|
|
|
->setCart($this->cart()); |
|
93
|
|
|
|
|
94
|
|
|
$expected = [ |
|
95
|
|
|
'identificacao' => 'app%40test.com', |
|
96
|
|
|
'identificacao2' => 'partner%40test.com', |
|
97
|
|
|
'url_retorno' => 'https%3A%2F%2Fminha_loja.com.br%2Fipag%2Fcallback', |
|
98
|
|
|
'retorno_tipo' => 'xml', |
|
99
|
|
|
'boleto_tipo' => 'xml', |
|
100
|
|
|
'pedido' => '10000', |
|
101
|
|
|
'operacao' => '', |
|
102
|
|
|
'valor' => '10', |
|
103
|
|
|
'parcelas' => '1', |
|
104
|
|
|
'vencto' => '', |
|
105
|
|
|
'stelo_fingerprint' => '', |
|
106
|
|
|
'metodo' => 'visa', |
|
107
|
|
|
'num_cartao' => '4066553613548107', |
|
108
|
|
|
'nome_cartao' => 'FULANO', |
|
109
|
|
|
'mes_cartao' => '10', |
|
110
|
|
|
'ano_cartao' => '2025', |
|
111
|
|
|
'cvv_cartao' => '123', |
|
112
|
|
|
'gera_token_cartao' => '1', |
|
113
|
|
|
'nome' => 'Fulano+da+Silva', |
|
114
|
|
|
'email' => 'fulanodasilva%40gmail.com', |
|
115
|
|
|
'doc' => '79999338801', |
|
116
|
|
|
'fone' => '11988883333', |
|
117
|
|
|
'endereco' => 'Rua+J%C3%BAlio+Gonzalez', |
|
118
|
|
|
'numero_endereco' => '1000', |
|
119
|
|
|
'complemento' => '', |
|
120
|
|
|
'bairro' => 'Barra+Funda', |
|
121
|
|
|
'cidade' => 'S%C3%A3o+Paulo', |
|
122
|
|
|
'estado' => 'SP', |
|
123
|
|
|
'pais' => 'BR', |
|
124
|
|
|
'cep' => '01156060', |
|
125
|
|
|
'instrucoes[0]' => 'Instru%C3%A7%C3%A3o+1', |
|
126
|
|
|
'instrucoes[1]' => 'Instru%C3%A7%C3%A3o+2', |
|
127
|
|
|
'instrucoes[2]' => 'Instru%C3%A7%C3%A3o+3', |
|
128
|
|
|
'softdescriptor' => 'EMPRESA', |
|
129
|
|
|
'descricao_pedido' => '%7B%221%22%3A%7B%22descr%22%3A%22Produto+1%22%2C%22valor%22%3A1%2C%22quant%22%3A2%2C%22id%22%3A%22G9F07GSD96FA8%22%7D%7D', |
|
130
|
|
|
]; |
|
131
|
|
|
|
|
132
|
|
|
$this->assertEquals( |
|
133
|
|
|
$expected, |
|
134
|
|
|
$this->serializePayment($this->transaction, Action::PAYMENT, Operation::PAYMENT) |
|
135
|
|
|
); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function testSerializeWithCreditCardToken() |
|
139
|
|
|
{ |
|
140
|
|
|
$this->transaction->getOrder() |
|
141
|
|
|
->setPayment($this->ipag->payment() |
|
142
|
|
|
->setMethod(Method::VISA) |
|
143
|
|
|
->setCreditCard($this->ipag->creditCard() |
|
144
|
|
|
->setToken('123456789') |
|
145
|
|
|
) |
|
146
|
|
|
)->setCustomer($this->customer()); |
|
147
|
|
|
|
|
148
|
|
|
$expected = [ |
|
149
|
|
|
'identificacao' => 'app%40test.com', |
|
150
|
|
|
'url_retorno' => 'https%3A%2F%2Fminha_loja.com.br%2Fipag%2Fcallback', |
|
151
|
|
|
'retorno_tipo' => 'xml', |
|
152
|
|
|
'boleto_tipo' => 'xml', |
|
153
|
|
|
'pedido' => '10000', |
|
154
|
|
|
'operacao' => '', |
|
155
|
|
|
'valor' => '10', |
|
156
|
|
|
'parcelas' => '1', |
|
157
|
|
|
'vencto' => '', |
|
158
|
|
|
'stelo_fingerprint' => '', |
|
159
|
|
|
'metodo' => 'visa', |
|
160
|
|
|
'token_cartao' => '123456789', |
|
161
|
|
|
'nome' => 'Fulano+da+Silva', |
|
162
|
|
|
'email' => 'fulanodasilva%40gmail.com', |
|
163
|
|
|
'doc' => '79999338801', |
|
164
|
|
|
'fone' => '11988883333', |
|
165
|
|
|
'endereco' => 'Rua+J%C3%BAlio+Gonzalez', |
|
166
|
|
|
'numero_endereco' => '1000', |
|
167
|
|
|
'complemento' => '', |
|
168
|
|
|
'bairro' => 'Barra+Funda', |
|
169
|
|
|
'cidade' => 'S%C3%A3o+Paulo', |
|
170
|
|
|
'estado' => 'SP', |
|
171
|
|
|
'pais' => 'BR', |
|
172
|
|
|
'cep' => '01156060', |
|
173
|
|
|
]; |
|
174
|
|
|
|
|
175
|
|
|
$this->assertEquals( |
|
176
|
|
|
$expected, |
|
177
|
|
|
$this->serializePayment($this->transaction, Action::PAYMENT, Operation::PAYMENT) |
|
178
|
|
|
); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
public function testSerializeWithoutCustomer() |
|
182
|
|
|
{ |
|
183
|
|
|
$this->transaction->getOrder() |
|
184
|
|
|
->setPayment($this->ipag->payment() |
|
185
|
|
|
->setMethod(Method::VISA) |
|
186
|
|
|
->setCreditCard($this->ipag->creditCard() |
|
187
|
|
|
->setToken('123456789') |
|
188
|
|
|
) |
|
189
|
|
|
); |
|
190
|
|
|
|
|
191
|
|
|
$expected = [ |
|
192
|
|
|
'identificacao' => 'app%40test.com', |
|
193
|
|
|
'url_retorno' => 'https%3A%2F%2Fminha_loja.com.br%2Fipag%2Fcallback', |
|
194
|
|
|
'retorno_tipo' => 'xml', |
|
195
|
|
|
'boleto_tipo' => 'xml', |
|
196
|
|
|
'pedido' => '10000', |
|
197
|
|
|
'operacao' => '', |
|
198
|
|
|
'valor' => '10', |
|
199
|
|
|
'parcelas' => '1', |
|
200
|
|
|
'vencto' => '', |
|
201
|
|
|
'stelo_fingerprint' => '', |
|
202
|
|
|
'metodo' => 'visa', |
|
203
|
|
|
'token_cartao' => '123456789', |
|
204
|
|
|
]; |
|
205
|
|
|
|
|
206
|
|
|
$this->assertEquals( |
|
207
|
|
|
$expected, |
|
208
|
|
|
$this->serializePayment($this->transaction, Action::PAYMENT, Operation::PAYMENT) |
|
209
|
|
|
); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
public function testSerializeWithoutCustomerAddress() |
|
213
|
|
|
{ |
|
214
|
|
|
$this->transaction->getOrder() |
|
215
|
|
|
->setPayment($this->ipag->payment() |
|
216
|
|
|
->setMethod(Method::VISA) |
|
217
|
|
|
->setCreditCard($this->ipag->creditCard() |
|
218
|
|
|
->setToken('123456789') |
|
219
|
|
|
) |
|
220
|
|
|
)->setCustomer($this->ipag->customer() |
|
221
|
|
|
->setName('Fulano da Silva') |
|
222
|
|
|
->setTaxpayerId('799.993.388-01') |
|
223
|
|
|
->setPhone('11', '98888-3333') |
|
224
|
|
|
->setEmail('[email protected]')); |
|
225
|
|
|
|
|
226
|
|
|
$expected = [ |
|
227
|
|
|
'identificacao' => 'app%40test.com', |
|
228
|
|
|
'url_retorno' => 'https%3A%2F%2Fminha_loja.com.br%2Fipag%2Fcallback', |
|
229
|
|
|
'retorno_tipo' => 'xml', |
|
230
|
|
|
'boleto_tipo' => 'xml', |
|
231
|
|
|
'pedido' => '10000', |
|
232
|
|
|
'operacao' => '', |
|
233
|
|
|
'valor' => '10', |
|
234
|
|
|
'parcelas' => '1', |
|
235
|
|
|
'vencto' => '', |
|
236
|
|
|
'stelo_fingerprint' => '', |
|
237
|
|
|
'metodo' => 'visa', |
|
238
|
|
|
'token_cartao' => '123456789', |
|
239
|
|
|
'nome' => 'Fulano+da+Silva', |
|
240
|
|
|
'email' => 'fulanodasilva%40gmail.com', |
|
241
|
|
|
'doc' => '79999338801', |
|
242
|
|
|
'fone' => '11988883333', |
|
243
|
|
|
]; |
|
244
|
|
|
|
|
245
|
|
|
$this->assertEquals( |
|
246
|
|
|
$expected, |
|
247
|
|
|
$this->serializePayment($this->transaction, Action::PAYMENT, Operation::PAYMENT) |
|
248
|
|
|
); |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
public function testSerializeWithoutOrderShouldThrowException() |
|
252
|
|
|
{ |
|
253
|
|
|
$this->expectException(\Exception::class); |
|
254
|
|
|
|
|
255
|
|
|
$this->serializePayment($this->ipag->transaction(), Action::PAYMENT, Operation::PAYMENT); |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
public function testSerializeWithoutPaymentShouldThrowException() |
|
259
|
|
|
{ |
|
260
|
|
|
$this->expectException(\Exception::class); |
|
261
|
|
|
|
|
262
|
|
|
$this->serializePayment($this->transaction, Action::PAYMENT, Operation::PAYMENT); |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
public function testSerializeBoletoPayment() |
|
266
|
|
|
{ |
|
267
|
|
|
$this->transaction->getOrder() |
|
268
|
|
|
->setPayment($this->ipag->payment() |
|
269
|
|
|
->setMethod(Method::BANKSLIP_ITAU) |
|
270
|
|
|
)->setCustomer($this->customer()); |
|
271
|
|
|
|
|
272
|
|
|
$expected = [ |
|
273
|
|
|
'identificacao' => 'app%40test.com', |
|
274
|
|
|
'url_retorno' => 'https%3A%2F%2Fminha_loja.com.br%2Fipag%2Fcallback', |
|
275
|
|
|
'retorno_tipo' => 'xml', |
|
276
|
|
|
'boleto_tipo' => 'xml', |
|
277
|
|
|
'pedido' => '10000', |
|
278
|
|
|
'operacao' => '', |
|
279
|
|
|
'valor' => '10', |
|
280
|
|
|
'parcelas' => '1', |
|
281
|
|
|
'vencto' => '', |
|
282
|
|
|
'stelo_fingerprint' => '', |
|
283
|
|
|
'metodo' => 'boleto_itau', |
|
284
|
|
|
'nome' => 'Fulano+da+Silva', |
|
285
|
|
|
'email' => 'fulanodasilva%40gmail.com', |
|
286
|
|
|
'doc' => '79999338801', |
|
287
|
|
|
'fone' => '11988883333', |
|
288
|
|
|
'endereco' => 'Rua+J%C3%BAlio+Gonzalez', |
|
289
|
|
|
'numero_endereco' => '1000', |
|
290
|
|
|
'complemento' => '', |
|
291
|
|
|
'bairro' => 'Barra+Funda', |
|
292
|
|
|
'cidade' => 'S%C3%A3o+Paulo', |
|
293
|
|
|
'estado' => 'SP', |
|
294
|
|
|
'pais' => 'BR', |
|
295
|
|
|
'cep' => '01156060', |
|
296
|
|
|
]; |
|
297
|
|
|
|
|
298
|
|
|
$this->assertEquals( |
|
299
|
|
|
$expected, |
|
300
|
|
|
$this->serializePayment($this->transaction, Action::PAYMENT, Operation::PAYMENT) |
|
301
|
|
|
); |
|
302
|
|
|
} |
|
303
|
|
|
|
|
304
|
|
|
public function testSerializeWithSubscription() |
|
305
|
|
|
{ |
|
306
|
|
|
$this->transaction->getOrder() |
|
307
|
|
|
->setPayment($this->ipag->payment() |
|
308
|
|
|
->setMethod(Method::VISA) |
|
309
|
|
|
->setCreditCard($this->ipag->creditCard() |
|
310
|
|
|
->setToken('123456789') |
|
311
|
|
|
) |
|
312
|
|
|
)->setCustomer($this->customer()) |
|
313
|
|
|
->setSubscription($this->ipag->subscription() |
|
314
|
|
|
->setFrequency(1) |
|
315
|
|
|
->setInterval('month') |
|
316
|
|
|
); |
|
317
|
|
|
|
|
318
|
|
|
$expected = [ |
|
319
|
|
|
'identificacao' => 'app%40test.com', |
|
320
|
|
|
'url_retorno' => 'https%3A%2F%2Fminha_loja.com.br%2Fipag%2Fcallback', |
|
321
|
|
|
'retorno_tipo' => 'xml', |
|
322
|
|
|
'boleto_tipo' => 'xml', |
|
323
|
|
|
'pedido' => '10000', |
|
324
|
|
|
'operacao' => '', |
|
325
|
|
|
'valor' => '10', |
|
326
|
|
|
'parcelas' => '1', |
|
327
|
|
|
'vencto' => '', |
|
328
|
|
|
'stelo_fingerprint' => '', |
|
329
|
|
|
'metodo' => 'visa', |
|
330
|
|
|
'token_cartao' => '123456789', |
|
331
|
|
|
'nome' => 'Fulano+da+Silva', |
|
332
|
|
|
'email' => 'fulanodasilva%40gmail.com', |
|
333
|
|
|
'doc' => '79999338801', |
|
334
|
|
|
'fone' => '11988883333', |
|
335
|
|
|
'endereco' => 'Rua+J%C3%BAlio+Gonzalez', |
|
336
|
|
|
'numero_endereco' => '1000', |
|
337
|
|
|
'complemento' => '', |
|
338
|
|
|
'bairro' => 'Barra+Funda', |
|
339
|
|
|
'cidade' => 'S%C3%A3o+Paulo', |
|
340
|
|
|
'estado' => 'SP', |
|
341
|
|
|
'pais' => 'BR', |
|
342
|
|
|
'cep' => '01156060', |
|
343
|
|
|
'profile_id' => '', |
|
344
|
|
|
'frequencia' => '1', |
|
345
|
|
|
'intervalo' => 'month', |
|
346
|
|
|
'inicio' => '', |
|
347
|
|
|
'ciclos' => '', |
|
348
|
|
|
'valor_rec' => '', |
|
349
|
|
|
'trial' => '', |
|
350
|
|
|
'trial_ciclos' => '', |
|
351
|
|
|
'trial_frequencia' => '', |
|
352
|
|
|
'trial_valor' => '', |
|
353
|
|
|
]; |
|
354
|
|
|
|
|
355
|
|
|
$this->assertEquals( |
|
356
|
|
|
$expected, |
|
357
|
|
|
$this->serializePayment($this->transaction, Action::PAYMENT, Operation::PAYMENT) |
|
358
|
|
|
); |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
|
|
public function testSerializePaymentWithEmptyOrder() |
|
362
|
|
|
{ |
|
363
|
|
|
$this->expectException(\Exception::class); |
|
364
|
|
|
$this->expectExceptionMessage('É necessário informar os dados do Pedido (Order)'); |
|
365
|
|
|
|
|
366
|
|
|
$this->serializePayment($this->ipag->transaction(), Action::PAYMENT, Operation::PAYMENT); |
|
367
|
|
|
} |
|
368
|
|
|
} |
|
369
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.