virementmaitrise 0.6.2

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 (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/CHANGELOG.md +6 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +8 -0
  8. data/Gemfile.lock +59 -0
  9. data/LICENSE.txt +674 -0
  10. data/README.md +404 -0
  11. data/Rakefile +8 -0
  12. data/bin/console +15 -0
  13. data/bin/setup +8 -0
  14. data/exemples/ais.rb +53 -0
  15. data/exemples/pis.rb +148 -0
  16. data/exemples/ressources.rb +23 -0
  17. data/lib/virementmaitrise/ais_client.rb +112 -0
  18. data/lib/virementmaitrise/api/ais/account_holders.rb +60 -0
  19. data/lib/virementmaitrise/api/ais/accounts.rb +62 -0
  20. data/lib/virementmaitrise/api/ais/authorize.rb +71 -0
  21. data/lib/virementmaitrise/api/ais/authorize_decoupled.rb +67 -0
  22. data/lib/virementmaitrise/api/ais/connect.rb +66 -0
  23. data/lib/virementmaitrise/api/ais/delete_customer.rb +53 -0
  24. data/lib/virementmaitrise/api/ais/transactions.rb +62 -0
  25. data/lib/virementmaitrise/api/auth/authentication.rb +80 -0
  26. data/lib/virementmaitrise/api/pis/connect.rb +80 -0
  27. data/lib/virementmaitrise/api/pis/initiate.rb +54 -0
  28. data/lib/virementmaitrise/api/pis/payments.rb +55 -0
  29. data/lib/virementmaitrise/api/pis/refund.rb +67 -0
  30. data/lib/virementmaitrise/api/pis/request_to_pay.rb +61 -0
  31. data/lib/virementmaitrise/api/pis/settlements.rb +50 -0
  32. data/lib/virementmaitrise/api/ressources/applications.rb +57 -0
  33. data/lib/virementmaitrise/api/ressources/providers.rb +63 -0
  34. data/lib/virementmaitrise/api/ressources/test_accounts.rb +62 -0
  35. data/lib/virementmaitrise/base_url.rb +23 -0
  36. data/lib/virementmaitrise/endpoints/ais.rb +16 -0
  37. data/lib/virementmaitrise/endpoints/authentication.rb +13 -0
  38. data/lib/virementmaitrise/endpoints/pis.rb +16 -0
  39. data/lib/virementmaitrise/endpoints/ressources.rb +13 -0
  40. data/lib/virementmaitrise/exceptions.rb +62 -0
  41. data/lib/virementmaitrise/faraday/authentication/connection.rb +177 -0
  42. data/lib/virementmaitrise/pis_client.rb +118 -0
  43. data/lib/virementmaitrise/utils/constants.rb +11 -0
  44. data/lib/virementmaitrise/utils/crypto.rb +75 -0
  45. data/lib/virementmaitrise/utils/date.rb +15 -0
  46. data/lib/virementmaitrise/utils/json_parser.rb +37 -0
  47. data/lib/virementmaitrise/utils/query_builder.rb +18 -0
  48. data/lib/virementmaitrise/utils/validation.rb +32 -0
  49. data/lib/virementmaitrise/version.rb +5 -0
  50. data/lib/virementmaitrise.rb +66 -0
  51. data/virementmaitrise.gemspec +46 -0
  52. metadata +157 -0
data/README.md ADDED
@@ -0,0 +1,404 @@
1
+ # Virement Maitrisé
2
+
3
+ Virement Maitrisé is connected with most European banks and enables a user to initiate a payment directly from their bank account. This results to a bank transfer sent from the user's bank account directly to your bank account, skipping all intermediaries. Within the SEPA region, transfers take between 10 seconds to 1 business day to arrive on your bank account. No hidden fees. Check out [our website](https://www.virementmaitrise.societegenerale.eu).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'virementmaitrise'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install virementmaitrise
20
+
21
+ ## Usage
22
+
23
+ Get started by subscribing to a free developer account. Join today to get access to our sandbox by registering on the [developer console](https://console.virementmaitrise.societegenerale.eu/auth/register) by creating your first sets of API Keys. When creating an account, specify you are an ECOMMERCE. When you’re ready to deploy to production, just go through the Activation Form in your console. Once the Virement Maitrisé Team activates your account, you’ll be ready to start receiving real bank transfers directly on the bank account specified during activation.
24
+
25
+ By default `sandbox` is the initial environment, but you can change to production when initializing your PIS or AIS client:
26
+
27
+ ### Initialize your PIS client
28
+
29
+ ```ruby
30
+ pis_client = Fintecture::PisClient.new({
31
+ environment: 'sandbox', # => ["sandbox", "test", "production"]
32
+ app_id: 'your_app_id',
33
+ app_secret: 'your_app_secret',
34
+ private_key: %q(your_private_key)
35
+ })
36
+ ```
37
+
38
+
39
+
40
+ ### Initialize your AIS client
41
+
42
+ ```ruby
43
+ ais_client = Fintecture::AisClient.new({
44
+ environment: 'sandbox', # => ["sandbox", "test", "production"]
45
+ app_id: 'your_app_id',
46
+ app_secret: 'your_app_secret',
47
+ private_key: %q(your_private_key)
48
+ })
49
+ ```
50
+
51
+
52
+
53
+ ## PIS
54
+
55
+ PIS client properties
56
+ ```ruby
57
+ pis_client.app_id
58
+ pis_client.app_secret
59
+ pis_client.private_key
60
+ pis_client.environment
61
+ pis_client.token
62
+ pis_client.token_expires_in
63
+ ```
64
+
65
+ ### Access token
66
+ This method return the token and store it in the client for future requests
67
+ ```ruby
68
+ pis_client.generate_token
69
+ ```
70
+
71
+
72
+ ### POST /connect
73
+
74
+ Creates a connect session for a PSU to initiate a payment.
75
+
76
+ Documentation:
77
+ - https://doc.virementmaitrise.societegenerale.eu/reference/createpisv2connect
78
+
79
+ ```ruby
80
+ # connect (payload, state, redirect_uri = nil, origin_uri = nil, with_virtualbeneficiary: false)
81
+ # payload: {}
82
+ # state: string
83
+ # redirect_uri: string
84
+ # origin_uri: string
85
+
86
+ response = pis_client.connect payload, "my-state", "https://www.my-redirect-uri.fr", "https://www.my-origine-uri.fr", with_virtualbeneficiary: true
87
+ ```
88
+
89
+ ### GET /payments
90
+
91
+ Get the details of all transfers or of a specific transfer, with virtual beneficiary information if required.
92
+
93
+ Documentation:
94
+ - Get all payments: https://doc.virementmaitrise.societegenerale.eu/reference/getpisv2payments
95
+ - Get a specific payment: https://doc.virementmaitrise.societegenerale.eu/reference/getpaymentsession
96
+
97
+ ```ruby
98
+ # payments (session_id = nil, with_virtualbeneficiary: false)
99
+ # session_id: string
100
+
101
+ response = pis_client.payments
102
+ # OR
103
+ response = pis_client.payments "7f47d3675f5d4964bc416b43af63b06e"
104
+ # OR
105
+ response = pis_client.payments "7f47d3675f5d4964bc416b43af63b06e", with_virtualbeneficiary: true
106
+ ```
107
+
108
+ ### POST /refund
109
+
110
+ Initiates a refund. If the amount is not specified, refunds the total.
111
+
112
+ Documentation:
113
+ - https://doc.virementmaitrise.societegenerale.eu/reference/createpisv2refund
114
+
115
+ ```ruby
116
+ # refund (session_id, amount = nil, user_id = nil))
117
+ # session_id: string
118
+ # amount: number
119
+ # user_id: string
120
+
121
+ response = pis_client.refund "7f47d3675f5d4964bc416b43af63b06e", 5.75, "8886aaa4-527d-4253-8951-a07d8bf4cf52"
122
+ ```
123
+
124
+ ### POST /request-to-pay
125
+
126
+ Creates a request to pay that merchant can then share by link, mail or sms to a customer for asynchronous payment.
127
+
128
+ Documentation:
129
+ - https://doc.virementmaitrise.societegenerale.eu/reference/createpisv2requesttopay
130
+
131
+ ```ruby
132
+ # refund (payload, x_language, redirect_uri = nil)
133
+ # payload: {}
134
+ # x_language: string
135
+ # redirect_uri: string
136
+
137
+ response = pis_client.request_to_pay payload, 'fr', "https://www.my-redirect-uri.fr"
138
+ ```
139
+
140
+ ### GET /settlements
141
+
142
+ Get the details of all settlements or of a specific settlement.
143
+
144
+ Documentation:
145
+ - Get all settlements: https://doc.virementmaitrise.societegenerale.eu/reference/getpisv2settlements
146
+ - Get a specific settlement: https://doc.virementmaitrise.societegenerale.eu/reference/getpisv2settlement
147
+
148
+ ```ruby
149
+ # settlements (settlement_id = nil, include_payments = false)
150
+ # settlement_id: string
151
+ # include_payments: boolean
152
+
153
+ response = pis_client.settlements
154
+ OR
155
+ response = pis_client.settlements "127335fdeb073e0eb2313ba0bd71ad44"
156
+ OR
157
+ response = pis_client.settlements "127335fdeb073e0eb2313ba0bd71ad44", true
158
+ ```
159
+
160
+ ## AIS
161
+ AIS client properties
162
+ ```ruby
163
+ ais_client.app_id
164
+ ais_client.app_secret
165
+ ais_client.private_key
166
+ ais_client.environment
167
+ ais_client.token
168
+ ais_client.refresh_token
169
+ ais_client.token_expires_in
170
+ ```
171
+ ### GET /connect
172
+
173
+ Get a connect session for a PSU to create a connection that will enable access to AIS features.
174
+
175
+ Documentation:
176
+ - https://doc.virementmaitrise.societegenerale.eu/reference/getaisv2connect
177
+
178
+ ```ruby
179
+ # connect (state, redirect_uri, scope = nil)
180
+ # state: string
181
+ # redirect_uri: string
182
+ # scope: string
183
+
184
+ response = ais_client.connect "my-state", "https://www.my-redirect-uri.fr"
185
+ ```
186
+ When you follow the returned url, you'll be redirect with "customer_id" & "code" parameters
187
+ ```ruby
188
+ customer_id = "fa51058b5f8306f1e048f1adda5488a9"
189
+ code = "f66ec660b0bbd2797bf6847fb4b98454"
190
+ ```
191
+
192
+ ### Access token
193
+
194
+ Returns the token and store it in the client for future requests.
195
+
196
+ Documentation:
197
+ - https://doc.virementmaitrise.societegenerale.eu/reference/createaccesstoken
198
+
199
+ ```ruby
200
+ ais_client.generate_token code
201
+ ```
202
+
203
+ ### Refresh token
204
+
205
+ Returns the token and store it in the client for future requests.
206
+ If you do not pass the refreshtoken as a parameter, the client refreshtoken will be used.
207
+
208
+ Documentation:
209
+ - https://doc.virementmaitrise.societegenerale.eu/reference/createrefreshtoken
210
+
211
+ ```ruby
212
+ # generate_refresh_token (refresh_token = nil)
213
+ # refresh_token: string
214
+
215
+ ais_client.generate_refresh_token
216
+ ```
217
+
218
+ ### GET /authorize
219
+
220
+ Authenticates your customer to their Bank for AIS access
221
+
222
+ Documentation:
223
+ - https://doc.virementmaitrise.societegenerale.eu/reference/getaisv1providerauthorization
224
+
225
+ ```ruby
226
+ # authorize (app_id_auth: false, provider_id:, redirect_uri:, state: nil, x_psu_id: nil, x_psu_ip_address: nil)
227
+ # app_id_auth: boolean
228
+ # provider_id: string
229
+ # redirect_uri: string
230
+ # state: string
231
+ # x_psu_id: string
232
+ # x_psu_ip_address: string
233
+
234
+ response = ais_client.authorize app_id_auth: false, provider_id: "agfbfr", redirect_uri: "https://www.google.fr", state: "ok", x_psu_id: "123456", x_psu_ip_address: "192.168.1.1"
235
+ ```
236
+
237
+ ### GET /accounts
238
+
239
+ Get all accounts linked to a specific AIS connection.
240
+
241
+ Documentation:
242
+ - https://doc.virementmaitrise.societegenerale.eu/reference/getaisv1customeraccounts
243
+
244
+ ```ruby
245
+ # accounts (customer_id:, account_id: nil, remove_nulls: nil, withBalances: nil)
246
+ # customer_id: string
247
+ # account_id: string
248
+ # remove_nulls: boolean
249
+ # withBalances: boolean
250
+
251
+ response = ais_client.accounts customer_id: customer_id, account_id: nil, remove_nulls: nil, withBalances: nil
252
+ ```
253
+
254
+ ### GET /transactions
255
+
256
+ Get all transactions linked to a specific AIS connection for a specific account.
257
+
258
+ Documentation:
259
+ - https://doc.virementmaitrise.societegenerale.eu/reference/getaisv1customeraccounttransactions
260
+
261
+ ```ruby
262
+ # transactions (customer_id:, account_id:, remove_nulls: nil, convert_dates: nil, filters: nil)
263
+ # customer_id: string
264
+ # account_id: string
265
+ # remove_nulls: boolean
266
+ # convert_dates: boolean
267
+ # filters: {}
268
+
269
+ transactions_filters = {
270
+ "filter[date_to]": "2020-01-01",
271
+ 'filter[date_from]': "max" # Date or 'max'
272
+ }
273
+ response = ais_client.transactions customer_id: customer_id, account_id: "b71722204d1a3f5ecd895", remove_nulls: true, convert_dates: true, filters: transactions_filters
274
+ ```
275
+
276
+ ### GET /accountholders
277
+
278
+ Retrieves all personal information of the client such as name, address and contact details for all the beneficiary owners.
279
+
280
+ Documentation:
281
+ - https://doc.virementmaitrise.societegenerale.eu/reference/getaisv1customeraccountholders
282
+
283
+ ```ruby
284
+ # account_holders (customer_id:, remove_nulls: nil)
285
+ # customer_id: string
286
+ # remove_nulls: boolean
287
+
288
+ response = ais_client.account_holders customer_id: customer_id, remove_nulls: true
289
+ ```
290
+
291
+ ### DELETE /customer
292
+
293
+ Deletes all active access tokens and all PSU data linked to requested connection.
294
+
295
+ Documentation:
296
+ - https://doc.virementmaitrise.societegenerale.eu/reference/deleteaisv1customer
297
+
298
+ ```ruby
299
+ # account_holders (customer_id:)
300
+ # customer_id: string
301
+
302
+ response = ais_client.delete_customer customer_id: customer_id
303
+ ```
304
+ ## RESSOURCES
305
+ Use the PIS client to get ressources. The "generate_token" step is not needed for this calls
306
+
307
+ ### GET /providers
308
+
309
+ Documentation:
310
+ - https://doc.virementmaitrise.societegenerale.eu/reference/getresv1providers
311
+
312
+ ```ruby
313
+ # providers (provider_id: nil, paramsProviders: nil)
314
+ # provider_id: string
315
+ # paramsProviders: string
316
+
317
+ paramsProviders = {
318
+ 'filter[country]': 'FR',
319
+ 'filter[pis]': 'SEPA',
320
+ 'filter[ais]': 'Accounts',
321
+ 'filter[psu_type]': 'retail',
322
+ 'filter[auth_model]': 'redirect',
323
+ 'sort[name]': 'DESC',
324
+ 'sort[full_name]': 'DESC',
325
+ 'sort[country]': 'DESC',
326
+ 'sort[provider_id]': 'DESC'
327
+ }
328
+ response = pis_client.providers provider_id: 'agfbfr', paramsProviders: paramsProviders
329
+ ```
330
+
331
+ ### GET /applications
332
+
333
+ Documentation:
334
+ - https://doc.virementmaitrise.societegenerale.eu/reference/getresv1applications
335
+
336
+ ```ruby
337
+ # applications ()
338
+
339
+ response = pis_client.applications
340
+ ```
341
+
342
+ ## API Errors handling
343
+ Hash version
344
+ ```ruby
345
+ begin
346
+ pis_client.refund "7f47d3675f5d4964bc416b43af63b06e", 1
347
+ rescue => e
348
+ error = JSON.parse e.to_s
349
+ puts error
350
+ end
351
+ ```
352
+
353
+ ```ruby
354
+ {
355
+ "type"=>"Virement Maitrisé api",
356
+ "status"=>401,
357
+ "errors"=>[
358
+ {
359
+ "code"=>"invalid_token",
360
+ "title"=>"Invalid Token",
361
+ "message"=>"The token is either invalid or expired."
362
+ }
363
+ ],
364
+ "error_string"=>"\nVirement Maitrisé server errors : \n status: 401 \n code: unauthorized\n id : 3006ddbf-2f97-44d8-9f63-35711b78e8a6\n\n code: invalid_token\n title: Invalid Token\n message: The token is either invalid or expired.\n\n"
365
+ }
366
+ ```
367
+ Text version
368
+ ```ruby
369
+ begin
370
+ pis_client.refund "7f47d3675f5d4964bc416b43af63b06e", 1
371
+ rescue => e
372
+ error = JSON.parse e.to_s
373
+ puts error['error_string']
374
+ end
375
+ ```
376
+
377
+ ```ruby
378
+ Fintecture server errors :
379
+ status: 401
380
+ code: unauthorized
381
+ id : 2adb9e35-ff0d-4477-959e-b1b1a7d7c812
382
+
383
+ code: invalid_token
384
+ title: Invalid Token
385
+ message: The token is either invalid or expired.
386
+
387
+ ```
388
+ ## Development
389
+
390
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
391
+
392
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
393
+
394
+ ## Contributing
395
+
396
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Virementmaitrise/virementmaitrise-sdk-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
397
+
398
+ ## License
399
+
400
+ The gem is available as open source under the terms of the [GPL-3.0 License](http://www.gnu.org/licenses/gpl-3.0.txt).
401
+
402
+ ## Code of Conduct
403
+
404
+ Everyone interacting in the Virement Maitrisé project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Virementmaitrise/virementmaitrise-sdk-ruby/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'virementmaitrise'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exemples/ais.rb ADDED
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require './lib/virementmaitrise'
4
+
5
+ config = JSON.parse(File.read('./exemples/config_ais.json'))
6
+
7
+ ais_client = VirementMaitrise::AisClient.new({
8
+ environment: config['environment'],
9
+ app_id: config['app_id'],
10
+ app_secret: config['app_secret'],
11
+ private_key: config['private_key']
12
+ })
13
+
14
+ # ######################## AIS ########################
15
+
16
+ # ------------ Connect ------------
17
+ connect_response = ais_client.connect 'ok', 'https://www.google.fr'
18
+ connect_id = connect_response['meta']['connect_id']
19
+ url = connect_response['meta']['url']
20
+
21
+ puts "Connect url => #{url}"
22
+
23
+ # Put the return of connect url here
24
+ customer_id = 'c84e6a2c66862f6ce169a11262b28f4c'
25
+ code = '173535d0acc16271e7942cc6e1772a5b'
26
+
27
+ # ------------ Get access token ------------
28
+ ais_client.generate_token code
29
+ ais_client.generate_refresh_token
30
+ # ------------ Authorize ------------
31
+ puts ais_client.authorize app_id_auth: true, provider_id: 'agfbfr', redirect_uri: 'https://www.google.fr', state: 'ok',
32
+ x_psu_id: nil, x_psu_ip_address: nil
33
+ # ------------ Authorize decoupled ------------
34
+ puts ais_client.authorize_decoupled app_id_auth: false, provider_id: 'agfbfr', polling_id: '1234'
35
+ # ------------ Get accounts ------------
36
+ accounts_response = ais_client.accounts customer_id: customer_id, account_id: nil, remove_nulls: nil, withBalances: nil
37
+ account = accounts_response['data'].first
38
+ account_id = account['id']
39
+ # ------------ Get transactions ------------
40
+ transactions_filters = {
41
+ "filter[date_to]": '2020-01-01',
42
+ 'filter[date_from]': 'max'
43
+ }
44
+ transactions_response = ais_client.transactions customer_id: customer_id, account_id: account_id, remove_nulls: true,
45
+ convert_dates: true, filters: transactions_filters
46
+ transaction = transactions_response['data'].first
47
+ puts transaction
48
+ # ------------ Get account holders ------------
49
+ # Caution the hasAccountholders field in db must have a value = 1.
50
+ puts ais_client.account_holders customer_id: customer_id, remove_nulls: nil
51
+ # ------------ Delete customer ------------
52
+ # Customer not found if customer you don't use the api before
53
+ puts ais_client.delete_customer customer_id: customer_id
data/exemples/pis.rb ADDED
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ require './lib/virementmaitrise'
4
+
5
+ config = JSON.parse(File.read('./exemples/config_pis.json'))
6
+
7
+ pis_client = VirementMaitrise::PisClient.new({
8
+ environment: config['environment'],
9
+ app_id: config['app_id'],
10
+ app_secret: config['app_secret'],
11
+ private_key: config['private_key']
12
+ })
13
+
14
+ payload_connect = {
15
+ meta: {
16
+ psu_name: 'John Doe', # Mandatory
17
+ psu_email: 'John.Doe@gmail.com', # Mandatory
18
+ psu_phone: '666777888', # Mandatory
19
+ psu_phone_prefix: '', # Optionnal
20
+ psu_ip: '127.0.0.1', # Optionnal (Plante la signature)
21
+ psu_form: '', # Mandatory - if no fixed beneficiary
22
+ psu_incorporation: '', # Mandatory - if no fixed beneficiary
23
+ psu_address: {
24
+ street: 'Main St.', # Mandatory
25
+ # number: '123', # Optional
26
+ complement: '2nd floor', # Optional
27
+ city: 'Paris', # Mandatory
28
+ zip: '75000', # Mandatory
29
+ country: 'fr' # Mandatory
30
+ }
31
+ },
32
+ data: {
33
+ type: 'PIS',
34
+ attributes: {
35
+ amount: '123', # Mandatory
36
+ currency: 'EUR', # Mandatory
37
+ communication: 'Thanks Mom!' # Mandatory
38
+ # execution_date: '2021-09-31', # Optional
39
+ # beneficiary: { # Optional
40
+ # name: "Dummy SA", # Conditional
41
+ # iban: "FR1420041010050500013M02606", # Conditional
42
+ # swift_bic: "FTSBSESSXXX", # Conditional
43
+ # street: "road of somewhere", # Conditional
44
+ # number: "2", # Optional
45
+ # complement:"", # Optional
46
+ # city: "Paris", # Conditional
47
+ # zip: "93160", # Conditional
48
+ # country: "FR", # Conditional
49
+ # form: "", # Mandatory if no fixed beneficiary
50
+ # incorporation: "" # Mandatory if no fixed beneficiary
51
+ # },
52
+ # debited_account_id: 'FR1420041010050500013M02606', # Optional
53
+ # debited_account_type: 'iban', # Mandatory if debited_account_id exist
54
+ # end_to_end_id: '5f78e902907e4209aa8df63659b05d24',
55
+ # scheme: 'AUTO' # Optional
56
+ }
57
+ }
58
+ }
59
+
60
+ payload_request_to_pay = {
61
+ meta: {
62
+ psu_name: 'John Doe', # Mandatory
63
+ psu_email: 'John.Doe@gmail.com', # Mandatory
64
+ psu_phone: '666777888', # Mandatory
65
+ psu_phone_prefix: '+33', # Optionnal
66
+ psu_address: {
67
+ street: 'Main St.', # Mandatory
68
+ number: '123', # Optional
69
+ city: 'Paris', # Mandatory
70
+ zip: '75000', # Mandatory
71
+ country: 'fr' # Mandatory
72
+ },
73
+ expirary: 86_400, # Optional
74
+ cc: 'John.Doe@gmail.com', # Optional
75
+ bcc: 'John.Doe@gmail.com' # Optional
76
+ },
77
+ data: {
78
+ type: 'REQUEST_TO_PAY',
79
+ attributes: {
80
+ amount: 123, # Mandatory
81
+ currency: 'EUR', # Mandatory
82
+ communication: 'Thanks Mom!' # Mandatory
83
+ }
84
+ }
85
+ }
86
+
87
+ payload_initiate = {
88
+ "meta": {
89
+ "psu_name": 'Bob McCheese',
90
+ "psu_email": 'John.Doe@gmail.com',
91
+ "psu_phone": '09743593535',
92
+ "psu_address": {
93
+ "street": 'route de la france',
94
+ "number": '33',
95
+ "complement": '2nd floor',
96
+ "zip": '12001',
97
+ "city": 'Paris',
98
+ "country": 'FR'
99
+ }
100
+ },
101
+ "data": {
102
+ "type": 'PIS',
103
+ "attributes": {
104
+ "amount": '149.30',
105
+ "currency": 'EUR',
106
+ "communication": 'Order 6543321'
107
+ # "beneficiary": {
108
+ # "name": "Bob Smith",
109
+ # "street": "road of somewhere",
110
+ # "number": "2",
111
+ # "city": "Paris",
112
+ # "zip": "93160",
113
+ # "country": "FR",
114
+ # "iban": "FR1420041010050500013M02606",
115
+ # "swift_bic": "BANKFRXXXXX"
116
+ # }
117
+ }
118
+ }
119
+ }
120
+
121
+ paramsProviders = {
122
+ 'filter[country]': 'FR',
123
+ 'filter[pis]': 'SEPA',
124
+ 'filter[ais]': 'Accounts',
125
+ 'filter[psu_type]': 'retail',
126
+ 'filter[auth_model]': 'redirect',
127
+ 'sort[name]': 'ASC',
128
+ 'sort[full_name]': 'ASC',
129
+ 'sort[country]': 'ASC',
130
+ 'sort[provider_id]': 'ASC'
131
+ }
132
+
133
+ # ######################## PIS ########################
134
+ # ------------ Get access token ------------
135
+ pis_client.generate_token
136
+ # ------------ Connect ------------
137
+ puts pis_client.connect payload_connect, 'ok', 'https://www.google.fr'
138
+ # ------------ Request to pay ------------
139
+ puts pis_client.request_to_pay payload_request_to_pay, 'fr', 'https://www.google.fr'
140
+ # ------------ Get payments ------------
141
+ puts pis_client.payments '7f47d3675f5d4964bc416b43af63b06e'
142
+ # ------------ Initiate ------------
143
+ puts pis_client.initiate payload_initiate, 'cmcifrpp', 'https://www.google.fr', 'ok'
144
+ # ------------ Refund ------------
145
+ puts pis_client.refund '7f47d3675f5d4964bc416b43af63b06e', 1
146
+ # ------------ settlements ------------
147
+ pis_client.settlements
148
+ pis_client.settlements '127335fdeb073e0eb2313ba0bd71ad44', true
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require './lib/virementmaitrise'
4
+
5
+ # ------------ Test class -------------
6
+ config = JSON.parse(File.read('./exemples/config_pis.json'))
7
+
8
+ pis_client = VirementMaitrise::PisClient.new({
9
+ environment: config['environment'],
10
+ app_id: config['app_id'],
11
+ app_secret: config['app_secret'],
12
+ private_key: config['private_key']
13
+ })
14
+
15
+ # ######################## RESSOURCES ########################
16
+ # ------------ Get providers ------------
17
+ puts pis_client.providers provider_id: 'agfbfr'
18
+ puts pis_client.providers paramsProviders: paramsProviders
19
+ # ------------ Get applications ------------
20
+ puts pis_client.applications
21
+ # ------------ Get test accounts ------------
22
+ puts pis_client.test_accounts
23
+ puts pis_client.test_accounts 'bbvaes'