mangopay 3.4.0 → 3.26.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.
- checksums.yaml +4 -4
- data/.github/workflows/ruby_cd.yml +34 -0
- data/.github/workflows/ruby_ci.yml +30 -0
- data/CHANGELOG.md +249 -4
- data/README.md +19 -0
- data/lib/mangopay/authorization_token.rb +1 -1
- data/lib/mangopay/bankingaliases_iban.rb +2 -2
- data/lib/mangopay/card.rb +10 -0
- data/lib/mangopay/client.rb +0 -5
- data/lib/mangopay/conversion.rb +39 -0
- data/lib/mangopay/deposit.rb +20 -0
- data/lib/mangopay/dispute.rb +2 -2
- data/lib/mangopay/errors.rb +2 -2
- data/lib/mangopay/filter_parameters.rb +7 -2
- data/lib/mangopay/pay_in.rb +150 -1
- data/lib/mangopay/pay_out.rb +11 -0
- data/lib/mangopay/payment_method_metadata.rb +13 -0
- data/lib/mangopay/refund.rb +1 -0
- data/lib/mangopay/regulatory.rb +22 -0
- data/lib/mangopay/ubo_declaration.rb +6 -4
- data/lib/mangopay/version.rb +1 -1
- data/lib/mangopay.rb +102 -8
- data/spec/mangopay/bankingaliases_spec.rb +1 -1
- data/spec/mangopay/card_registration_spec.rb +17 -2
- data/spec/mangopay/client_spec.rb +12 -12
- data/spec/mangopay/configuration_spec.rb +98 -0
- data/spec/mangopay/conversion_spec.rb +64 -0
- data/spec/mangopay/deposit_spec.rb +75 -0
- data/spec/mangopay/kyc_document_spec.rb +1 -0
- data/spec/mangopay/payin_applepay_direct_spec.rb +1 -1
- data/spec/mangopay/payin_bancontact_web_spec.rb +30 -0
- data/spec/mangopay/payin_blik_web_spec.rb +32 -0
- data/spec/mangopay/payin_giropay_web_spec.rb +30 -0
- data/spec/mangopay/payin_googlepay_direct_spec.rb +21 -0
- data/spec/mangopay/payin_ideal_web_spec.rb +30 -0
- data/spec/mangopay/payin_klarna_web_spec.rb +32 -0
- data/spec/mangopay/payin_mbway_web_spec.rb +32 -0
- data/spec/mangopay/payin_multibanco_web_spec.rb +31 -0
- data/spec/mangopay/payin_payconiq_web_spec.rb +25 -0
- data/spec/mangopay/payin_paypal_web_spec.rb +21 -0
- data/spec/mangopay/payin_preauthorized_direct_spec.rb +21 -1
- data/spec/mangopay/payin_satispay_web_spec.rb +32 -0
- data/spec/mangopay/payment_method_metadata_spec.rb +15 -0
- data/spec/mangopay/payout_bankwire_spec.rb +20 -0
- data/spec/mangopay/preauthorization_spec.rb +1 -2
- data/spec/mangopay/recurring_payin_spec.rb +82 -0
- data/spec/mangopay/regulatory_spec.rb +26 -0
- data/spec/mangopay/shared_resources.rb +714 -219
- data/spec/mangopay/transaction_spec.rb +5 -0
- data/spec/mangopay/ubo_declaration_spec.rb +14 -3
- data/spec/mangopay/ubo_spec.rb +3 -3
- data/spec/mangopay/user_spec.rb +16 -1
- data/spec/mangopay/wallet_spec.rb +5 -0
- metadata +39 -4
- data/.travis.yml +0 -19
data/lib/mangopay/pay_in.rb
CHANGED
@@ -21,6 +21,7 @@ module MangoPay
|
|
21
21
|
# See http://docs.mangopay.com/api-references/payins/payins-card-web/
|
22
22
|
class Web < Resource
|
23
23
|
include HTTPCalls::Create
|
24
|
+
|
24
25
|
def self.url(*)
|
25
26
|
"#{MangoPay.api_path}/payins/card/#{CGI.escape(class_name.downcase)}"
|
26
27
|
end
|
@@ -40,6 +41,7 @@ module MangoPay
|
|
40
41
|
# See http://docs.mangopay.com/api-references/payins/payindirectcard/
|
41
42
|
class Direct < Resource
|
42
43
|
include HTTPCalls::Create
|
44
|
+
|
43
45
|
def self.url(*)
|
44
46
|
"#{MangoPay.api_path}/payins/card/#{CGI.escape(class_name.downcase)}"
|
45
47
|
end
|
@@ -52,9 +54,14 @@ module MangoPay
|
|
52
54
|
# See http://docs.mangopay.com/api-references/payins/preauthorized-payin/
|
53
55
|
class Direct < Resource
|
54
56
|
include HTTPCalls::Create
|
57
|
+
|
55
58
|
def self.url(*)
|
56
59
|
"#{MangoPay.api_path}/payins/preauthorized/direct"
|
57
60
|
end
|
61
|
+
|
62
|
+
def self.create_pre_authorized_deposit_pay_in(params, idempotency_key = nil)
|
63
|
+
MangoPay.request(:post, "#{MangoPay.api_path}/payins/deposit-preauthorized/direct/full-capture", params, {}, idempotency_key)
|
64
|
+
end
|
58
65
|
end
|
59
66
|
|
60
67
|
end
|
@@ -64,6 +71,7 @@ module MangoPay
|
|
64
71
|
# See http://docs.mangopay.com/api-references/payins/payinbankwire/
|
65
72
|
class Direct < Resource
|
66
73
|
include HTTPCalls::Create
|
74
|
+
|
67
75
|
def self.url(*)
|
68
76
|
"#{MangoPay.api_path}/payins/bankwire/direct"
|
69
77
|
end
|
@@ -79,6 +87,7 @@ module MangoPay
|
|
79
87
|
# See http://docs.mangopay.com/api-references/payins/direct-debit-pay-in-web/
|
80
88
|
class Web < Resource
|
81
89
|
include HTTPCalls::Create
|
90
|
+
|
82
91
|
def self.url(*)
|
83
92
|
"#{MangoPay.api_path}/payins/directdebit/#{CGI.escape(class_name.downcase)}"
|
84
93
|
end
|
@@ -87,6 +96,7 @@ module MangoPay
|
|
87
96
|
# See https://docs.mangopay.com/api-references/payins/direct-debit-pay-in-direct/
|
88
97
|
class Direct < Resource
|
89
98
|
include HTTPCalls::Create
|
99
|
+
|
90
100
|
def self.url(*)
|
91
101
|
"#{MangoPay.api_path}/payins/directdebit/#{CGI.escape(class_name.downcase)}"
|
92
102
|
end
|
@@ -97,11 +107,38 @@ module MangoPay
|
|
97
107
|
module PayPal
|
98
108
|
|
99
109
|
# See https://docs.mangopay.com/api-references/payins/paypal-payin/
|
110
|
+
# # <b>DEPRECATED</b>: 'create' function is now deprecated.
|
111
|
+
# Please use the 'create_v2' function - MangoPay::PayIn::PayPal::Web.create_new(params)
|
100
112
|
class Web < Resource
|
101
113
|
include HTTPCalls::Create
|
114
|
+
|
102
115
|
def self.url(*)
|
103
116
|
"#{MangoPay.api_path}/payins/paypal/#{CGI.escape(class_name.downcase)}"
|
104
117
|
end
|
118
|
+
|
119
|
+
def self.create_v2(params, idempotency_key = nil)
|
120
|
+
MangoPay.request(:post, "#{MangoPay.api_path}/payins/payment-methods/paypal", params, {}, idempotency_key)
|
121
|
+
end
|
122
|
+
|
123
|
+
# Add tracking information to a PayPal PayIn (add the tracking number and carrier for LineItems shipments.)
|
124
|
+
# Caution – Tracking information cannot be edited
|
125
|
+
# You can’t modify the TrackingNumber, Carrier, or NotifyBuyer once added.
|
126
|
+
# You can only send a unique tracking number once.
|
127
|
+
def self.add_paypal_tracking_information(pay_in_id, params, idempotency_key = nil)
|
128
|
+
MangoPay.request(:put, "#{MangoPay.api_path}/payins/#{pay_in_id}/trackings", params, {}, idempotency_key)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
module Payconiq
|
135
|
+
|
136
|
+
class Web < Resource
|
137
|
+
include HTTPCalls::Create
|
138
|
+
|
139
|
+
def self.url(*)
|
140
|
+
"#{MangoPay.api_path}/payins/payconiq/#{CGI.escape(class_name.downcase)}"
|
141
|
+
end
|
105
142
|
end
|
106
143
|
|
107
144
|
end
|
@@ -121,7 +158,119 @@ module MangoPay
|
|
121
158
|
include HTTPCalls::Create
|
122
159
|
|
123
160
|
def self.url(*)
|
124
|
-
"#{MangoPay.api_path}/payins/googlepay
|
161
|
+
"#{MangoPay.api_path}/payins/payment-methods/googlepay"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
module Mbway
|
167
|
+
class Web < Resource
|
168
|
+
include HTTPCalls::Create
|
169
|
+
|
170
|
+
def self.url(*)
|
171
|
+
"#{MangoPay.api_path}/payins/payment-methods/mbway"
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
module Multibanco
|
177
|
+
class Web < Resource
|
178
|
+
include HTTPCalls::Create
|
179
|
+
|
180
|
+
def self.url(*)
|
181
|
+
"#{MangoPay.api_path}/payins/payment-methods/multibanco"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
module Blik
|
187
|
+
class Web < Resource
|
188
|
+
include HTTPCalls::Create
|
189
|
+
|
190
|
+
def self.url(*)
|
191
|
+
"#{MangoPay.api_path}/payins/payment-methods/blik"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
module Satispay
|
197
|
+
class Web < Resource
|
198
|
+
include HTTPCalls::Create
|
199
|
+
|
200
|
+
def self.url(*)
|
201
|
+
"#{MangoPay.api_path}/payins/payment-methods/satispay"
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
module Klarna
|
207
|
+
class Web < Resource
|
208
|
+
include HTTPCalls::Create
|
209
|
+
|
210
|
+
def self.url(*)
|
211
|
+
"#{MangoPay.api_path}/payins/payment-methods/klarna"
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
module Ideal
|
217
|
+
class Web < Resource
|
218
|
+
include HTTPCalls::Create
|
219
|
+
|
220
|
+
def self.url(*)
|
221
|
+
"#{MangoPay.api_path}/payins/payment-methods/ideal"
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
module Giropay
|
227
|
+
class Web < Resource
|
228
|
+
include HTTPCalls::Create
|
229
|
+
|
230
|
+
def self.url(*)
|
231
|
+
"#{MangoPay.api_path}/payins/payment-methods/giropay"
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
module Bancontact
|
237
|
+
class Web < Resource
|
238
|
+
include HTTPCalls::Create
|
239
|
+
|
240
|
+
def self.url(*)
|
241
|
+
"#{MangoPay.api_path}/payins/payment-methods/bancontact"
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
module RecurringPayments
|
247
|
+
class Recurring < Resource
|
248
|
+
include HTTPCalls::Create
|
249
|
+
include HTTPCalls::Fetch
|
250
|
+
include HTTPCalls::Update
|
251
|
+
|
252
|
+
def self.url(*args)
|
253
|
+
if args.any?
|
254
|
+
"#{MangoPay.api_path}/recurringpayinregistrations/#{args.first}"
|
255
|
+
else
|
256
|
+
"#{MangoPay.api_path}/recurringpayinregistrations"
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
class CIT < Resource
|
262
|
+
include HTTPCalls::Create
|
263
|
+
|
264
|
+
def self.url(*)
|
265
|
+
"#{MangoPay.api_path}/payins/recurring/card/direct"
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
class MIT < Resource
|
270
|
+
include HTTPCalls::Create
|
271
|
+
|
272
|
+
def self.url(*)
|
273
|
+
"#{MangoPay.api_path}/payins/recurring/card/direct"
|
125
274
|
end
|
126
275
|
end
|
127
276
|
end
|
data/lib/mangopay/pay_out.rb
CHANGED
@@ -26,5 +26,16 @@ module MangoPay
|
|
26
26
|
MangoPay.request(:get, url);
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
30
|
+
# See https://docs.mangopay.com/endpoints/v2.01/payouts#e1058_check-instant-payout-eligibility
|
31
|
+
module InstantPayoutEligibility
|
32
|
+
class Reachability < Resource
|
33
|
+
include HTTPCalls::Create
|
34
|
+
|
35
|
+
def self.url(*)
|
36
|
+
"#{MangoPay.api_path}/payouts/reachability"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
29
40
|
end
|
30
41
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module MangoPay
|
2
|
+
class PaymentMethodMetadata < Resource
|
3
|
+
include HTTPCalls::Fetch
|
4
|
+
include HTTPCalls::Update
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def get_metadata(metadata)
|
8
|
+
url = "#{MangoPay.api_path}/payment-methods/metadata"
|
9
|
+
MangoPay.request(:post, url, metadata)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/mangopay/refund.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
module MangoPay
|
2
|
+
# Provides API methods for the UBO entity.
|
3
|
+
class Regulatory < Resource
|
4
|
+
class << self
|
5
|
+
def one_country_url(country_iso)
|
6
|
+
"#{MangoPay.api_path_no_client}/countries/#{country_iso}/authorizations"
|
7
|
+
end
|
8
|
+
|
9
|
+
def all_countries_url
|
10
|
+
"#{MangoPay.api_path_no_client}/countries/authorizations"
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_country_authorizations(country_iso)
|
14
|
+
MangoPay.request(:get, one_country_url(country_iso))
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_all_countries_authorizations
|
18
|
+
MangoPay.request(:get, all_countries_url)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -10,15 +10,17 @@ module MangoPay
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
def create(user_id, idempotency_key)
|
13
|
+
def create(user_id, idempotency_key = nil)
|
14
14
|
MangoPay.request(:post, url(user_id), {}, {}, idempotency_key)
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
# Fetches the Ubo declaration belonging to the given +user_id+ if given, with the given +id+.
|
18
|
+
def fetch(user_id, id, idempotency_key = nil)
|
19
|
+
url = (user_id) ? url(user_id, id) : "#{MangoPay.api_path}/kyc/ubodeclarations/#{CGI.escape(id.to_s)}"
|
20
|
+
MangoPay.request(:get, url, {}, {}, idempotency_key)
|
19
21
|
end
|
20
22
|
|
21
|
-
def update(user_id, id, params = {}, idempotency_key)
|
23
|
+
def update(user_id, id, params = {}, idempotency_key = nil)
|
22
24
|
request_params = {
|
23
25
|
Status: params['Status'],
|
24
26
|
Ubos: params['Ubos']
|
data/lib/mangopay/version.rb
CHANGED
data/lib/mangopay.rb
CHANGED
@@ -5,6 +5,7 @@ require 'multi_json'
|
|
5
5
|
require 'benchmark'
|
6
6
|
require 'logger'
|
7
7
|
require 'time'
|
8
|
+
require 'securerandom'
|
8
9
|
|
9
10
|
# helpers
|
10
11
|
require 'mangopay/version'
|
@@ -42,15 +43,38 @@ module MangoPay
|
|
42
43
|
autoload :BankingAliasesIBAN, 'mangopay/bankingaliases_iban'
|
43
44
|
autoload :UboDeclaration, 'mangopay/ubo_declaration'
|
44
45
|
autoload :Ubo, 'mangopay/ubo'
|
46
|
+
autoload :Regulatory, 'mangopay/regulatory'
|
47
|
+
autoload :Deposit, 'mangopay/deposit'
|
48
|
+
autoload :Conversion, 'mangopay/conversion'
|
49
|
+
autoload :PaymentMethodMetadata, 'mangopay/payment_method_metadata'
|
45
50
|
|
46
51
|
# temporary
|
47
52
|
autoload :Temp, 'mangopay/temp'
|
48
53
|
|
54
|
+
@configurations = {}
|
55
|
+
|
49
56
|
class Configuration
|
50
57
|
attr_accessor :preproduction, :root_url,
|
51
58
|
:client_id, :client_apiKey,
|
52
|
-
:temp_dir, :log_file, :http_timeout,
|
53
|
-
:
|
59
|
+
:temp_dir, :log_file, :log_trace_headers, :http_timeout,
|
60
|
+
:http_max_retries, :http_open_timeout,
|
61
|
+
:logger, :use_ssl, :uk_header_flag
|
62
|
+
|
63
|
+
def apply_configuration
|
64
|
+
MangoPay.configure do |config|
|
65
|
+
config.preproduction = @preproduction
|
66
|
+
config.client_id = @client_id
|
67
|
+
config.client_apiKey = @client_apiKey
|
68
|
+
config.log_file = @log_file
|
69
|
+
config.log_trace_headers = @log_trace_headers
|
70
|
+
config.http_timeout = @http_timeout
|
71
|
+
config.http_max_retries = @http_max_retries
|
72
|
+
config.http_open_timeout = @http_open_timeout
|
73
|
+
config.use_ssl = @use_ssl
|
74
|
+
config.logger = @logger
|
75
|
+
config.uk_header_flag = @uk_header_flag
|
76
|
+
end
|
77
|
+
end
|
54
78
|
|
55
79
|
def preproduction
|
56
80
|
@preproduction || false
|
@@ -61,7 +85,31 @@ module MangoPay
|
|
61
85
|
end
|
62
86
|
|
63
87
|
def http_timeout
|
64
|
-
@http_timeout ||
|
88
|
+
@http_timeout || 30
|
89
|
+
end
|
90
|
+
|
91
|
+
def http_max_retries
|
92
|
+
@http_max_retries || 1
|
93
|
+
end
|
94
|
+
|
95
|
+
def http_open_timeout
|
96
|
+
@http_open_timeout || 30
|
97
|
+
end
|
98
|
+
|
99
|
+
def use_ssl?
|
100
|
+
return true unless preproduction == true
|
101
|
+
return true unless defined?(@use_ssl)
|
102
|
+
return false if @use_ssl == false
|
103
|
+
|
104
|
+
true
|
105
|
+
end
|
106
|
+
|
107
|
+
def log_trace_headers
|
108
|
+
@log_trace_headers || false
|
109
|
+
end
|
110
|
+
|
111
|
+
def uk_header_flag
|
112
|
+
@uk_header_flag || false
|
65
113
|
end
|
66
114
|
end
|
67
115
|
|
@@ -74,6 +122,10 @@ module MangoPay
|
|
74
122
|
"/#{version_code}/#{MangoPay.configuration.client_id}"
|
75
123
|
end
|
76
124
|
|
125
|
+
def api_path_no_client
|
126
|
+
"/#{version_code}"
|
127
|
+
end
|
128
|
+
|
77
129
|
def api_uri(url='')
|
78
130
|
URI(configuration.root_url + url)
|
79
131
|
end
|
@@ -114,6 +166,23 @@ module MangoPay
|
|
114
166
|
@ratelimit = obj
|
115
167
|
end
|
116
168
|
|
169
|
+
# Add MangoPay.Configuration to the list of configs
|
170
|
+
def add_config(name, config)
|
171
|
+
@configurations[name] = config
|
172
|
+
end
|
173
|
+
|
174
|
+
# Fetch a MangoPay configuration from the list of configs. Throw error if not found
|
175
|
+
def get_config(name)
|
176
|
+
config = @configurations[name]
|
177
|
+
raise "Could not find any configuration with name '#{name}'" unless config
|
178
|
+
config
|
179
|
+
end
|
180
|
+
|
181
|
+
def remove_config(name)
|
182
|
+
raise "Could not find any configuration with name '#{name}'" unless @configurations[name]
|
183
|
+
@configurations[name] = nil
|
184
|
+
end
|
185
|
+
|
117
186
|
#
|
118
187
|
# - +method+: HTTP method; lowercase symbol, e.g. :get, :post etc.
|
119
188
|
# - +url+: the part after Configuration#root_url
|
@@ -135,7 +204,13 @@ module MangoPay
|
|
135
204
|
headers['Idempotency-Key'] = headers_or_idempotency_key if headers_or_idempotency_key != nil
|
136
205
|
end
|
137
206
|
|
138
|
-
|
207
|
+
if configuration.uk_header_flag
|
208
|
+
headers['x-tenant-id'] = 'uk'
|
209
|
+
end
|
210
|
+
|
211
|
+
res = Net::HTTP.start(uri.host, uri.port, :use_ssl => configuration.use_ssl?, :read_timeout => configuration.http_timeout,
|
212
|
+
:max_retries => configuration.http_max_retries,
|
213
|
+
:open_timeout => configuration.http_open_timeout, ssl_version: :TLSv1_2) do |http|
|
139
214
|
req = Net::HTTP::const_get(method.capitalize).new(uri.request_uri, headers)
|
140
215
|
req.body = JSON.dump(params)
|
141
216
|
before_request_proc.call(req) if before_request_proc
|
@@ -145,7 +220,13 @@ module MangoPay
|
|
145
220
|
raise MangoPay::ResponseError.new(uri, '408', {'Message' => 'Request Timeout'}) if res.nil?
|
146
221
|
|
147
222
|
# decode json data
|
148
|
-
|
223
|
+
begin
|
224
|
+
data = res.body.to_s.empty? ? {} : JSON.load(res.body.to_s)
|
225
|
+
rescue MultiJson::ParseError
|
226
|
+
details = {}
|
227
|
+
details['Message'] = res.body
|
228
|
+
raise MangoPay::ResponseError.new(uri, res.code, details)
|
229
|
+
end
|
149
230
|
|
150
231
|
unless res.is_a?(Net::HTTPOK)
|
151
232
|
raise MangoPay::ResponseError.new(uri, res.code, data)
|
@@ -199,6 +280,9 @@ module MangoPay
|
|
199
280
|
'Authorization' => "#{auth_token['token_type']} #{auth_token['access_token']}",
|
200
281
|
'Content-Type' => 'application/json'
|
201
282
|
}
|
283
|
+
if configuration.log_trace_headers
|
284
|
+
headers.update('x_mangopay_trace-id' => SecureRandom.uuid)
|
285
|
+
end
|
202
286
|
begin
|
203
287
|
headers.update('x_mangopay_client_user_agent' => JSON.dump(user_agent))
|
204
288
|
rescue => e
|
@@ -217,7 +301,12 @@ module MangoPay
|
|
217
301
|
def do_request_with_log(http, req, uri)
|
218
302
|
res, time = nil, nil
|
219
303
|
params = FilterParameters.request(req.body)
|
220
|
-
|
304
|
+
if configuration.log_trace_headers
|
305
|
+
trace_headers = JSON.dump({ 'Idempotency-Key' => req['Idempotency-Key'] , 'x_mangopay_trace-id' => req['x_mangopay_trace-id'] })
|
306
|
+
line = "[#{Time.now.iso8601}] #{req.method.upcase} \"#{uri.to_s}\" #{params} #{trace_headers}"
|
307
|
+
else
|
308
|
+
line = "[#{Time.now.iso8601}] #{req.method.upcase} \"#{uri.to_s}\" #{params}"
|
309
|
+
end
|
221
310
|
begin
|
222
311
|
time = Benchmark.realtime {
|
223
312
|
begin
|
@@ -229,12 +318,17 @@ module MangoPay
|
|
229
318
|
res
|
230
319
|
ensure
|
231
320
|
line = "#{log_severity(res)} #{line}"
|
321
|
+
if time.nil?
|
322
|
+
time_log = "[Unknown ms]"
|
323
|
+
else
|
324
|
+
time_log = "[#{(time * 1000).round(1)}ms]"
|
325
|
+
end
|
232
326
|
if res.nil?
|
233
327
|
params = ''
|
234
|
-
line += "\n
|
328
|
+
line += "\n #{time_log} 408 Request Timeout #{params}\n"
|
235
329
|
else
|
236
330
|
params = FilterParameters.response(res.body)
|
237
|
-
line += "\n
|
331
|
+
line += "\n #{time_log} #{res.code} #{params}\n"
|
238
332
|
end
|
239
333
|
logger.info { line }
|
240
334
|
end
|
@@ -6,7 +6,6 @@ describe MangoPay::CardRegistration do
|
|
6
6
|
it 'creates a new card registration' do
|
7
7
|
created = new_card_registration
|
8
8
|
expect(created['Id']).not_to be_nil
|
9
|
-
expect(created['Id'].to_i).to be > 0
|
10
9
|
expect(created['AccessKey']).not_to be_nil
|
11
10
|
expect(created['PreregistrationData']).not_to be_nil
|
12
11
|
expect(created['CardRegistrationURL']).not_to be_nil
|
@@ -51,7 +50,6 @@ describe MangoPay::CardRegistration do
|
|
51
50
|
|
52
51
|
# card id filled-in...
|
53
52
|
expect(card_id).not_to be_nil
|
54
|
-
expect(card_id.to_i).to be > 0
|
55
53
|
|
56
54
|
# ...and points to existing (newly created) card
|
57
55
|
card = MangoPay::Card.fetch(card_id)
|
@@ -92,4 +90,21 @@ describe MangoPay::CardRegistration do
|
|
92
90
|
expect(transactions).to be_an(Array)
|
93
91
|
end
|
94
92
|
end
|
93
|
+
|
94
|
+
describe 'VALIDATE CARD' do
|
95
|
+
it "validates a card" do
|
96
|
+
created = new_card_registration_completed
|
97
|
+
validated = create_card_validation(created['UserId'], created['CardId'])
|
98
|
+
|
99
|
+
expect(validated).to_not be_nil
|
100
|
+
end
|
101
|
+
|
102
|
+
it "fetches card validation" do
|
103
|
+
created = new_card_registration_completed
|
104
|
+
card_validation = create_card_validation(created['UserId'], created['CardId'])
|
105
|
+
fetched_card_validation = MangoPay::Card.get_card_validation(created['CardId'], card_validation['Id'])
|
106
|
+
|
107
|
+
expect(card_validation['Id']).equal? fetched_card_validation['Id']
|
108
|
+
end
|
109
|
+
end
|
95
110
|
end
|
@@ -126,18 +126,18 @@ describe MangoPay::Client do
|
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
|
-
describe 'validate' do
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
end
|
129
|
+
# describe 'validate' do
|
130
|
+
# it 'validates card' do
|
131
|
+
# client = MangoPay::Client.fetch
|
132
|
+
# completed = new_card_registration_completed
|
133
|
+
# card_id = completed['CardId']
|
134
|
+
# client_id = client['ClientId']
|
135
|
+
#
|
136
|
+
# card = MangoPay::Client.validate(client_id, card_id)
|
137
|
+
# expect(client).not_to be_nil
|
138
|
+
# expect(card).not_to be_nil
|
139
|
+
# end
|
140
|
+
# end
|
141
141
|
|
142
142
|
describe 'create_bank_account' do
|
143
143
|
it 'creates a new bank account' do
|
@@ -13,12 +13,110 @@ describe MangoPay::Configuration do
|
|
13
13
|
}
|
14
14
|
end
|
15
15
|
|
16
|
+
it 'fails when calling with wrong client credentials, but succeeds after applying a new (correct) config' do
|
17
|
+
# create a wrong configuration
|
18
|
+
wrong_config = MangoPay::Configuration.new
|
19
|
+
wrong_config.client_id = 'placeholder'
|
20
|
+
wrong_config.client_apiKey = '0000'
|
21
|
+
wrong_config.preproduction = true
|
22
|
+
|
23
|
+
# create a valid configuration
|
24
|
+
valid_config = MangoPay::Configuration.new
|
25
|
+
valid_config.client_id = 'sdk-unit-tests'
|
26
|
+
valid_config.client_apiKey = 'cqFfFrWfCcb7UadHNxx2C9Lo6Djw8ZduLi7J9USTmu8bhxxpju'
|
27
|
+
valid_config.preproduction = true
|
28
|
+
|
29
|
+
# add the 2 configs to the list of MangoPay configs
|
30
|
+
MangoPay.add_config('wrong', wrong_config)
|
31
|
+
MangoPay.add_config('valid', valid_config)
|
32
|
+
|
33
|
+
# apply wrong config
|
34
|
+
MangoPay.get_config('wrong').apply_configuration
|
35
|
+
|
36
|
+
expect {
|
37
|
+
MangoPay::User.fetch()
|
38
|
+
}.to raise_error { |err|
|
39
|
+
expect(err).to be_a MangoPay::ResponseError
|
40
|
+
expect(err.code).to eq '401'
|
41
|
+
expect(err.message).to eq 'invalid_client'
|
42
|
+
}
|
43
|
+
|
44
|
+
# apply valid configuration
|
45
|
+
MangoPay.get_config('valid').apply_configuration
|
46
|
+
|
47
|
+
# expect success
|
48
|
+
users = MangoPay::User.fetch()
|
49
|
+
expect(users).to be_kind_of(Array)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'fails when fetching a config that does not exist' do
|
53
|
+
expect {
|
54
|
+
MangoPay.get_config('placeholder')
|
55
|
+
}.to raise_error { |err|
|
56
|
+
expect(err).to be_a RuntimeError
|
57
|
+
expect(err.message).to eq "Could not find any configuration with name 'placeholder'"
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'succeeds when removing config' do
|
62
|
+
wrong_config = MangoPay::Configuration.new
|
63
|
+
wrong_config.client_id = 'placeholder'
|
64
|
+
wrong_config.client_apiKey = '0000'
|
65
|
+
wrong_config.preproduction = true
|
66
|
+
|
67
|
+
MangoPay.add_config('wrong', wrong_config)
|
68
|
+
|
69
|
+
# pass when fetching config before removing it
|
70
|
+
MangoPay.get_config('wrong')
|
71
|
+
|
72
|
+
# remove config
|
73
|
+
MangoPay.remove_config('wrong')
|
74
|
+
|
75
|
+
# fail when trying to fetch after removal
|
76
|
+
expect {
|
77
|
+
MangoPay.get_config('wrong')
|
78
|
+
}.to raise_error { |err|
|
79
|
+
expect(err).to be_a RuntimeError
|
80
|
+
expect(err.message).to eq "Could not find any configuration with name 'wrong'"
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
16
84
|
it 'goes ok when calling with correct client credentials' do
|
17
85
|
reset_mangopay_configuration
|
18
86
|
users = MangoPay::User.fetch()
|
19
87
|
expect(users).to be_kind_of(Array)
|
20
88
|
end
|
21
89
|
|
90
|
+
describe '.use_ssl?' do
|
91
|
+
let(:configuration) { MangoPay::Configuration.new }
|
92
|
+
|
93
|
+
it 'defaults to true' do
|
94
|
+
expect(configuration.use_ssl?).to eq(true)
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'when assigned to false in production' do
|
98
|
+
before do
|
99
|
+
configuration.use_ssl = false
|
100
|
+
configuration.preproduction = false
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'uses true as value' do
|
104
|
+
expect(configuration.use_ssl?).to eq(true)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'when assigned to false in preproduction' do
|
109
|
+
before do
|
110
|
+
configuration.use_ssl = false
|
111
|
+
configuration.preproduction = true
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'uses assigned as value' do
|
115
|
+
expect(configuration.use_ssl?).to eq(false)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
22
120
|
describe 'logger' do
|
23
121
|
around(:each) do |example|
|
24
122
|
c = MangoPay.configuration
|