modulr-api 0.0.28 → 0.0.30

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: 0d095d43ccee60d099ae8d7ac57d86cd8104259577ff908fb5cfcd6f33d260a5
4
- data.tar.gz: a5a1e05cda5006f6397baa5460e67b7986ef537d742f9a2eeae7b4d69869e087
3
+ metadata.gz: dfee429f389323b1d5272e26a6dd289ac0accfafa4364af2634d90596ff5bc04
4
+ data.tar.gz: df4e737338758aa5ec2a00dff6dfa66751da635d61e53f4b6f6b2973d8dc965f
5
5
  SHA512:
6
- metadata.gz: 9befecbaa71d544887fefab95c0d677fa4134abdf2964fee2a275c006ac534d929dd55ccf37c783624ad646b93a888ff03fe9ae93314f2db037533eb9ed6661a
7
- data.tar.gz: 9cd97815ad18668bba5fc12d72721c46d742466086afaf95cb26cc81eb05e54caa1c9498a31d0e6476eb5690e81a63d1e77317d090e00cddaabaa9b17d2a24b6
6
+ metadata.gz: f4f43fbc7f0817edf67cff3d576fbf964b916fca83297c7dae1c60fb367be0b173c273c89a9fd67088a335fa9cb05478fc6bc955518e27406237928b407db714
7
+ data.tar.gz: 7bd2779a0bc733012a84598fc4492fb9ce8b3e4e62f54c15f81f442a5fb6afcc7b4bd67a129393751252e7f2d990ce6698c3bfde5ebaa510e33e8733d2ab1eaf
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- modulr-api (0.0.28)
4
+ modulr-api (0.0.30)
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!
@@ -3,10 +3,10 @@
3
3
  module Modulr
4
4
  module API
5
5
  class PaymentsService < Service
6
- def find(id:, **opts)
6
+ def find(id:)
7
7
  response = client.get("/payments", { id: id })
8
8
  payment_attributes = response.body[:content]&.first
9
- payment_attributes_with_type(id, payment_attributes) if include_transaction?(opts)
9
+ raise NotFoundError, "Payment #{id} not found" unless payment_attributes
10
10
 
11
11
  Resources::Payments::Payment.new(response.env[:raw_body], payment_attributes)
12
12
  end
@@ -15,19 +15,10 @@ module Modulr
15
15
  return find(id: opts[:id]) if opts[:id]
16
16
 
17
17
  response = client.get("/payments", build_query_params(opts))
18
- payments_attributes = response.body[:content]
19
-
20
- if include_transaction?(opts)
21
- payments_attributes.each do |payment_attributes|
22
- payment_attributes_with_type(payment_attributes[:id], payment_attributes)
23
- end
24
- end
25
-
26
- Resources::Payments::Collection.new(response.env[:raw_body], payments_attributes)
18
+ Resources::Payments::Collection.new(response.env[:raw_body], response.body[:content])
27
19
  end
28
20
 
29
- # rubocop:disable Metrics/ParameterLists
30
- def create(account_id:, destination:, reference:, currency:, amount:, **opts)
21
+ def create(account_id:, destination:, reference:, currency:, amount:, **opts) # rubocop:disable Metrics/ParameterLists
31
22
  payload = {
32
23
  sourceAccountId: account_id,
33
24
  destination: destination,
@@ -40,12 +31,10 @@ module Modulr
40
31
  payload[:endToEndReference] = opts[:e2e_reference] if opts[:e2e_reference]
41
32
 
42
33
  response = client.post("/payments", payload)
43
- Resources::Payments::Payment.new(response.env[:raw_body], response.body)
34
+ Resources::Payments::Payment.new(response.env[:raw_body], response.body, { network_scheme: false })
44
35
  end
45
- # rubocop:enable Metrics/ParameterLists
46
36
 
47
- # rubocop:disable Metrics/AbcSize
48
- private def build_query_params(opts)
37
+ private def build_query_params(opts) # rubocop:disable Metrics/AbcSize
49
38
  same_name_params = [:type, :status]
50
39
  date_params = { to: :toCreatedDate, from: :fromCreatedDate, updated_since: :modifiedSince }
51
40
  mapped_params = {
@@ -59,48 +48,6 @@ module Modulr
59
48
  mapped_params.each { |original, mapped| params[mapped] = opts[original] if opts[original] }
60
49
  end
61
50
  end
62
- # rubocop:enable Metrics/AbcSize
63
-
64
- private def include_transaction?(opts)
65
- return true if opts[:include_transaction].nil?
66
-
67
- opts[:include_transaction]
68
- end
69
-
70
- private def payment_attributes_with_type(id, attrs)
71
- raise NotFoundError, "Payment #{id} not found" unless attrs
72
-
73
- @details = attrs[:details]
74
- type = if outgoing && !internal
75
- fetch_transaction_type
76
- elsif incoming
77
- @details[:type]
78
- elsif internal
79
- @details[:destinationType]
80
- end
81
-
82
- attrs[:type] = type
83
- attrs
84
- end
85
-
86
- private def fetch_transaction_type
87
- client.transactions.list(
88
- account_id: @details[:sourceAccountId],
89
- source_id: @details[:id]
90
- )&.first&.type
91
- end
92
-
93
- private def incoming
94
- @details[:sourceAccountId].nil?
95
- end
96
-
97
- private def internal
98
- @details[:sourceAccountId] && @details[:destinationId]
99
- end
100
-
101
- private def outgoing
102
- !@details[:sourceAccountId].nil? && @details[:destinationId].nil?
103
- end
104
51
  end
105
52
  end
106
53
  end
@@ -15,26 +15,28 @@ module Modulr
15
15
  map :message, :message
16
16
  map :type
17
17
 
18
- def initialize(raw_response, attributes = {})
18
+ def initialize(raw_response, attributes = {}, opts = { network_scheme: true })
19
19
  super(raw_response, attributes)
20
- parse_attributes(attributes)
21
- @end_to_end_id = if incoming_sepa?(attributes)
22
- sepa_end_to_end_id(attributes)
23
- elsif incoming_faster_payments?(attributes)
24
- 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
25
27
  end
26
28
  end
27
29
 
28
- private def incoming_sepa?(attributes)
29
- %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))
30
32
  end
31
33
 
32
- private def incoming_faster_payments?(attributes)
33
- attributes[:details]&.dig(:type) == "PI_FAST"
34
+ private def incoming_faster_payments?
35
+ @attributes[:details]&.dig(:type) == "PI_FAST"
34
36
  end
35
37
 
36
- private def sepa_end_to_end_id(attributes)
37
- 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)
38
40
  return unless doc
39
41
 
40
42
  doc_type = doc.dig(:header, :type)
@@ -48,44 +50,66 @@ module Modulr
48
50
  end
49
51
  end
50
52
 
51
- private def faster_payments_end_to_end_id(attributes)
52
- attributes[:details].dig(:details, :fpsTransaction, :paymentInfo, :endToEndId)
53
+ private def faster_payments_end_to_end_id
54
+ @attr_details.dig(:details, :fpsTransaction, :paymentInfo, :endToEndId)
53
55
  end
54
56
 
55
- private def parse_attributes(attributes)
56
- parse_details(attributes)
57
- parse_scheme if type
57
+ private def parse_attributes
58
+ parse_details
59
+ parse_scheme if @opts[:network_scheme]
58
60
  end
59
61
 
60
- private def parse_details(attributes)
61
- details = attributes[:details]
62
- detail_type = details&.dig(:type) || details&.dig(:destinationType)
62
+ private def parse_details
63
+ @attr_details = @attributes[:details]
64
+ detail_type = @attr_details&.dig(:type) || @attr_details&.dig(:destinationType)
63
65
 
64
66
  case detail_type
65
67
  when "PI_SECT", "PI_SEPA_INST", "PI_FAST", "PI_REV"
66
- incoming_detail(details)
68
+ incoming_detail
67
69
  when "ACCOUNT"
68
- incoming_internal_details(details)
70
+ incoming_internal_details
69
71
  else
70
- outgoing_detail(details)
72
+ outgoing_detail
71
73
  end
72
74
  end
73
75
 
76
+ private def payment_type
77
+ @type = if incoming?
78
+ @attr_details[:type]
79
+ elsif internal?
80
+ "INT_INTERC"
81
+ else
82
+ outgoing_type
83
+ end
84
+ @type
85
+ end
86
+
74
87
  private def parse_scheme
75
- case type
88
+ case payment_type
76
89
  when "PI_SECT", "PO_SECT"
77
90
  sepa_regular
78
91
  when "PI_SEPA_INST", "PO_SEPA_INST"
79
92
  sepa_instant
80
93
  when "PI_FAST", "PO_FAST"
81
94
  faster_payments
82
- when "ACCOUNT", "INT_INTERC"
95
+ when "INT_INTERC"
83
96
  internal
84
97
  else
85
98
  raise "Unable to find network and scheme for payment with ID: #{id} and Type: #{type}"
86
99
  end
87
100
  end
88
101
 
102
+ private def outgoing_type
103
+ return "PO_FAST" if @attributes.dig(:schemeInfo, :id)&.include?("MODULO")
104
+
105
+ case @attributes.dig(:schemeInfo, :name)
106
+ when "SEPA_INSTANT"
107
+ "PO_SEPA_INST"
108
+ when "SEPA_CREDIT_TRANSFER"
109
+ "PO_SECT"
110
+ end
111
+ end
112
+
89
113
  private def sepa_regular
90
114
  @network = "SEPA"
91
115
  @scheme = "SEPA Credit Transfers"
@@ -106,16 +130,25 @@ module Modulr
106
130
  @scheme = "INTERNAL"
107
131
  end
108
132
 
109
- private def incoming_detail(details)
110
- @details = Details::Incoming::General.new(nil, details)
133
+ private def incoming_detail
134
+ @details = Details::Incoming::General.new(nil, @attr_details)
135
+ end
136
+
137
+ private def outgoing_detail
138
+ @details = Details::Outgoing::General.new(nil, @attr_details)
139
+ end
140
+
141
+ private def incoming_internal_details
142
+ @details = Details::Incoming::Internal.new(nil, @attr_details)
111
143
  end
112
144
 
113
- private def outgoing_detail(details)
114
- @details = Details::Outgoing::General.new(nil, details)
145
+ private def incoming?
146
+ !@attr_details.key?(:sourceAccountId)
115
147
  end
116
148
 
117
- private def incoming_internal_details(details)
118
- @details = Details::Incoming::Internal.new(nil, details)
149
+ private def internal?
150
+ (@attr_details[:sourceAccountId] && @attr_details.key?(:destinationId)) ||
151
+ @attributes[:schemeInfo].empty?
119
152
  end
120
153
  end
121
154
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Modulr
4
- VERSION = "0.0.28"
4
+ VERSION = "0.0.30"
5
5
  end
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,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.28
4
+ version: 0.0.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aitor García Rey
@@ -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