mangopay 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/README.md +43 -14
  4. data/lib/mangopay.rb +43 -34
  5. data/lib/mangopay/authorization_token.rb +76 -0
  6. data/lib/mangopay/bank_account.rb +14 -7
  7. data/lib/mangopay/client.rb +11 -17
  8. data/lib/mangopay/errors.rb +22 -2
  9. data/lib/mangopay/http_calls.rb +24 -2
  10. data/lib/mangopay/legal_user.rb +1 -1
  11. data/lib/mangopay/natural_user.rb +1 -1
  12. data/lib/mangopay/payin.rb +2 -2
  13. data/lib/mangopay/payout.rb +1 -1
  14. data/lib/mangopay/resource.rb +1 -1
  15. data/lib/mangopay/transaction.rb +17 -2
  16. data/lib/mangopay/version.rb +1 -1
  17. data/spec/lib/mangopay/authorization_token_spec.rb +72 -0
  18. data/spec/lib/mangopay/bank_account_spec.rb +25 -26
  19. data/spec/lib/mangopay/card_registration_spec.rb +40 -16
  20. data/spec/lib/mangopay/client_spec.rb +14 -9
  21. data/spec/lib/mangopay/configuration_spec.rb +20 -0
  22. data/spec/lib/mangopay/fetch_filters_spec.rb +65 -0
  23. data/spec/lib/mangopay/payin_card_direct_spec.rb +70 -0
  24. data/spec/lib/mangopay/payin_card_web_spec.rb +53 -0
  25. data/spec/lib/mangopay/payout_bankwire_spec.rb +56 -0
  26. data/spec/lib/mangopay/shared_resources.rb +123 -82
  27. data/spec/lib/mangopay/transaction_spec.rb +48 -2
  28. data/spec/lib/mangopay/transfer_spec.rb +51 -15
  29. data/spec/lib/mangopay/user_spec.rb +1 -0
  30. data/spec/lib/mangopay/wallet_spec.rb +31 -32
  31. data/spec/spec_helper.rb +11 -4
  32. data/spec/tmp/.keep +0 -0
  33. metadata +17 -8
  34. data/spec/lib/mangopay/card_spec.rb +0 -35
  35. data/spec/lib/mangopay/payin_spec.rb +0 -34
  36. data/spec/lib/mangopay/payout_spec.rb +0 -34
@@ -0,0 +1,53 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe MangoPay::PayIn::Card::Web, type: :feature do
4
+ include_context 'payins'
5
+
6
+ def check_type_and_status(payin)
7
+ expect(payin['Type']).to eq('PAYIN')
8
+ expect(payin['Nature']).to eq('REGULAR')
9
+ expect(payin['PaymentType']).to eq('CARD')
10
+ expect(payin['ExecutionType']).to eq('WEB')
11
+
12
+ # not SUCCEEDED yet: waiting for processing
13
+ expect(payin['Status']).to eq('CREATED')
14
+ expect(payin['ResultCode']).to be_nil
15
+ expect(payin['ResultMessage']).to be_nil
16
+ expect(payin['ExecutionDate']).to be_nil
17
+ end
18
+
19
+ describe 'CREATE' do
20
+ it 'creates a card web payin' do
21
+ created = new_payin_card_web
22
+ expect(created['Id']).not_to be_nil
23
+ check_type_and_status(created)
24
+ end
25
+ end
26
+
27
+ describe 'FETCH' do
28
+ it 'fetches a payin' do
29
+ created = new_payin_card_web
30
+ fetched = MangoPay::PayIn.fetch(created['Id'])
31
+ expect(fetched['Id']).to eq(created['Id'])
32
+ expect(fetched['CreationDate']).to eq(created['CreationDate'])
33
+ expect(fetched['CreditedFunds']).to eq(created['CreditedFunds'])
34
+ expect(fetched['CreditedWalletId']).to eq(created['CreditedWalletId'])
35
+ check_type_and_status(created)
36
+ check_type_and_status(fetched)
37
+ end
38
+ end
39
+
40
+ describe 'REFUND' do
41
+ it 'refunds a payin' do
42
+ payin = new_payin_card_web
43
+ expect {
44
+ MangoPay::PayIn.refund(payin['Id'], {AuthorId: payin['AuthorId']})
45
+ }.to raise_error { |err|
46
+ err.should be_a MangoPay::ResponseError
47
+ err.type.should eq 'other'
48
+ err.message.should eq "Impossible to refund the transaction, can't have negative amount."
49
+ }
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,56 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe MangoPay::PayOut::BankWire, type: :feature do
4
+ include_context 'bank_accounts'
5
+ include_context 'payins'
6
+ include_context 'payouts'
7
+
8
+ def check_type_and_status(payout)
9
+ expect(payout['Type']).to eq('PAYOUT')
10
+ expect(payout['Nature']).to eq('REGULAR')
11
+ expect(payout['PaymentType']).to eq('BANK_WIRE')
12
+
13
+ # linked to correct bank account
14
+ expect(payout['BankAccountId']).to eq(new_bank_account['Id'])
15
+
16
+ # not SUCCEEDED yet: waiting for processing
17
+ expect(payout['Status']).to eq('CREATED')
18
+ expect(payout['ResultCode']).to be_nil
19
+ expect(payout['ResultMessage']).to be_nil
20
+ expect(payout['ExecutionDate']).to be_nil
21
+ end
22
+
23
+ describe 'CREATE' do
24
+
25
+ it 'creates a bank wire payout' do
26
+ payin = new_payin_card_direct # this payin is successfull so payout may happen
27
+ payout = create_new_payout_bankwire(payin)
28
+ expect(payout['Id']).not_to be_nil
29
+ check_type_and_status(payout)
30
+ expect(payout['DebitedWalletId']).to eq(payin['CreditedWalletId'])
31
+ end
32
+
33
+ it 'fails if not enough money' do
34
+ payin = new_payin_card_web # this payin is NOT processed yet so payout may NOT happen
35
+ expect {
36
+ create_new_payout_bankwire(payin)
37
+ }.to raise_error { |err|
38
+ err.should be_a MangoPay::ResponseError
39
+ err.type.should eq 'other'
40
+ err.message.should eq 'The amount you wish to spend must be smaller than the amount left in your collection.'
41
+ }
42
+ end
43
+ end
44
+
45
+ describe 'FETCH' do
46
+ it 'fetches a payout' do
47
+ created = new_payout_bankwire
48
+ fetched = MangoPay::PayOut.fetch(created['Id'])
49
+ expect(fetched['Id']).to eq(created['Id'])
50
+ expect(fetched['CreationDate']).to eq(created['CreationDate'])
51
+ check_type_and_status(created)
52
+ check_type_and_status(fetched)
53
+ end
54
+ end
55
+
56
+ end
@@ -1,4 +1,8 @@
1
+ ###############################################
1
2
  shared_context 'clients' do
3
+ ###############################################
4
+
5
+ require 'securerandom'
2
6
 
3
7
  let(:client_id) {
4
8
  SecureRandom.hex(10)
@@ -25,11 +29,13 @@ shared_context 'clients' do
25
29
  }
26
30
  end
27
31
 
32
+ ###############################################
28
33
  shared_context 'users' do
34
+ ###############################################
29
35
 
30
36
  let(:new_natural_user) {
31
37
  MangoPay::NaturalUser.create({
32
- Tag: 'test',
38
+ Tag: 'Test natural user',
33
39
  Email: 'my@email.com',
34
40
  FirstName: 'John',
35
41
  LastName: 'Doe',
@@ -62,132 +68,167 @@ shared_context 'users' do
62
68
  }
63
69
  end
64
70
 
71
+ ###############################################
65
72
  shared_context 'wallets' do
73
+ ###############################################
74
+ include_context 'users'
66
75
 
67
- let(:new_wallet) {
76
+ let(:new_wallet) { create_new_wallet(new_natural_user) }
77
+ let(:new_wallet_legal) { create_new_wallet(new_legal_user) }
78
+ def create_new_wallet(user)
68
79
  MangoPay::Wallet.create({
69
- Owners: [new_natural_user['Id']],
80
+ Owners: [user['Id']],
70
81
  Description: 'A test wallet',
71
82
  Currency: 'EUR',
72
- Tag: 'Test Time'
83
+ Tag: 'Test wallet'
73
84
  })
74
- }
85
+ end
86
+
87
+ def wallets_check_amounts(wlt1, amnt1, wlt2 = nil, amnt2 = nil)
88
+ expect(wlt1['Balance']['Amount']).to eq amnt1
89
+ expect(wlt2['Balance']['Amount']).to eq amnt2 if wlt2
90
+ end
91
+
92
+ def wallets_reload_and_check_amounts(wlt1, amnt1, wlt2 = nil, amnt2 = nil)
93
+ wlt1 = MangoPay::Wallet::fetch(wlt1['Id'])
94
+ wlt2 = MangoPay::Wallet::fetch(wlt2['Id']) if wlt2
95
+ wallets_check_amounts(wlt1, amnt1, wlt2, amnt2)
96
+ end
75
97
  end
76
98
 
77
- shared_context 'bank_details' do
99
+ ###############################################
100
+ shared_context 'bank_accounts' do
101
+ ###############################################
102
+ include_context 'users'
78
103
 
79
- let(:new_iban_bank_detail) {
104
+ let(:new_bank_account) {
80
105
  MangoPay::BankAccount.create(new_natural_user['Id'], {
81
106
  Type: 'IBAN',
82
107
  OwnerName: 'John',
83
108
  OwnerAddress: 'Here',
84
109
  IBAN: 'FR76 1790 6000 3200 0833 5232 973',
85
110
  BIC: 'AGRIFRPP879',
86
- Tag: 'Test Time'
111
+ Tag: 'Test bank account'
87
112
  })
88
113
  }
89
114
  end
90
115
 
91
- shared_context 'payin_card_web' do
116
+ ###############################################
117
+ shared_context 'payins' do
118
+ ###############################################
119
+ include_context 'users'
120
+ include_context 'wallets'
121
+
122
+ ###############################################
123
+ # card/web
124
+ ###############################################
125
+
92
126
  let(:new_payin_card_web) {
93
- card = MangoPay::PayIn::Card::Web.create({
127
+ MangoPay::PayIn::Card::Web.create({
94
128
  AuthorId: new_natural_user['Id'],
95
129
  CreditedUserId: new_wallet['Owners'][0],
130
+ CreditedWalletId: new_wallet['Id'],
96
131
  DebitedFunds: { Currency: 'EUR', Amount: 1000 },
97
132
  Fees: { Currency: 'EUR', Amount: 0 },
98
- CreditedWalletId: new_wallet['Id'],
99
133
  CardType: 'CB_VISA_MASTERCARD',
100
134
  ReturnURL: MangoPay.configuration.root_url,
101
135
  Culture: 'FR',
102
136
  Tag: 'Test PayIn/Card/Web'
103
137
  })
104
- # visit(card['RedirectURL'])
105
- # fill_in('number', with: '4970100000000154')
106
- # fill_in('cvv', with: '123')
107
- # click_button('paybutton')
108
- # card = MangoPay::PayIn.fetch(card['Id'])
109
- # while card["Status"] == 'CREATED' do
110
- # card = MangoPay::PayIn.fetch(card['Id'])
111
- # end
112
- card
113
138
  }
114
- end
115
139
 
116
- shared_context 'payout_bankwire' do
117
- let(:new_payout_bankwire){
118
- MangoPay::PayOut::BankWire.create({
119
- AuthorId: new_payin_card_web['CreditedUserId'],
120
- DebitedFunds: { Currency: 'EUR', Amount: 500 },
121
- Fees: { Currency: 'EUR', Amount: 0 },
122
- DebitedWalletId: new_payin_card_web['CreditedWalletId'],
123
- BankAccountId: new_iban_bank_detail['Id'],
124
- Communication: 'This is a test',
125
- Tag: 'Test Bank Wire'
126
- })
127
- }
128
- end
140
+ ###############################################
141
+ # card/direct
142
+ ###############################################
129
143
 
130
- shared_context 'transfer' do
131
- let(:credited_wallet) {
132
- MangoPay::Wallet.create({
133
- Owners: [new_natural_user['Id']],
134
- Description: 'A test wallet',
144
+ let(:new_card_registration) {
145
+ MangoPay::CardRegistration.create({
146
+ UserId: new_natural_user['Id'],
135
147
  Currency: 'EUR',
136
- Tag: 'Test Time'
148
+ Tag: 'Test Card Registration'
137
149
  })
138
150
  }
139
151
 
140
- let(:debited_wallet) {
141
- MangoPay::Wallet.create({
142
- Owners: [new_legal_user['Id']],
143
- Description: 'A test wallet',
144
- Currency: 'EUR',
145
- Tag: 'Test Time'
152
+ let(:new_card_registration_completed) {
153
+ # 1st step: create
154
+ cardreg = new_card_registration
155
+
156
+ # 2nd step: tokenize by payline (fills-in RegistrationData)
157
+ data = {
158
+ data: cardreg['PreregistrationData'],
159
+ accessKeyRef: cardreg['AccessKey'],
160
+ cardNumber: 4970101122334406,
161
+ cardExpirationDate: 1214,
162
+ cardCvx: 123}
163
+ res = Net::HTTP.post_form(URI(cardreg['CardRegistrationURL']), data)
164
+ raise Exception, [res, res.body] unless (res.is_a?(Net::HTTPOK) && res.body.start_with?('data='))
165
+ cardreg['RegistrationData'] = res.body
166
+
167
+ # 3rd step: update (fills-in CardId) and return it
168
+ MangoPay::CardRegistration.update(cardreg['Id'], {
169
+ RegistrationData: cardreg['RegistrationData']
146
170
  })
147
171
  }
148
172
 
149
- let(:web_card_contribution) {
150
- card = MangoPay::PayIn::Card::Web.create({
151
- AuthorId: debited_wallet['Owners'][0],
152
- CreditedUserId: debited_wallet['Owners'][0],
153
- DebitedFunds: { Currency: 'EUR', Amount: 1000 },
173
+ let(:new_payin_card_direct) { create_new_payin_card_direct(new_wallet) }
174
+ def create_new_payin_card_direct(to_wallet, amnt = 1000)
175
+ cardreg = new_card_registration_completed
176
+ MangoPay::PayIn::Card::Direct.create({
177
+ AuthorId: new_natural_user['Id'],
178
+ CreditedUserId: to_wallet['Owners'][0],
179
+ CreditedWalletId: to_wallet['Id'],
180
+ DebitedFunds: { Currency: 'EUR', Amount: amnt },
154
181
  Fees: { Currency: 'EUR', Amount: 0 },
155
- CreditedWalletId: debited_wallet['Id'],
156
182
  CardType: 'CB_VISA_MASTERCARD',
157
- ReturnURL: MangoPay.configuration.root_url,
158
- Culture: 'FR',
159
- Tag: 'Test PayIn/Card/Web'
183
+ CardId: cardreg['CardId'],
184
+ SecureModeReturnURL: 'http://test.com',
185
+ Tag: 'Test PayIn/Card/Direct'
160
186
  })
161
- # visit(card['RedirectURL'])
162
- # fill_in('number', with: '4970100000000154')
163
- # fill_in('cvv', with: '123')
164
- # click_button('paybutton')
165
- # card = MangoPay::PayIn.fetch(card['Id'])
166
- # while card["Status"] == 'CREATED' do
167
- # card = MangoPay::PayIn.fetch(card['Id'])
168
- # end
169
- card
170
- }
187
+ end
171
188
 
172
- let(:new_transfer) {
173
- MangoPay::Transfer.create({
174
- AuthorId: web_card_contribution['CreditedUserId'],
175
- CreditedUserId: credited_wallet['Owners'][0],
176
- DebitedFunds: { Currency: 'EUR', Amount: 500},
177
- Fees: { Currency: 'EUR', Amout: 0},
178
- DebitedWalletId: web_card_contribution['CreditedWalletId'],
179
- CreditedWalletId: credited_wallet['Id'],
180
- Tag: 'Test Transfer'
181
- })
182
- }
183
189
  end
184
190
 
185
- shared_context 'card_registration' do
186
- let(:new_card_registration) {
187
- MangoPay::CardRegistration.create({
188
- UserId: new_natural_user['Id'],
189
- Currency: 'EUR',
190
- Tag: 'Test Card Registration'
191
+ ###############################################
192
+ shared_context 'payouts' do
193
+ ###############################################
194
+ include_context 'bank_accounts'
195
+
196
+ let(:new_payout_bankwire) { create_new_payout_bankwire(new_payin_card_direct) }
197
+ def create_new_payout_bankwire(payin, amnt = 500)
198
+ MangoPay::PayOut::BankWire.create({
199
+ AuthorId: payin['CreditedUserId'],
200
+ DebitedWalletId: payin['CreditedWalletId'],
201
+ DebitedFunds: { Currency: 'EUR', Amount: amnt },
202
+ Fees: { Currency: 'EUR', Amount: 0 },
203
+ BankAccountId: new_bank_account['Id'],
204
+ Communication: 'This is a test',
205
+ Tag: 'Test PayOut/Bank/Wire'
191
206
  })
207
+ end
208
+ end
209
+
210
+ ###############################################
211
+ shared_context 'transfers' do
212
+ ###############################################
213
+ include_context 'users'
214
+ include_context 'wallets'
215
+ include_context 'payins'
216
+
217
+ let(:new_transfer) {
218
+ wlt1 = new_wallet
219
+ wlt2 = new_wallet_legal
220
+ create_new_payin_card_direct(wlt1, 1000) # feed wlt1 with money
221
+ create_new_transfer(wlt1, wlt2, 500) # transfer wlt1 => wlt2
192
222
  }
223
+ def create_new_transfer(from_wallet, to_wallet, amnt = 500)
224
+ MangoPay::Transfer.create({
225
+ AuthorId: from_wallet['Owners'][0],
226
+ DebitedWalletId: from_wallet['Id'],
227
+ CreditedUserId: to_wallet['Owners'][0],
228
+ CreditedWalletId: to_wallet['Id'],
229
+ DebitedFunds: { Currency: 'EUR', Amount: amnt},
230
+ Fees: { Currency: 'EUR', Amout: 0},
231
+ Tag: 'Test transfer'
232
+ })
233
+ end
193
234
  end
@@ -1,14 +1,60 @@
1
1
  require_relative '../../spec_helper'
2
2
 
3
3
  describe MangoPay::Transaction do
4
- include_context 'users'
5
4
  include_context 'wallets'
5
+ include_context 'payins'
6
+ include_context 'payouts'
6
7
 
7
8
  describe 'FETCH' do
8
- it 'fetches the an empty list of transactions' do
9
+
10
+ it 'fetches empty list of transactions if no transactions done' do
9
11
  transactions = MangoPay::Transaction.fetch(new_wallet['Id'])
10
12
  expect(transactions).to be_kind_of(Array)
11
13
  expect(transactions).to be_empty
12
14
  end
15
+
16
+ it 'fetches list with single transaction after payin done' do
17
+ payin = new_payin_card_direct
18
+ transactions = MangoPay::Transaction.fetch(new_wallet['Id'])
19
+ expect(transactions).to be_kind_of(Array)
20
+ expect(transactions.count).to eq 1
21
+ expect(transactions.first['Id']).to eq payin['Id']
22
+ end
23
+
24
+ it 'fetches list with two transactions after payin and payout done' do
25
+ payin = new_payin_card_direct
26
+ payout = create_new_payout_bankwire(payin)
27
+ transactions = MangoPay::Transaction.fetch(new_wallet['Id'])
28
+ expect(transactions).to be_kind_of(Array)
29
+ expect(transactions.count).to eq 2
30
+ expect(transactions[0]['Id']).to eq payout['Id'] # last on top, so payout is before payin
31
+ expect(transactions[1]['Id']).to eq payin['Id']
32
+ end
33
+
34
+ it 'accepts filtering params' do
35
+ payin = new_payin_card_direct
36
+ payout = create_new_payout_bankwire(payin)
37
+ wallet_id = new_wallet['Id']
38
+
39
+ by_nature_reg = MangoPay::Transaction.fetch(wallet_id, {'Nature' => 'REGULAR'})
40
+ by_nature_ref = MangoPay::Transaction.fetch(wallet_id, {'Nature' => 'REFUND'})
41
+ expect(by_nature_reg.count).to eq 2
42
+ expect(by_nature_ref.count).to eq 0
43
+
44
+ by_type_pyin = MangoPay::Transaction.fetch(wallet_id, {'Type' => 'PAYIN'})
45
+ by_type_pyout = MangoPay::Transaction.fetch(wallet_id, {'Type' => 'PAYOUT'})
46
+ expect(by_type_pyin.count).to eq 1
47
+ expect(by_type_pyout.count).to eq 1
48
+ expect(by_type_pyin.first['Id']).to eq payin['Id']
49
+ expect(by_type_pyout.first['Id']).to eq payout['Id']
50
+
51
+ by_dir_cred = MangoPay::Transaction.fetch(wallet_id, {'Direction' => 'CREDIT'})
52
+ by_dir_debt = MangoPay::Transaction.fetch(wallet_id, {'Direction' => 'DEBIT'})
53
+ expect(by_dir_cred.count).to eq 1
54
+ expect(by_dir_debt.count).to eq 1
55
+ expect(by_dir_cred.first['Id']).to eq payin['Id']
56
+ expect(by_dir_debt.first['Id']).to eq payout['Id']
57
+ end
58
+
13
59
  end
14
60
  end
@@ -1,35 +1,71 @@
1
1
  require_relative '../../spec_helper'
2
2
 
3
3
  describe MangoPay::Transfer, type: :feature do
4
- include_context 'users'
5
4
  include_context 'wallets'
6
- include_context 'transfer'
5
+ include_context 'payins'
6
+ include_context 'transfers'
7
+
8
+ def check_type_and_status(trans)
9
+ expect(trans['Type']).to eq('TRANSFER')
10
+ expect(trans['Nature']).to eq('REGULAR')
11
+
12
+ # SUCCEEDED
13
+ expect(trans['Status']).to eq('SUCCEEDED')
14
+ expect(trans['ResultCode']).to eq('000000')
15
+ expect(trans['ResultMessage']).to eq('Success')
16
+ expect(trans['ExecutionDate']).to be > 0
17
+ end
7
18
 
8
19
  describe 'CREATE' do
9
20
  it 'creates a new Transfer' do
10
- expect(new_transfer['Id']).not_to be_nil
11
- #expect(new_transfer['Status']).to eq('SUCCEEDED') # cannot test yet
12
- expect(new_transfer['Status']).to eq('FAILED')
21
+ created = new_transfer
22
+ expect(created['Id']).not_to be_nil
23
+ check_type_and_status(created)
13
24
  end
14
25
  end
15
26
 
16
27
  describe 'FETCH' do
17
28
  it 'fetches a Transfer' do
18
- transfer = MangoPay::Transfer.fetch(new_transfer['Id'])
19
- expect(transfer['Id']).to eq(new_transfer['Id'])
20
- #expect(new_transfer['Status']).to eq('SUCCEEDED') # cannot test yet
21
- expect(new_transfer['Status']).to eq('FAILED')
29
+ created = new_transfer
30
+ fetched = MangoPay::Transfer.fetch(created['Id'])
31
+ expect(fetched['Id']).to eq(created['Id'])
32
+ check_type_and_status(created)
33
+ check_type_and_status(fetched)
22
34
  end
23
35
  end
24
36
 
25
37
  describe 'REFUND' do
26
38
  it 'refunds a transfer' do
27
- transfer_refund = MangoPay::Transfer.refund(new_transfer['Id'], {
28
- AuthorId: new_transfer['AuthorId']
29
- })
30
- expect(transfer_refund['Id']).not_to be_nil
31
- #expect(transfer_refund['Status']).to eq('SUCCEEDED') # cannot test yet
32
- expect(transfer_refund['Status']).to be_nil
39
+ trans = new_transfer
40
+ refund = MangoPay::Transfer.refund(trans['Id'], {AuthorId: trans['AuthorId']})
41
+ expect(refund['Id']).not_to be_nil
42
+ expect(refund['Status']).to eq('SUCCEEDED')
43
+ expect(refund['Type']).to eq('TRANSFER')
44
+ expect(refund['Nature']).to eq('REFUND')
45
+ expect(refund['InitialTransactionType']).to eq('TRANSFER')
46
+ expect(refund['InitialTransactionId']).to eq(trans['Id'])
47
+ expect(refund['DebitedWalletId']).to eq(trans['CreditedWalletId'])
48
+ expect(refund['CreditedWalletId']).to eq(trans['DebitedWalletId'])
49
+ end
50
+ end
51
+
52
+ describe 'CASH FLOW' do
53
+ it 'changes balances correctly' do
54
+ wlt1 = new_wallet
55
+ wlt2 = new_wallet_legal
56
+ wallets_check_amounts(wlt1, 0, wlt2, 0)
57
+
58
+ # payin: feed wlt1 with money
59
+ create_new_payin_card_direct(wlt1, 1000)
60
+ wallets_reload_and_check_amounts(wlt1, 1000, wlt2, 0)
61
+
62
+ # trnasfer wlt1 => wlt2
63
+ trans = create_new_transfer(wlt1, wlt2, 600)
64
+ wallets_reload_and_check_amounts(wlt1, 400, wlt2, 600)
65
+
66
+ # refund the trnasfer
67
+ refund = MangoPay::Transfer.refund(trans['Id'], {AuthorId: trans['AuthorId']})
68
+ wallets_reload_and_check_amounts(wlt1, 1000, wlt2, 0)
33
69
  end
34
70
  end
35
71
  end