mangopay 3.0.31 → 3.0.36

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73c15899898b7b234b4acf3ce46155a7a206bd629b5ef98d682e6125d3c5cd52
4
- data.tar.gz: f2e564568a12d93c36eb1fc42b70c21b6cf5753c18810b5cef5d28e8f1e1ae93
3
+ metadata.gz: 8cd7631afb582279a222aeb5c81d6f8a507e47bc7a0a6e23e171f34c9e519034
4
+ data.tar.gz: 472287e318eb7470c7020a09a889e9b9d630c98db2c095c7a8dd628cdffab223
5
5
  SHA512:
6
- metadata.gz: df581e3dd8afa4312a20388604c2b1f907908898e92d26db4cd3bab264e5ac11ea2a2448cccac73b55054fcdb68bbed07b58bff7e5ab99996dd0a378fce3d819
7
- data.tar.gz: 48e91bdd987927f105cd7fea1ef4863211b78e1f2728106cd0ab2618049db67988cd6d445e542ece17915c829a4c29f88995e05d480434e712fb40cb9ceecbea
6
+ metadata.gz: 8748baa780499d4881d9f9a8c9abcbaf5c804a5b9f5bbe78821bc79ea6e26773b40dbb056f6e459ab238e06f21328d87688db12e84cb6a78afb25f6b94f4f818
7
+ data.tar.gz: 4e0360de8ff724d8ea0c22796fd719235e5effeea7cce897c6d0a177ebc9589b59d70846d7d7fa18257ce91447fa3bce6789a6dd0856795128ca1f45e69698b7
@@ -1,6 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
3
+ - 2.0.0
4
+ - 2.1
5
+ - 2.2
6
+ - 2.3
7
+ - 2.4
8
+ - 2.5
4
9
  script: bundle exec rspec
5
10
  deploy:
6
11
  provider: rubygems
@@ -0,0 +1,39 @@
1
+ ## [3.0.36] - 2020-08-28
2
+ - Forces TLS version to 1.2
3
+
4
+ ## [3.0.35] - 2020-08-24
5
+ - Improvement to Net::ReadTimeout handling
6
+ - "User-agent" format in the headers changed, aligned to other assets 👤
7
+
8
+ ## [3.0.34] - 2020-06-25
9
+ ### Added
10
+ - This SDK is now GooglePay-ready ! Feel free to ask our lovely support for more infos about its activation.
11
+ - `UBODeclaration` is now directly available through its ID.
12
+ - If a bankwire is done from a UK bankaccount on one of your `BankingAlias`, you could find its `AccountNumber` on `GET /payins/` response
13
+ - You can now send a `Culture` parameter for Paypal PayIns. Thanks to it, payment page can be displayed in various languages.
14
+
15
+ ### Changed
16
+ - `PAYLINEV2`value for Payin Web has been added on `TemplateURLOptions` object. You now should use it instead of `PAYLINE` for page customization.
17
+
18
+ ### Fixed
19
+ - Missing filters parameters have been added
20
+ - You can now send headers in update requests
21
+ - Loggers have been enhanced
22
+
23
+ ## [3.0.33] - 2019-09-23
24
+ ### Added
25
+ - ApplePay `Payin` functions are now available. More info about activation to come in the following weeks...
26
+ ### Changed
27
+ - GET EMoney method now supports year and month parameters. More info on our [docs](https://docs.mangopay.com/endpoints/v2.01/user-emoney#e895_view-a-users-emoney)
28
+
29
+ ## [v3.0.32] - 2019-06-19
30
+ ### Added
31
+ - New UBO Declaration system (more info [here](https://docs.mangopay.com/endpoints/v2.01/ubo-declarations#e1024_the-ubo-declaration-object))
32
+ ### Changed
33
+ - Paypal buyer account email that has been used is now available for Payin Paypal
34
+ - Your `HeadquartersPhoneNumber` can now be updated for your client account directly from our API
35
+ ### BREAKING
36
+ - `APIKey` is now replacing `passphrase` property for credentials. You must update it by updating to 3.0.32 SDK version and upper ones.
37
+
38
+
39
+
data/README.md CHANGED
@@ -4,7 +4,7 @@ The gem for interacting with the version 2 of the Mangopay API.
4
4
  See the [API documentation](http://docs.mangopay.com/api-references/)
5
5
  for more details on the API.
6
6
 
7
- Tested on the following versions of Ruby: 1.9.2, 1.9.3, 2.0.0
7
+ Tested on the following versions of Ruby: 1.9.2, 1.9.3, 2.0.0 and 2.x up to 2.5
8
8
 
9
9
  ## NEWS
10
10
 
@@ -37,7 +37,7 @@ require 'mangopay'
37
37
  MangoPay.configure do |c|
38
38
  c.preproduction = true
39
39
  c.client_id = 'YOUR_CLIENT_ID'
40
- c.client_passphrase = 'YOUR_CLIENT_PASSWORD'
40
+ c.client_apiKey = 'YOUR_CLIENT_API_KEY'
41
41
  c.log_file = File.join('mypath', 'mangopay.log')
42
42
  c.http_timeout = 10000
43
43
  end
@@ -96,13 +96,13 @@ Along with each request, the rate limiting headers are automatically updated in
96
96
  MangoPay.ratelimit
97
97
 
98
98
  {
99
- :limit=>["74", "74", "75", "908"],
100
- :remaining=>["2226", "4426", "8725", "104692"],
99
+ :limit=>["74", "74", "75", "908"],
100
+ :remaining=>["2226", "4426", "8725", "104692"],
101
101
  :reset=>["1495615620", "1495616520", "1495618320", "1495701060"]
102
102
  }
103
103
  ```
104
104
 
105
- Read more about rate limiting on [our documetiation](https://docs.mangopay.com/guide/rate-limiting).
105
+ Read more about rate limiting on [our documentation](https://docs.mangopay.com/guide/rate-limiting).
106
106
 
107
107
  ### Log requests and responses
108
108
  You can easily enable logs by setting the ```log_file``` configuration option (see the section **configuration** above). If you don't want logs, remove the ```log_file``` line.
@@ -17,7 +17,7 @@ module Mangopay
17
17
  client = client_id_valid?
18
18
  remove_file 'config/initializers/mangopay.rb'
19
19
  @client_id = client_id
20
- @client_passphrase = client['Passphrase']
20
+ @client_apiKey = client['APIKey']
21
21
  template 'mangopay.rb.erb', 'config/initializers/mangopay.rb'
22
22
  rescue => e
23
23
  puts e.message
@@ -1,5 +1,5 @@
1
1
  MangoPay.configure do |c|
2
2
  c.preproduction = <%= options[:preproduction] %>
3
3
  c.client_id = '<%= @client_id %>'
4
- c.client_passphrase = '<%= @client_passphrase %>'
4
+ c.client_apiKey = '<%= @client_apiKey %>'
5
5
  end
@@ -41,14 +41,16 @@ module MangoPay
41
41
  autoload :BankingAliases, 'mangopay/bankingaliases'
42
42
  autoload :BankingAliasesIBAN, 'mangopay/bankingaliases_iban'
43
43
  autoload :UboDeclaration, 'mangopay/ubo_declaration'
44
+ autoload :Ubo, 'mangopay/ubo'
44
45
 
45
46
  # temporary
46
47
  autoload :Temp, 'mangopay/temp'
47
48
 
48
49
  class Configuration
49
50
  attr_accessor :preproduction, :root_url,
50
- :client_id, :client_passphrase,
51
- :temp_dir, :log_file, :http_timeout
51
+ :client_id, :client_apiKey,
52
+ :temp_dir, :log_file, :http_timeout,
53
+ :logger
52
54
 
53
55
  def preproduction
54
56
  @preproduction || false
@@ -133,13 +135,15 @@ module MangoPay
133
135
  headers['Idempotency-Key'] = headers_or_idempotency_key if headers_or_idempotency_key != nil
134
136
  end
135
137
 
136
- res = Net::HTTP.start(uri.host, uri.port, use_ssl: true, :read_timeout => configuration.http_timeout) do |http|
138
+ res = Net::HTTP.start(uri.host, uri.port, use_ssl: true, :read_timeout => configuration.http_timeout, ssl_version: :TLSv1_2) do |http|
137
139
  req = Net::HTTP::const_get(method.capitalize).new(uri.request_uri, headers)
138
140
  req.body = JSON.dump(params)
139
141
  before_request_proc.call(req) if before_request_proc
140
142
  do_request(http, req, uri)
141
143
  end
142
144
 
145
+ raise MangoPay::ResponseError.new(uri, '408', {'Message' => 'Request Timeout'}) if res.nil?
146
+
143
147
  # decode json data
144
148
  data = res.body.to_s.empty? ? {} : JSON.load(res.body.to_s)
145
149
 
@@ -157,7 +161,7 @@ module MangoPay
157
161
  limit: res['x-ratelimit'].split(", "),
158
162
  remaining: res['x-ratelimit-remaining'].split(", "),
159
163
  reset: res['x-ratelimit-reset'].split(", ")
160
- }
164
+ }
161
165
  end
162
166
 
163
167
  data
@@ -191,7 +195,7 @@ module MangoPay
191
195
  def request_headers
192
196
  auth_token = AuthorizationToken::Manager.get_token
193
197
  headers = {
194
- 'User-Agent' => "MANGOPAY V2 RubyBindings/#{VERSION}",
198
+ 'User-Agent' => "MangoPay V2 SDK Ruby Bindings #{VERSION}",
195
199
  'Authorization' => "#{auth_token['token_type']} #{auth_token['access_token']}",
196
200
  'Content-Type' => 'application/json'
197
201
  }
@@ -203,10 +207,10 @@ module MangoPay
203
207
  end
204
208
 
205
209
  def do_request(http, req, uri)
206
- if configuration.log_file.nil?
207
- do_request_without_log(http, req)
208
- else
210
+ if logs_required?
209
211
  do_request_with_log(http, req, uri)
212
+ else
213
+ do_request_without_log(http, req)
210
214
  end
211
215
  end
212
216
 
@@ -215,12 +219,23 @@ module MangoPay
215
219
  params = FilterParameters.request(req.body)
216
220
  line = "[#{Time.now.iso8601}] #{req.method.upcase} \"#{uri.to_s}\" #{params}"
217
221
  begin
218
- time = Benchmark.realtime { res = do_request_without_log(http, req) }
222
+ time = Benchmark.realtime {
223
+ begin
224
+ res = do_request_without_log(http, req)
225
+ rescue Net::ReadTimeout
226
+ res = nil
227
+ end
228
+ }
219
229
  res
220
230
  ensure
221
- params = FilterParameters.response(res.body)
222
231
  line = "#{log_severity(res)} #{line}"
223
- line += "\n [#{(time * 1000).round(1)}ms] #{res.code} #{params}\n"
232
+ if res.nil?
233
+ params = ''
234
+ line += "\n [#{(time * 1000).round(1)}ms] 408 Request Timeout #{params}\n"
235
+ else
236
+ params = FilterParameters.response(res.body)
237
+ line += "\n [#{(time * 1000).round(1)}ms] #{res.code} #{params}\n"
238
+ end
224
239
  logger.info { line }
225
240
  end
226
241
  end
@@ -235,15 +250,23 @@ module MangoPay
235
250
  end
236
251
 
237
252
  def logger
238
- raise NotImplementedError if configuration.log_file.nil?
239
- if @logger.nil?
253
+ raise NotImplementedError unless logs_required?
254
+ return @logger if @logger
255
+
256
+ if !configuration.logger.nil?
257
+ @logger = configuration.logger
258
+ elsif !configuration.log_file.nil?
240
259
  @logger = Logger.new(configuration.log_file)
241
- @logger.formatter = proc do |severity, datetime, progname, msg|
260
+ @logger.formatter = proc do |_, _, _, msg|
242
261
  "#{msg}\n"
243
262
  end
244
263
  end
264
+
245
265
  @logger
246
266
  end
247
267
 
268
+ def logs_required?
269
+ !configuration.log_file.nil? || !configuration.logger.nil?
270
+ end
248
271
  end
249
272
  end
@@ -19,7 +19,7 @@ module MangoPay
19
19
  if token.nil? || token['timestamp'].nil? || token['timestamp'] <= Time.now || token['environment_key'] != env_key
20
20
  token = MangoPay.request(:post, "/#{MangoPay.version_code}/oauth/token", {}, {}, {}, Proc.new do |req|
21
21
  cfg = MangoPay.configuration
22
- req.basic_auth cfg.client_id, cfg.client_passphrase
22
+ req.basic_auth cfg.client_id, cfg.client_apiKey
23
23
  req.body = 'grant_type=client_credentials'
24
24
  req.add_field('Content-Type', 'application/x-www-form-urlencoded')
25
25
  end)
@@ -32,7 +32,7 @@ module MangoPay
32
32
 
33
33
  def get_environment_key_for_token
34
34
  cfg = MangoPay.configuration
35
- key = "#{cfg.root_url}|#{cfg.client_id}|#{cfg.client_passphrase}"
35
+ key = "#{cfg.root_url}|#{cfg.client_id}|#{cfg.client_apiKey}"
36
36
  key = Digest::MD5.hexdigest(key)
37
37
  key
38
38
  end
@@ -13,7 +13,12 @@ module MangoPay
13
13
 
14
14
  def self.response(body)
15
15
  return '' if body.to_s.empty?
16
- body = JSON.load(body)
16
+
17
+ begin
18
+ body = JSON.load(body)
19
+ rescue MultiJson::LoadError => e
20
+ return body
21
+ end
17
22
  filter_hash(body, res_confidential_params)
18
23
  JSON.dump(body)
19
24
  end
@@ -21,8 +21,8 @@ module MangoPay
21
21
 
22
22
  module Update
23
23
  module ClassMethods
24
- def update(id = nil, params = {})
25
- MangoPay.request(:put, url(id), params)
24
+ def update(id = nil, params = {}, idempotency_key = nil)
25
+ MangoPay.request(:put, url(id), params, {}, idempotency_key)
26
26
  end
27
27
  end
28
28
 
@@ -35,20 +35,20 @@ module MangoPay
35
35
  module ClassMethods
36
36
 
37
37
  # - Fetching _single_entity_ by +id+:
38
- #
38
+ #
39
39
  # MangoPay::User.fetch("user-id") # => {"FirstName"=>"Mango", "LastName"=>"Pay", ...}
40
- #
40
+ #
41
41
  # - or fetching _multiple_entities_ with _optional_ +filters+ hash,
42
42
  # including _pagination_ and _sorting_ params
43
43
  # +page+, +per_page+, +sort+ (see http://docs.mangopay.com/api-references/pagination/):
44
- #
44
+ #
45
45
  # MangoPay::User.fetch() # => [{...}, ...]: list of user data hashes (10 per page by default)
46
46
  # MangoPay::User.fetch({'page' => 2, 'per_page' => 3}) # => list of 3 hashes from 2nd page
47
47
  # MangoPay::BankAccount.fetch(user_id, {'sort' => 'CreationDate:desc'}) # => bank accounts by user, sorting by date descending (with default pagination)
48
48
  # MangoPay::BankAccount.fetch(user_id, {'sort' => 'CreationDate:desc', 'page' => 2, 'per_page' => 3}) # both sorting and pagination params provided
49
- #
49
+ #
50
50
  # - For paginated queries the +filters+ param will be supplemented by +total_pages+ and +total_items+ info:
51
- #
51
+ #
52
52
  # MangoPay::User.fetch(filter = {'page' => 2, 'per_page' => 3})
53
53
  # filter # => {"page"=>2, "per_page"=>3, "total_pages"=>1969, "total_items"=>5905}
54
54
  #
@@ -13,14 +13,6 @@ module MangoPay
13
13
  end
14
14
 
15
15
  class << self
16
-
17
- # Create a UBO declaration.
18
- # @param +user_id+ ID of the legal user owning the declaration
19
- # @param +ubo_declaration+ Object containing UBO declaration data
20
- # @return Newly-created UBO declaration entity data
21
- def create_ubo_declaration(user_id, ubo_declaration)
22
- MangoPay.request(:post, "#{url(user_id)}/ubodeclarations", ubo_declaration)
23
- end
24
16
  end
25
17
  end
26
18
  end
@@ -106,5 +106,25 @@ module MangoPay
106
106
 
107
107
  end
108
108
 
109
+ module ApplePay
110
+ class Direct < Resource
111
+ include HTTPCalls::Create
112
+
113
+ def self.url(*)
114
+ "#{MangoPay.api_path}/payins/applepay/#{CGI.escape(class_name.downcase)}"
115
+ end
116
+ end
117
+ end
118
+
119
+ module GooglePay
120
+ class Direct < Resource
121
+ include HTTPCalls::Create
122
+
123
+ def self.url(*)
124
+ "#{MangoPay.api_path}/payins/googlepay/#{CGI.escape(class_name.downcase)}"
125
+ end
126
+ end
127
+ end
128
+
109
129
  end
110
130
  end
@@ -0,0 +1,26 @@
1
+ module MangoPay
2
+ # Provides API methods for the UBO entity.
3
+ class Ubo < Resource
4
+ class << self
5
+ def url(user_id, ubo_declaration_id, id = nil)
6
+ if id
7
+ "#{MangoPay.api_path}/users/#{user_id}/kyc/ubodeclarations/#{ubo_declaration_id}/ubos/#{id}"
8
+ else
9
+ "#{MangoPay.api_path}/users/#{user_id}/kyc/ubodeclarations/#{ubo_declaration_id}/ubos"
10
+ end
11
+ end
12
+
13
+ def create(user_id, ubo_declaration_id, params)
14
+ MangoPay.request(:post, url(user_id, ubo_declaration_id), params)
15
+ end
16
+
17
+ def fetch(user_id, ubo_declaration_id, ubo_id)
18
+ MangoPay.request(:get, url(user_id, ubo_declaration_id, ubo_id))
19
+ end
20
+
21
+ def update(user_id, ubo_declaration_id, ubo_id, params)
22
+ MangoPay.request(:put, url(user_id, ubo_declaration_id, ubo_id), params)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,19 +1,30 @@
1
1
  module MangoPay
2
-
3
2
  # Provides API methods for the UBO declaration entity.
4
3
  class UboDeclaration < Resource
5
- include HTTPCalls::Fetch
6
-
7
4
  class << self
8
-
9
- def update(id = nil, params = {})
10
- declared_ubo_ids = []
11
- params['DeclaredUBOs'].each do |ubo|
12
- declared_ubo_ids << (ubo.key?('UserId') ? ubo['UserId'] : ubo)
5
+ def url(user_id, id = nil)
6
+ if id
7
+ "#{MangoPay.api_path}/users/#{user_id}/kyc/ubodeclarations/#{id}"
8
+ else
9
+ "#{MangoPay.api_path}/users/#{user_id}/kyc/ubodeclarations"
13
10
  end
14
- params['DeclaredUBOs'] = declared_ubo_ids
15
- MangoPay.request(:put, url(id), params)
11
+ end
12
+
13
+ def create(user_id)
14
+ MangoPay.request(:post, url(user_id))
15
+ end
16
+
17
+ def fetch(user_id, id)
18
+ MangoPay.request(:get, url(user_id, id))
19
+ end
20
+
21
+ def update(user_id, id, params = {})
22
+ request_params = {
23
+ Status: params['Status'],
24
+ Ubos: params['Ubos']
25
+ }
26
+ MangoPay.request(:put, url(user_id, id), request_params)
16
27
  end
17
28
  end
18
29
  end
19
- end
30
+ end
@@ -12,7 +12,7 @@ module MangoPay
12
12
  # Fetches list of wallets belonging to the given +user_id+.
13
13
  # Optional +filters+ is a hash accepting following keys:
14
14
  # - +page+, +per_page+, +sort+: pagination and sorting params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
15
- def wallets(user_id, filters={})
15
+ def wallets(user_id, filters = {})
16
16
  MangoPay.request(:get, url(user_id) + '/wallets', {}, filters)
17
17
  end
18
18
 
@@ -20,14 +20,14 @@ module MangoPay
20
20
  # Optional +filters+ is a hash accepting following keys:
21
21
  # - +page+, +per_page+, +sort+: pagination and sorting params
22
22
  # (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
23
- def bank_accounts(user_id, filters={})
23
+ def bank_accounts(user_id, filters = {})
24
24
  MangoPay.request(:get, url(user_id) + '/bankaccounts', {}, filters)
25
25
  end
26
26
 
27
27
  # Fetches list of cards belonging to the given +user_id+.
28
28
  # Optional +filters+ is a hash accepting following keys:
29
29
  # - +page+, +per_page+, +sort+: pagination and sorting params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
30
- def cards(user_id, filters={})
30
+ def cards(user_id, filters = {})
31
31
  MangoPay.request(:get, url(user_id) + '/cards', {}, filters)
32
32
  end
33
33
 
@@ -35,7 +35,7 @@ module MangoPay
35
35
  # Optional +filters+ is a hash accepting following keys:
36
36
  # - +page+, +per_page+, +sort+: pagination and sorting params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
37
37
  # - other keys specific for transactions filtering (see MangoPay::Transaction#fetch)
38
- def transactions(user_id, filters={})
38
+ def transactions(user_id, filters = {})
39
39
  MangoPay.request(:get, url(user_id) + '/transactions', {}, filters)
40
40
  end
41
41
 
@@ -43,21 +43,25 @@ module MangoPay
43
43
  # Optional +filters+ is a hash accepting following keys:
44
44
  # - +page+, +per_page+, +sort+: pagination and sorting params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
45
45
  # - other keys specific for transactions filtering (see MangoPay::Transaction#fetch)
46
- def emoney(user_id, filters={})
47
- MangoPay.request(:get, url(user_id) + '/emoney', {}, filters)
46
+ def emoney(user_id, year, month = nil, filters = {})
47
+ if month
48
+ MangoPay.request(:get, url(user_id) + "/emoney/#{year}/#{month}", {}, filters)
49
+ else
50
+ MangoPay.request(:get, url(user_id) + "/emoney/#{year}", {}, filters)
51
+ end
48
52
  end
49
53
 
50
54
  # Fetches list of kyc documents belonging to the given +user_id+.
51
55
  # Optional +filters+ is a hash accepting following keys:
52
56
  # - +page+, +per_page+, +sort+, +BeforeDate+, +AfterDate+, +Status+: pagination and sorting params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
53
- def kyc_documents(user_id, filters={})
57
+ def kyc_documents(user_id, filters = {})
54
58
  MangoPay.request(:get, url(user_id) + '/KYC/documents', {}, filters)
55
59
  end
56
60
 
57
61
  # Fetches list of pre-authorizations belonging to the given +user_id+.
58
62
  # Optional +filters+ is a hash accepting the following keys:
59
63
  # - +page+, +per_page+, +sort+, +Status+, +ResultCode+, +PaymentStatus+: pagination and sorting/filtering params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
60
- def pre_authorizations(user_id, filters={})
64
+ def pre_authorizations(user_id, filters = {})
61
65
  MangoPay.request(:get, url(user_id) + '/preauthorizations', {}, filters)
62
66
  end
63
67
  end