modulr-api 0.0.27 → 0.0.28

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: 0d095d43ccee60d099ae8d7ac57d86cd8104259577ff908fb5cfcd6f33d260a5
4
+ data.tar.gz: a5a1e05cda5006f6397baa5460e67b7986ef537d742f9a2eeae7b4d69869e087
5
5
  SHA512:
6
- metadata.gz: 93df6c1115b144cf48b6483873a336deb266698067b7cb2bb68934757bf8a81cb4ff44f67af0447fd5039708f93b1da7899989e6243d26e158bfb12aadebecb1
7
- data.tar.gz: 684f71d53386979cfb5840d468b9d461e8f373960a06a76e961fcaa3f052d72bc4a2626c28c345e0fd30e4938b33b4de35ff3c475ac49ad217626f668519c989
6
+ metadata.gz: 9befecbaa71d544887fefab95c0d677fa4134abdf2964fee2a275c006ac534d929dd55ccf37c783624ad646b93a888ff03fe9ae93314f2db037533eb9ed6661a
7
+ data.tar.gz: 9cd97815ad18668bba5fc12d72721c46d742466086afaf95cb26cc81eb05e54caa1c9498a31d0e6476eb5690e81a63d1e77317d090e00cddaabaa9b17d2a24b6
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.28)
5
5
  faraday (~> 1.0)
6
6
  faraday_middleware (~> 1.0)
7
7
 
@@ -3,10 +3,10 @@
3
3
  module Modulr
4
4
  module API
5
5
  class PaymentsService < Service
6
- def find(id:)
6
+ def find(id:, **opts)
7
7
  response = client.get("/payments", { id: id })
8
8
  payment_attributes = response.body[:content]&.first
9
- raise NotFoundError, "Payment #{id} not found" unless payment_attributes
9
+ payment_attributes_with_type(id, payment_attributes) if include_transaction?(opts)
10
10
 
11
11
  Resources::Payments::Payment.new(response.env[:raw_body], payment_attributes)
12
12
  end
@@ -15,7 +15,15 @@ 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
- Resources::Payments::Collection.new(response.env[:raw_body], response.body[:content])
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)
19
27
  end
20
28
 
21
29
  # rubocop:disable Metrics/ParameterLists
@@ -52,6 +60,47 @@ module Modulr
52
60
  end
53
61
  end
54
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
55
104
  end
56
105
  end
57
106
  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,10 +13,11 @@ 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
18
  def initialize(raw_response, attributes = {})
18
19
  super(raw_response, attributes)
19
- @details = parse_details(attributes)
20
+ parse_attributes(attributes)
20
21
  @end_to_end_id = if incoming_sepa?(attributes)
21
22
  sepa_end_to_end_id(attributes)
22
23
  elsif incoming_faster_payments?(attributes)
@@ -51,18 +52,71 @@ module Modulr
51
52
  attributes[:details].dig(:details, :fpsTransaction, :paymentInfo, :endToEndId)
52
53
  end
53
54
 
55
+ private def parse_attributes(attributes)
56
+ parse_details(attributes)
57
+ parse_scheme if type
58
+ end
59
+
54
60
  private def parse_details(attributes)
55
61
  details = attributes[:details]
62
+ detail_type = details&.dig(:type) || details&.dig(:destinationType)
56
63
 
57
- case details&.dig(:type) || details&.dig(:destinationType)
64
+ case detail_type
58
65
  when "PI_SECT", "PI_SEPA_INST", "PI_FAST", "PI_REV"
59
- Details::Incoming::General.new(nil, details)
66
+ incoming_detail(details)
60
67
  when "ACCOUNT"
61
- Details::Incoming::Internal.new(nil, details)
68
+ incoming_internal_details(details)
69
+ else
70
+ outgoing_detail(details)
71
+ end
72
+ end
73
+
74
+ private def parse_scheme
75
+ case type
76
+ when "PI_SECT", "PO_SECT"
77
+ sepa_regular
78
+ when "PI_SEPA_INST", "PO_SEPA_INST"
79
+ sepa_instant
80
+ when "PI_FAST", "PO_FAST"
81
+ faster_payments
82
+ when "ACCOUNT", "INT_INTERC"
83
+ internal
62
84
  else
63
- Details::Outgoing::General.new(nil, details)
85
+ raise "Unable to find network and scheme for payment with ID: #{id} and Type: #{type}"
64
86
  end
65
87
  end
88
+
89
+ private def sepa_regular
90
+ @network = "SEPA"
91
+ @scheme = "SEPA Credit Transfers"
92
+ end
93
+
94
+ private def sepa_instant
95
+ @network = "SEPA"
96
+ @scheme = "SEPA Instant Credit Transfers"
97
+ end
98
+
99
+ private def faster_payments
100
+ @network = "FPS"
101
+ @scheme = "Faster Payments"
102
+ end
103
+
104
+ private def internal
105
+ @network = "INTERNAL"
106
+ @scheme = "INTERNAL"
107
+ end
108
+
109
+ private def incoming_detail(details)
110
+ @details = Details::Incoming::General.new(nil, details)
111
+ end
112
+
113
+ private def outgoing_detail(details)
114
+ @details = Details::Outgoing::General.new(nil, details)
115
+ end
116
+
117
+ private def incoming_internal_details(details)
118
+ @details = Details::Incoming::Internal.new(nil, details)
119
+ end
66
120
  end
67
121
  end
68
122
  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.28"
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
 
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.28
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