1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Classes\Services; |
4
|
|
|
|
5
|
|
|
use Ipag\Classes\Services\CallbackService; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use stdClass; |
8
|
|
|
|
9
|
|
|
class CallbackServiceTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
public function setUp() |
12
|
|
|
{ |
13
|
|
|
parent::setUp(); |
14
|
|
|
|
15
|
|
|
$this->callbackService = new CallbackService(); |
|
|
|
|
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
private function xmlDummyResponse() |
19
|
|
|
{ |
20
|
|
|
return '<?xml version="1.0" encoding="utf-8" ?> |
21
|
|
|
<retorno> |
22
|
|
|
<id_transacao>123456789</id_transacao> |
23
|
|
|
<valor>10.00</valor> |
24
|
|
|
<num_pedido>123456</num_pedido> |
25
|
|
|
<status_pagamento>8</status_pagamento> |
26
|
|
|
<mensagem_transacao>Transação Autorizada</mensagem_transacao> |
27
|
|
|
<metodo>visa</metodo> |
28
|
|
|
<operadora>cielo</operadora> |
29
|
|
|
<operadora_mensagem>Transação autorizada</operadora_mensagem> |
30
|
|
|
<id_librepag>12345</id_librepag> |
31
|
|
|
<autorizacao_id>123456</autorizacao_id> |
32
|
|
|
<redirect>false</redirect> |
33
|
|
|
<url_autenticacao>https://minhaloja.com.br/ipag/retorno</url_autenticacao> |
34
|
|
|
</retorno>'; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testGetResponse() |
38
|
|
|
{ |
39
|
|
|
$expected = new stdClass(); |
40
|
|
|
$expected->tid = '123456789'; |
41
|
|
|
$expected->amount = 10.00; |
42
|
|
|
|
43
|
|
|
$expected->payment = new stdClass(); |
44
|
|
|
$expected->payment->status = '8'; |
45
|
|
|
|
46
|
|
|
$response = $this->callbackService->getResponse($this->xmlDummyResponse()); |
47
|
|
|
|
48
|
|
|
$this->assertInstanceOf('stdClass', $response); |
49
|
|
|
$this->assertEquals($expected->tid, $response->tid); |
50
|
|
|
$this->assertEquals($expected->amount, $response->amount); |
51
|
|
|
$this->assertEquals($expected->payment->status, $response->payment->status); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|