modulr-api 0.0.28 → 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: 0d095d43ccee60d099ae8d7ac57d86cd8104259577ff908fb5cfcd6f33d260a5
4
- data.tar.gz: a5a1e05cda5006f6397baa5460e67b7986ef537d742f9a2eeae7b4d69869e087
3
+ metadata.gz: c8c9dbb9dd8e49d7371b05d2e68e7222d5e37c654ffe46e389d6d5d113ebffbd
4
+ data.tar.gz: 37a5c32437eaedaad272ae831543be0626b2334438692a6a483ba78af6cdd6fa
5
5
  SHA512:
6
- metadata.gz: 9befecbaa71d544887fefab95c0d677fa4134abdf2964fee2a275c006ac534d929dd55ccf37c783624ad646b93a888ff03fe9ae93314f2db037533eb9ed6661a
7
- data.tar.gz: 9cd97815ad18668bba5fc12d72721c46d742466086afaf95cb26cc81eb05e54caa1c9498a31d0e6476eb5690e81a63d1e77317d090e00cddaabaa9b17d2a24b6
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.28)
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!
@@ -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,65 @@ 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
73
+ end
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
71
83
  end
72
84
  end
73
85
 
74
86
  private def parse_scheme
75
- case type
87
+ case payment_type
76
88
  when "PI_SECT", "PO_SECT"
77
89
  sepa_regular
78
90
  when "PI_SEPA_INST", "PO_SEPA_INST"
79
91
  sepa_instant
80
92
  when "PI_FAST", "PO_FAST"
81
93
  faster_payments
82
- when "ACCOUNT", "INT_INTERC"
94
+ when "ACCOUNT"
83
95
  internal
84
96
  else
85
97
  raise "Unable to find network and scheme for payment with ID: #{id} and Type: #{type}"
86
98
  end
87
99
  end
88
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
+
89
112
  private def sepa_regular
90
113
  @network = "SEPA"
91
114
  @scheme = "SEPA Credit Transfers"
@@ -106,16 +129,24 @@ module Modulr
106
129
  @scheme = "INTERNAL"
107
130
  end
108
131
 
109
- private def incoming_detail(details)
110
- @details = Details::Incoming::General.new(nil, details)
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)
111
142
  end
112
143
 
113
- private def outgoing_detail(details)
114
- @details = Details::Outgoing::General.new(nil, details)
144
+ private def incoming?
145
+ !@attr_details.key?(:sourceAccountId)
115
146
  end
116
147
 
117
- private def incoming_internal_details(details)
118
- @details = Details::Incoming::Internal.new(nil, details)
148
+ private def internal?
149
+ @attr_details[:sourceAccountId] && @attr_details[:destinationId]
119
150
  end
120
151
  end
121
152
  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.29"
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.29
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