modulr-api 0.0.25 → 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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/modulr/api/payments_service.rb +52 -3
- data/lib/modulr/api/services.rb +0 -3
- data/lib/modulr/resources/payments/payment.rb +93 -6
- data/lib/modulr/version.rb +1 -1
- data/lib/modulr.rb +2 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d095d43ccee60d099ae8d7ac57d86cd8104259577ff908fb5cfcd6f33d260a5
|
4
|
+
data.tar.gz: a5a1e05cda5006f6397baa5460e67b7986ef537d742f9a2eeae7b4d69869e087
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9befecbaa71d544887fefab95c0d677fa4134abdf2964fee2a275c006ac534d929dd55ccf37c783624ad646b93a888ff03fe9ae93314f2db037533eb9ed6661a
|
7
|
+
data.tar.gz: 9cd97815ad18668bba5fc12d72721c46d742466086afaf95cb26cc81eb05e54caa1c9498a31d0e6476eb5690e81a63d1e77317d090e00cddaabaa9b17d2a24b6
|
data/Gemfile.lock
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
data/lib/modulr/api/services.rb
CHANGED
@@ -4,7 +4,7 @@ module Modulr
|
|
4
4
|
module Resources
|
5
5
|
module Payments
|
6
6
|
class Payment < Base
|
7
|
-
attr_reader :details
|
7
|
+
attr_reader :details, :end_to_end_id, :network, :scheme
|
8
8
|
|
9
9
|
map :id, [:id, :payment_reference_id]
|
10
10
|
map :status
|
@@ -12,24 +12,111 @@ module Modulr
|
|
12
12
|
map :externalReference, :external_reference
|
13
13
|
map :createdDate, :created_at
|
14
14
|
map :approvalStatus, :approval_status
|
15
|
+
map :message, :message
|
16
|
+
map :type
|
15
17
|
|
16
18
|
def initialize(raw_response, attributes = {})
|
17
19
|
super(raw_response, attributes)
|
18
|
-
|
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)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private def incoming_sepa?(attributes)
|
29
|
+
%w[PI_SECT PI_SEPA_INST].include?(attributes[:details]&.dig(:type))
|
30
|
+
end
|
31
|
+
|
32
|
+
private def incoming_faster_payments?(attributes)
|
33
|
+
attributes[:details]&.dig(:type) == "PI_FAST"
|
34
|
+
end
|
35
|
+
|
36
|
+
private def sepa_end_to_end_id(attributes)
|
37
|
+
doc = attributes[:details].dig(:details, :payload, :docs, :doc)
|
38
|
+
return unless doc
|
39
|
+
|
40
|
+
doc_type = doc.dig(:header, :type)
|
41
|
+
key = doc_type.downcase.to_sym
|
42
|
+
|
43
|
+
case doc_type
|
44
|
+
when "IFCCTRNS" # SEPA instant
|
45
|
+
doc.dig(key, :document, :fitoFICstmrCdtTrf, :cdtTrfTxInf, :pmtId, :endToEndId)
|
46
|
+
when "FFCCTRNS" # SEPA regular
|
47
|
+
doc.dig(key, :document, :fitoFICstmrCdtTrf, :cdtTrfTxInf).first&.dig(:pmtId, :endToEndId)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private def faster_payments_end_to_end_id(attributes)
|
52
|
+
attributes[:details].dig(:details, :fpsTransaction, :paymentInfo, :endToEndId)
|
53
|
+
end
|
54
|
+
|
55
|
+
private def parse_attributes(attributes)
|
56
|
+
parse_details(attributes)
|
57
|
+
parse_scheme if type
|
19
58
|
end
|
20
59
|
|
21
60
|
private def parse_details(attributes)
|
22
61
|
details = attributes[:details]
|
62
|
+
detail_type = details&.dig(:type) || details&.dig(:destinationType)
|
23
63
|
|
24
|
-
case
|
64
|
+
case detail_type
|
25
65
|
when "PI_SECT", "PI_SEPA_INST", "PI_FAST", "PI_REV"
|
26
|
-
|
66
|
+
incoming_detail(details)
|
27
67
|
when "ACCOUNT"
|
28
|
-
|
68
|
+
incoming_internal_details(details)
|
29
69
|
else
|
30
|
-
|
70
|
+
outgoing_detail(details)
|
31
71
|
end
|
32
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
|
84
|
+
else
|
85
|
+
raise "Unable to find network and scheme for payment with ID: #{id} and Type: #{type}"
|
86
|
+
end
|
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
|
33
120
|
end
|
34
121
|
end
|
35
122
|
end
|
data/lib/modulr/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aitor García Rey
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -242,7 +242,7 @@ metadata:
|
|
242
242
|
source_code_uri: https://github.com/devengoapp/modulr-ruby
|
243
243
|
changelog_uri: https://github.com/devengoapp/modulr-ruby/blob/master/CHANGELOG.md
|
244
244
|
rubygems_mfa_required: 'true'
|
245
|
-
post_install_message:
|
245
|
+
post_install_message:
|
246
246
|
rdoc_options: []
|
247
247
|
require_paths:
|
248
248
|
- lib
|
@@ -258,7 +258,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
258
258
|
version: '0'
|
259
259
|
requirements: []
|
260
260
|
rubygems_version: 3.4.10
|
261
|
-
signing_key:
|
261
|
+
signing_key:
|
262
262
|
specification_version: 4
|
263
263
|
summary: Ruby client for Modulr Finance API.
|
264
264
|
test_files: []
|