mangopay4-ruby-sdk 3.44.0

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 (126) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ruby_cd.yml +34 -0
  3. data/.github/workflows/ruby_ci.yml +30 -0
  4. data/.gitignore +30 -0
  5. data/.rspec +3 -0
  6. data/CHANGELOG.md +640 -0
  7. data/Gemfile +2 -0
  8. data/LICENSE +20 -0
  9. data/README.md +162 -0
  10. data/Rakefile +5 -0
  11. data/bin/mangopay +9 -0
  12. data/lib/generators/mangopay/install_generator.rb +60 -0
  13. data/lib/generators/templates/mangopay.rb.erb +5 -0
  14. data/lib/mangopay/acquiring.rb +56 -0
  15. data/lib/mangopay/authorization_token.rb +89 -0
  16. data/lib/mangopay/bank_account.rb +49 -0
  17. data/lib/mangopay/bankingaliases.rb +29 -0
  18. data/lib/mangopay/bankingaliases_iban.rb +16 -0
  19. data/lib/mangopay/card.rb +54 -0
  20. data/lib/mangopay/card_registration.rb +9 -0
  21. data/lib/mangopay/client.rb +94 -0
  22. data/lib/mangopay/conversion.rb +49 -0
  23. data/lib/mangopay/deposit.rb +36 -0
  24. data/lib/mangopay/dispute.rb +152 -0
  25. data/lib/mangopay/errors.rb +66 -0
  26. data/lib/mangopay/event.rb +18 -0
  27. data/lib/mangopay/filter_parameters.rb +56 -0
  28. data/lib/mangopay/hook.rb +9 -0
  29. data/lib/mangopay/http_calls.rb +88 -0
  30. data/lib/mangopay/identity_verification.rb +16 -0
  31. data/lib/mangopay/json.rb +14 -0
  32. data/lib/mangopay/kyc_document.rb +83 -0
  33. data/lib/mangopay/legal_user.rb +21 -0
  34. data/lib/mangopay/legal_user_sca.rb +25 -0
  35. data/lib/mangopay/mandate.rb +42 -0
  36. data/lib/mangopay/natural_user.rb +20 -0
  37. data/lib/mangopay/natural_user_sca.rb +25 -0
  38. data/lib/mangopay/pay_in.rb +415 -0
  39. data/lib/mangopay/pay_out.rb +41 -0
  40. data/lib/mangopay/payment_method_metadata.rb +13 -0
  41. data/lib/mangopay/pre_authorization.rb +17 -0
  42. data/lib/mangopay/recipient.rb +35 -0
  43. data/lib/mangopay/refund.rb +19 -0
  44. data/lib/mangopay/regulatory.rb +22 -0
  45. data/lib/mangopay/report.rb +24 -0
  46. data/lib/mangopay/report_v2.rb +21 -0
  47. data/lib/mangopay/resource.rb +21 -0
  48. data/lib/mangopay/settlement.rb +21 -0
  49. data/lib/mangopay/transaction.rb +24 -0
  50. data/lib/mangopay/transfer.rb +20 -0
  51. data/lib/mangopay/ubo.rb +26 -0
  52. data/lib/mangopay/ubo_declaration.rb +32 -0
  53. data/lib/mangopay/user.rb +100 -0
  54. data/lib/mangopay/version.rb +3 -0
  55. data/lib/mangopay/virtual_account.rb +44 -0
  56. data/lib/mangopay/wallet.rb +17 -0
  57. data/lib/mangopay.rb +456 -0
  58. data/mangopay.gemspec +30 -0
  59. data/spec/mangopay/acquiring_spec.rb +176 -0
  60. data/spec/mangopay/authorization_token_spec.rb +70 -0
  61. data/spec/mangopay/bank_account_spec.rb +105 -0
  62. data/spec/mangopay/bankingaliases_spec.rb +29 -0
  63. data/spec/mangopay/card_registration_spec.rb +123 -0
  64. data/spec/mangopay/client_spec.png +0 -0
  65. data/spec/mangopay/client_spec.rb +213 -0
  66. data/spec/mangopay/configuration_spec.rb +249 -0
  67. data/spec/mangopay/conversion_spec.rb +96 -0
  68. data/spec/mangopay/deposit_spec.rb +107 -0
  69. data/spec/mangopay/dispute_spec.png +0 -0
  70. data/spec/mangopay/dispute_spec.rb +294 -0
  71. data/spec/mangopay/event_spec.rb +33 -0
  72. data/spec/mangopay/fetch_filters_spec.rb +63 -0
  73. data/spec/mangopay/hook_spec.rb +37 -0
  74. data/spec/mangopay/idempotency_spec.rb +41 -0
  75. data/spec/mangopay/identity_verification_spec.rb +47 -0
  76. data/spec/mangopay/kyc_document_spec.png +0 -0
  77. data/spec/mangopay/kyc_document_spec.rb +118 -0
  78. data/spec/mangopay/log_requests_filter_spec.rb +26 -0
  79. data/spec/mangopay/mandate_spec.rb +99 -0
  80. data/spec/mangopay/payin_applepay_direct_spec.rb +21 -0
  81. data/spec/mangopay/payin_bancontact_web_spec.rb +30 -0
  82. data/spec/mangopay/payin_bankwire_direct_spec.rb +74 -0
  83. data/spec/mangopay/payin_bankwire_external_instruction_spec.rb +104 -0
  84. data/spec/mangopay/payin_bizum_web_spec.rb +54 -0
  85. data/spec/mangopay/payin_blik_web_spec.rb +41 -0
  86. data/spec/mangopay/payin_card_direct_spec.rb +69 -0
  87. data/spec/mangopay/payin_card_web_spec.rb +64 -0
  88. data/spec/mangopay/payin_directdebit_direct_spec.rb +37 -0
  89. data/spec/mangopay/payin_directdebit_web_spec.rb +38 -0
  90. data/spec/mangopay/payin_giropay_web_spec.rb +30 -0
  91. data/spec/mangopay/payin_googlepay_direct_spec.rb +21 -0
  92. data/spec/mangopay/payin_ideal_web_spec.rb +30 -0
  93. data/spec/mangopay/payin_intent_spec.rb +151 -0
  94. data/spec/mangopay/payin_klarna_web_spec.rb +32 -0
  95. data/spec/mangopay/payin_mbway_web_spec.rb +32 -0
  96. data/spec/mangopay/payin_multibanco_web_spec.rb +31 -0
  97. data/spec/mangopay/payin_paybybank_web_spec.rb +56 -0
  98. data/spec/mangopay/payin_payconiq_web_spec.rb +31 -0
  99. data/spec/mangopay/payin_paypal_web_spec.rb +113 -0
  100. data/spec/mangopay/payin_preauthorized_direct_spec.rb +118 -0
  101. data/spec/mangopay/payin_satispay_web_spec.rb +32 -0
  102. data/spec/mangopay/payin_swish_web_spec.rb +30 -0
  103. data/spec/mangopay/payin_twint_web_spec.rb +30 -0
  104. data/spec/mangopay/payment_method_metadata_spec.rb +15 -0
  105. data/spec/mangopay/payout_bankwire_spec.rb +93 -0
  106. data/spec/mangopay/preauthorization_spec.rb +51 -0
  107. data/spec/mangopay/recipient_spec.rb +134 -0
  108. data/spec/mangopay/recurring_payin_spec.rb +222 -0
  109. data/spec/mangopay/refund_spec.rb +34 -0
  110. data/spec/mangopay/regulatory_spec.rb +26 -0
  111. data/spec/mangopay/report_spec.rb +40 -0
  112. data/spec/mangopay/report_v2_spec.rb +117 -0
  113. data/spec/mangopay/report_wallets_spec.rb +40 -0
  114. data/spec/mangopay/settlement_sample.csv +8 -0
  115. data/spec/mangopay/settlement_spec.rb +38 -0
  116. data/spec/mangopay/shared_resources.rb +1380 -0
  117. data/spec/mangopay/transaction_spec.rb +59 -0
  118. data/spec/mangopay/transfer_spec.rb +77 -0
  119. data/spec/mangopay/ubo_declaration_spec.rb +44 -0
  120. data/spec/mangopay/ubo_spec.rb +39 -0
  121. data/spec/mangopay/user_spec.rb +444 -0
  122. data/spec/mangopay/virtual_account_spec.rb +52 -0
  123. data/spec/mangopay/wallet_spec.rb +100 -0
  124. data/spec/spec_helper.rb +31 -0
  125. data/spec/tmp/.keep +0 -0
  126. metadata +280 -0
@@ -0,0 +1,59 @@
1
+ describe MangoPay::Transaction do
2
+ include_context 'wallets'
3
+ include_context 'payins'
4
+ include_context 'payouts'
5
+
6
+ describe 'FETCH' do
7
+
8
+ it 'fetches empty list of transactions if no transactions done' do
9
+ transactions = MangoPay::Transaction.fetch(new_wallet['Id'])
10
+ expect(transactions).to be_kind_of(Array)
11
+ expect(transactions).to be_empty
12
+ end
13
+
14
+ it 'fetches list with single transaction after payin done' do
15
+ payin = new_payin_card_direct
16
+ transactions = MangoPay::Transaction.fetch(new_wallet['Id'])
17
+ expect(transactions).to be_kind_of(Array)
18
+ expect(transactions.count).to eq 1
19
+ expect(transactions.first['Id']).to eq payin['Id']
20
+ end
21
+
22
+ it 'fetches list with two transactions after payin and payout done' do
23
+ payin = new_payin_card_direct
24
+ payout = create_new_payout_bankwire(payin)
25
+ # wait for the transactions to be created
26
+ sleep(2)
27
+ transactions = MangoPay::Transaction.fetch(new_wallet['Id'])
28
+
29
+ expect(transactions).to be_kind_of(Array)
30
+ expect(transactions.count).to eq 2
31
+
32
+ transactions_ids = transactions.map {|t| t['Id']}
33
+ expect(transactions_ids).to include payin['Id']
34
+ expect(transactions_ids).to include payout['Id']
35
+ end
36
+
37
+ it 'accepts filtering params' do
38
+ payin = new_payin_card_direct
39
+ payout = create_new_payout_bankwire(payin)
40
+ wallet_id = new_wallet['Id']
41
+
42
+ # wait for the transactions to be created
43
+ sleep(2)
44
+
45
+ by_nature_reg = MangoPay::Transaction.fetch(wallet_id, {'Nature' => 'REGULAR'})
46
+ by_nature_ref = MangoPay::Transaction.fetch(wallet_id, {'Nature' => 'REFUND'})
47
+ expect(by_nature_reg.count).to eq 2
48
+ expect(by_nature_ref.count).to eq 0
49
+
50
+ by_type_pyin = MangoPay::Transaction.fetch(wallet_id, {'Type' => 'PAYIN'})
51
+ by_type_pyout = MangoPay::Transaction.fetch(wallet_id, {'Type' => 'PAYOUT'})
52
+ expect(by_type_pyin.count).to eq 1
53
+ expect(by_type_pyout.count).to eq 1
54
+ expect(by_type_pyin.first['Id']).to eq payin['Id']
55
+ expect(by_type_pyout.first['Id']).to eq payout['Id']
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,77 @@
1
+ describe MangoPay::Transfer, type: :feature do
2
+ include_context 'wallets'
3
+ include_context 'payins'
4
+ include_context 'transfers'
5
+
6
+ def check_type_and_status(trans)
7
+ expect(trans['Type']).to eq('TRANSFER')
8
+ expect(trans['Nature']).to eq('REGULAR')
9
+
10
+ # SUCCEEDED
11
+ expect(trans['Status']).to eq('SUCCEEDED')
12
+ expect(trans['ResultCode']).to eq('000000')
13
+ expect(trans['ResultMessage']).to eq('Success')
14
+ expect(trans['ExecutionDate']).to be > 0
15
+ end
16
+
17
+ describe 'CREATE' do
18
+ it 'creates a new Transfer' do
19
+ created = new_transfer
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 Transfer' do
27
+ created = new_transfer
28
+ fetched = MangoPay::Transfer.fetch(created['Id'])
29
+ expect(fetched['Id']).to eq(created['Id'])
30
+ check_type_and_status(created)
31
+ check_type_and_status(fetched)
32
+ end
33
+ end
34
+
35
+ describe 'REFUND' do
36
+ it 'refunds a transfer' do
37
+ trans = new_transfer
38
+ refund = MangoPay::Transfer.refund(trans['Id'], {AuthorId: trans['AuthorId']})
39
+ expect(refund['Id']).not_to be_nil
40
+ expect(refund['Status']).to eq('SUCCEEDED')
41
+ expect(refund['Type']).to eq('TRANSFER')
42
+ expect(refund['Nature']).to eq('REFUND')
43
+ expect(refund['InitialTransactionType']).to eq('TRANSFER')
44
+ expect(refund['InitialTransactionId']).to eq(trans['Id'])
45
+ expect(refund['DebitedWalletId']).to eq(trans['CreditedWalletId'])
46
+ expect(refund['CreditedWalletId']).to eq(trans['DebitedWalletId'])
47
+ end
48
+ end
49
+
50
+ describe 'CASH FLOW' do
51
+ it 'changes balances correctly' do
52
+ wlt1 = new_wallet
53
+ wlt2 = new_wallet_legal
54
+ wallets_check_amounts(wlt1, 0, wlt2, 0)
55
+
56
+ # payin: feed wlt1 with money
57
+ create_new_payin_card_direct(wlt1, 1000)
58
+ wallets_reload_and_check_amounts(wlt1, 1000, wlt2, 0)
59
+
60
+ # trnasfer wlt1 => wlt2
61
+ trans = create_new_transfer(wlt1, wlt2, 600)
62
+ wallets_reload_and_check_amounts(wlt1, 400, wlt2, 600)
63
+
64
+ # refund the trnasfer
65
+ refund = MangoPay::Transfer.refund(trans['Id'], {AuthorId: trans['AuthorId']})
66
+ wallets_reload_and_check_amounts(wlt1, 1000, wlt2, 0)
67
+ end
68
+ end
69
+
70
+ describe 'FETCH Refunds' do
71
+ it "fetches a transfer's refunds" do
72
+ transfer = new_transfer
73
+ refunds = MangoPay::Transfer.refunds(transfer['Id'])
74
+ expect(refunds).to be_an(Array)
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,44 @@
1
+ describe MangoPay::UboDeclaration do
2
+ include_context 'users'
3
+ include_context 'ubo'
4
+
5
+ describe 'FETCH' do
6
+ it 'can fetch a UBO declaration' do
7
+ legal_user = new_legal_user
8
+
9
+ ubo_declaration = MangoPay::UboDeclaration.create(legal_user['Id'])
10
+
11
+ ubo_declaration_byId = MangoPay::UboDeclaration.fetch(legal_user['Id'], ubo_declaration['Id'])
12
+
13
+ expect(ubo_declaration).not_to be_nil
14
+ expect(ubo_declaration_byId).not_to be_nil
15
+ end
16
+
17
+ it 'fetches ubo declaration just by id' do
18
+ legal_user = new_legal_user
19
+
20
+ ubo_declaration = MangoPay::UboDeclaration.create(legal_user['Id'], nil)
21
+
22
+ ubo_declaration_byId = MangoPay::UboDeclaration.fetch(nil, ubo_declaration['Id'], nil)
23
+
24
+ expect(ubo_declaration).not_to be_nil
25
+ expect(ubo_declaration_byId).not_to be_nil
26
+ end
27
+
28
+ describe 'UPDATE' do
29
+ it 'can update a UBO declaration' do
30
+ legal_user = new_legal_user
31
+ ubo_declaration = MangoPay::UboDeclaration.create(legal_user['Id'])
32
+ ubo_declaration['Status'] = 'VALIDATION_ASKED'
33
+
34
+ ubo = new_ubo(legal_user, ubo_declaration)
35
+
36
+ ubo_declaration['Ubos'] = [ubo]
37
+ ubo_declaration = MangoPay::UboDeclaration.update(legal_user['Id'], ubo_declaration['Id'], ubo_declaration)
38
+
39
+ expect(ubo_declaration).not_to be_nil
40
+ expect(ubo_declaration['Status']).to eq 'VALIDATION_ASKED'
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,39 @@
1
+ describe MangoPay::Ubo do
2
+ include_context 'users'
3
+ include_context 'ubo'
4
+
5
+ describe 'FETCH' do
6
+ it 'can fetch a Ubo' do
7
+ legal_user = new_legal_user
8
+ ubo_declaration = MangoPay::UboDeclaration.create(legal_user['Id'])
9
+ ubo = new_ubo(legal_user, ubo_declaration)
10
+ result = MangoPay::Ubo.fetch(legal_user['Id'], ubo_declaration['Id'], ubo['Id'])
11
+ expect(result).not_to be_nil
12
+ expect(result['Id']).equal? ubo['Id']
13
+ end
14
+ end
15
+
16
+ describe 'CREATE' do
17
+ it 'can create a new Ubo' do
18
+ legal_user = new_legal_user
19
+ ubo_declaration = MangoPay::UboDeclaration.create(legal_user['Id'])
20
+ result = new_ubo(legal_user, ubo_declaration)
21
+ expect(result).not_to be_nil
22
+ end
23
+ end
24
+
25
+ describe 'UPDATE' do
26
+ it 'can update a Ubo' do
27
+ legal_user = new_legal_user
28
+ ubo_declaration = MangoPay::UboDeclaration.create(legal_user['Id'])
29
+ ubo = new_ubo(legal_user, ubo_declaration)
30
+ ubo['FirstName'] = 'Santa'
31
+ ubo['LastName'] = 'Clause'
32
+
33
+ result = MangoPay::Ubo.update(legal_user['Id'], ubo_declaration['Id'], ubo['Id'], ubo)
34
+ expect(result).not_to be_nil
35
+ expect(result['FirstName']).equal? ubo['FirstName']
36
+ expect(result['LastName']).equal? ubo['LastName']
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,444 @@
1
+ describe MangoPay::User do
2
+ include_context 'users'
3
+ include_context 'payins'
4
+ include_context 'payouts'
5
+ include_context 'wallets'
6
+ include_context 'kyc_documents'
7
+
8
+ describe 'CREATE' do
9
+ it 'creates a new natural user' do
10
+ expect(new_natural_user["FirstName"]).to eq('John')
11
+ end
12
+
13
+ it 'creates a new legal user' do
14
+ expect(new_legal_user["LegalRepresentativeFirstName"]).to eq('John')
15
+ end
16
+
17
+ it 'creates a new legal user' do
18
+ expect(new_legal_user["CompanyNumber"]).to eq('LU123456789')
19
+ end
20
+ end
21
+
22
+ describe 'CREATE SCA' do
23
+ it 'creates a new SCA natural user payer' do
24
+ user = new_natural_user_sca_payer
25
+ expect(user["FirstName"]).to eq('Alex')
26
+ expect(user["UserCategory"]).to eq('PAYER')
27
+ expect(user["UserStatus"]).to eq('ACTIVE')
28
+ end
29
+
30
+ it 'creates a new SCA natural user owner' do
31
+ user = new_natural_user_sca_owner
32
+ expect(user["FirstName"]).to eq('Alex')
33
+ expect(user["UserCategory"]).to eq('OWNER')
34
+ expect(user["UserStatus"]).to eq('PENDING_USER_ACTION')
35
+ expect(user["PendingUserAction"]["RedirectUrl"]).not_to be_nil
36
+ end
37
+
38
+ it 'creates a new SCA legal user payer' do
39
+ user = new_legal_user_sca_payer
40
+ expect(user["Name"]).to eq('Alex Smith')
41
+ expect(user["UserCategory"]).to eq('PAYER')
42
+ expect(user["UserStatus"]).to eq('ACTIVE')
43
+ end
44
+
45
+ it 'creates a new SCA legal user owner' do
46
+ user = new_legal_user_sca_owner
47
+ expect(user["Name"]).to eq('Alex Smith')
48
+ expect(user["UserCategory"]).to eq('OWNER')
49
+ expect(user["UserStatus"]).to eq('PENDING_USER_ACTION')
50
+ expect(user["PendingUserAction"]["RedirectUrl"]).not_to be_nil
51
+ end
52
+ end
53
+
54
+ describe 'UPDATE' do
55
+ it 'updates a natural user' do
56
+ updated_user = MangoPay::NaturalUser.update(new_natural_user['Id'] ,{
57
+ FirstName: 'Jack',
58
+ TermsAndConditionsAccepted: true
59
+ })
60
+ expect(updated_user['FirstName']).to eq('Jack')
61
+ end
62
+
63
+ it 'updates a legal user' do
64
+ updated_user = MangoPay::LegalUser.update(new_legal_user['Id'], {
65
+ LegalRepresentativeFirstName: 'Jack',
66
+ TermsAndConditionsAccepted: true
67
+ })
68
+ expect(updated_user['LegalRepresentativeFirstName']).to eq('Jack')
69
+ end
70
+
71
+ it 'updates a natural user terms and conditions accepted' do
72
+ updated_user = MangoPay::NaturalUser.update(new_natural_user['Id'] ,{
73
+ TermsAndConditionsAccepted: true
74
+ })
75
+ expect(updated_user['TermsAndConditionsAccepted']).to eq(true)
76
+ end
77
+
78
+ it 'updates a legal user terms and conditions accepted' do
79
+ updated_user = MangoPay::LegalUser.update(new_legal_user['Id'], {
80
+ TermsAndConditionsAccepted: true
81
+ })
82
+ expect(updated_user['TermsAndConditionsAccepted']).to eq(true)
83
+ end
84
+ end
85
+
86
+ describe 'UPDATE SCA' do
87
+ it 'updates a SCA natural user' do
88
+ user = new_natural_user_sca_owner
89
+ updated_user = MangoPay::NaturalUserSca.update(user['Id'] ,{
90
+ FirstName: 'Jack',
91
+ TermsAndConditionsAccepted: true
92
+ })
93
+ fetched = MangoPay::NaturalUserSca.fetch(user['Id'])
94
+ expect(updated_user['FirstName']).to eq('Jack')
95
+ expect(updated_user['FirstName']).to eq(fetched['FirstName'])
96
+ end
97
+
98
+ it 'updates a SCA legal user' do
99
+ user = new_legal_user_sca_owner
100
+ legal_representative = user['LegalRepresentative']
101
+ legal_representative['FirstName'] = 'Jack'
102
+ updated_user = MangoPay::LegalUserSca.update(user['Id'] ,{
103
+ LegalRepresentative: legal_representative,
104
+ TermsAndConditionsAccepted: true
105
+ })
106
+ fetched = MangoPay::LegalUserSca.fetch(user['Id'])
107
+ expect(updated_user['LegalRepresentative']['FirstName']).to eq('Jack')
108
+ expect(updated_user['LegalRepresentative']['FirstName']).to eq(fetched['LegalRepresentative']['FirstName'])
109
+ end
110
+ end
111
+
112
+ describe 'CATEGORIZE SCA' do
113
+ it 'transitions SCA natural user Payer to Owner' do
114
+ user = new_natural_user_sca_payer
115
+ categorized = MangoPay::NaturalUserSca.categorize(user['Id'] ,{
116
+ "UserCategory": "OWNER",
117
+ "TermsAndConditionsAccepted": true,
118
+ "Birthday": 652117514,
119
+ "Nationality": "FR",
120
+ "CountryOfResidence": "FR"
121
+ })
122
+ fetched = MangoPay::NaturalUserSca.fetch(user['Id'])
123
+ expect(user['UserCategory']).to eq('PAYER')
124
+ expect(categorized['UserCategory']).to eq('OWNER')
125
+ expect(fetched['UserCategory']).to eq('OWNER')
126
+ end
127
+
128
+ it 'transitions SCA legal user Payer to Owner' do
129
+ user = new_legal_user_sca_payer
130
+ categorized = MangoPay::LegalUserSca.categorize(user['Id'] ,{
131
+ "UserCategory": "OWNER",
132
+ "TermsAndConditionsAccepted": true,
133
+ "LegalRepresentative": {
134
+ "Birthday": 652117514,
135
+ "Nationality": "FR",
136
+ "CountryOfResidence": "FR",
137
+ "Email": "alex.smith@example.com"
138
+ },
139
+ "HeadquartersAddress": {
140
+ "AddressLine1": "3 rue de la Cité",
141
+ "AddressLine2": "Appartement 7",
142
+ "City": "Paris",
143
+ "Region": "Île-de-France",
144
+ "PostalCode": "75004",
145
+ "Country": "FR"
146
+ },
147
+ "CompanyNumber": "123456789"
148
+ })
149
+ fetched = MangoPay::LegalUserSca.fetch(user['Id'])
150
+ expect(user['UserCategory']).to eq('PAYER')
151
+ expect(categorized['UserCategory']).to eq('OWNER')
152
+ expect(fetched['UserCategory']).to eq('OWNER')
153
+ end
154
+ end
155
+
156
+ describe 'ENROLL SCA' do
157
+ it 'enrolls user' do
158
+ user = new_natural_user
159
+ enrollment_result = MangoPay::User.enroll_sca(user['Id'])
160
+ expect(enrollment_result["PendingUserAction"]["RedirectUrl"]).not_to be_nil
161
+ end
162
+ end
163
+
164
+ describe 'MANAGE CONSENT' do
165
+ it 'manages consent' do
166
+ user = new_natural_user
167
+
168
+ enrollment_result = MangoPay::User.enroll_sca(user['Id'])
169
+ expect(enrollment_result["PendingUserAction"]["RedirectUrl"]).not_to be_nil
170
+
171
+ consent_result = MangoPay::User.manage_consent(user['Id'])
172
+ expect(consent_result["PendingUserAction"]["RedirectUrl"]).not_to be_nil
173
+ end
174
+ end
175
+
176
+ describe 'FETCH' do
177
+ it 'fetches all the users' do
178
+ users = MangoPay::User.fetch()
179
+ expect(users).to be_kind_of(Array)
180
+ expect(users).not_to be_empty
181
+ end
182
+
183
+ it 'fetches a legal user using the User module' do
184
+ legal_user = MangoPay::User.fetch(new_legal_user['Id'])
185
+ expect(legal_user['Id']).to eq(new_legal_user['Id'])
186
+ end
187
+
188
+ it 'fetches a natural user using the User module' do
189
+ natural_user = MangoPay::User.fetch(new_natural_user['Id'])
190
+ expect(natural_user['Id']).to eq(new_natural_user['Id'])
191
+ end
192
+
193
+ it 'fetches a legal user' do
194
+ user = MangoPay::LegalUser.fetch(new_legal_user['Id'])
195
+ expect(user['Id']).to eq(new_legal_user['Id'])
196
+ end
197
+
198
+ it 'fetches a natural user' do
199
+ user = MangoPay::NaturalUser.fetch(new_natural_user['Id'])
200
+ expect(user['Id']).to eq(new_natural_user['Id'])
201
+ end
202
+ end
203
+
204
+ describe 'FETCH SCA' do
205
+ it 'fetches a SCA legal user using the User module' do
206
+ user = new_legal_user_sca_owner
207
+ fetched = MangoPay::User.fetch_sca(new_legal_user_sca_owner['Id'])
208
+ expect(fetched['Id']).to eq(user['Id'])
209
+ end
210
+
211
+ it 'fetches a SCA natural user using the User module' do
212
+ user = new_natural_user_sca_owner
213
+ fetched = MangoPay::User.fetch_sca(user['Id'])
214
+ expect(fetched['Id']).to eq(user['Id'])
215
+ end
216
+
217
+ it 'fetches a SCA legal user' do
218
+ user = new_legal_user_sca_owner
219
+ fetched = MangoPay::LegalUserSca.fetch(user['Id'])
220
+ expect(fetched['Id']).to eq(user['Id'])
221
+ end
222
+
223
+ it 'fetches a SCA natural user' do
224
+ user = new_natural_user_sca_owner
225
+ fetched = MangoPay::NaturalUserSca.fetch(user['Id'])
226
+ expect(fetched['Id']).to eq(user['Id'])
227
+ end
228
+ end
229
+
230
+ describe 'FETCH TRANSACTIONS' do
231
+ it 'fetches empty list of transactions if no transactions done' do
232
+ transactions = MangoPay::User.transactions(new_natural_user['Id'])
233
+ expect(transactions).to be_kind_of(Array)
234
+ expect(transactions).to be_empty
235
+ end
236
+
237
+ it 'fetches list with single transaction after payin done' do
238
+ payin = new_payin_card_direct
239
+ transactions = MangoPay::User.transactions(new_natural_user['Id'])
240
+ expect(transactions).to be_kind_of(Array)
241
+ expect(transactions.count).to eq 1
242
+ expect(transactions.first['Id']).to eq payin['Id']
243
+ end
244
+
245
+ it 'fetches list with two transactions after payin and payout done' do
246
+ payin = new_payin_card_direct
247
+ payout = create_new_payout_bankwire(payin)
248
+ # wait for the transactions to be created
249
+ sleep(2)
250
+ transactions = MangoPay::User.transactions(new_natural_user['Id'])
251
+
252
+ expect(transactions).to be_kind_of(Array)
253
+ expect(transactions.count).to eq 2
254
+
255
+ transactions_ids = transactions.map {|t| t['Id']}
256
+ expect(transactions_ids).to include payin['Id']
257
+ expect(transactions_ids).to include payout['Id']
258
+ end
259
+
260
+ it 'fetches transactions sca' do
261
+ begin
262
+ MangoPay::User.transactions(new_natural_user['Id'], {'ScaContext': 'USER_PRESENT'})
263
+ rescue MangoPay::ResponseError => ex
264
+ expect(ex.details['RedirectUrl']).not_to be_nil
265
+ end
266
+ end
267
+ end
268
+
269
+ describe 'FETCH WALLETS' do
270
+ it 'fetches empty list of wallets if no wallets created' do
271
+ wallets = MangoPay::User.wallets(new_natural_user['Id'])
272
+ expect(wallets).to be_kind_of(Array)
273
+ expect(wallets).to be_empty
274
+ end
275
+
276
+ it 'fetches list with single wallet after created' do
277
+ wallet = new_wallet
278
+ wallets = MangoPay::User.wallets(new_natural_user['Id'])
279
+ expect(wallets).to be_kind_of(Array)
280
+ expect(wallets.count).to eq 1
281
+ expect(wallets.first['Id']).to eq wallet['Id']
282
+ end
283
+
284
+ it 'fetches wallets sca' do
285
+ begin
286
+ MangoPay::User.wallets(new_natural_user['Id'], {'ScaContext': 'USER_PRESENT'})
287
+ rescue MangoPay::ResponseError => ex
288
+ expect(ex.details['RedirectUrl']).not_to be_nil
289
+ end
290
+ end
291
+ end
292
+
293
+ describe 'FETCH CARDS' do
294
+ it 'fetches empty list of cards if no cards created' do
295
+ cards = MangoPay::User.cards(new_natural_user['Id'])
296
+ expect(cards).to be_kind_of(Array)
297
+ expect(cards).to be_empty
298
+ end
299
+
300
+ it 'fetches list with single card after created' do
301
+ card = new_card_registration_completed
302
+ cards = MangoPay::User.cards(new_natural_user['Id'])
303
+ expect(cards).to be_kind_of(Array)
304
+ expect(cards.count).to eq 1
305
+ expect(cards.first['Id']).to eq card['CardId']
306
+ end
307
+
308
+ it 'fetches card details' do
309
+ card = new_card_registration_completed
310
+ fetched = MangoPay::Card.fetch(card['CardId'])
311
+
312
+ expect(fetched['Id']).not_to be_nil
313
+ expect(fetched['UserId']).to eq(new_natural_user["Id"])
314
+ expect(fetched['Currency']).to eq('EUR')
315
+ end
316
+ end
317
+
318
+ describe 'FETCH BANK ACCOUNTS' do
319
+ it 'fetches empty list of bank accounts if no bank_accounts created' do
320
+ bank_accounts = MangoPay::User.bank_accounts(new_natural_user['Id'])
321
+ expect(bank_accounts).to be_kind_of(Array)
322
+ expect(bank_accounts).to be_empty
323
+ end
324
+
325
+ it 'fetches list with single bank_account after created' do
326
+ bank_account = new_bank_account
327
+ bank_accounts = MangoPay::User.bank_accounts(new_natural_user['Id'])
328
+ expect(bank_accounts).to be_kind_of(Array)
329
+ expect(bank_accounts.count).to eq 1
330
+ expect(bank_accounts.first['Id']).to eq bank_account['Id']
331
+ end
332
+ end
333
+
334
+ describe 'FETCH EMONEY' do
335
+ it 'fetches emoney for the user for year 2019' do
336
+ emoney = MangoPay::User.emoney(new_natural_user['Id'], 2019)
337
+ expect(emoney['UserId']).to eq new_natural_user['Id']
338
+ expect(emoney['CreditedEMoney']['Amount']).to eq 0
339
+ expect(emoney['CreditedEMoney']['Currency']).to eq 'EUR'
340
+ expect(emoney['DebitedEMoney']['Amount']).to eq 0
341
+ expect(emoney['DebitedEMoney']['Currency']).to eq 'EUR'
342
+ end
343
+
344
+ it 'fetches emoney for the user for date 08/2019' do
345
+ emoney = MangoPay::User.emoney(new_natural_user['Id'], 2019, 8)
346
+ expect(emoney['UserId']).to eq new_natural_user['Id']
347
+ expect(emoney['CreditedEMoney']['Amount']).to eq 0
348
+ expect(emoney['CreditedEMoney']['Currency']).to eq 'EUR'
349
+ expect(emoney['DebitedEMoney']['Amount']).to eq 0
350
+ expect(emoney['DebitedEMoney']['Currency']).to eq 'EUR'
351
+ end
352
+ end
353
+
354
+ describe 'FETCH Kyc Document' do
355
+ it 'fetches empty list of kyc documents if no kyc document created' do
356
+ documents = MangoPay::User.kyc_documents(new_natural_user['Id'])
357
+ expect(documents).to be_kind_of(Array)
358
+ expect(documents).to be_empty
359
+ end
360
+
361
+ it 'fetches list with single kyc document after created' do
362
+ document = new_document
363
+ documents = MangoPay::User.kyc_documents(document['UserId'])
364
+ expect(documents).to be_kind_of(Array)
365
+ expect(documents.count).to eq 1
366
+ expect(documents.first['Id']).to eq document['Id']
367
+ end
368
+ end
369
+
370
+ #describe 'CREATE UBO DECLARATION' do
371
+ # it 'creates a UBO declaration' do
372
+ # legal_user = new_legal_user
373
+ # natural_user = define_new_natural_user
374
+ # natural_user['Capacity'] = 'DECLARATIVE'
375
+ # natural_user = MangoPay::NaturalUser.create(natural_user)
376
+ # ubo_declaration = MangoPay::LegalUser.create_ubo_declaration(legal_user['Id'])
377
+
378
+ # expect(ubo_declaration).not_to be_nil
379
+ # expect(ubo_declaration['Status']).to eq 'CREATED'
380
+ # expect(ubo_declaration['UserId']).to eq legal_user['Id']
381
+ # expect(ubo_declaration['DeclaredUBOs'][0]['UserId']).to eq natural_user['Id']
382
+ # end
383
+ #end
384
+
385
+ describe 'FETCH Pre-Authorizations' do
386
+ it "fetches list of user's pre-authorizations belonging" do
387
+ legal_user = new_legal_user
388
+ pre_authorizations = MangoPay::User.pre_authorizations(legal_user['Id'])
389
+ expect(pre_authorizations).to be_an(Array)
390
+ end
391
+ end
392
+
393
+ =begin
394
+ describe 'FETCH Block Status' do
395
+ it "fetches user's block status" do
396
+ legal_user = new_legal_user
397
+ block_status = MangoPay::User.block_status(legal_user['Id'])
398
+ expect(block_status).to_not be_nil
399
+ end
400
+ end
401
+ =end
402
+
403
+ describe 'CLOSE' do
404
+ it 'closes a natural user' do
405
+ new_user = create_new_natural_user
406
+ MangoPay::NaturalUser.close(new_user['Id'])
407
+ closed = MangoPay::User.fetch(new_user['Id'])
408
+ expect(closed['UserStatus']).to eq('CLOSED')
409
+ end
410
+
411
+ it 'closes a legal user' do
412
+ new_user = new_legal_user
413
+ MangoPay::LegalUser.close(new_user['Id'])
414
+ closed = MangoPay::User.fetch(new_user['Id'])
415
+ expect(closed['UserStatus']).to eq('CLOSED')
416
+ end
417
+ end
418
+
419
+ describe 'Validate User Data Format' do
420
+ it 'validates successfully' do
421
+ validation = {
422
+ "CompanyNumber": {
423
+ "CompanyNumber": "AB123456",
424
+ "CountryCode": "IT"
425
+ }
426
+ }
427
+ result = MangoPay::User.validate_data_format(validation)
428
+ expect(result['CompanyNumber']).not_to be_nil
429
+ end
430
+
431
+ it 'validates with error' do
432
+ validation = {
433
+ "CompanyNumber": {
434
+ "CompanyNumber": "123"
435
+ }
436
+ }
437
+ expect { MangoPay::User.validate_data_format(validation) }.to raise_error { |err|
438
+ expect(err).to be_a MangoPay::ResponseError
439
+ expect(err.code).to eq '400'
440
+ expect(err.type).to eq 'param_error'
441
+ }
442
+ end
443
+ end
444
+ end