|
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_bankaccount_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
|
|
|
->setAmount($amount) |
|
23
|
|
|
->transferToBankAccount($bank_number, $agency_number, $agency_check_number, $account_number, $account_check_number) |
|
24
|
|
|
->setHolder($holder_name, $tax_document) |
|
25
|
|
|
->execute(); |
|
26
|
|
|
|
|
27
|
|
|
return $transfer; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
View Code Duplication |
private function createBankAccount() |
|
|
|
|
|
|
31
|
|
|
{ |
|
32
|
|
|
$this->mockHttpSession($this->body_bank_account_create); |
|
33
|
|
|
|
|
34
|
|
|
$account_id = 'MPA-3C5358FF2296'; |
|
35
|
|
|
|
|
36
|
|
|
$bank_account = $this->moip->bankaccount() |
|
37
|
|
|
->setBankNumber('237') |
|
38
|
|
|
->setAgencyNumber('12345') |
|
39
|
|
|
->setAgencyCheckNumber('0') |
|
40
|
|
|
->setAccountNumber('12345678') |
|
41
|
|
|
->setAccountCheckNumber('7') |
|
42
|
|
|
->setType('CHECKING') |
|
43
|
|
|
->setHolder('Demo Moip', '622.134.533-22', 'CPF') |
|
44
|
|
|
->create($account_id); |
|
45
|
|
|
|
|
46
|
|
|
return $bank_account; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testShouldCreateTransfer() |
|
50
|
|
|
{ |
|
51
|
|
|
$transfer = $this->createTransfer(); |
|
52
|
|
|
$this->assertNotEmpty($transfer->getId()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
View Code Duplication |
public function testShouldCreateTransferWithBankAccountId() |
|
|
|
|
|
|
56
|
|
|
{ |
|
57
|
|
|
$bank_account = $this->createBankAccount(); |
|
58
|
|
|
|
|
59
|
|
|
$this->mockHttpSession($this->body_transfers_bankaccount_create); |
|
60
|
|
|
|
|
61
|
|
|
$amount = 500; |
|
62
|
|
|
$transfer = $this->moip->transfers() |
|
63
|
|
|
->setAmount($amount) |
|
64
|
|
|
->transferWithBankAccountId($bank_account->getId()) |
|
65
|
|
|
->execute(); |
|
66
|
|
|
|
|
67
|
|
|
$this->assertNotEmpty($transfer->getId()); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
View Code Duplication |
public function testShouldCreateTransferWithMoipAccountId() |
|
|
|
|
|
|
71
|
|
|
{ |
|
72
|
|
|
$this->mockHttpSession($this->body_transfers_moipaccount_create); |
|
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
$ammount = 500; |
|
75
|
|
|
$moipAccountId = 'MPA-5E1C4C369E8C'; |
|
76
|
|
|
$transfer = $this->moip->transfers() |
|
77
|
|
|
->setAmount($ammount) |
|
78
|
|
|
->transferToMoipAccount($moipAccountId) |
|
79
|
|
|
->execute(); |
|
80
|
|
|
|
|
81
|
|
|
$this->assertNotEmpty($transfer->getAmount()); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function testShouldGetTransfer() |
|
85
|
|
|
{ |
|
86
|
|
|
$transfer_id = $this->createTransfer()->getId(); |
|
87
|
|
|
|
|
88
|
|
|
$this->mockHttpSession($this->body_transfers_bankaccount_create); |
|
89
|
|
|
|
|
90
|
|
|
$transfer = $this->moip->transfers()->get($transfer_id); |
|
91
|
|
|
$this->assertEquals($transfer_id, $transfer->getId()); |
|
92
|
|
|
|
|
93
|
|
|
$transfer_data = $transfer->getTransfers(); |
|
94
|
|
|
$this->assertEquals(500, $transfer_data->amount); |
|
95
|
|
|
|
|
96
|
|
|
$transfer_instrument = $transfer_data->transferInstrument; |
|
97
|
|
|
$this->assertEquals('BANK_ACCOUNT', $transfer_instrument->method); |
|
98
|
|
|
|
|
99
|
|
|
$bank_account = $transfer_instrument->bankAccount; |
|
100
|
|
|
$this->assertEquals('001', $bank_account->bankNumber); |
|
101
|
|
|
$this->assertEquals('1111', $bank_account->agencyNumber); |
|
102
|
|
|
$this->assertEquals('2', $bank_account->agencyCheckNumber); |
|
103
|
|
|
$this->assertEquals('9999', $bank_account->accountNumber); |
|
104
|
|
|
$this->assertEquals('8', $bank_account->accountCheckNumber); |
|
105
|
|
|
|
|
106
|
|
|
$holder = $transfer->getHolder(); |
|
107
|
|
|
$this->assertEquals('Integração Taxa por canal', $holder->fullname); |
|
108
|
|
|
|
|
109
|
|
|
$tax_document = $holder->taxDocument; |
|
110
|
|
|
$this->assertEquals('033.575.852-51', $tax_document->number); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function testShouldRevertTransfer() |
|
114
|
|
|
{ |
|
115
|
|
|
$transfer_id = $this->createTransfer()->getId(); |
|
116
|
|
|
|
|
117
|
|
|
$this->mockHttpSession($this->body_transfers_revert); |
|
118
|
|
|
|
|
119
|
|
|
$transfer = $this->moip->transfers()->revert($transfer_id); |
|
120
|
|
|
$this->assertNotEmpty($transfer->getId()); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: