modulr-api 0.0.41 → 0.0.44

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b785321b93c4589e2996011d3f8ed21b55e726c11f612aa7d0d7aba428e3431e
4
- data.tar.gz: ff08457f58c8dc076664257cab5089e71e6087870a27e578853f70c76eede15f
3
+ metadata.gz: 985e67e8a7284607d6d6ab83c5961c56d7ab92a8ef4fe24713908730afe063b6
4
+ data.tar.gz: 57c5b585f5039a0c69942f0311017d1f13e0505fb2f8c9900d501948a3d448a9
5
5
  SHA512:
6
- metadata.gz: d4e9f77ff3c94907fdec892b37397ff4661aeb6b57fdeb9c3f0d2764c48177eb4bf93bebb2612dbfd2c2337af3ec6562781f40ae5849f4aa78cdea23d5b02b70
7
- data.tar.gz: d459b648d9050e4c5a3ad8f8dd4ce441612c9166345d189aae2c72533d903b6cdab5a5dc7992fc6b1135b23fd915671e48cd2020da5c5a5df97382213bf09160
6
+ metadata.gz: 198a8ece89370a7f720622874bf1d0f6dce08862eede48664f3405b8db19a0aa2c63cdc162f2d8e04ff846809baf64d8bb3e85a60368de9e663b10505b52c491
7
+ data.tar.gz: 7b97f877c66a30566c2fa484664ee0433fb84650b31bd4109312ece4cbee41f77d02c052f68bb5b74979011c157a4ede681354b2697699636c9ea1055dd6eb05
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- modulr-api (0.0.41)
4
+ modulr-api (0.0.44)
5
5
  faraday (~> 1.0)
6
6
  faraday_middleware (~> 1.0)
7
7
 
@@ -11,7 +11,7 @@ GEM
11
11
  addressable (2.8.1)
12
12
  public_suffix (>= 2.0.2, < 6.0)
13
13
  ast (2.4.2)
14
- byebug (9.1.0)
14
+ byebug (11.1.3)
15
15
  coderay (1.1.3)
16
16
  crack (0.4.5)
17
17
  rexml
@@ -129,12 +129,14 @@ GEM
129
129
  PLATFORMS
130
130
  arm64-darwin-20
131
131
  arm64-darwin-21
132
+ arm64-darwin-22
133
+ arm64-darwin-23
132
134
  x86_64-darwin-20
133
135
  x86_64-darwin-22
134
136
  x86_64-linux
135
137
 
136
138
  DEPENDENCIES
137
- byebug (~> 9.0)
139
+ byebug (~> 11.1)
138
140
  guard (~> 2.0)
139
141
  guard-rspec (~> 4.0)
140
142
  modulr-api!
@@ -148,4 +150,4 @@ DEPENDENCIES
148
150
  webmock (~> 2.1)
149
151
 
150
152
  BUNDLED WITH
151
- 2.4.3
153
+ 2.4.19
@@ -27,14 +27,14 @@ module Modulr
27
27
  }
28
28
  payload[:externalReference] = opts[:external_reference] if opts[:external_reference]
29
29
 
30
- response = client.post("/customers/#{customer_id}/accounts", payload)
30
+ response = client.post("/customers/#{customer_id}/accounts", payload, opts)
31
31
  attributes = response.body
32
32
 
33
33
  Resources::Accounts::Account.new(response, attributes)
34
34
  end
35
35
 
36
- def close(account_id:)
37
- client.post("/accounts/#{account_id}/close")
36
+ def close(account_id:, **opts)
37
+ client.post("/accounts/#{account_id}/close", nil, opts)
38
38
 
39
39
  nil
40
40
  end
@@ -32,7 +32,7 @@ module Modulr
32
32
  payload[:customerTrust] = opts[:customer_trust] if opts[:customer_trust]
33
33
  payload[:taxProfile] = opts[:tax_profile] if opts[:tax_profile]
34
34
 
35
- response = client.post("/customers", payload)
35
+ response = client.post("/customers", payload, opts)
36
36
  attributes = response.body
37
37
 
38
38
  Resources::Customers::Customer.new(response, attributes)
@@ -24,7 +24,7 @@ module Modulr
24
24
  destinations: destinations,
25
25
  config: config,
26
26
  }
27
- response = client.post("#{base_notification_url(opts)}/notifications", payload)
27
+ response = client.post("#{base_notification_url(opts)}/notifications", payload, opts)
28
28
  attributes = response.body
29
29
 
30
30
  Resources::Notifications::Notification.new(response, attributes)
@@ -36,7 +36,7 @@ module Modulr
36
36
  destinations: destinations,
37
37
  config: config,
38
38
  }
39
- response = client.put("#{base_notification_url(opts)}/notifications/#{id}", payload)
39
+ response = client.put("#{base_notification_url(opts)}/notifications/#{id}", payload, opts)
40
40
  attributes = response.body
41
41
 
42
42
  Resources::Notifications::Notification.new(response, attributes)
@@ -31,8 +31,9 @@ module Modulr
31
31
 
32
32
  payload[:externalReference] = opts[:external_reference] if opts[:external_reference]
33
33
  payload[:endToEndReference] = opts[:e2e_reference] if opts[:e2e_reference]
34
+ payload[:permittedScheme] = opts[:permitted_scheme] if opts[:permitted_scheme]
34
35
 
35
- response = client.post("/payments", payload)
36
+ response = client.post("/payments", payload, opts)
36
37
  attributes = response.body
37
38
 
38
39
  Resources::Payments::Payment.new(response, attributes, { network_scheme: false })
@@ -45,6 +46,7 @@ module Modulr
45
46
  external_reference: :externalReference,
46
47
  has_external_reference: :hasExternalReference,
47
48
  account_id: :sourceAccountId,
49
+ permitted_scheme: :permittedScheme,
48
50
  }
49
51
  {}.tap do |params|
50
52
  same_name_params.each { |param| params[param] = opts[param] if opts[param] }
@@ -9,6 +9,12 @@ module Modulr
9
9
  @client = client
10
10
  end
11
11
 
12
+ def idempotency_headers(options)
13
+ headers = {}
14
+ headers[:idempotency_key] = options[:idempotency_key] if options[:idempotency_key]
15
+ headers
16
+ end
17
+
12
18
  def format_datetime(datetime)
13
19
  datetime.strftime("%Y-%m-%dT%H:%M:%S%z")
14
20
  end
@@ -23,7 +23,8 @@ module Modulr
23
23
  ].join(",")
24
24
  end
25
25
 
26
- def self.calculate(apikey:, apisecret:, nonce: SecureRandom.base64(30), timestamp: DateTime.now.httpdate)
26
+ def self.calculate(apikey:, apisecret:, nonce: nil, timestamp: DateTime.now.httpdate)
27
+ nonce ||= SecureRandom.base64(30)
27
28
  signature_string = "date: #{timestamp}\nx-mod-nonce: #{nonce}"
28
29
  digest = OpenSSL::HMAC.digest(
29
30
  "SHA512",
data/lib/modulr/client.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "base64"
4
+ require "openssl"
3
5
  require "faraday"
4
6
  require "faraday_middleware"
5
7
  require "json"
@@ -44,19 +46,21 @@ module Modulr
44
46
  end
45
47
 
46
48
  def get(path, options = {})
47
- execute :get, path, nil, options
49
+ request :get, path, nil, options
48
50
  end
49
51
 
50
52
  def post(path, data = nil, options = {})
51
- execute :post, path, data, options
53
+ request :post, path, data, options
52
54
  end
53
55
 
54
56
  def put(path, data = nil, options = {})
55
- execute :put, path, data, options
57
+ request :put, path, data, options
56
58
  end
57
59
 
58
- def execute(method, path, data = nil, options = {})
59
- request(method, path, data, options)
60
+ def self.idempotency_nonce(idempotency_key)
61
+ digest = OpenSSL::Digest.new("SHA256")
62
+ hash = OpenSSL::HMAC.digest(digest, ENV["MODULR_APIKEY"], idempotency_key)
63
+ Base64.urlsafe_encode64(hash)
60
64
  end
61
65
 
62
66
  def request(method, path, data = nil, options = {})
@@ -65,16 +69,19 @@ module Modulr
65
69
 
66
70
  begin
67
71
  connection.run_request(method, uri, request_options[:body], request_options[:headers]) do |request|
68
- request.params.update(options) if options
72
+ merge_query_params(request, method, options)
69
73
  end
70
74
  rescue StandardError => e
71
75
  handle_request_error(e)
72
76
  end
73
77
  end
74
78
 
75
- def request_options(_method, _path, data, _options)
79
+ alias execute request
80
+
81
+ def request_options(method, _path, data, options)
76
82
  default_options.tap do |defaults|
77
83
  add_auth_options!(defaults)
84
+ add_idempotency_headers!(defaults[:headers], method, options) if options
78
85
  defaults[:body] = JSON.dump(data) if data
79
86
  end
80
87
  end
@@ -91,9 +98,28 @@ module Modulr
91
98
 
92
99
  def auth_options(options)
93
100
  signature = Auth::Signature.calculate(apikey: @apikey, apisecret: @apisecret)
101
+
94
102
  options[:headers][:authorization] = signature.authorization
95
103
  options[:headers][:date] = signature.timestamp
96
- options[:headers][:"x-mod-nonce"] = signature.nonce
104
+ options[:headers][:"x-mod-nonce"] ||= signature.nonce
105
+ end
106
+
107
+ private def add_idempotency_headers!(headers, method, options)
108
+ return if method == :get
109
+
110
+ idempotency_key = options.delete(:idempotency_key)
111
+ return unless idempotency_key
112
+
113
+ nonce = self.class.idempotency_nonce(idempotency_key)
114
+ headers[:"x-mod-nonce"] = nonce
115
+ headers[:"x-mod-retry"] = "true" if nonce && !nonce.empty?
116
+ end
117
+
118
+ private def merge_query_params(request, method, options)
119
+ return unless options
120
+ return unless method == :get
121
+
122
+ request.params.update(options.reject { |k, _| k == :idempotency_key })
97
123
  end
98
124
 
99
125
  def handle_request_error(error)
@@ -10,6 +10,7 @@ module Modulr
10
10
  map :status
11
11
  map :reference
12
12
  map :externalReference, :external_reference
13
+ map :permittedScheme, :permitted_scheme
13
14
  map :createdDate, :created_at
14
15
  map :approvalStatus, :approval_status
15
16
  map :message, :message
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Modulr
4
- VERSION = "0.0.41"
4
+ VERSION = "0.0.44"
5
5
  end
data/modulr.gemspec CHANGED
@@ -39,7 +39,7 @@ Gem::Specification.new do |spec|
39
39
 
40
40
  spec.add_dependency "faraday", "~> 1.0"
41
41
  spec.add_dependency "faraday_middleware", "~> 1.0"
42
- spec.add_development_dependency "byebug", "~> 9.0"
42
+ spec.add_development_dependency "byebug", "~> 11.1"
43
43
  spec.add_development_dependency "guard", "~> 2.0"
44
44
  spec.add_development_dependency "guard-rspec", "~> 4.0"
45
45
  spec.add_development_dependency "rake", "~> 12.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modulr-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.41
4
+ version: 0.0.44
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aitor García Rey
@@ -10,10 +10,9 @@ authors:
10
10
  - Iván Guardado
11
11
  - Carlos López
12
12
  - Nacho Ortiz
13
- autorequire:
14
13
  bindir: exe
15
14
  cert_chain: []
16
- date: 2024-01-18 00:00:00.000000000 Z
15
+ date: 1980-01-02 00:00:00.000000000 Z
17
16
  dependencies:
18
17
  - !ruby/object:Gem::Dependency
19
18
  name: faraday
@@ -49,14 +48,14 @@ dependencies:
49
48
  requirements:
50
49
  - - "~>"
51
50
  - !ruby/object:Gem::Version
52
- version: '9.0'
51
+ version: '11.1'
53
52
  type: :development
54
53
  prerelease: false
55
54
  version_requirements: !ruby/object:Gem::Requirement
56
55
  requirements:
57
56
  - - "~>"
58
57
  - !ruby/object:Gem::Version
59
- version: '9.0'
58
+ version: '11.1'
60
59
  - !ruby/object:Gem::Dependency
61
60
  name: guard
62
61
  requirement: !ruby/object:Gem::Requirement
@@ -267,7 +266,6 @@ metadata:
267
266
  source_code_uri: https://github.com/devengoapp/modulr-ruby
268
267
  changelog_uri: https://github.com/devengoapp/modulr-ruby/blob/master/CHANGELOG.md
269
268
  rubygems_mfa_required: 'true'
270
- post_install_message:
271
269
  rdoc_options: []
272
270
  require_paths:
273
271
  - lib
@@ -282,8 +280,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
282
280
  - !ruby/object:Gem::Version
283
281
  version: '0'
284
282
  requirements: []
285
- rubygems_version: 3.5.3
286
- signing_key:
283
+ rubygems_version: 3.6.9
287
284
  specification_version: 4
288
285
  summary: Ruby client for Modulr Finance API.
289
286
  test_files: []