1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Moip\Tests\Resource; |
4
|
|
|
|
5
|
|
|
use Moip\Tests\TestCase; |
6
|
|
|
|
7
|
|
|
class TransfersTest extends TestCase |
8
|
|
|
{ |
9
|
|
|
private function createTransfer() |
10
|
|
|
{ |
11
|
|
|
$this->mockHttpSession($this->body_transfers_create); |
12
|
|
|
|
13
|
|
|
$amount = 500; |
14
|
|
|
$bank_number = '001'; |
15
|
|
|
$agency_number = '1111'; |
16
|
|
|
$agency_check_number = '2'; |
17
|
|
|
$account_number = '9999'; |
18
|
|
|
$account_check_number = '8'; |
19
|
|
|
$holder_name = 'Integração Taxa por canal'; |
20
|
|
|
$tax_document = '033.575.852-51'; |
21
|
|
|
$transfer = $this->moip->transfers() |
22
|
|
|
->setTransfers($amount, $bank_number, $agency_number, $agency_check_number, $account_number, $account_check_number) |
23
|
|
|
->setHolder($holder_name, $tax_document) |
24
|
|
|
->execute(); |
25
|
|
|
|
26
|
|
|
return $transfer; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
View Code Duplication |
private function createBankAccount() |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
$this->mockHttpSession($this->body_bank_account_create); |
32
|
|
|
|
33
|
|
|
$account_id = 'MPA-3C5358FF2296'; |
34
|
|
|
|
35
|
|
|
$bank_account = $this->moip->bankaccount() |
36
|
|
|
->setBankNumber('237') |
37
|
|
|
->setAgencyNumber('12345') |
38
|
|
|
->setAgencyCheckNumber('0') |
39
|
|
|
->setAccountNumber('12345678') |
40
|
|
|
->setAccountCheckNumber('7') |
41
|
|
|
->setType('CHECKING') |
42
|
|
|
->setHolder('Demo Moip', '622.134.533-22', 'CPF') |
43
|
|
|
->create($account_id); |
44
|
|
|
|
45
|
|
|
return $bank_account; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testShouldCreateTransfer() |
49
|
|
|
{ |
50
|
|
|
$transfer = $this->createTransfer(); |
51
|
|
|
$this->assertNotEmpty($transfer->getId()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testShouldCreateTransferWithBankAccountId() |
55
|
|
|
{ |
56
|
|
|
$bank_account = $this->createBankAccount(); |
57
|
|
|
|
58
|
|
|
$this->mockHttpSession($this->body_transfers_create); |
59
|
|
|
|
60
|
|
|
$amount = 500; |
61
|
|
|
$transfer = $this->moip->transfers() |
62
|
|
|
->setTransfersToBankAccount($amount, $bank_account->getId()) |
63
|
|
|
->execute(); |
64
|
|
|
|
65
|
|
|
$this->assertNotEmpty($transfer->getId()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testShouldGetTransfer() |
69
|
|
|
{ |
70
|
|
|
$transfer_id = $this->createTransfer()->getId(); |
71
|
|
|
|
72
|
|
|
$this->mockHttpSession($this->body_transfers_create); |
73
|
|
|
|
74
|
|
|
$transfer = $this->moip->transfers()->get($transfer_id); |
75
|
|
|
$this->assertEquals($transfer_id, $transfer->getId()); |
76
|
|
|
|
77
|
|
|
$transfer_data = $transfer->getTransfers(); |
78
|
|
|
$this->assertEquals(500, $transfer_data->amount); |
79
|
|
|
|
80
|
|
|
$transfer_instrument = $transfer_data->transferInstrument; |
81
|
|
|
$this->assertEquals('BANK_ACCOUNT', $transfer_instrument->method); |
82
|
|
|
|
83
|
|
|
$bank_account = $transfer_instrument->bankAccount; |
84
|
|
|
$this->assertEquals('001', $bank_account->bankNumber); |
85
|
|
|
$this->assertEquals('1111', $bank_account->agencyNumber); |
86
|
|
|
$this->assertEquals('2', $bank_account->agencyCheckNumber); |
87
|
|
|
$this->assertEquals('9999', $bank_account->accountNumber); |
88
|
|
|
$this->assertEquals('8', $bank_account->accountCheckNumber); |
89
|
|
|
|
90
|
|
|
$holder = $transfer->getHolder(); |
91
|
|
|
$this->assertEquals('Integração Taxa por canal', $holder->fullname); |
92
|
|
|
|
93
|
|
|
$tax_document = $holder->taxDocument; |
94
|
|
|
$this->assertEquals('033.575.852-51', $tax_document->number); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function testShouldRevertTransfer() |
98
|
|
|
{ |
99
|
|
|
$transfer_id = $this->createTransfer()->getId(); |
100
|
|
|
|
101
|
|
|
$this->mockHttpSession($this->body_transfers_revert); |
102
|
|
|
|
103
|
|
|
$transfer = $this->moip->transfers()->revert($transfer_id); |
104
|
|
|
$this->assertNotEmpty($transfer->getId()); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.