modulr-api 0.0.27 → 0.0.29

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: 3a8dc5b6d30c7a03695474663299d7144939699e1c02a95d2a7cf99137142912
4
- data.tar.gz: 92f676165aff5e801db76c001da6373a56454a97dbd18901dd53a07ac0656ef3
3
+ metadata.gz: c8c9dbb9dd8e49d7371b05d2e68e7222d5e37c654ffe46e389d6d5d113ebffbd
4
+ data.tar.gz: 37a5c32437eaedaad272ae831543be0626b2334438692a6a483ba78af6cdd6fa
5
5
  SHA512:
6
- metadata.gz: 93df6c1115b144cf48b6483873a336deb266698067b7cb2bb68934757bf8a81cb4ff44f67af0447fd5039708f93b1da7899989e6243d26e158bfb12aadebecb1
7
- data.tar.gz: 684f71d53386979cfb5840d468b9d461e8f373960a06a76e961fcaa3f052d72bc4a2626c28c345e0fd30e4938b33b4de35ff3c475ac49ad217626f668519c989
6
+ metadata.gz: 7626340f7c17049a55fce43f692b69309427327d16e6b23d4419201c73eeee433520732847ebcd0060c8c1970ac88c58b79bc92faf7436a6d3c2a0d35b1e1075
7
+ data.tar.gz: '078b0409afa38715e68dbc9421df171f8068595f90cddc70776bf36d682f2c03545c0cf8e22ee7a45793501d9ec9d6723df4390b155cab08c50bc0a48dfca26e'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- modulr-api (0.0.27)
4
+ modulr-api (0.0.29)
5
5
  faraday (~> 1.0)
6
6
  faraday_middleware (~> 1.0)
7
7
 
@@ -11,6 +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
15
  coderay (1.1.3)
15
16
  crack (0.4.5)
16
17
  rexml
@@ -133,6 +134,7 @@ PLATFORMS
133
134
  x86_64-linux
134
135
 
135
136
  DEPENDENCIES
137
+ byebug (~> 9.0)
136
138
  guard (~> 2.0)
137
139
  guard-rspec (~> 4.0)
138
140
  modulr-api!
@@ -18,8 +18,7 @@ module Modulr
18
18
  Resources::Payments::Collection.new(response.env[:raw_body], response.body[:content])
19
19
  end
20
20
 
21
- # rubocop:disable Metrics/ParameterLists
22
- def create(account_id:, destination:, reference:, currency:, amount:, **opts)
21
+ def create(account_id:, destination:, reference:, currency:, amount:, **opts) # rubocop:disable Metrics/ParameterLists
23
22
  payload = {
24
23
  sourceAccountId: account_id,
25
24
  destination: destination,
@@ -32,12 +31,10 @@ module Modulr
32
31
  payload[:endToEndReference] = opts[:e2e_reference] if opts[:e2e_reference]
33
32
 
34
33
  response = client.post("/payments", payload)
35
- Resources::Payments::Payment.new(response.env[:raw_body], response.body)
34
+ Resources::Payments::Payment.new(response.env[:raw_body], response.body, { network_scheme: false })
36
35
  end
37
- # rubocop:enable Metrics/ParameterLists
38
36
 
39
- # rubocop:disable Metrics/AbcSize
40
- private def build_query_params(opts)
37
+ private def build_query_params(opts) # rubocop:disable Metrics/AbcSize
41
38
  same_name_params = [:type, :status]
42
39
  date_params = { to: :toCreatedDate, from: :fromCreatedDate, updated_since: :modifiedSince }
43
40
  mapped_params = {
@@ -51,7 +48,6 @@ module Modulr
51
48
  mapped_params.each { |original, mapped| params[mapped] = opts[original] if opts[original] }
52
49
  end
53
50
  end
54
- # rubocop:enable Metrics/AbcSize
55
51
  end
56
52
  end
57
53
  end
@@ -1,9 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "service"
4
- require_relative "accounts_service"
5
- require_relative "payments_service"
6
- require_relative "transactions_service"
7
4
 
8
5
  module Modulr
9
6
  module API
@@ -4,7 +4,7 @@ module Modulr
4
4
  module Resources
5
5
  module Payments
6
6
  class Payment < Base
7
- attr_reader :details, :end_to_end_id
7
+ attr_reader :details, :end_to_end_id, :network, :scheme
8
8
 
9
9
  map :id, [:id, :payment_reference_id]
10
10
  map :status
@@ -13,27 +13,30 @@ module Modulr
13
13
  map :createdDate, :created_at
14
14
  map :approvalStatus, :approval_status
15
15
  map :message, :message
16
+ map :type
16
17
 
17
- def initialize(raw_response, attributes = {})
18
+ def initialize(raw_response, attributes = {}, opts = { network_scheme: true })
18
19
  super(raw_response, attributes)
19
- @details = parse_details(attributes)
20
- @end_to_end_id = if incoming_sepa?(attributes)
21
- sepa_end_to_end_id(attributes)
22
- elsif incoming_faster_payments?(attributes)
23
- faster_payments_end_to_end_id(attributes)
20
+ @attributes = attributes
21
+ @opts = opts
22
+ parse_attributes
23
+ @end_to_end_id = if incoming_sepa?
24
+ sepa_end_to_end_id
25
+ elsif incoming_faster_payments?
26
+ faster_payments_end_to_end_id
24
27
  end
25
28
  end
26
29
 
27
- private def incoming_sepa?(attributes)
28
- %w[PI_SECT PI_SEPA_INST].include?(attributes[:details]&.dig(:type))
30
+ private def incoming_sepa?
31
+ %w[PI_SECT PI_SEPA_INST].include?(@attributes[:details]&.dig(:type))
29
32
  end
30
33
 
31
- private def incoming_faster_payments?(attributes)
32
- attributes[:details]&.dig(:type) == "PI_FAST"
34
+ private def incoming_faster_payments?
35
+ @attributes[:details]&.dig(:type) == "PI_FAST"
33
36
  end
34
37
 
35
- private def sepa_end_to_end_id(attributes)
36
- doc = attributes[:details].dig(:details, :payload, :docs, :doc)
38
+ private def sepa_end_to_end_id
39
+ doc = @attributes[:details].dig(:details, :payload, :docs, :doc)
37
40
  return unless doc
38
41
 
39
42
  doc_type = doc.dig(:header, :type)
@@ -47,22 +50,104 @@ module Modulr
47
50
  end
48
51
  end
49
52
 
50
- private def faster_payments_end_to_end_id(attributes)
51
- attributes[:details].dig(:details, :fpsTransaction, :paymentInfo, :endToEndId)
53
+ private def faster_payments_end_to_end_id
54
+ @attr_details.dig(:details, :fpsTransaction, :paymentInfo, :endToEndId)
52
55
  end
53
56
 
54
- private def parse_details(attributes)
55
- details = attributes[:details]
57
+ private def parse_attributes
58
+ parse_details
59
+ parse_scheme if @opts[:network_scheme]
60
+ end
61
+
62
+ private def parse_details
63
+ @attr_details = @attributes[:details]
64
+ detail_type = @attr_details&.dig(:type) || @attr_details&.dig(:destinationType)
56
65
 
57
- case details&.dig(:type) || details&.dig(:destinationType)
66
+ case detail_type
58
67
  when "PI_SECT", "PI_SEPA_INST", "PI_FAST", "PI_REV"
59
- Details::Incoming::General.new(nil, details)
68
+ incoming_detail
60
69
  when "ACCOUNT"
61
- Details::Incoming::Internal.new(nil, details)
70
+ incoming_internal_details
62
71
  else
63
- Details::Outgoing::General.new(nil, details)
72
+ outgoing_detail
64
73
  end
65
74
  end
75
+
76
+ private def payment_type
77
+ if incoming?
78
+ @attr_details[:type]
79
+ elsif internal?
80
+ @attr_details[:destinationType]
81
+ else
82
+ outgoing_type
83
+ end
84
+ end
85
+
86
+ private def parse_scheme
87
+ case payment_type
88
+ when "PI_SECT", "PO_SECT"
89
+ sepa_regular
90
+ when "PI_SEPA_INST", "PO_SEPA_INST"
91
+ sepa_instant
92
+ when "PI_FAST", "PO_FAST"
93
+ faster_payments
94
+ when "ACCOUNT"
95
+ internal
96
+ else
97
+ raise "Unable to find network and scheme for payment with ID: #{id} and Type: #{type}"
98
+ end
99
+ end
100
+
101
+ private def outgoing_type
102
+ return "PO_FAST" if @attributes.dig(:schemeInfo, :id)&.include?("MODULO")
103
+
104
+ case @attributes.dig(:schemeInfo, :name)
105
+ when "SEPA_INSTANT"
106
+ "PO_SEPA_INST"
107
+ when "SEPA_CREDIT_TRANSFER"
108
+ "PO_SECT"
109
+ end
110
+ end
111
+
112
+ private def sepa_regular
113
+ @network = "SEPA"
114
+ @scheme = "SEPA Credit Transfers"
115
+ end
116
+
117
+ private def sepa_instant
118
+ @network = "SEPA"
119
+ @scheme = "SEPA Instant Credit Transfers"
120
+ end
121
+
122
+ private def faster_payments
123
+ @network = "FPS"
124
+ @scheme = "Faster Payments"
125
+ end
126
+
127
+ private def internal
128
+ @network = "INTERNAL"
129
+ @scheme = "INTERNAL"
130
+ end
131
+
132
+ private def incoming_detail
133
+ @details = Details::Incoming::General.new(nil, @attr_details)
134
+ end
135
+
136
+ private def outgoing_detail
137
+ @details = Details::Outgoing::General.new(nil, @attr_details)
138
+ end
139
+
140
+ private def incoming_internal_details
141
+ @details = Details::Incoming::Internal.new(nil, @attr_details)
142
+ end
143
+
144
+ private def incoming?
145
+ !@attr_details.key?(:sourceAccountId)
146
+ end
147
+
148
+ private def internal?
149
+ @attr_details[:sourceAccountId] && @attr_details[:destinationId]
150
+ end
66
151
  end
67
152
  end
68
153
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Modulr
4
- VERSION = "0.0.27"
4
+ VERSION = "0.0.29"
5
5
  end
data/lib/modulr.rb CHANGED
@@ -8,8 +8,9 @@ require_relative "modulr/api/service"
8
8
  require_relative "modulr/api/services"
9
9
  require_relative "modulr/api/accounts_service"
10
10
  require_relative "modulr/api/customers_service"
11
- require_relative "modulr/api/payments_service"
12
11
  require_relative "modulr/api/notifications_service"
12
+ require_relative "modulr/api/payments_service"
13
+ require_relative "modulr/api/transactions_service"
13
14
 
14
15
  require_relative "modulr/resources/base"
15
16
 
data/modulr.gemspec CHANGED
@@ -33,6 +33,7 @@ Gem::Specification.new do |spec|
33
33
 
34
34
  spec.add_dependency "faraday", "~> 1.0"
35
35
  spec.add_dependency "faraday_middleware", "~> 1.0"
36
+ spec.add_development_dependency "byebug", "~> 9.0"
36
37
  spec.add_development_dependency "guard", "~> 2.0"
37
38
  spec.add_development_dependency "guard-rspec", "~> 4.0"
38
39
  spec.add_development_dependency "rake", "~> 12.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modulr-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.27
4
+ version: 0.0.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aitor García Rey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-23 00:00:00.000000000 Z
11
+ date: 2023-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '9.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '9.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: guard
43
57
  requirement: !ruby/object:Gem::Requirement