mangopay 3.0.23 → 3.0.25.pre.alpha.pre.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +28 -26
  3. data/.rspec +2 -2
  4. data/.travis.yml +13 -0
  5. data/Gemfile +2 -2
  6. data/LICENSE +20 -20
  7. data/README.md +126 -123
  8. data/bin/mangopay +9 -9
  9. data/lib/generators/mangopay/install_generator.rb +60 -60
  10. data/lib/generators/templates/mangopay.rb.erb +5 -5
  11. data/lib/mangopay.rb +225 -158
  12. data/lib/mangopay/authorization_token.rb +88 -88
  13. data/lib/mangopay/bank_account.rb +38 -38
  14. data/lib/mangopay/card.rb +8 -8
  15. data/lib/mangopay/card_registration.rb +9 -9
  16. data/lib/mangopay/client.rb +74 -74
  17. data/lib/mangopay/dispute.rb +130 -130
  18. data/lib/mangopay/errors.rb +61 -61
  19. data/lib/mangopay/event.rb +18 -18
  20. data/lib/mangopay/filter_parameters.rb +46 -0
  21. data/lib/mangopay/hook.rb +9 -9
  22. data/lib/mangopay/http_calls.rb +85 -85
  23. data/lib/mangopay/json.rb +14 -14
  24. data/lib/mangopay/kyc_document.rb +70 -70
  25. data/lib/mangopay/legal_user.rb +15 -15
  26. data/lib/mangopay/mandate.rb +32 -32
  27. data/lib/mangopay/natural_user.rb +14 -14
  28. data/lib/mangopay/pay_in.rb +85 -73
  29. data/lib/mangopay/pay_out.rb +14 -14
  30. data/lib/mangopay/pre_authorization.rb +13 -13
  31. data/lib/mangopay/refund.rb +7 -7
  32. data/lib/mangopay/report.rb +17 -17
  33. data/lib/mangopay/resource.rb +21 -21
  34. data/lib/mangopay/temp.rb +74 -74
  35. data/lib/mangopay/transaction.rb +24 -24
  36. data/lib/mangopay/transfer.rb +9 -9
  37. data/lib/mangopay/user.rb +43 -35
  38. data/lib/mangopay/version.rb +3 -3
  39. data/lib/mangopay/wallet.rb +17 -17
  40. data/mangopay.gemspec +31 -30
  41. data/spec/mangopay/authorization_token_spec.rb +70 -70
  42. data/spec/mangopay/bank_account_spec.rb +97 -97
  43. data/spec/mangopay/card_registration_spec.rb +73 -73
  44. data/spec/mangopay/client_spec.rb +110 -110
  45. data/spec/mangopay/configuration_spec.rb +95 -18
  46. data/spec/mangopay/dispute_spec.rb +262 -262
  47. data/spec/mangopay/event_spec.rb +31 -31
  48. data/spec/mangopay/fetch_filters_spec.rb +63 -63
  49. data/spec/mangopay/hook_spec.rb +37 -37
  50. data/spec/mangopay/idempotency_spec.rb +41 -41
  51. data/spec/mangopay/kyc_document_spec.rb +103 -103
  52. data/spec/mangopay/log_requests_filter_spec.rb +25 -0
  53. data/spec/mangopay/mandate_spec.rb +92 -92
  54. data/spec/mangopay/payin_bankwire_direct_spec.rb +74 -74
  55. data/spec/mangopay/payin_card_direct_spec.rb +68 -68
  56. data/spec/mangopay/payin_card_web_spec.rb +38 -38
  57. data/spec/mangopay/payin_directdebit_direct_spec.rb +37 -37
  58. data/spec/mangopay/payin_directdebit_web_spec.rb +38 -38
  59. data/spec/mangopay/payin_paypal_web_spec.rb +38 -0
  60. data/spec/mangopay/payin_preauthorized_direct_spec.rb +68 -68
  61. data/spec/mangopay/payout_bankwire_spec.rb +54 -54
  62. data/spec/mangopay/preauthorization_spec.rb +42 -42
  63. data/spec/mangopay/refund_spec.rb +21 -21
  64. data/spec/mangopay/report_spec.rb +39 -39
  65. data/spec/mangopay/shared_resources.rb +381 -365
  66. data/spec/mangopay/temp_paymentcard_spec.rb +31 -31
  67. data/spec/mangopay/transaction_spec.rb +54 -54
  68. data/spec/mangopay/transfer_spec.rb +69 -69
  69. data/spec/mangopay/user_spec.rb +137 -122
  70. data/spec/mangopay/wallet_spec.rb +80 -80
  71. data/spec/spec_helper.rb +31 -31
  72. metadata +11 -5
@@ -0,0 +1,25 @@
1
+ describe MangoPay do
2
+ include_context 'users'
3
+ include_context 'payins'
4
+
5
+ describe 'requests log file' do
6
+
7
+ let(:log_file) do
8
+ File.join(MangoPay.configuration.temp_dir, 'mangopay.log.tmp')
9
+ end
10
+
11
+ it 'filters confidential parameters' do
12
+ FileUtils.rm_f(log_file)
13
+ MangoPay.configuration.log_file = log_file
14
+ created = new_card_registration
15
+ lines = File.open(log_file).select { |l| l.include?('AccessKey') }
16
+ lines.each do |line|
17
+ result = JSON.load(/({.+})\s+$/.match(line)[0])
18
+ expect(result['AccessKey']).to eq('[FILTERED]')
19
+ expect(result['Id']).not_to eq('[FILTERED]')
20
+ end
21
+ FileUtils.rm_f(log_file)
22
+ end
23
+
24
+ end
25
+ end
@@ -1,92 +1,92 @@
1
- describe MangoPay::Mandate do
2
- include_context 'mandates'
3
-
4
- def check_status(mandate)
5
- expect(mandate['Status']).to eq('CREATED')
6
- expect(mandate['MandateType']).to eq('DIRECT_DEBIT')
7
- expect(mandate['ExecutionType']).to eq('WEB')
8
- end
9
-
10
- describe 'CREATE' do
11
- it 'creates a mandate' do
12
- mandate = new_mandate
13
- expect(mandate['Id']).to_not be_nil
14
- check_status(mandate)
15
- end
16
- end
17
-
18
- describe 'FETCH' do
19
-
20
- it 'fetches a mandate' do
21
- created = new_mandate
22
- fetched = MangoPay::Mandate.fetch(created['Id'])
23
- expect(fetched['Id']).to eq(created['Id'])
24
- expect(fetched['CreationDate']).to eq(created['CreationDate'])
25
- expect(fetched['UserId']).to eq(created['UserId'])
26
- expect(fetched['BankAccountId']).to eq(created['BankAccountId'])
27
- check_status(created)
28
- check_status(fetched)
29
- end
30
-
31
- it 'fetches (all) mandates' do
32
- created1 = create_new_mandate()
33
- created2 = create_new_mandate()
34
- fetched = MangoPay::Mandate.fetch({'per_page' => 2, 'sort' => 'CreationDate:desc'})
35
-
36
- expect(fetched).to be_kind_of(Array)
37
- expect(fetched.count).to eq 2 # exactly 2 as pagiantion requested
38
-
39
- # all 2 are at top as lastly created
40
- # but may share the same CreationDate
41
- # so the order between them is undetermined
42
- expect(fetched.map {|m| m['Id']}).to include(created1['Id'], created2['Id'])
43
- end
44
-
45
- end
46
-
47
- describe 'FETCH FOR USER AND BANK ACCOUNT' do
48
-
49
- it 'fetches mandates for user' do
50
- created1 = create_new_mandate()
51
- created2 = create_new_mandate()
52
- expect(created1['UserId']).to eq(created2['UserId']) # both for same user
53
-
54
- user_id = created1['UserId']
55
- fetched = MangoPay::Mandate.fetch_for_user(user_id, {'per_page' => 2, 'sort' => 'CreationDate:desc'})
56
-
57
- expect(fetched).to be_kind_of(Array)
58
- expect(fetched.count).to eq 2 # exactly 2 as pagiantion requested
59
- expect(fetched.map {|m| m['Id']}).to include(created1['Id'], created2['Id'])
60
- expect((fetched.map {|m| m['UserId']}).uniq).to eq([user_id])
61
- end
62
-
63
- it 'fetches mandates for user bank account' do
64
- created1 = create_new_mandate()
65
- created2 = create_new_mandate()
66
- expect(created1['UserId']).to eq(created2['UserId']) # both for same user
67
- expect(created1['BankAccountId']).to eq(created2['BankAccountId']) # both for same bank account
68
-
69
- user_id = created1['UserId']
70
- bank_acc_id = created1['BankAccountId']
71
- fetched = MangoPay::Mandate.fetch_for_user_bank_account(user_id, bank_acc_id, {'per_page' => 2, 'sort' => 'CreationDate:desc'})
72
-
73
- expect(fetched).to be_kind_of(Array)
74
- expect(fetched.count).to eq 2 # exactly 2 as pagiantion requested
75
- expect(fetched.map {|m| m['Id']}).to include(created1['Id'], created2['Id'])
76
- expect((fetched.map {|m| m['UserId']}).uniq).to eq([user_id])
77
- end
78
-
79
- end
80
-
81
- describe 'CANCEL' do
82
- it 'cancels a mandate' do
83
- created = new_mandate
84
- expect { MangoPay::Mandate.cancel(created['Id']) }.to raise_error { |err|
85
- expect(err).to be_a MangoPay::ResponseError
86
- expect(err.code).to eq '400'
87
- expect(err.type).to eq 'mandate_cannot_be_cancelled'
88
- }
89
- end
90
- end
91
-
92
- end
1
+ describe MangoPay::Mandate do
2
+ include_context 'mandates'
3
+
4
+ def check_status(mandate)
5
+ expect(mandate['Status']).to eq('CREATED')
6
+ expect(mandate['MandateType']).to eq('DIRECT_DEBIT')
7
+ expect(mandate['ExecutionType']).to eq('WEB')
8
+ end
9
+
10
+ describe 'CREATE' do
11
+ it 'creates a mandate' do
12
+ mandate = new_mandate
13
+ expect(mandate['Id']).to_not be_nil
14
+ check_status(mandate)
15
+ end
16
+ end
17
+
18
+ describe 'FETCH' do
19
+
20
+ it 'fetches a mandate' do
21
+ created = new_mandate
22
+ fetched = MangoPay::Mandate.fetch(created['Id'])
23
+ expect(fetched['Id']).to eq(created['Id'])
24
+ expect(fetched['CreationDate']).to eq(created['CreationDate'])
25
+ expect(fetched['UserId']).to eq(created['UserId'])
26
+ expect(fetched['BankAccountId']).to eq(created['BankAccountId'])
27
+ check_status(created)
28
+ check_status(fetched)
29
+ end
30
+
31
+ it 'fetches (all) mandates' do
32
+ created1 = create_new_mandate()
33
+ created2 = create_new_mandate()
34
+ fetched = MangoPay::Mandate.fetch({'per_page' => 2, 'sort' => 'CreationDate:desc'})
35
+
36
+ expect(fetched).to be_kind_of(Array)
37
+ expect(fetched.count).to eq 2 # exactly 2 as pagiantion requested
38
+
39
+ # all 2 are at top as lastly created
40
+ # but may share the same CreationDate
41
+ # so the order between them is undetermined
42
+ expect(fetched.map {|m| m['Id']}).to include(created1['Id'], created2['Id'])
43
+ end
44
+
45
+ end
46
+
47
+ describe 'FETCH FOR USER AND BANK ACCOUNT' do
48
+
49
+ it 'fetches mandates for user' do
50
+ created1 = create_new_mandate()
51
+ created2 = create_new_mandate()
52
+ expect(created1['UserId']).to eq(created2['UserId']) # both for same user
53
+
54
+ user_id = created1['UserId']
55
+ fetched = MangoPay::Mandate.fetch_for_user(user_id, {'per_page' => 2, 'sort' => 'CreationDate:desc'})
56
+
57
+ expect(fetched).to be_kind_of(Array)
58
+ expect(fetched.count).to eq 2 # exactly 2 as pagiantion requested
59
+ expect(fetched.map {|m| m['Id']}).to include(created1['Id'], created2['Id'])
60
+ expect((fetched.map {|m| m['UserId']}).uniq).to eq([user_id])
61
+ end
62
+
63
+ it 'fetches mandates for user bank account' do
64
+ created1 = create_new_mandate()
65
+ created2 = create_new_mandate()
66
+ expect(created1['UserId']).to eq(created2['UserId']) # both for same user
67
+ expect(created1['BankAccountId']).to eq(created2['BankAccountId']) # both for same bank account
68
+
69
+ user_id = created1['UserId']
70
+ bank_acc_id = created1['BankAccountId']
71
+ fetched = MangoPay::Mandate.fetch_for_user_bank_account(user_id, bank_acc_id, {'per_page' => 2, 'sort' => 'CreationDate:desc'})
72
+
73
+ expect(fetched).to be_kind_of(Array)
74
+ expect(fetched.count).to eq 2 # exactly 2 as pagiantion requested
75
+ expect(fetched.map {|m| m['Id']}).to include(created1['Id'], created2['Id'])
76
+ expect((fetched.map {|m| m['UserId']}).uniq).to eq([user_id])
77
+ end
78
+
79
+ end
80
+
81
+ describe 'CANCEL' do
82
+ it 'cancels a mandate' do
83
+ created = new_mandate
84
+ expect { MangoPay::Mandate.cancel(created['Id']) }.to raise_error { |err|
85
+ expect(err).to be_a MangoPay::ResponseError
86
+ expect(err.code).to eq '400'
87
+ expect(err.type).to eq 'mandate_cannot_be_cancelled'
88
+ }
89
+ end
90
+ end
91
+
92
+ end
@@ -1,74 +1,74 @@
1
- describe MangoPay::PayIn::BankWire::Direct, type: :feature do
2
- include_context 'wallets'
3
- include_context 'payins'
4
-
5
- def check_type_and_status(payin)
6
- expect(payin['Type']).to eq('PAYIN')
7
- expect(payin['Nature']).to eq('REGULAR')
8
- expect(payin['PaymentType']).to eq('BANK_WIRE')
9
- expect(payin['ExecutionType']).to eq('DIRECT')
10
-
11
- expect(payin['Status']).to eq('CREATED')
12
- expect(payin['ResultCode']).to be_nil
13
- expect(payin['ResultMessage']).to be_nil
14
- expect(payin['ExecutionDate']).to be_nil
15
- end
16
-
17
- describe 'CREATE' do
18
- it 'creates a bankwire direct payin' do
19
- created = new_payin_bankwire_direct
20
- expect(created['Id']).not_to be_nil
21
- check_type_and_status(created)
22
- end
23
- end
24
-
25
- describe 'FETCH' do
26
- it 'fetches a payin' do
27
- created = new_payin_bankwire_direct
28
- fetched = MangoPay::PayIn.fetch(created['Id'])
29
- expect(fetched['Id']).to eq(created['Id'])
30
- expect(fetched['CreationDate']).to eq(created['CreationDate'])
31
- expect(fetched['DeclaredDebitedFunds']).to eq(created['DeclaredDebitedFunds'])
32
- expect(fetched['CreditedWalletId']).to eq(created['CreditedWalletId'])
33
- check_type_and_status(created)
34
- check_type_and_status(fetched)
35
- end
36
- end
37
-
38
- ###############################################
39
- # refund not implemented for this type of payin
40
- ###############################################
41
- # describe 'REFUND' do
42
- # it 'refunds a payin' do
43
- # payin = new_payin_bankwire_direct
44
- # refund = MangoPay::PayIn.refund(payin['Id'], {AuthorId: payin['AuthorId']})
45
- # expect(refund['Id']).not_to be_nil
46
- # expect(refund['Status']).to eq('SUCCEEDED')
47
- # expect(refund['Type']).to eq('PAYOUT')
48
- # expect(refund['Nature']).to eq('REFUND')
49
- # expect(refund['InitialTransactionType']).to eq('PAYIN')
50
- # expect(refund['InitialTransactionId']).to eq(payin['Id'])
51
- # expect(refund['DebitedWalletId']).to eq(payin['CreditedWalletId'])
52
- # end
53
- # end
54
- #
55
- ###############################################
56
- # status is CREATED instead of SUCCEEDED
57
- # so no cash flow yet
58
- ###############################################
59
- # describe 'CASH FLOW' do
60
- # it 'changes balances correctly' do
61
- # wlt = new_wallet
62
- # wallets_check_amounts(wlt, 0)
63
- #
64
- # # payin: feed wlt1 with money
65
- # payin = create_new_payin_bankwire_direct(wlt, 1000)
66
- # wallets_reload_and_check_amounts(wlt, 1000)
67
- #
68
- # # refund the payin
69
- # refund = MangoPay::PayIn.refund(payin['Id'], {AuthorId: payin['AuthorId']})
70
- # wallets_reload_and_check_amounts(wlt, 0)
71
- # end
72
- # end
73
-
74
- end
1
+ describe MangoPay::PayIn::BankWire::Direct, type: :feature do
2
+ include_context 'wallets'
3
+ include_context 'payins'
4
+
5
+ def check_type_and_status(payin)
6
+ expect(payin['Type']).to eq('PAYIN')
7
+ expect(payin['Nature']).to eq('REGULAR')
8
+ expect(payin['PaymentType']).to eq('BANK_WIRE')
9
+ expect(payin['ExecutionType']).to eq('DIRECT')
10
+
11
+ expect(payin['Status']).to eq('CREATED')
12
+ expect(payin['ResultCode']).to be_nil
13
+ expect(payin['ResultMessage']).to be_nil
14
+ expect(payin['ExecutionDate']).to be_nil
15
+ end
16
+
17
+ describe 'CREATE' do
18
+ it 'creates a bankwire direct payin' do
19
+ created = new_payin_bankwire_direct
20
+ expect(created['Id']).not_to be_nil
21
+ check_type_and_status(created)
22
+ end
23
+ end
24
+
25
+ describe 'FETCH' do
26
+ it 'fetches a payin' do
27
+ created = new_payin_bankwire_direct
28
+ fetched = MangoPay::PayIn.fetch(created['Id'])
29
+ expect(fetched['Id']).to eq(created['Id'])
30
+ expect(fetched['CreationDate']).to eq(created['CreationDate'])
31
+ expect(fetched['DeclaredDebitedFunds']).to eq(created['DeclaredDebitedFunds'])
32
+ expect(fetched['CreditedWalletId']).to eq(created['CreditedWalletId'])
33
+ check_type_and_status(created)
34
+ check_type_and_status(fetched)
35
+ end
36
+ end
37
+
38
+ ###############################################
39
+ # refund not implemented for this type of payin
40
+ ###############################################
41
+ # describe 'REFUND' do
42
+ # it 'refunds a payin' do
43
+ # payin = new_payin_bankwire_direct
44
+ # refund = MangoPay::PayIn.refund(payin['Id'], {AuthorId: payin['AuthorId']})
45
+ # expect(refund['Id']).not_to be_nil
46
+ # expect(refund['Status']).to eq('SUCCEEDED')
47
+ # expect(refund['Type']).to eq('PAYOUT')
48
+ # expect(refund['Nature']).to eq('REFUND')
49
+ # expect(refund['InitialTransactionType']).to eq('PAYIN')
50
+ # expect(refund['InitialTransactionId']).to eq(payin['Id'])
51
+ # expect(refund['DebitedWalletId']).to eq(payin['CreditedWalletId'])
52
+ # end
53
+ # end
54
+ #
55
+ ###############################################
56
+ # status is CREATED instead of SUCCEEDED
57
+ # so no cash flow yet
58
+ ###############################################
59
+ # describe 'CASH FLOW' do
60
+ # it 'changes balances correctly' do
61
+ # wlt = new_wallet
62
+ # wallets_check_amounts(wlt, 0)
63
+ #
64
+ # # payin: feed wlt1 with money
65
+ # payin = create_new_payin_bankwire_direct(wlt, 1000)
66
+ # wallets_reload_and_check_amounts(wlt, 1000)
67
+ #
68
+ # # refund the payin
69
+ # refund = MangoPay::PayIn.refund(payin['Id'], {AuthorId: payin['AuthorId']})
70
+ # wallets_reload_and_check_amounts(wlt, 0)
71
+ # end
72
+ # end
73
+
74
+ end
@@ -1,68 +1,68 @@
1
- describe MangoPay::PayIn::Card::Direct, type: :feature do
2
- include_context 'wallets'
3
- include_context 'payins'
4
-
5
- def check_type_and_status(payin)
6
- expect(payin['Type']).to eq('PAYIN')
7
- expect(payin['Nature']).to eq('REGULAR')
8
- expect(payin['PaymentType']).to eq('CARD')
9
- expect(payin['ExecutionType']).to eq('DIRECT')
10
-
11
- # SUCCEEDED
12
- expect(payin['Status']).to eq('SUCCEEDED')
13
- expect(payin['ResultCode']).to eq('000000')
14
- expect(payin['ResultMessage']).to eq('Success')
15
- expect(payin['ExecutionDate']).to be > 0
16
- end
17
-
18
- describe 'CREATE' do
19
- it 'creates a card direct payin' do
20
- created = new_payin_card_direct
21
- expect(created['Id']).not_to be_nil
22
- check_type_and_status(created)
23
- end
24
- end
25
-
26
- describe 'FETCH' do
27
- it 'fetches a payin' do
28
- created = new_payin_card_direct
29
- fetched = MangoPay::PayIn.fetch(created['Id'])
30
- expect(fetched['Id']).to eq(created['Id'])
31
- expect(fetched['CreationDate']).to eq(created['CreationDate'])
32
- expect(fetched['CreditedFunds']).to eq(created['CreditedFunds'])
33
- expect(fetched['CreditedWalletId']).to eq(created['CreditedWalletId'])
34
- check_type_and_status(created)
35
- check_type_and_status(fetched)
36
- end
37
- end
38
-
39
- describe 'REFUND' do
40
- it 'refunds a payin' do
41
- payin = new_payin_card_direct
42
- refund = MangoPay::PayIn.refund(payin['Id'], {AuthorId: payin['AuthorId']})
43
- expect(refund['Id']).not_to be_nil
44
- expect(refund['Status']).to eq('SUCCEEDED')
45
- expect(refund['Type']).to eq('PAYOUT')
46
- expect(refund['Nature']).to eq('REFUND')
47
- expect(refund['InitialTransactionType']).to eq('PAYIN')
48
- expect(refund['InitialTransactionId']).to eq(payin['Id'])
49
- expect(refund['DebitedWalletId']).to eq(payin['CreditedWalletId'])
50
- end
51
- end
52
-
53
- describe 'CASH FLOW' do
54
- it 'changes balances correctly' do
55
- wlt = new_wallet
56
- wallets_check_amounts(wlt, 0)
57
-
58
- # payin: feed wlt1 with money
59
- payin = create_new_payin_card_direct(wlt, 1000)
60
- wallets_reload_and_check_amounts(wlt, 1000)
61
-
62
- # refund the payin
63
- refund = MangoPay::PayIn.refund(payin['Id'], {AuthorId: payin['AuthorId']})
64
- wallets_reload_and_check_amounts(wlt, 0)
65
- end
66
- end
67
-
68
- end
1
+ describe MangoPay::PayIn::Card::Direct, type: :feature do
2
+ include_context 'wallets'
3
+ include_context 'payins'
4
+
5
+ def check_type_and_status(payin)
6
+ expect(payin['Type']).to eq('PAYIN')
7
+ expect(payin['Nature']).to eq('REGULAR')
8
+ expect(payin['PaymentType']).to eq('CARD')
9
+ expect(payin['ExecutionType']).to eq('DIRECT')
10
+
11
+ # SUCCEEDED
12
+ expect(payin['Status']).to eq('SUCCEEDED')
13
+ expect(payin['ResultCode']).to eq('000000')
14
+ expect(payin['ResultMessage']).to eq('Success')
15
+ expect(payin['ExecutionDate']).to be > 0
16
+ end
17
+
18
+ describe 'CREATE' do
19
+ it 'creates a card direct payin' do
20
+ created = new_payin_card_direct
21
+ expect(created['Id']).not_to be_nil
22
+ check_type_and_status(created)
23
+ end
24
+ end
25
+
26
+ describe 'FETCH' do
27
+ it 'fetches a payin' do
28
+ created = new_payin_card_direct
29
+ fetched = MangoPay::PayIn.fetch(created['Id'])
30
+ expect(fetched['Id']).to eq(created['Id'])
31
+ expect(fetched['CreationDate']).to eq(created['CreationDate'])
32
+ expect(fetched['CreditedFunds']).to eq(created['CreditedFunds'])
33
+ expect(fetched['CreditedWalletId']).to eq(created['CreditedWalletId'])
34
+ check_type_and_status(created)
35
+ check_type_and_status(fetched)
36
+ end
37
+ end
38
+
39
+ describe 'REFUND' do
40
+ it 'refunds a payin' do
41
+ payin = new_payin_card_direct
42
+ refund = MangoPay::PayIn.refund(payin['Id'], {AuthorId: payin['AuthorId']})
43
+ expect(refund['Id']).not_to be_nil
44
+ expect(refund['Status']).to eq('SUCCEEDED')
45
+ expect(refund['Type']).to eq('PAYOUT')
46
+ expect(refund['Nature']).to eq('REFUND')
47
+ expect(refund['InitialTransactionType']).to eq('PAYIN')
48
+ expect(refund['InitialTransactionId']).to eq(payin['Id'])
49
+ expect(refund['DebitedWalletId']).to eq(payin['CreditedWalletId'])
50
+ end
51
+ end
52
+
53
+ describe 'CASH FLOW' do
54
+ it 'changes balances correctly' do
55
+ wlt = new_wallet
56
+ wallets_check_amounts(wlt, 0)
57
+
58
+ # payin: feed wlt1 with money
59
+ payin = create_new_payin_card_direct(wlt, 1000)
60
+ wallets_reload_and_check_amounts(wlt, 1000)
61
+
62
+ # refund the payin
63
+ refund = MangoPay::PayIn.refund(payin['Id'], {AuthorId: payin['AuthorId']})
64
+ wallets_reload_and_check_amounts(wlt, 0)
65
+ end
66
+ end
67
+
68
+ end