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,49 @@
1
+ module MangoPay
2
+
3
+ class Conversion < Resource
4
+ include HTTPCalls::Fetch
5
+ include HTTPCalls::Update
6
+
7
+ class << self
8
+ def get_rate(debited_currency, credited_currency, params)
9
+ url = "#{MangoPay.api_path}/conversions/rate/#{debited_currency}/#{credited_currency}"
10
+ MangoPay.request(:get, url, params)
11
+ end
12
+
13
+ def create_instant_conversion(params, idempotency_key = nil)
14
+ url = "#{MangoPay.api_path}/conversions/instant-conversion"
15
+ MangoPay.request(:post, url, params, {}, idempotency_key)
16
+ end
17
+
18
+ def create_quoted_conversion(params, idempotency_key = nil)
19
+ url = "#{MangoPay.api_path}/conversions/quoted-conversion"
20
+ MangoPay.request(:post, url, params, {}, idempotency_key)
21
+ end
22
+
23
+ def get(id, params)
24
+ url = "#{MangoPay.api_path}/conversions/#{id}"
25
+ MangoPay.request(:get, url, params)
26
+ end
27
+
28
+ def create_quote(params, idempotency_key = nil)
29
+ url = "#{MangoPay.api_path}/conversions/quote"
30
+ MangoPay.request(:post, url, params, {}, idempotency_key)
31
+ end
32
+
33
+ def get_quote(id, params)
34
+ url = "#{MangoPay.api_path}/conversions/quote/#{id}"
35
+ MangoPay.request(:get, url, params)
36
+ end
37
+
38
+ def create_client_wallets_quoted_conversion(params, idempotency_key = nil)
39
+ url = "#{MangoPay.api_path}/clients/conversions/quoted-conversion"
40
+ MangoPay.request(:post, url, params, {}, idempotency_key)
41
+ end
42
+
43
+ def create_client_wallets_instant_conversion(params, idempotency_key = nil)
44
+ url = "#{MangoPay.api_path}/clients/conversions/instant-conversion"
45
+ MangoPay.request(:post, url, params, {}, idempotency_key)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,36 @@
1
+ module MangoPay
2
+
3
+ # See http://docs.mangopay.com/api-references/payins/preauthorized-payin/
4
+ class Deposit < Resource
5
+ def self.create(params, idempotency_key = nil)
6
+ MangoPay.request(:post, "#{MangoPay.api_path}/deposit-preauthorizations/card/direct", params, {}, idempotency_key)
7
+ end
8
+
9
+ def self.get(deposit_id, filters = {})
10
+ MangoPay.request(:get, "#{MangoPay.api_path}/deposit-preauthorizations/#{deposit_id}", {}, filters)
11
+ end
12
+
13
+ def self.cancel(deposit_id)
14
+ params = {
15
+ PaymentStatus: 'CANCELED'
16
+ }
17
+ MangoPay.request(:put, "#{MangoPay.api_path}/deposit-preauthorizations/#{deposit_id}", params)
18
+ end
19
+
20
+ def self.update(deposit_id, params)
21
+ MangoPay.request(:put, "#{MangoPay.api_path}/deposit-preauthorizations/#{deposit_id}", params)
22
+ end
23
+
24
+ def self.get_all_for_user(user_id, filters = {})
25
+ MangoPay.request(:get, "#{MangoPay.api_path}/users/#{user_id}/deposit-preauthorizations", {}, filters)
26
+ end
27
+
28
+ def self.get_all_for_card(card_id, filters = {})
29
+ MangoPay.request(:get, "#{MangoPay.api_path}/cards/#{card_id}/deposit-preauthorizations", {}, filters)
30
+ end
31
+
32
+ def self.get_transactions(deposit_id, filters = {})
33
+ MangoPay.request(:get, "#{MangoPay.api_path}/deposit-preauthorizations/#{deposit_id}/transactions", {}, filters)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,152 @@
1
+ require 'base64'
2
+
3
+ module MangoPay
4
+
5
+ # See https://docs.mangopay.com/api-references/disputes/disputes/
6
+ class Dispute < Resource
7
+ include HTTPCalls::Fetch
8
+ include HTTPCalls::Update
9
+ class << self
10
+
11
+ def close(dispute_id, idempotency_key = nil)
12
+ url = url(dispute_id) + "/close/"
13
+ MangoPay.request(:put, url, {}, {}, idempotency_key)
14
+ end
15
+
16
+ # +contested_funds+: Money hash
17
+ # see 'Contest' section @ https://docs.mangopay.com/api-references/disputes/disputes/
18
+ def contest(dispute_id, contested_funds)
19
+ url = url(dispute_id) + "/submit/"
20
+ MangoPay.request(:put, url, {ContestedFunds: contested_funds})
21
+ end
22
+
23
+ def resubmit(dispute_id)
24
+ url = url(dispute_id) + "/submit/"
25
+ MangoPay.request(:put, url)
26
+ end
27
+
28
+ def transactions(dispute_id, filters = {})
29
+ url = url(dispute_id) + "/transactions/"
30
+ MangoPay.request(:get, url, {}, filters)
31
+ end
32
+
33
+ def fetch_for_user(user_id, filters = {})
34
+ url = "#{MangoPay.api_path}/users/#{user_id}/disputes"
35
+ MangoPay.request(:get, url, {}, filters)
36
+ end
37
+
38
+ def fetch_for_wallet(wallet_id, filters = {})
39
+ url = "#{MangoPay.api_path}/wallets/#{wallet_id}/disputes"
40
+ MangoPay.request(:get, url, {}, filters)
41
+ end
42
+
43
+ def fetch_for_pay_in(pay_in_id, filters = {})
44
+ url = "#{MangoPay.api_path}/payins/#{pay_in_id}/disputes"
45
+ MangoPay.request(:get, url, {}, filters)
46
+ end
47
+
48
+ def fetch_pending_settlement(filters = {})
49
+ url = "#{MangoPay.api_path}/disputes/pendingsettlement"
50
+ MangoPay.request(:get, url, {}, filters)
51
+ end
52
+
53
+ #####################################################
54
+ # repudiations / settlement transfers
55
+ #####################################################
56
+
57
+ # see https://docs.mangopay.com/api-references/disputes/repudiations/
58
+ def fetch_repudiation(repudiation_id, idempotency_key = nil)
59
+ url = "#{MangoPay.api_path}/repudiations/#{repudiation_id}"
60
+ MangoPay.request(:get, url, {}, {}, idempotency_key)
61
+ end
62
+
63
+ # +params+: hash; see https://docs.mangopay.com/api-references/disputes/settlement-transfers/
64
+ def create_settlement_transfer(repudiation_id, params, idempotency_key = nil)
65
+ url = "#{MangoPay.api_path}/repudiations/#{repudiation_id}/settlementtransfer/"
66
+ MangoPay.request(:post, url, params, {}, idempotency_key)
67
+ end
68
+
69
+ # see https://docs.mangopay.com/api-references/disputes/settlement-transfers/
70
+ def fetch_settlement_transfer(transfer_id)
71
+ url = "#{MangoPay.api_path}/settlements/#{transfer_id}"
72
+ MangoPay.request(:get, url)
73
+ end
74
+
75
+ #####################################################
76
+ # documents
77
+ #####################################################
78
+
79
+ # +params+: hash; see https://docs.mangopay.com/api-references/disputes/dispute-documents/
80
+ def create_document(dispute_id, params, idempotency_key = nil)
81
+ url = url(dispute_id) + "/documents/"
82
+ MangoPay.request(:post, url, params, {}, idempotency_key)
83
+ end
84
+
85
+ def fetch_document(document_id)
86
+ url = "#{MangoPay.api_path}/dispute-documents/#{document_id}"
87
+ MangoPay.request(:get, url)
88
+ end
89
+
90
+ # +params+: hash; see 'Edit' section @ https://docs.mangopay.com/api-references/disputes/dispute-documents/
91
+ def update_document(dispute_id, document_id, params)
92
+ url = url(dispute_id) + "/documents/#{document_id}"
93
+ MangoPay.request(:put, url, params)
94
+ end
95
+
96
+ # Fetches list of dispute documents:
97
+ # - for the particular dispute if +dispute_id+ is provided (not nil)
98
+ # - or for all disputes otherwise.
99
+ #
100
+ # Optional +filters+ is a hash accepting following keys:
101
+ # - +page+, +per_page+, +sort+: pagination and sorting params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
102
+ # - filters such as +Type+ (e.g. 'REFUND_PROOF') and +Status+ (e.g. 'VALIDATED')
103
+ # - +BeforeDate+ (timestamp): filters documents with CreationDate _before_ this date
104
+ # - +AfterDate+ (timestamp): filters documents with CreationDate _after_ this date
105
+ #
106
+ # See https://docs.mangopay.com/api-references/disputes/dispute-documents/
107
+ #
108
+ def fetch_documents(dispute_id = nil, filters = {})
109
+ url = (dispute_id) ? url(dispute_id) + "/documents/" : "#{MangoPay.api_path}/dispute-documents/"
110
+ MangoPay.request(:get, url, {}, filters)
111
+ end
112
+
113
+ # Adds the file page (attachment) to the given document.
114
+ #
115
+ # See https://docs.mangopay.com/api-references/disputes/dispute-document-pages/ :
116
+ # - Document have to be in 'CREATED' Status
117
+ # - You can create as many pages as needed
118
+ # - Change Status to 'VALIDATION_ASKED' to submit dispute documents
119
+ #
120
+ # The file_content_base64 param may be:
121
+ # - Base64 encoded file content
122
+ # - or nil: in this case pass the file path in the next param
123
+ #
124
+ def create_document_page(dispute_id, document_id, file_content_base64, file_path = nil, idempotency_key = nil)
125
+ if file_content_base64.nil? && !file_path.nil?
126
+ bts = File.open(file_path, 'rb') { |f| f.read }
127
+ file_content_base64 = Base64.encode64(bts)
128
+ end
129
+ # normally it returns 204 HTTP code on success
130
+ begin
131
+ url = url(dispute_id) + "/documents/#{document_id}/pages"
132
+ MangoPay.request(:post, url, {'File' => file_content_base64}, {}, idempotency_key)
133
+ rescue ResponseError => ex
134
+ raise ex unless ex.code == '204'
135
+ end
136
+ end
137
+
138
+ # Creates temporary URLs where each page of
139
+ # a dispute document can be viewed.
140
+ #
141
+ # @param +document_id+ ID of the document whose pages to consult
142
+ # @return Array of consults for viewing the dispute document's pages
143
+ def create_document_consult(document_id)
144
+ MangoPay.request(:get, consult_url(document_id), {}, {})
145
+ end
146
+
147
+ def consult_url(document_id)
148
+ "#{MangoPay.api_path}/dispute-documents/#{document_id}/consult"
149
+ end
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,66 @@
1
+ module MangoPay
2
+
3
+ # Generic error superclass for MangoPay specific errors.
4
+ # Currently never instantiated directly.
5
+ # Currently only single subclass used.
6
+ class Error < StandardError
7
+ end
8
+
9
+ # See http://docs.mangopay.com/api-references/response-codes-rules/
10
+ # and http://docs.mangopay.com/api-references/error-codes/
11
+ #
12
+ # Thrown from any MangoPay API call whenever
13
+ # it returns response with HTTP code != 200.
14
+ # Check @details hash for further info.
15
+ #
16
+ # Two example exceptions with details:
17
+ #
18
+ # #<MangoPay::ResponseError:
19
+ # One or several required parameters are missing or incorrect. [...]
20
+ # Email: The Email field is required.>
21
+ # {"Message"=>"One or several required parameters are missing or incorrect.
22
+ # An incorrect resource ID also raises this kind of error.",
23
+ # "Type"=>"param_error",
24
+ # "Id"=>"66936e92-3f21-4a35-b6cf-f1d17c2fb6e5",
25
+ # "Date"=>1409047252.0,
26
+ # "errors"=>{"Email"=>"The Email field is required."},
27
+ # "Code"=>"400",
28
+ # "Url"=>"/v2/sdk-unit-tests/users/natural"}
29
+ #
30
+ # #<MangoPay::ResponseError: Internal Server Error>
31
+ # {"Message"=>"Internal Server Error",
32
+ # "Type"=>"other",
33
+ # "Id"=>"7bdc5c6f-2000-4cd3-96f3-2a3fcb746f07",
34
+ # "Date"=>1409047251.0,
35
+ # "errors"=>nil,
36
+ # "Code"=>"500",
37
+ # "Url"=>"/v2/sdk-unit-tests/payins/3380640/refunds"}
38
+ class ResponseError < Error
39
+
40
+ attr_reader :request_url, :code, :details
41
+
42
+ def initialize(request_url, code, details)
43
+ @request_url, @code, @details = request_url, code, details
44
+
45
+ @details['Code'] = code
46
+ @details['Url'] = request_url.request_uri
47
+
48
+ super(message) if message
49
+ end
50
+
51
+ def type; @details['Type'] || @details['type']; end
52
+ def error; @details['error']; end
53
+ def errors; @details['errors'] || @details['Errors'] || error; end
54
+
55
+ def message;
56
+ if error
57
+ msg = error
58
+ else
59
+ msg = @details['Message'] || @details['message']
60
+ msg += errors.sort.map {|k,v| " #{k}: #{v}"}.join if (errors && errors.is_a?(Hash))
61
+ msg
62
+ end
63
+ end
64
+
65
+ end
66
+ end
@@ -0,0 +1,18 @@
1
+ module MangoPay
2
+
3
+ # See http://docs.mangopay.com/api-references/events/
4
+ class Event < Resource
5
+
6
+ # Fetches list of events (PayIns, PayOuts, Transfers).
7
+ #
8
+ # Optional +filters+ is a hash accepting following keys:
9
+ # - +page+, +per_page+, +sort+: pagination and sorting params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
10
+ # - +EventType+: {PAYIN_NORMAL_CREATED, PAYIN_NORMAL_SUCCEEDED, PAYIN_NORMAL_FAILED etc...} (see http://docs.mangopay.com/api-references/events/)
11
+ # - +BeforeDate+ (timestamp): filters events with Date _before_ this date
12
+ # - +AfterDate+ (timestamp): filters events with Date _after_ this date
13
+ #
14
+ def self.fetch(filters={})
15
+ MangoPay.request(:get, url(), {}, filters)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,56 @@
1
+ module MangoPay
2
+ module FilterParameters
3
+
4
+ def self.request(body)
5
+ begin
6
+ body = JSON.load(body)
7
+ rescue MultiJson::LoadError => e
8
+ return body
9
+ end
10
+ filter_hash(body, req_confidential_params)
11
+ JSON.dump(body)
12
+ end
13
+
14
+ def self.response(body)
15
+ return '' if body.to_s.empty?
16
+
17
+ begin
18
+ body = JSON.load(body)
19
+ rescue MultiJson::LoadError => e
20
+ return body
21
+ end
22
+ filter_hash(body, res_confidential_params)
23
+ JSON.dump(body)
24
+ end
25
+
26
+ private
27
+
28
+ def self.filter_hash(hash, to_filter)
29
+ hash.each do |k,v|
30
+ if v.is_a?(Hash)
31
+ filter_hash(v, to_filter)
32
+ else
33
+ hash[k] = '[FILTERED]' if to_filter.include?(k)
34
+ end
35
+ end
36
+ end
37
+
38
+ def self.res_confidential_params
39
+ @@res_confidential_params ||= [
40
+ 'access_token', 'AccessKey', 'IBAN', 'CardRegistrationURL',
41
+ 'PreregistrationData', 'RedirectURL', 'RegistrationData',
42
+ 'SecureModeRedirectUrl', 'OwnerName', 'OwnerAddress', 'BIC',
43
+ 'FirstName', 'LastName', 'Email', 'AddressLine1',
44
+ 'AddressLine2',
45
+ ].freeze
46
+ end
47
+
48
+ def self.req_confidential_params
49
+ @@req_confidential_params ||= [
50
+ 'File', 'IBAN', 'OwnerName', 'OwnerAddress', 'BIC', 'FirstName',
51
+ 'LastName', 'Email', 'AddressLine1', 'AddressLine2',
52
+ ].freeze
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,9 @@
1
+ module MangoPay
2
+
3
+ # See http://docs.mangopay.com/api-references/notifications/
4
+ class Hook < Resource
5
+ include HTTPCalls::Create
6
+ include HTTPCalls::Update
7
+ include HTTPCalls::Fetch
8
+ end
9
+ end
@@ -0,0 +1,88 @@
1
+ module MangoPay
2
+ module HTTPCalls
3
+ module Create
4
+ module ClassMethods
5
+
6
+ def create(params, id = nil, idempotency_key = nil)
7
+ # LEGACY SUPPORT FOR OLD SIGNATURE: def create(*id, params)
8
+ if !params.is_a?(Hash) && id.is_a?(Hash)
9
+ temp = params
10
+ params = id
11
+ id = temp
12
+ end
13
+ MangoPay.request(:post, url(id), params, {}, idempotency_key)
14
+ end
15
+ end
16
+
17
+ def self.included(base)
18
+ base.extend(ClassMethods)
19
+ end
20
+ end
21
+
22
+ module Update
23
+ module ClassMethods
24
+ def update(id = nil, params = {}, idempotency_key = nil)
25
+ MangoPay.request(:put, url(id), params, {}, idempotency_key)
26
+ end
27
+ end
28
+
29
+ def self.included(base)
30
+ base.extend(ClassMethods)
31
+ end
32
+ end
33
+
34
+ module Fetch
35
+ module ClassMethods
36
+
37
+ # - Fetching _single_entity_ by +id+:
38
+ #
39
+ # MangoPay::User.fetch("user-id") # => {"FirstName"=>"Mango", "LastName"=>"Pay", ...}
40
+ #
41
+ # - or fetching _multiple_entities_ with _optional_ +filters+ hash,
42
+ # including _pagination_ and _sorting_ params
43
+ # +page+, +per_page+, +sort+ (see http://docs.mangopay.com/api-references/pagination/):
44
+ #
45
+ # MangoPay::User.fetch() # => [{...}, ...]: list of user data hashes (10 per page by default)
46
+ # MangoPay::User.fetch({'page' => 2, 'per_page' => 3}) # => list of 3 hashes from 2nd page
47
+ # MangoPay::BankAccount.fetch(user_id, {'sort' => 'CreationDate:desc'}) # => bank accounts by user, sorting by date descending (with default pagination)
48
+ # MangoPay::BankAccount.fetch(user_id, {'sort' => 'CreationDate:desc', 'page' => 2, 'per_page' => 3}) # both sorting and pagination params provided
49
+ #
50
+ # - For paginated queries the +filters+ param will be supplemented by +total_pages+ and +total_items+ info:
51
+ #
52
+ # MangoPay::User.fetch(filter = {'page' => 2, 'per_page' => 3})
53
+ # filter # => {"page"=>2, "per_page"=>3, "total_pages"=>1969, "total_items"=>5905}
54
+ #
55
+ def fetch(id_or_filters = nil, idempotency_key = nil, query_params_get_by_id = nil)
56
+ id, filters = HTTPCalls::Fetch.parse_id_or_filters(id_or_filters)
57
+ if query_params_get_by_id != nil and query_params_get_by_id != {}
58
+ filters = query_params_get_by_id
59
+ end
60
+ response = MangoPay.request(:get, url(id), {}, filters, idempotency_key)
61
+ end
62
+ end
63
+
64
+ def self.included(base)
65
+ base.extend(ClassMethods)
66
+ end
67
+
68
+ def self.parse_id_or_filters(id_or_filters = nil)
69
+ id_or_filters.is_a?(Hash) ? [nil, id_or_filters] : [id_or_filters, {}]
70
+ end
71
+ end
72
+
73
+ module Refund
74
+ module ClassMethods
75
+
76
+ # See http://docs.mangopay.com/api-references/refund/%E2%80%A2-refund-a-pay-in/
77
+ # See http://docs.mangopay.com/api-references/refund/%E2%80%A2-refund-a-transfer/
78
+ def refund(id = nil, params = {}, idempotency_key = nil)
79
+ MangoPay.request(:post, url(id) + '/refunds', params, {}, idempotency_key)
80
+ end
81
+ end
82
+
83
+ def self.included(base)
84
+ base.extend(ClassMethods)
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,16 @@
1
+ module MangoPay
2
+
3
+ class IdentityVerification < Resource
4
+ def self.create(params, user_id, idempotency_key = nil)
5
+ MangoPay.request(:post, "#{MangoPay.api_path}/users/#{user_id}/identity-verifications", params, {}, idempotency_key)
6
+ end
7
+
8
+ def self.get(identity_verification_id, filters = {})
9
+ MangoPay.request(:get, "#{MangoPay.api_path}/identity-verifications/#{identity_verification_id}", {}, filters)
10
+ end
11
+
12
+ def self.get_all(user_id, filters = {})
13
+ MangoPay.request(:get, "#{MangoPay.api_path}/users/#{user_id}/identity-verifications", {}, filters)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ # We can use MultiJson directly , why do we even have this module ?
2
+ module MangoPay
3
+ module JSON
4
+ class << self
5
+ def dump(*args)
6
+ MultiJson.dump(*args)
7
+ end
8
+
9
+ def load(*args)
10
+ MultiJson.load(*args)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,83 @@
1
+ require 'base64'
2
+
3
+ module MangoPay
4
+
5
+ # See http://docs.mangopay.com/api-references/kyc/documents/
6
+ class KycDocument < Resource
7
+ class << self
8
+ def create(user_id, params, idempotency_key = nil)
9
+ MangoPay.request(:post, url(user_id), params, {}, idempotency_key)
10
+ end
11
+
12
+ def update(user_id, document_id, params = {}, idempotency_key = nil)
13
+ MangoPay.request(:put, url(user_id, document_id), params, {}, idempotency_key)
14
+ end
15
+
16
+ # Fetches the KYC document belonging to the given +user_id+, with the given +document_id+.
17
+ def fetch(user_id, document_id, idempotency_key = nil)
18
+ url = (user_id) ? url(user_id, document_id) : "#{MangoPay.api_path}/KYC/documents/#{CGI.escape(document_id.to_s)}"
19
+ MangoPay.request(:get, url, {}, {}, idempotency_key)
20
+ end
21
+
22
+ # Fetches list of KYC documents:
23
+ # - for the particular user if +user_id+ is provided (not nil)
24
+ # - or for all users otherwise.
25
+ #
26
+ # Optional +filters+ is a hash accepting following keys:
27
+ # - +page+, +per_page+, +sort+: pagination and sorting params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
28
+ # - filters such as +Type+ (e.g. 'IDENTITY_PROOF') and +Status+ (e.g. 'VALIDATED')
29
+ # - +BeforeDate+ (timestamp): filters documents with CreationDate _before_ this date
30
+ # - +AfterDate+ (timestamp): filters documents with CreationDate _after_ this date
31
+ #
32
+ def fetch_all(user_id = nil, filters = {})
33
+ url = (user_id) ? url(user_id) : "#{MangoPay.api_path}/KYC/documents"
34
+ MangoPay.request(:get, url, {}, filters)
35
+ end
36
+
37
+ # Adds the file page (attachment) to the given document.
38
+ #
39
+ # See http://docs.mangopay.com/api-references/kyc/pages/ :
40
+ # - Document have to be in 'CREATED' Status
41
+ # - You can create as many pages as needed
42
+ # - Change Status to 'VALIDATION_ASKED' to submit KYC documents
43
+ #
44
+ # The file_content_base64 param may be:
45
+ # - Base64 encoded file content
46
+ # - or nil: in this case pass the file path in the next param
47
+ #
48
+ def create_page(user_id, document_id, file_content_base64, file_path = nil, idempotency_key = nil)
49
+ if file_content_base64.nil? && !file_path.nil?
50
+ bts = File.open(file_path, 'rb') { |f| f.read }
51
+ file_content_base64 = Base64.encode64(bts)
52
+ end
53
+ # normally it returns 204 HTTP code on success
54
+ begin
55
+ MangoPay.request(:post, url(user_id, document_id) + '/pages', {'File' => file_content_base64}, {}, idempotency_key)
56
+ rescue ResponseError => ex
57
+ raise ex unless ex.code == '204'
58
+ end
59
+ end
60
+
61
+ def url(user_id, document_id = nil)
62
+ if document_id
63
+ "#{MangoPay.api_path}/users/#{CGI.escape(user_id.to_s)}/KYC/documents/#{CGI.escape(document_id.to_s)}"
64
+ else
65
+ "#{MangoPay.api_path}/users/#{CGI.escape(user_id.to_s)}/KYC/documents"
66
+ end
67
+ end
68
+
69
+ # Creates temporary URLs where each page of
70
+ # a KYC document can be viewed.
71
+ #
72
+ # @param +document_id+ ID of the document whose pages to consult
73
+ # @return Array of consults for viewing the KYC document's pages
74
+ def create_documents_consult(document_id)
75
+ MangoPay.request(:post, consult_url(document_id), {}, {})
76
+ end
77
+
78
+ def consult_url(document_id)
79
+ "#{MangoPay.api_path}/KYC/documents/#{document_id}/consult"
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,21 @@
1
+ module MangoPay
2
+
3
+ # See http://docs.mangopay.com/api-references/users/legal-users/
4
+ # See also parent class MangoPay::User
5
+ class LegalUser < User
6
+
7
+ def self.url(id = nil)
8
+ if id
9
+ "#{MangoPay.api_path}/users/legal/#{CGI.escape(id.to_s)}"
10
+ else
11
+ "#{MangoPay.api_path}/users/legal"
12
+ end
13
+ end
14
+
15
+ class << self
16
+ def close(user_id)
17
+ MangoPay.request(:delete, url(user_id))
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ module MangoPay
2
+
3
+ # See https://docs.mangopay.com/api-reference/users/legal-user-object-sca
4
+ class LegalUserSca < User
5
+
6
+ def self.url(id = nil)
7
+ if id
8
+ "#{MangoPay.api_path}/sca/users/legal/#{CGI.escape(id.to_s)}"
9
+ else
10
+ "#{MangoPay.api_path}/sca/users/legal"
11
+ end
12
+ end
13
+
14
+ class << self
15
+ def categorize(user_id, params)
16
+ url = "#{MangoPay.api_path}/sca/users/legal/#{user_id}/category"
17
+ MangoPay.request(:put, url, params)
18
+ end
19
+
20
+ def close(user_id)
21
+ MangoPay.request(:delete, url(user_id))
22
+ end
23
+ end
24
+ end
25
+ end