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,294 @@
1
+ describe MangoPay::Dispute do
2
+
3
+ =begin
4
+ comment out all Dispute related unit tests please
5
+ these require manual actions on our side
6
+ and it's infact not suitable like that
7
+
8
+ # IMPORTANT NOTE!
9
+ #
10
+ # Due to the fact the disputes CANNOT be created on user's side,
11
+ # a special approach in testing is needed.
12
+ # In order to get the tests below pass, a bunch of disputes have
13
+ # to be prepared on the API server side - if they're not, you can
14
+ # just skip these tests, as they won't pass.
15
+ before(:each) do
16
+ @disputes = MangoPay::Dispute.fetch({'page' => 1, 'per_page' => 100})
17
+ end
18
+
19
+ describe 'FETCH' do
20
+ it 'fetches disputes' do
21
+ expect(@disputes).to be_kind_of(Array)
22
+ expect(@disputes).not_to be_empty
23
+ end
24
+ it 'fetches a dispute' do
25
+ id = @disputes.first['Id']
26
+ dispute = MangoPay::Dispute.fetch(id)
27
+ expect(dispute['Id']).to eq(id)
28
+ end
29
+ end
30
+
31
+ describe 'TRANSACTIONS' do
32
+ it 'fetches transactions for dispute' do
33
+ dispute = @disputes.find { |d| d['DisputeType'] == 'NOT_CONTESTABLE' }
34
+ id = dispute['Id']
35
+ transactions = MangoPay::Dispute.transactions(id, {'per_page' => 1})
36
+ expect(transactions).to be_kind_of(Array)
37
+ expect(transactions).not_to be_empty
38
+ end
39
+ end
40
+
41
+ describe 'FETCH FOR USER AND WALLET' do
42
+ it 'fetches disputes for user' do
43
+ dispute = @disputes.find { |d| d['DisputeType'] == 'NOT_CONTESTABLE' }
44
+ id = dispute['Id']
45
+ transactions = MangoPay::Dispute.transactions(id, {'per_page' => 1})
46
+ user_id = transactions[0]['AuthorId']
47
+ disputes = MangoPay::Dispute.fetch_for_user(user_id, {'per_page' => 1})
48
+ expect(disputes).to be_kind_of(Array)
49
+ expect(disputes).not_to be_empty
50
+ end
51
+ it 'fetches disputes for wallet' do
52
+ payin = MangoPay::PayIn.fetch("133379281")
53
+ wallet_id = payin['CreditedWalletId']
54
+ disputes = MangoPay::Dispute.fetch_for_wallet(wallet_id, {'per_page' => 1})
55
+ expect(disputes).to be_kind_of(Array)
56
+ expect(disputes).not_to be_empty
57
+ end
58
+ it 'fetches disputes for payin' do
59
+ disputes = MangoPay::Dispute.fetch_for_pay_in("133379281", {'per_page' => 1})
60
+ expect(disputes).to be_kind_of(Array)
61
+ expect(disputes).not_to be_empty
62
+ end
63
+ end
64
+
65
+ describe 'UPDATE' do
66
+ it 'updates a dispute' do
67
+ dispute = @disputes.first
68
+ id = dispute['Id']
69
+ new_tag = dispute['Tag'] + '.com'
70
+ changed_dispute = MangoPay::Dispute.update(id, {Tag: new_tag})
71
+ expect(changed_dispute['Tag']).to eq(new_tag)
72
+ end
73
+ end
74
+
75
+ describe 'FETCH REPUDIATION' do
76
+ it 'fetches a repudiation' do
77
+ dispute = @disputes.find {|disp| disp['InitialTransactionId'] != nil && disp['DisputeType'] == 'NOT_CONTESTABLE'}
78
+ expect(dispute).not_to be_nil, "Cannot test closing dispute because there's no not contestable disputes with transaction ID in the disputes list."
79
+ transactions = MangoPay::Dispute.transactions(dispute['Id'], {'per_page' => 1})
80
+ repudiation_id = transactions[0]['Id']
81
+ repudiation = MangoPay::Dispute.fetch_repudiation(repudiation_id)
82
+ expect(repudiation['Id']).to eq(repudiation_id)
83
+ expect(repudiation['Nature']).to eq('REPUDIATION')
84
+ end
85
+ end
86
+
87
+ describe 'CREATE AND FETCH SETTLEMENT TRANSFER' do
88
+ it 'creates and fetches settlement transfer' do
89
+ dispute = @disputes.find {|disp| disp['Status'] == 'CLOSED' && disp['DisputeType'] == 'NOT_CONTESTABLE'}
90
+ expect(dispute).not_to be_nil, "Cannot test creating settlement transfer because there's no closed, not contestable disputes in the disputes list."
91
+ transactions = MangoPay::Dispute.transactions(dispute['Id'], {'per_page' => 1})
92
+ repudiation_id = transactions[0]['Id']
93
+ repudiation = MangoPay::Dispute.fetch_repudiation(repudiation_id)
94
+ params = {
95
+ AuthorId: repudiation['AuthorId'],
96
+ DebitedFunds: {Currency: 'EUR', Amount: 1},
97
+ Fees: {Currency: 'EUR', Amount: 0},
98
+ Tag: 'Custom tag data'
99
+ }
100
+
101
+ transfer = MangoPay::Dispute.create_settlement_transfer(repudiation_id, params)
102
+ expect(transfer['Type']).to eq('TRANSFER')
103
+ expect(transfer['Nature']).to eq('SETTLEMENT')
104
+
105
+ fetched_transfer = MangoPay::Dispute.fetch_settlement_transfer(transfer['Id'])
106
+ expect(fetched_transfer['Id']).to eq(transfer['Id'])
107
+ expect(fetched_transfer['CreationDate']).to eq(transfer['CreationDate'])
108
+ end
109
+ end
110
+
111
+ # NOTE: This test has not been run. Please check it if you have the chance.
112
+ describe 'GET DISPUTES PENDING SETTLEMENT' do
113
+ it 'retrieves disputes awaiting settlement actions' do
114
+ disputes_pending = MangoPay::Dispute.fetch_pending_settlement
115
+
116
+ expect(disputes_pending).to be_kind_of Array
117
+ disputes_pending.each do |dispute|
118
+ expect(dispute['Id']).not_to be_nil
119
+ # TODO: Maybe check for corresponding status
120
+ end
121
+ end
122
+ end
123
+
124
+ describe 'DISPUTE DOCUMENTS API' do
125
+
126
+ def find_dispute
127
+ dispute = @disputes.find {|disp| ['PENDING_CLIENT_ACTION', 'REOPENED_PENDING_CLIENT_ACTION'].include?(disp['Status'])}
128
+ expect(dispute).not_to be_nil, "Cannot test dispute document API because there's no dispute with expected status in the disputes list."
129
+ dispute
130
+ end
131
+
132
+ def create_doc(dispute = nil)
133
+ no_dispute_passed = dispute.nil?
134
+ dispute = find_dispute if no_dispute_passed
135
+ params = { Type: 'DELIVERY_PROOF', Tag: 'Custom tag data' }
136
+ doc = MangoPay::Dispute.create_document(dispute['Id'], params)
137
+ doc['dispute'] = dispute if no_dispute_passed # add it for testing purposes
138
+ doc
139
+ end
140
+
141
+ it 'creates dispute document' do
142
+ doc = create_doc
143
+ expect(doc['Type']).to eq('DELIVERY_PROOF')
144
+ expect(doc['Tag']).to eq('Custom tag data')
145
+ expect(doc['Status']).to eq('CREATED')
146
+ end
147
+
148
+ it 'fetches dispute document' do
149
+ created_doc = create_doc
150
+ fetched_doc = MangoPay::Dispute.fetch_document(created_doc['Id'])
151
+ fields = ['Id', 'Type', 'Tag', 'Status', 'CreationDate', 'RefusedReasonType', 'RefusedReasonMessage']
152
+ fields.each do |field|
153
+ expect(fetched_doc[field]).to eq(created_doc[field])
154
+ end
155
+ end
156
+
157
+ it 'updates dispute document' do
158
+ created_doc = create_doc
159
+
160
+ fnm = __FILE__.sub('.rb', '.png')
161
+ ret = MangoPay::Dispute.create_document_page(created_doc['dispute']['Id'], created_doc['Id'], nil, fnm)
162
+
163
+ changed_doc = MangoPay::Dispute.update_document(created_doc['dispute']['Id'], created_doc['Id'], {
164
+ Status: 'VALIDATION_ASKED'
165
+ })
166
+ expect(changed_doc['Id']).to eq(created_doc['Id'])
167
+ expect(changed_doc['Status']).to eq('VALIDATION_ASKED')
168
+ end
169
+
170
+ it 'fetches a list of documents' do
171
+ disp = @disputes.find {|disp| disp['Status'] == 'SUBMITTED'}
172
+ disp = test_contest_dispute if disp == nil
173
+ expect(disp).not_to be_nil, "Cannot test fetching dispute documents because there's no dispute with expected status in the disputes list."
174
+
175
+ doc1 = create_doc(disp)
176
+ doc2 = create_doc(disp) # for the same dispute
177
+
178
+ filters = {'per_page' => 2, 'sort' => 'CreationDate:desc'}
179
+
180
+ # fetch last 2 docs for the dispute
181
+ docs = MangoPay::Dispute.fetch_documents(disp['Id'], filters)
182
+ expect(docs).to be_kind_of(Array)
183
+ expect(docs.count).to eq 2 # exactly 2 as pagiantion requested
184
+ # all 2 are at top as lastly created
185
+ # but may share the same CreationDate
186
+ # so the order between them is undetermined
187
+ expect(docs).to include(doc1, doc2)
188
+
189
+ # fetch all docs ever
190
+ docs = MangoPay::Dispute.fetch_documents()
191
+ expect(docs).to be_kind_of(Array)
192
+ expect(docs.count).to be >= 2
193
+
194
+ # fetch last 2 docs ever (sorting by date descending)
195
+ docs = MangoPay::Dispute.fetch_documents(nil, filters)
196
+ expect(docs).to be_kind_of(Array)
197
+ expect(docs.count).to eq 2 # exactly 2 as pagiantion requested
198
+ expect(docs).to include(doc1, doc2)
199
+ end
200
+
201
+ def create_doc_page(file)
202
+ disp = find_dispute
203
+ doc = create_doc(disp)
204
+ MangoPay::Dispute.create_document_page(disp['Id'], doc['Id'], file)
205
+ end
206
+
207
+ it 'create_document_page accepts Base64 encoded file content' do
208
+ fnm = __FILE__.sub('.rb', '.png')
209
+ bts = File.open(fnm, 'rb') { |f| f.read }
210
+ b64 = Base64.encode64(bts)
211
+ ret = create_doc_page(b64)
212
+ expect(ret).to be_nil
213
+ end
214
+
215
+ it 'create_document_page accepts file path' do
216
+ fnm = __FILE__.sub('.rb', '.png')
217
+ disp = find_dispute
218
+ doc = create_doc(disp)
219
+ ret = MangoPay::Dispute.create_document_page(disp['Id'], doc['Id'], nil, fnm)
220
+ expect(ret).to be_nil
221
+ end
222
+
223
+ it 'create_document_page fails when input string is not base64-encoded' do
224
+ file = 'any file content...'
225
+ expect { create_doc_page(file) }.to raise_error { |err|
226
+ expect(err).to be_a MangoPay::ResponseError
227
+ expect(err.code).to eq '400'
228
+ expect(err.type).to eq 'param_error'
229
+ }
230
+ end
231
+ end
232
+
233
+ # TODO: Run this test when possible
234
+ it 'create_document_consult fetches a list of document page consults' do
235
+ fnm = __FILE__.sub('.rb', '.png')
236
+ disp = find_dispute
237
+ doc = create_doc(disp)
238
+ MangoPay::Dispute.create_document_page(disp['Id'], doc['Id'], nil, fnm)
239
+ consults = MangoPay::Dispute.create_document_consult(doc['Id'])
240
+
241
+ expect(consults).not_to be_nil
242
+ expect(consults).to be_kind_of(Array)
243
+ end
244
+
245
+ def test_contest_dispute
246
+ dispute = @disputes.find do |disp|
247
+ ['PENDING_CLIENT_ACTION', 'REOPENED_PENDING_CLIENT_ACTION'].include?(disp['Status']) &&
248
+ ['CONTESTABLE', 'RETRIEVAL'].include?(disp['DisputeType'])
249
+ end
250
+ expect(dispute).not_to be_nil, "Cannot test contesting dispute because there's no available disputes with expected status and type in the disputes list."
251
+ id = dispute['Id']
252
+ contested_funds = dispute['Status'] == 'PENDING_CLIENT_ACTION' ? { Amount: 10, Currency: 'EUR' } : nil;
253
+ changed_dispute = MangoPay::Dispute.contest(id, contested_funds)
254
+ expect(changed_dispute['Id']).to eq(id)
255
+ expect(changed_dispute['Status']).to eq('SUBMITTED')
256
+ changed_dispute
257
+ end
258
+
259
+ describe 'CONTEST' do
260
+ it 'contests a dispute' do
261
+ test_contest_dispute
262
+ end
263
+ end
264
+
265
+ describe 'RESUBMIT' do
266
+ it 'resubmits a dispute' do
267
+ dispute = @disputes.find do |disp|
268
+ ['REOPENED_PENDING_CLIENT_ACTION'].include?(disp['Status'])
269
+ end
270
+ expect(dispute).not_to be_nil, "Cannot test resubmiting dispute because there's no available disputes with expected status in the disputes list."
271
+ id = dispute['Id']
272
+ changed_dispute = MangoPay::Dispute.resubmit(id)
273
+ expect(changed_dispute['Id']).to eq(id)
274
+ expect(changed_dispute['Status']).to eq('SUBMITTED')
275
+ end
276
+ end
277
+
278
+ describe 'CLOSE' do
279
+ it 'closes a dispute' do
280
+ dispute = @disputes.find do |disp|
281
+ ['PENDING_CLIENT_ACTION', 'REOPENED_PENDING_CLIENT_ACTION'].include?(disp['Status']) &&
282
+ ['CONTESTABLE', 'RETRIEVAL'].include?(disp['DisputeType'])
283
+ end
284
+ expect(dispute).not_to be_nil, "Cannot test closing dispute because there's no available disputes with expected status in the disputes list."
285
+ id = dispute['Id']
286
+ changed_dispute = MangoPay::Dispute.close(id)
287
+ expect(changed_dispute['Id']).to eq(id)
288
+ expect(changed_dispute['Status']).to eq('CLOSED')
289
+ end
290
+ end
291
+
292
+ =end
293
+
294
+ end
@@ -0,0 +1,33 @@
1
+ describe MangoPay::Event do
2
+
3
+ include_context 'payins'
4
+ include_context 'payouts'
5
+
6
+ describe 'FETCH' do
7
+
8
+ it 'accepts filtering params' do
9
+
10
+ # let's have at least 2 events
11
+ payin = new_payin_card_direct
12
+ create_new_payout_bankwire(payin)
13
+
14
+ # get all #
15
+ events = MangoPay::Event.fetch
16
+ expect(events).to be_kind_of(Array)
17
+ expect(events.count).to be >= 2
18
+
19
+ # only one per page #
20
+ events = MangoPay::Event.fetch({'per_page' => 1})
21
+ expect(events).to be_kind_of(Array)
22
+ expect(events.count).to eq 1
23
+
24
+ # filter by date
25
+ eventDate = events[0]["Date"]
26
+ resourceId=events[0]["ResourceId"]
27
+ events = MangoPay::Event.fetch({'AfterDate' => eventDate - 1, 'BeforeDate' => eventDate + 1})
28
+ expect(events).to be_kind_of(Array)
29
+ expect(events.count).to be >= 1
30
+ expect(events.count {|e| e['ResourceId'] == resourceId}).to be >= 1
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,63 @@
1
+ describe 'FETCH WITH FILTERS' do
2
+ include_context 'users'
3
+ include_context 'bank_accounts'
4
+
5
+ describe 'FETCH USERS' do
6
+
7
+ it 'returns single hash when called with id' do
8
+ id = new_natural_user['Id']
9
+ res = MangoPay::User.fetch(id)
10
+ expect(res).to be_kind_of Hash
11
+ expect(res['Id']).to eq id
12
+ end
13
+
14
+ it 'returns list of hashes with default pagination when called with no param' do
15
+ res = MangoPay::User.fetch()
16
+ expect(res).to be_kind_of Array
17
+ expect(res.count).to eq 10
18
+ end
19
+
20
+ it 'returns list of hashes with default pagination when called with empty filters' do
21
+ res = MangoPay::User.fetch(filters = {})
22
+ expect(res).to be_kind_of Array
23
+ expect(res.count).to eq 10
24
+ expect(filters['total_items']).to be > 0
25
+ expect(filters['total_pages']).to be > 0
26
+ end
27
+
28
+ it 'returns list of hashes with correct pagination when called with pagination filters' do
29
+ res = MangoPay::User.fetch(filters = {page:2, per_page:3})
30
+ expect(res).to be_kind_of Array
31
+ expect(res.count).to eq 3 # 3 items per page as requested
32
+ expect(filters['total_items']).to be > 0
33
+ expect(filters['total_pages']).to be > 0
34
+ end
35
+ end
36
+
37
+ describe 'FETCH BANK ACCOUNTS OF USER' do
38
+
39
+ it 'returns single hash when called with user id and account id' do
40
+ bank_account = new_bank_account
41
+ res = MangoPay::BankAccount.fetch(bank_account['UserId'], bank_account['Id'])
42
+ expect(res).to be_kind_of Hash
43
+ expect(res['Id']).to eq bank_account['Id']
44
+ end
45
+
46
+ it 'returns list of hashes with default pagination when called with user id only' do
47
+ bank_account = new_bank_account
48
+ res = MangoPay::BankAccount.fetch(bank_account['UserId'])
49
+ expect(res).to be_kind_of Array
50
+ expect(res.count).to eq 1 # not enough items to fill-in whole page
51
+ end
52
+
53
+ it 'returns list of hashes with default pagination when called with empty filters' do
54
+ bank_account = new_bank_account
55
+ res = MangoPay::BankAccount.fetch(bank_account['UserId'], filters = {})
56
+ expect(res).to be_kind_of Array
57
+ expect(res.count).to eq 1 # not enough items to fill-in whole page
58
+ expect(filters['total_items']).to eq 1
59
+ expect(filters['total_pages']).to eq 1
60
+ end
61
+ end
62
+
63
+ end
@@ -0,0 +1,37 @@
1
+ describe MangoPay::Hook do
2
+ include_context 'hooks'
3
+
4
+ describe 'CREATE' do
5
+ it 'creates a hook' do
6
+ expect(new_hook['Id']).to_not be_nil
7
+ end
8
+ end
9
+
10
+ describe 'UPDATE' do
11
+ it 'updates a hook' do
12
+ new_url = new_hook['Url'] + '.com'
13
+ updated_hook = MangoPay::Hook.update(new_hook['Id'], {
14
+ Url: new_url,
15
+ Tag: 'Updated Tag'
16
+ })
17
+ expect(updated_hook['Url']).to eq(new_url)
18
+ expect(updated_hook['Tag']).to eq('Updated Tag')
19
+ end
20
+ end
21
+
22
+ describe 'FETCH' do
23
+
24
+ it 'fetches a hook' do
25
+ hook = MangoPay::Hook.fetch(new_hook['Id'])
26
+ expect(hook['Id']).to eq(new_hook['Id'])
27
+ end
28
+
29
+ it 'fetches all the hooks' do
30
+ hooks = MangoPay::Hook.fetch()
31
+ expect(hooks).to be_kind_of(Array)
32
+ expect(hooks).not_to be_empty
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,41 @@
1
+ describe MangoPay do
2
+
3
+ # see https://docs.mangopay.com/api-references/idempotency-support/
4
+
5
+ include_context 'users'
6
+ require 'securerandom'
7
+
8
+ describe 'post requests' do
9
+
10
+ it 'if called with no idempotency key, act independently' do
11
+ u = define_new_natural_user
12
+ u1 = MangoPay::NaturalUser.create(u)
13
+ u2 = MangoPay::NaturalUser.create(u)
14
+ expect(u2['Id']).to be > u1['Id']
15
+ end
16
+
17
+ it 'if called with same idempotency key, the 2nd call is blocked' do
18
+ idempotency_key = SecureRandom.uuid
19
+ u = define_new_natural_user
20
+ u1 = MangoPay::NaturalUser.create(u, nil, idempotency_key)
21
+ expect {
22
+ u2 = MangoPay::NaturalUser.create(u, nil, idempotency_key)
23
+ }.to raise_error(MangoPay::ResponseError)
24
+ end
25
+
26
+ it 'if called with different idempotency key, act independently and responses may be retreived later' do
27
+ idempotency_key1 = SecureRandom.uuid
28
+ idempotency_key2 = SecureRandom.uuid
29
+ u = define_new_natural_user
30
+ u1 = MangoPay::NaturalUser.create(u, nil, idempotency_key1)
31
+ u2 = MangoPay::NaturalUser.create(u, nil, idempotency_key2)
32
+ expect(u2['Id']).to be > u1['Id']
33
+
34
+ resp1 = MangoPay.fetch_response(idempotency_key1)
35
+ resp2 = MangoPay.fetch_response(idempotency_key2)
36
+ expect(resp1['Resource']['Id']).to eq u1['Id']
37
+ expect(resp2['Resource']['Id']).to eq u2['Id']
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,47 @@
1
+ describe MangoPay::IdentityVerification do
2
+ include_context 'users'
3
+
4
+ describe 'CREATE' do
5
+ it 'creates a new identity verification' do
6
+ created = create_new_identity_verification
7
+ expect(created).not_to be_nil
8
+ expect(created['HostedUrl']).not_to be_nil
9
+ expect(created['ReturnUrl']).not_to be_nil
10
+ expect(created['Status']).to eq('PENDING')
11
+ end
12
+ end
13
+
14
+ describe 'GET' do
15
+ it 'fetches existing identity verification' do
16
+ created = create_new_identity_verification
17
+ fetched = MangoPay::IdentityVerification.get(created['Id'])
18
+
19
+ expect(fetched).not_to be_nil
20
+ expect(created['HostedUrl']).to eq(fetched['HostedUrl'])
21
+ expect(created['ReturnUrl']).to eq(fetched['ReturnUrl'])
22
+ expect(created['Status']).to eq(fetched['Status'])
23
+ end
24
+
25
+ it 'fetches all identity verifications for a user' do
26
+ create_new_identity_verification
27
+ user = new_natural_user
28
+ fetched = MangoPay::IdentityVerification.get_all(user['Id'])
29
+
30
+ expect(fetched).not_to be_nil
31
+ expect(fetched).to be_kind_of(Array)
32
+ expect(fetched).not_to be_empty
33
+ end
34
+ end
35
+
36
+ def create_new_identity_verification
37
+ user = new_natural_user
38
+ return MangoPay::IdentityVerification.create(
39
+ {
40
+ ReturnUrl: 'http://example.com',
41
+ Tag: 'created by the Ruby SDK'
42
+ },
43
+ user['Id']
44
+ )
45
+ end
46
+
47
+ end
Binary file
@@ -0,0 +1,118 @@
1
+ describe MangoPay::KycDocument do
2
+ include_context 'kyc_documents'
3
+
4
+ describe 'CREATE' do
5
+ it 'creates a document' do
6
+ expect(new_document['Id']).to_not be_nil
7
+ expect(new_document['Type']).to eq('IDENTITY_PROOF')
8
+ expect(new_document['Status']).to eq('CREATED')
9
+ expect(new_document['RefusedReasonType']).to be_nil
10
+ expect(new_document['RefusedReasonMessage']).to be_nil
11
+ expect(new_document['Flags']).to match_array([])
12
+ end
13
+ end
14
+
15
+ describe 'UPDATE' do
16
+ it 'updates a document' do
17
+ fnm = __FILE__.sub('.rb', '.png')
18
+ ret = MangoPay::KycDocument.create_page(new_natural_user['Id'], new_document['Id'], nil, fnm)
19
+
20
+ updated_document = MangoPay::KycDocument.update(new_natural_user['Id'], new_document['Id'], {
21
+ Status: 'VALIDATION_ASKED'
22
+ })
23
+ expect(updated_document['Id']).to eq(new_document['Id'])
24
+ expect(updated_document['Status']).to eq('VALIDATION_ASKED')
25
+ end
26
+ end
27
+
28
+ describe 'FETCH' do
29
+ it 'fetches a document' do
30
+ document = MangoPay::KycDocument.fetch(new_natural_user['Id'], new_document['Id'])
31
+ expect(document['Id']).to eq(new_document['Id'])
32
+ end
33
+
34
+ it 'fetches a document just by id' do
35
+ document = MangoPay::KycDocument.fetch(nil, new_document['Id'])
36
+ expect(document['Id']).to eq(new_document['Id'])
37
+ end
38
+ end
39
+
40
+ describe 'FETCH ALL' do
41
+ it 'fetches a list of documents' do
42
+ usr1 = create_new_natural_user()
43
+ usr2 = create_new_natural_user()
44
+ doc1 = create_new_document(usr1)
45
+ doc2 = create_new_document(usr1)
46
+ doc3 = create_new_document(usr2)
47
+
48
+ # fetch all docs for user 1
49
+ docs = MangoPay::KycDocument.fetch_all(usr1['Id'])
50
+ expect(docs).to be_kind_of(Array)
51
+ expect(docs.count).to eq 2
52
+ expect(docs[0]['Id']).to eq doc1['Id']
53
+ expect(docs[1]['Id']).to eq doc2['Id']
54
+
55
+ # fetch all docs for user 2
56
+ docs = MangoPay::KycDocument.fetch_all(usr2['Id'])
57
+ expect(docs).to be_kind_of(Array)
58
+ expect(docs.count).to eq 1
59
+ expect(docs[0]['Id']).to eq doc3['Id']
60
+
61
+ # fetch all docs ever
62
+ docs = MangoPay::KycDocument.fetch_all(nil, {'afterdate' => doc1['CreationDate'] - 500, 'beforedate' => doc1['CreationDate'] + 500})
63
+ expect(docs).to be_kind_of(Array)
64
+ expect(docs.count).to be >= 3 # at least last 3 docs, but probably many more
65
+
66
+ # fetch last 3 docs (sorting by date descending)
67
+ docs = MangoPay::KycDocument.fetch_all(nil, filter = {'page' => 1, 'per_page' => 3, 'sort' => 'CreationDate:desc', 'afterdate' => doc1['CreationDate'] - 500, 'beforedate' => doc1['CreationDate'] + 500})
68
+ expect(docs).to be_kind_of(Array)
69
+ expect(docs.count).to eq 3
70
+ # all 3 are at top as lastly created
71
+ # but may share the same CreationDate
72
+ # so the order between them is undetermined
73
+ expect(docs).to include(doc1, doc2, doc3)
74
+
75
+ end
76
+ end
77
+
78
+ describe 'CREATE PAGE' do
79
+
80
+ def create_page(file)
81
+ MangoPay::KycDocument.create_page(new_natural_user['Id'], new_document['Id'], file)
82
+ end
83
+
84
+ it 'accepts Base64 encoded file content' do
85
+ fnm = __FILE__.sub('.rb', '.png')
86
+ bts = File.open(fnm, 'rb') { |f| f.read }
87
+ b64 = Base64.encode64(bts)
88
+ ret = create_page(b64)
89
+ expect(ret).to_not be_nil
90
+ end
91
+
92
+ it 'accepts file path' do
93
+ fnm = __FILE__.sub('.rb', '.png')
94
+ ret = MangoPay::KycDocument.create_page(new_natural_user['Id'], new_document['Id'], nil, fnm)
95
+ expect(ret).to_not be_nil
96
+ end
97
+
98
+ it 'fails when input string is not base64-encoded' do
99
+ file = 'any file content...'
100
+ expect { create_page(file) }.to raise_error { |err|
101
+ expect(err).to be_a MangoPay::ResponseError
102
+ expect(err.code).to eq '400'
103
+ expect(err.type).to eq 'param_error'
104
+ }
105
+ end
106
+
107
+ describe 'CREATE CONSULT' do
108
+ it 'creates document pages consult' do
109
+ fnm = __FILE__.sub('.rb', '.png')
110
+ MangoPay::KycDocument.create_page(new_natural_user['Id'], new_document['Id'], nil, fnm)
111
+
112
+ consult = MangoPay::KycDocument.create_documents_consult(new_document['Id'])
113
+ expect(consult).not_to be_nil
114
+ expect(consult).to be_kind_of(Array)
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,26 @@
1
+ describe MangoPay do
2
+ include_context 'users'
3
+ include_context 'payins'
4
+ require 'json'
5
+
6
+ describe 'requests log file' do
7
+
8
+ let(:log_file) do
9
+ File.join(MangoPay.configuration.temp_dir, 'mangopay.log.tmp')
10
+ end
11
+
12
+ it 'filters confidential parameters' do
13
+ FileUtils.rm_f(log_file)
14
+ MangoPay.configuration.log_file = log_file
15
+ created = new_card_registration
16
+ lines = File.open(log_file).select { |l| l.include?('AccessKey') }
17
+ lines.each do |line|
18
+ result = JSON.load(/({.+})\s+$/.match(line)[0])
19
+ expect(result['AccessKey']).to eq('[FILTERED]')
20
+ expect(result['Id']).not_to eq('[FILTERED]')
21
+ end
22
+ FileUtils.rm_f(log_file)
23
+ end
24
+
25
+ end
26
+ end