lunixi-sdk 1.2.2 → 1.3.1
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/CHANGELOG.md +45 -0
- data/README.md +262 -9
- data/README.tr.md +266 -7
- data/lib/lunixi/bank_connect.rb +340 -0
- data/lib/lunixi/bank_connect_filters.rb +114 -0
- data/lib/lunixi/bank_connect_values.rb +205 -0
- data/lib/lunixi/bank_transfer.rb +106 -0
- data/lib/lunixi/card_requests.rb +150 -0
- data/lib/lunixi/client.rb +57 -16
- data/lib/lunixi/direct_method_payment_request.rb +243 -0
- data/lib/lunixi/enabled_installments.rb +28 -0
- data/lib/lunixi/errors.rb +69 -3
- data/lib/lunixi/fraud.rb +81 -5
- data/lib/lunixi/identity.rb +94 -0
- data/lib/lunixi/identity_values.rb +28 -0
- data/lib/lunixi/insurance.rb +294 -0
- data/lib/lunixi/insurance_request.rb +134 -0
- data/lib/lunixi/insurance_values.rb +200 -0
- data/lib/lunixi/kyc.rb +189 -0
- data/lib/lunixi/kyc_values.rb +158 -0
- data/lib/lunixi/marketplace.rb +264 -0
- data/lib/lunixi/marketplace_values.rb +86 -0
- data/lib/lunixi/method_fields.rb +142 -0
- data/lib/lunixi/money.rb +7 -4
- data/lib/lunixi/payment_link_filters.rb +32 -0
- data/lib/lunixi/payment_link_image_rules.rb +85 -0
- data/lib/lunixi/payment_link_rules.rb +132 -0
- data/lib/lunixi/payment_link_values.rb +134 -0
- data/lib/lunixi/payment_links.rb +152 -0
- data/lib/lunixi/payment_values.rb +86 -0
- data/lib/lunixi/payments.rb +154 -5
- data/lib/lunixi/physical_pos.rb +183 -0
- data/lib/lunixi/physical_pos_card_data.rb +117 -0
- data/lib/lunixi/physical_pos_card_number.rb +65 -0
- data/lib/lunixi/physical_pos_device_identity.rb +44 -0
- data/lib/lunixi/physical_pos_filters.rb +58 -0
- data/lib/lunixi/physical_pos_gateway.rb +153 -0
- data/lib/lunixi/physical_pos_identifiers.rb +62 -0
- data/lib/lunixi/physical_pos_management.rb +326 -0
- data/lib/lunixi/physical_pos_money.rb +46 -0
- data/lib/lunixi/physical_pos_request.rb +126 -0
- data/lib/lunixi/physical_pos_responses.rb +102 -0
- data/lib/lunixi/physical_pos_results.rb +52 -0
- data/lib/lunixi/physical_pos_settlement_policies.rb +71 -0
- data/lib/lunixi/physical_pos_value.rb +43 -0
- data/lib/lunixi/physical_pos_values.rb +203 -0
- data/lib/lunixi/physical_pos_webhook.rb +147 -0
- data/lib/lunixi/product_webhooks.rb +106 -0
- data/lib/lunixi/promissory_note.rb +155 -0
- data/lib/lunixi/reference.rb +41 -0
- data/lib/lunixi/route_request.rb +121 -0
- data/lib/lunixi/route_response.rb +101 -0
- data/lib/lunixi/route_table.rb +128 -0
- data/lib/lunixi/route_value.rb +60 -0
- data/lib/lunixi/sanction.rb +244 -0
- data/lib/lunixi/sanction_values.rb +132 -0
- data/lib/lunixi/split_payment.rb +145 -0
- data/lib/lunixi/subscription_resources.rb +355 -0
- data/lib/lunixi/subscription_values.rb +220 -0
- data/lib/lunixi/subscriptions.rb +202 -0
- data/lib/lunixi/version.rb +1 -1
- data/lib/lunixi/wallet.rb +153 -0
- data/lib/lunixi/wallet_resources.rb +402 -0
- data/lib/lunixi/wallet_routes.rb +123 -0
- data/lib/lunixi/wallet_values.rb +71 -0
- data/lib/lunixi/wire_money.rb +67 -0
- data/lib/lunixi.rb +57 -0
- metadata +58 -1
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lunixi
|
|
4
|
+
# Local checks shared by PhysicalPos and PhysicalPosManagement: field lists and value kinds. Single
|
|
5
|
+
# values are checked by PhysicalPosValue, card data is refused by PhysicalPosCardData, the
|
|
6
|
+
# Idempotency-Key and path identifiers are checked by PhysicalPosIdentifiers and filters by
|
|
7
|
+
# PhysicalPosFilters; answers and errors are read by PhysicalPosResponses.
|
|
8
|
+
# Shape and canonical money are checked here; value rules (operation set, ranges, item totals, target
|
|
9
|
+
# uniqueness) stay on the gateway, which answers with a typed physical_pos.* code.
|
|
10
|
+
module PhysicalPosRequest
|
|
11
|
+
BASE = '/api/v1/physical-pos'
|
|
12
|
+
ROUTE = %r{\A/api/v1/physical-pos(?:[/?]|\z)}
|
|
13
|
+
# A field check's answer for "leave the field out" (nil is a real value: an explicit clear).
|
|
14
|
+
OMIT = Object.new.freeze
|
|
15
|
+
SALE_ITEM_KINDS = {
|
|
16
|
+
'lineNo' => 'int*', 'name' => 'string*', 'quantityMilli' => 'int*', 'unitCode' => 'string*', 'unitPriceMinor' => 'money*',
|
|
17
|
+
'taxGroupCode' => 'string*', 'lineTotalMinor' => 'money*', 'barcode' => 'string'
|
|
18
|
+
}.freeze
|
|
19
|
+
REFUND_ITEM_KINDS = { 'lineNo' => 'int*', 'quantityMilli' => 'int*', 'amountMinor' => 'money' }.freeze
|
|
20
|
+
TARGET_KINDS = PHYSICAL_POS_PAYMENT_TARGET_FIELDS.to_h { |name| [name, 'string'] }.freeze
|
|
21
|
+
|
|
22
|
+
module_function
|
|
23
|
+
|
|
24
|
+
# ── Bodies ───────────────────────────────────────────────────────────────
|
|
25
|
+
|
|
26
|
+
# Builds a request body from a field list (PHYSICAL_POS_REQUEST_FIELDS): card-data keys first
|
|
27
|
+
# (PhysicalPosCardDataRejectedError), then unknown fields, required fields and value types
|
|
28
|
+
# (ConfigurationError), then card-number values in the scanned free-text fields. Keys are the wire
|
|
29
|
+
# names (String or Symbol); snake_case names are accepted too. Nothing is sent when a check fails.
|
|
30
|
+
def body!(request, kinds, label)
|
|
31
|
+
PhysicalPosCardData.reject_card_data!(request, '(body)') unless request.nil?
|
|
32
|
+
given = wire_keys!(request, kinds.keys, label)
|
|
33
|
+
body = {}
|
|
34
|
+
kinds.each do |key, kind|
|
|
35
|
+
unless given.key?(key)
|
|
36
|
+
raise ConfigurationError, "'#{key}' is required." if kind.end_with?('*')
|
|
37
|
+
|
|
38
|
+
next
|
|
39
|
+
end
|
|
40
|
+
checked = check_value(kind, given[key], key)
|
|
41
|
+
body[key] = checked unless checked.equal?(OMIT)
|
|
42
|
+
end
|
|
43
|
+
PhysicalPosCardData.reject_card_numbers!(body)
|
|
44
|
+
body
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# One value against its kind. Money is a canonical string; present nil or blank money is refused.
|
|
48
|
+
# nil is sent only for a nullable (?) field and left out for any other optional field; '' is left
|
|
49
|
+
# out for an optional string and refused for a required one.
|
|
50
|
+
def check_value(kind_spec, value, field)
|
|
51
|
+
required = kind_spec.end_with?('*')
|
|
52
|
+
nullable = kind_spec.end_with?('?')
|
|
53
|
+
kind = kind_spec.delete_suffix('*').delete_suffix('?')
|
|
54
|
+
return PhysicalPosValue.money!(value, field) if kind == 'money'
|
|
55
|
+
return nil_value(required, nullable, field) if value.nil?
|
|
56
|
+
return OMIT if value == '' && !required
|
|
57
|
+
|
|
58
|
+
case kind
|
|
59
|
+
when 'string' then PhysicalPosValue.string!(value, field)
|
|
60
|
+
when 'int' then PhysicalPosValue.integer!(value, field)
|
|
61
|
+
when 'rowVersion' then PhysicalPosIdentifiers.row_version!(value, field)
|
|
62
|
+
when 'bool' then PhysicalPosValue.boolean!(value, field)
|
|
63
|
+
when 'strings' then PhysicalPosValue.strings!(value, field)
|
|
64
|
+
when 'target' then object_of(value, TARGET_KINDS, field)
|
|
65
|
+
when 'saleItems' then items_of(value, SALE_ITEM_KINDS, field)
|
|
66
|
+
when 'refundItems' then items_of(value, REFUND_ITEM_KINDS, field)
|
|
67
|
+
else raise ConfigurationError, "Unsupported field kind '#{kind_spec}'."
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def nil_value(required, nullable, field)
|
|
72
|
+
return nil if nullable
|
|
73
|
+
raise ConfigurationError, "'#{field}' is required." if required
|
|
74
|
+
|
|
75
|
+
OMIT
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def object_of(value, kinds, field)
|
|
79
|
+
given = wire_keys!(value, kinds.keys, "'#{field}'")
|
|
80
|
+
kinds.each_with_object({}) do |(key, kind), out|
|
|
81
|
+
next unless given.key?(key)
|
|
82
|
+
|
|
83
|
+
checked = check_value(kind, given[key], "#{field}.#{key}")
|
|
84
|
+
out[key] = checked unless checked.equal?(OMIT)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def items_of(value, kinds, field)
|
|
89
|
+
unless value.is_a?(Array) && !value.empty?
|
|
90
|
+
raise ConfigurationError, "'#{field}' must be a non-empty array; leave the field out for a request without items."
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
value.each_with_index.map do |item, index|
|
|
94
|
+
path = "#{field}[#{index}]"
|
|
95
|
+
out = object_of(item, kinds, path)
|
|
96
|
+
kinds.each { |key, kind| raise ConfigurationError, "'#{path}.#{key}' is required." if kind.end_with?('*') && !out.key?(key) }
|
|
97
|
+
out
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Wire names of a body or filter set: String or Symbol keys, the wire name or its snake_case form.
|
|
102
|
+
def wire_keys!(value, allowed, label, kind = 'field')
|
|
103
|
+
raise ConfigurationError, "#{label} must be a Hash." unless value.is_a?(Hash)
|
|
104
|
+
|
|
105
|
+
unknown = []
|
|
106
|
+
given = value.each_with_object({}) do |(key, entry), out|
|
|
107
|
+
raise ConfigurationError, "#{label} keys must be strings or symbols." unless key.is_a?(String) || key.is_a?(Symbol)
|
|
108
|
+
|
|
109
|
+
name = key.to_s
|
|
110
|
+
wire = allowed.include?(name) ? name : camel(name)
|
|
111
|
+
next unknown << name unless allowed.include?(wire)
|
|
112
|
+
raise ConfigurationError, "#{label} #{kind} '#{wire}' is given twice." if out.key?(wire)
|
|
113
|
+
|
|
114
|
+
out[wire] = entry
|
|
115
|
+
end
|
|
116
|
+
return given if unknown.empty?
|
|
117
|
+
|
|
118
|
+
raise ConfigurationError, "Unknown #{label} #{kind}(s): #{unknown.join(', ')}. Allowed: #{allowed.join(', ')}. " \
|
|
119
|
+
'The gateway rejects unknown fields with 400.'
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def camel(name)
|
|
123
|
+
name.gsub(/_([a-z0-9])/) { Regexp.last_match(1).upcase }
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lunixi
|
|
4
|
+
# Reads physical POS answers (records, pages, keyed write results) and maps gateway errors to the
|
|
5
|
+
# typed physical POS errors.
|
|
6
|
+
module PhysicalPosResponses
|
|
7
|
+
module_function
|
|
8
|
+
|
|
9
|
+
def unwrap(response)
|
|
10
|
+
response.is_a?(Hash) && response.key?('data') ? response['data'] : response
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# data[name] of a single-record answer, or data itself when the wrapper is missing.
|
|
14
|
+
def member(response, name)
|
|
15
|
+
data = unwrap(response)
|
|
16
|
+
data.is_a?(Hash) && !data[name].nil? ? data[name] : data
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Paging from the envelope's top-level pageInfo.
|
|
20
|
+
def page(response)
|
|
21
|
+
payload = unwrap(response)
|
|
22
|
+
items = payload.is_a?(Hash) && payload['items'].is_a?(Array) ? payload['items'] : []
|
|
23
|
+
info = hash_at(response, 'pageInfo') || hash_at(payload, 'pageInfo') || {}
|
|
24
|
+
cursor = info['nextCursor'].is_a?(String) && !info['nextCursor'].empty? ? info['nextCursor'] : nil
|
|
25
|
+
total = info['totalCount'].is_a?(Integer) ? info['totalCount'] : nil
|
|
26
|
+
PhysicalPosPage.new(items: items, has_more: info['hasMore'] == true && !cursor.nil?, next_cursor: cursor, total_count: total)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def hash_at(value, key)
|
|
30
|
+
value[key] if value.is_a?(Hash) && value[key].is_a?(Hash)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Every item of every page, fetching the next page only when it is needed. Without a block it
|
|
34
|
+
# returns an Enumerator.
|
|
35
|
+
def each_item(filters, block, &fetch)
|
|
36
|
+
items = Enumerator.new do |yielder|
|
|
37
|
+
query = filters.transform_keys(&:to_sym)
|
|
38
|
+
loop do
|
|
39
|
+
page = fetch.call(query)
|
|
40
|
+
page.items.each { |item| yielder << item }
|
|
41
|
+
break unless page.has_more && page.next_cursor
|
|
42
|
+
|
|
43
|
+
query = query.merge(cursor: page.next_cursor)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
return items unless block
|
|
47
|
+
|
|
48
|
+
items.each(&block)
|
|
49
|
+
nil
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Keyed write answer: the route's data plus replayed, the status code and the key sent.
|
|
53
|
+
def write_result(response, key, fallback)
|
|
54
|
+
data = unwrap(response)
|
|
55
|
+
data = {} unless data.is_a?(Hash)
|
|
56
|
+
replayed = data['replayed'] == true
|
|
57
|
+
PhysicalPosWriteResult.new(data: data, replayed: replayed, status_code: status_code(response, fallback.call(replayed)), idempotency_key: key)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def status_code(response, fallback)
|
|
61
|
+
value = response.is_a?(Hash) ? response['statusCode'] : nil
|
|
62
|
+
value.is_a?(Integer) && value.between?(200, 299) ? value : fallback
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Typed physical POS errors for one answered request: card data (field path), void after
|
|
66
|
+
# end-of-day (allowed_operation), 429 (retry_after in seconds). The key of a write is attached.
|
|
67
|
+
def translate(error, key = nil)
|
|
68
|
+
return error unless error.is_a?(ApiError)
|
|
69
|
+
|
|
70
|
+
common = { status: error.status, code: error.code, request_id: error.request_id, details: error.details,
|
|
71
|
+
idempotency_key: key || error.idempotency_key, message: error.message }
|
|
72
|
+
if error.code == PhysicalPosCardDataRejectedError::CODE
|
|
73
|
+
field = error.details['field']
|
|
74
|
+
PhysicalPosCardDataRejectedError.new(field: field.is_a?(String) ? field : nil, retry_after: error.retry_after, **common)
|
|
75
|
+
elsif error.code == PhysicalPosVoidAfterSettlementError::CODE
|
|
76
|
+
allowed = error.details['allowedOperation']
|
|
77
|
+
PhysicalPosVoidAfterSettlementError.new(allowed_operation: allowed.is_a?(String) ? allowed : nil, retry_after: error.retry_after, **common)
|
|
78
|
+
elsif error.status == 429
|
|
79
|
+
PhysicalPosRateLimitError.new(retry_after: retry_after_seconds(error), **common)
|
|
80
|
+
elsif key.nil?
|
|
81
|
+
error
|
|
82
|
+
else
|
|
83
|
+
error.class.new(retry_after: error.retry_after, **common)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# The Retry-After header in seconds, or details.retryAfterSeconds when the header is missing.
|
|
88
|
+
def retry_after_seconds(error)
|
|
89
|
+
number(error.retry_after) || number(error.details['retryAfterSeconds'])
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def number(value)
|
|
93
|
+
return value if value.is_a?(Integer) || (value.is_a?(Float) && value.finite?)
|
|
94
|
+
return nil unless value.is_a?(String)
|
|
95
|
+
|
|
96
|
+
text = value.strip
|
|
97
|
+
return text.to_i if text.match?(/\A\d{1,9}\z/)
|
|
98
|
+
|
|
99
|
+
text.match?(/\A\d{1,9}\.\d{1,9}\z/) ? text.to_f : nil
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lunixi
|
|
4
|
+
# One page of a physical POS list. total_count is filled only with includeTotal: true on entity
|
|
5
|
+
# lists; pass next_cursor as cursor: for the next page (or use the iterate_* methods).
|
|
6
|
+
PhysicalPosPage = Struct.new(:items, :has_more, :next_cursor, :total_count, keyword_init: true)
|
|
7
|
+
|
|
8
|
+
# Answer of a physical POS write that carries an Idempotency-Key.
|
|
9
|
+
#
|
|
10
|
+
# data is the route's payload unchanged ({ 'payment' => … }, { 'store' => … },
|
|
11
|
+
# { 'device' => …, 'closedAssignment' => … }, { 'run' => … }); result['store'] reads it directly.
|
|
12
|
+
# replayed is true when the same key and body were sent before: the record is then its CURRENT state.
|
|
13
|
+
# status_code is 202 for a new payment, reversal or end-of-day run (accepted, not paid: follow the
|
|
14
|
+
# outcome by webhook or get_payment), 201 for a created record, 200 for a replay, a cancel or a state
|
|
15
|
+
# change. idempotency_key is the key sent; keep it with your order, an uncertain retry must reuse it.
|
|
16
|
+
class PhysicalPosWriteResult
|
|
17
|
+
attr_reader :data, :replayed, :status_code, :idempotency_key
|
|
18
|
+
|
|
19
|
+
def initialize(data:, replayed:, status_code:, idempotency_key:)
|
|
20
|
+
@data = data
|
|
21
|
+
@replayed = replayed
|
|
22
|
+
@status_code = status_code
|
|
23
|
+
@idempotency_key = idempotency_key
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def [](name)
|
|
27
|
+
data[name.to_s]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# The payment of a payment write (for a reversal, the new child payment).
|
|
31
|
+
def payment
|
|
32
|
+
data['payment']
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def replayed?
|
|
36
|
+
replayed
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# True for a newly accepted payment, reversal or end-of-day run (HTTP 202).
|
|
40
|
+
def accepted?
|
|
41
|
+
status_code == 202
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def to_h
|
|
45
|
+
data.merge('replayed' => replayed, 'statusCode' => status_code, 'idempotencyKey' => idempotency_key)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def inspect
|
|
49
|
+
"#<Lunixi::PhysicalPosWriteResult status_code=#{status_code} replayed=#{replayed}>"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lunixi
|
|
4
|
+
# End-of-day policy routes of PhysicalPosManagement (account → store → device). Mixed into
|
|
5
|
+
# PhysicalPosManagement; uses its request and path helpers.
|
|
6
|
+
#
|
|
7
|
+
# A level's policy replaces the level above it entirely. set_* sends the full setting: { mode
|
|
8
|
+
# (MANUAL | SCHEDULED | DEVICE_AUTO), scheduleTime?, timeZone?, scheduleDays?, retryWindowMinutes?,
|
|
9
|
+
# retryIntervalMinutes?, offlineBehavior?, overdueAlertHours?, expectedRowVersion? }. clear_* resets
|
|
10
|
+
# the account to MANUAL, or removes a store / device override (it then inherits).
|
|
11
|
+
# expectedRowVersion is the policy's rowVersion you read (409 physical_pos.version_conflict when it
|
|
12
|
+
# changed); leave it out for last write wins. Each call returns the policy.
|
|
13
|
+
module PhysicalPosSettlementPolicies
|
|
14
|
+
def get_account_settlement_policy # rubocop:disable Naming/AccessorMethodName
|
|
15
|
+
@gateway.record('GET', '/settlement-policy', 'policy')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def set_account_settlement_policy(request) # rubocop:disable Naming/AccessorMethodName
|
|
19
|
+
@gateway.record('PUT', '/settlement-policy', 'policy', body: settlement_policy(request))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def clear_account_settlement_policy(expected_row_version = nil)
|
|
23
|
+
@gateway.record('DELETE', '/settlement-policy', 'policy', query: expected_row_version_query(expected_row_version))
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def get_store_settlement_policy(store_id)
|
|
27
|
+
@gateway.record('GET', "#{store_path(store_id)}/settlement-policy", 'policy')
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def set_store_settlement_policy(store_id, request)
|
|
31
|
+
@gateway.record('PUT', "#{store_path(store_id)}/settlement-policy", 'policy', body: settlement_policy(request))
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def clear_store_settlement_policy(store_id, expected_row_version = nil)
|
|
35
|
+
@gateway.record('DELETE', "#{store_path(store_id)}/settlement-policy", 'policy', query: expected_row_version_query(expected_row_version))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def get_device_settlement_policy(device_id)
|
|
39
|
+
@gateway.record('GET', "#{device_path(device_id)}/settlement-policy", 'policy')
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# DEVICE_AUTO only on devices that report their end-of-day results.
|
|
43
|
+
def set_device_settlement_policy(device_id, request)
|
|
44
|
+
@gateway.record('PUT', "#{device_path(device_id)}/settlement-policy", 'policy', body: settlement_policy(request))
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def clear_device_settlement_policy(device_id, expected_row_version = nil)
|
|
48
|
+
@gateway.record('DELETE', "#{device_path(device_id)}/settlement-policy", 'policy', query: expected_row_version_query(expected_row_version))
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# The policy a device follows (GET /devices/{deviceId}/settlement-policy/effective): { deviceId,
|
|
52
|
+
# sourceScopeType (ACCOUNT | STORE | DEVICE), policy, serverSettlementSupported, deviceAutoSupported,
|
|
53
|
+
# nextScheduledAt, lastSettlementAt, overdue, scheduleWarning }.
|
|
54
|
+
def get_effective_settlement_policy(device_id)
|
|
55
|
+
@gateway.record('GET', "#{device_path(device_id)}/settlement-policy/effective", 'effective')
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
def settlement_policy(request)
|
|
61
|
+
body(request, 'setSettlementPolicy')
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# DELETE …/settlement-policy?expectedRowVersion= (left out when nil).
|
|
65
|
+
def expected_row_version_query(expected_row_version)
|
|
66
|
+
return {} if expected_row_version.nil?
|
|
67
|
+
|
|
68
|
+
{ 'expectedRowVersion' => PhysicalPosIdentifiers.row_version!(expected_row_version, 'expectedRowVersion').to_s }
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lunixi
|
|
4
|
+
# Single values of the physical POS bodies and filters: strings, JSON integers, booleans, string lists
|
|
5
|
+
# and canonical minor-unit money. The error names the field, never its value. Not a public API.
|
|
6
|
+
module PhysicalPosValue
|
|
7
|
+
MAX_SAFE_INTEGER = JsonBody::MAX_SAFE_INTEGER
|
|
8
|
+
|
|
9
|
+
module_function
|
|
10
|
+
|
|
11
|
+
def string!(value, field)
|
|
12
|
+
raise ConfigurationError, "'#{field}' must be a non-empty string." unless value.is_a?(String) && !value.empty?
|
|
13
|
+
|
|
14
|
+
value
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def integer!(value, field)
|
|
18
|
+
raise ConfigurationError, "'#{field}' must be an integer (a JSON number, not a string)." unless value.is_a?(Integer) && value.abs <= MAX_SAFE_INTEGER
|
|
19
|
+
|
|
20
|
+
value
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def boolean!(value, field)
|
|
24
|
+
raise ConfigurationError, "'#{field}' must be a boolean." unless [true, false].include?(value)
|
|
25
|
+
|
|
26
|
+
value
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def strings!(value, field)
|
|
30
|
+
unless value.is_a?(Array) && value.all? { |entry| entry.is_a?(String) && !entry.empty? }
|
|
31
|
+
raise ConfigurationError, "'#{field}' must be an array of non-empty strings."
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
value.dup
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def money!(value, field)
|
|
38
|
+
Money.minor(value, positive: true)
|
|
39
|
+
rescue ConfigurationError
|
|
40
|
+
raise ConfigurationError, "'#{field}' must be a canonical minor-unit string such as \"4500\" (not a number).", cause: nil
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lunixi
|
|
4
|
+
# Physical POS values, request fields and filters (/api/v1/physical-pos).
|
|
5
|
+
#
|
|
6
|
+
# Statuses and operations are open sets on the wire: the SDK lists the values the gateway sends today
|
|
7
|
+
# and never rejects one it does not know. The field and filter lists are closed: the gateway rejects
|
|
8
|
+
# an unknown body field or query parameter with 400, so the SDK checks them before sending.
|
|
9
|
+
module PhysicalPosPaymentOperation
|
|
10
|
+
SALE = 'SALE'
|
|
11
|
+
PREAUTH_OPEN = 'PREAUTH_OPEN'
|
|
12
|
+
REFUND_UNMATCHED = 'REFUND_UNMATCHED'
|
|
13
|
+
VOID = 'VOID'
|
|
14
|
+
REFUND = 'REFUND'
|
|
15
|
+
PREAUTH_CLOSE = 'PREAUTH_CLOSE'
|
|
16
|
+
PREAUTH_CANCEL = 'PREAUTH_CANCEL'
|
|
17
|
+
|
|
18
|
+
# Operations that start a root payment (create_payment).
|
|
19
|
+
ROOT = [SALE, PREAUTH_OPEN, REFUND_UNMATCHED].freeze
|
|
20
|
+
# Operations of a reversal (create_reversal).
|
|
21
|
+
REVERSAL = [VOID, REFUND, PREAUTH_CLOSE, PREAUTH_CANCEL].freeze
|
|
22
|
+
ALL = (ROOT + REVERSAL).freeze
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
module PhysicalPosPaymentStatus
|
|
26
|
+
NOT_STARTED = 'NOT_STARTED'
|
|
27
|
+
IN_PROGRESS = 'IN_PROGRESS'
|
|
28
|
+
APPROVED = 'APPROVED'
|
|
29
|
+
PARTIALLY_APPROVED = 'PARTIALLY_APPROVED'
|
|
30
|
+
DECLINED = 'DECLINED'
|
|
31
|
+
CANCELLED = 'CANCELLED'
|
|
32
|
+
EXPIRED = 'EXPIRED'
|
|
33
|
+
FAILED = 'FAILED'
|
|
34
|
+
UNKNOWN = 'UNKNOWN'
|
|
35
|
+
MANUAL_REVIEW = 'MANUAL_REVIEW'
|
|
36
|
+
|
|
37
|
+
ALL = [NOT_STARTED, IN_PROGRESS, APPROVED, PARTIALLY_APPROVED, DECLINED, CANCELLED, EXPIRED, FAILED, UNKNOWN, MANUAL_REVIEW].freeze
|
|
38
|
+
FINAL_STATUSES = [APPROVED, PARTIALLY_APPROVED, DECLINED, CANCELLED, EXPIRED, FAILED].freeze
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
module PhysicalPosReversalStatus
|
|
42
|
+
NONE = 'NONE'
|
|
43
|
+
PARTIALLY_REFUNDED = 'PARTIALLY_REFUNDED'
|
|
44
|
+
REFUNDED = 'REFUNDED'
|
|
45
|
+
VOIDED = 'VOIDED'
|
|
46
|
+
PREAUTH_CLOSED = 'PREAUTH_CLOSED'
|
|
47
|
+
PREAUTH_CANCELLED = 'PREAUTH_CANCELLED'
|
|
48
|
+
PREAUTH_EXPIRED = 'PREAUTH_EXPIRED'
|
|
49
|
+
|
|
50
|
+
ALL = [NONE, PARTIALLY_REFUNDED, REFUNDED, VOIDED, PREAUTH_CLOSED, PREAUTH_CANCELLED, PREAUTH_EXPIRED].freeze
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Webhook event types. physical_pos.payment.created and .in_progress are internal and never delivered.
|
|
54
|
+
# Reversals (void, refund, pre-authorisation close / cancel) use the same payment events; tell them
|
|
55
|
+
# apart with data.operation and data.rootPaymentId, and the original payment's source with
|
|
56
|
+
# data.original.origin.
|
|
57
|
+
#
|
|
58
|
+
# PAYMENT_DEVICE_SALE reports a sale made directly on the device (origin: DEVICE_DIRECT): it arrives
|
|
59
|
+
# approved, with deviceOccurredAt; no approved event is sent for it. Its refund comes with the usual
|
|
60
|
+
# payment events (data.original.origin: DEVICE_DIRECT).
|
|
61
|
+
#
|
|
62
|
+
# End-of-day events (physical_pos.settlement.*) have their own payloads: completed (the device's
|
|
63
|
+
# result with its bank lines; any source), failed (a scheduled run could not finish in its window),
|
|
64
|
+
# skipped (a scheduled run was skipped for a reason you can fix) and overdue (no result within the
|
|
65
|
+
# policy's threshold). They carry no historySeq; deduplicate them by the event id.
|
|
66
|
+
module PhysicalPosEvents
|
|
67
|
+
PAYMENT_APPROVED = 'physical_pos.payment.approved'
|
|
68
|
+
PAYMENT_PARTIALLY_APPROVED = 'physical_pos.payment.partially_approved'
|
|
69
|
+
PAYMENT_DECLINED = 'physical_pos.payment.declined'
|
|
70
|
+
PAYMENT_CANCELLED = 'physical_pos.payment.cancelled'
|
|
71
|
+
PAYMENT_EXPIRED = 'physical_pos.payment.expired'
|
|
72
|
+
PAYMENT_FAILED = 'physical_pos.payment.failed'
|
|
73
|
+
PAYMENT_UNKNOWN = 'physical_pos.payment.unknown'
|
|
74
|
+
PAYMENT_MANUAL_REVIEW = 'physical_pos.payment.manual_review'
|
|
75
|
+
PAYMENT_DEVICE_SALE = 'physical_pos.payment.device_sale'
|
|
76
|
+
FISCAL_DOCUMENT_ISSUED = 'physical_pos.fiscal_document.issued'
|
|
77
|
+
FISCAL_DOCUMENT_FAILED = 'physical_pos.fiscal_document.failed'
|
|
78
|
+
FISCAL_DOCUMENT_CANCELLED = 'physical_pos.fiscal_document.cancelled'
|
|
79
|
+
FISCAL_DOCUMENT_ACTION_REQUIRED = 'physical_pos.fiscal_document.action_required'
|
|
80
|
+
SETTLEMENT_COMPLETED = 'physical_pos.settlement.completed'
|
|
81
|
+
SETTLEMENT_FAILED = 'physical_pos.settlement.failed'
|
|
82
|
+
SETTLEMENT_OVERDUE = 'physical_pos.settlement.overdue'
|
|
83
|
+
SETTLEMENT_SKIPPED = 'physical_pos.settlement.skipped'
|
|
84
|
+
# Subscription pattern for every physical POS event.
|
|
85
|
+
ALL_EVENTS = 'physical_pos.*'
|
|
86
|
+
|
|
87
|
+
PAYMENT_EVENTS = [PAYMENT_APPROVED, PAYMENT_PARTIALLY_APPROVED, PAYMENT_DECLINED, PAYMENT_CANCELLED, PAYMENT_EXPIRED,
|
|
88
|
+
PAYMENT_FAILED, PAYMENT_UNKNOWN, PAYMENT_MANUAL_REVIEW, PAYMENT_DEVICE_SALE].freeze
|
|
89
|
+
FISCAL_DOCUMENT_EVENTS = [FISCAL_DOCUMENT_ISSUED, FISCAL_DOCUMENT_FAILED, FISCAL_DOCUMENT_CANCELLED, FISCAL_DOCUMENT_ACTION_REQUIRED].freeze
|
|
90
|
+
SETTLEMENT_EVENTS = [SETTLEMENT_COMPLETED, SETTLEMENT_FAILED, SETTLEMENT_OVERDUE, SETTLEMENT_SKIPPED].freeze
|
|
91
|
+
ALL = (PAYMENT_EVENTS + FISCAL_DOCUMENT_EVENTS + SETTLEMENT_EVENTS).freeze
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
PHYSICAL_POS_EVENT_PATTERN = PhysicalPosEvents::ALL_EVENTS
|
|
95
|
+
PHYSICAL_POS_EVENT_TYPES = PhysicalPosEvents::ALL
|
|
96
|
+
|
|
97
|
+
# Idempotency-Key of a physical POS route: 8–200 printable ASCII characters, no space.
|
|
98
|
+
PHYSICAL_POS_IDEMPOTENCY_KEY_PATTERN = /\A[\x21-\x7E]{8,200}\z/
|
|
99
|
+
PHYSICAL_POS_MAX_LIMIT = 100
|
|
100
|
+
PHYSICAL_POS_ROW_VERSION_MAX = 2_147_483_647
|
|
101
|
+
|
|
102
|
+
# 5xx codes after which the gateway guarantees nothing was written (the payment did not start). Any
|
|
103
|
+
# other 5xx, and a request without an HTTP answer, leaves the outcome of a payment write unknown.
|
|
104
|
+
PHYSICAL_POS_NOT_STARTED_CODES = %w[
|
|
105
|
+
physical_pos.presence.unavailable physical_pos.signing.unavailable physical_pos.service.busy
|
|
106
|
+
physical_pos.service.clock_skew physical_pos.service.not_configured
|
|
107
|
+
].freeze
|
|
108
|
+
|
|
109
|
+
PHYSICAL_POS_PAYMENT_TARGET_FIELDS = %w[deviceId vendorCode serialNumber externalRef].freeze
|
|
110
|
+
PHYSICAL_POS_SALE_ITEM_FIELDS = %w[lineNo name quantityMilli unitCode unitPriceMinor taxGroupCode lineTotalMinor barcode].freeze
|
|
111
|
+
PHYSICAL_POS_REFUND_ITEM_FIELDS = %w[lineNo quantityMilli amountMinor].freeze
|
|
112
|
+
|
|
113
|
+
# Request bodies: { field => kind }. Kinds: string, int, money, bool, strings (array of strings),
|
|
114
|
+
# rowVersion, target, saleItems, refundItems. A * suffix marks a required field; ? allows nil (an
|
|
115
|
+
# explicit clear, sent as JSON null).
|
|
116
|
+
PHYSICAL_POS_REQUEST_FIELDS = {
|
|
117
|
+
'createPayment' => {
|
|
118
|
+
'operation' => 'string*', 'target' => 'target*', 'amountMinor' => 'money*', 'currency' => 'string*',
|
|
119
|
+
'installmentCount' => 'int?', 'instrument' => 'string?', 'merchantReference' => 'string?',
|
|
120
|
+
'allowDuplicateReference' => 'bool', 'startTimeoutSeconds' => 'int?', 'terminalAcquirerId' => 'string?',
|
|
121
|
+
'items' => 'saleItems', 'interaction' => 'string?', 'terminalProviderId' => 'string?'
|
|
122
|
+
},
|
|
123
|
+
'createReversal' => {
|
|
124
|
+
'operation' => 'string*', 'amountMinor' => 'money', 'currency' => 'string*', 'merchantReference' => 'string?',
|
|
125
|
+
'startTimeoutSeconds' => 'int?', 'target' => 'target?', 'items' => 'refundItems'
|
|
126
|
+
},
|
|
127
|
+
'createStore' => {
|
|
128
|
+
'code' => 'string*', 'name' => 'string*', 'city' => 'string', 'district' => 'string', 'addressLine' => 'string',
|
|
129
|
+
'timezone' => 'string', 'externalRef' => 'string'
|
|
130
|
+
},
|
|
131
|
+
'updateStore' => {
|
|
132
|
+
'rowVersion' => 'rowVersion*', 'name' => 'string', 'city' => 'string?', 'district' => 'string?',
|
|
133
|
+
'addressLine' => 'string?', 'timezone' => 'string', 'externalRef' => 'string?'
|
|
134
|
+
},
|
|
135
|
+
'statusChange' => { 'rowVersion' => 'rowVersion*', 'reasonCode' => 'string*' },
|
|
136
|
+
'createRegister' => { 'code' => 'string*', 'name' => 'string*' },
|
|
137
|
+
'updateRegister' => { 'rowVersion' => 'rowVersion*', 'name' => 'string' },
|
|
138
|
+
'createTerminal' => {
|
|
139
|
+
'code' => 'string*', 'displayName' => 'string*', 'vendorCode' => 'string', 'virtualSerial' => 'string',
|
|
140
|
+
'vendorTerminalRef' => 'string'
|
|
141
|
+
},
|
|
142
|
+
'updateTerminal' => { 'rowVersion' => 'rowVersion*', 'displayName' => 'string', 'vendorCode' => 'string' },
|
|
143
|
+
'addTerminalAcquirer' => {
|
|
144
|
+
'vendorAcquirerRef' => 'string*', 'merchantNumber' => 'string*', 'terminalNumber' => 'string*', 'label' => 'string',
|
|
145
|
+
'currencies' => 'strings*'
|
|
146
|
+
},
|
|
147
|
+
'updateTerminalAcquirer' => { 'rowVersion' => 'rowVersion*', 'label' => 'string?', 'currencies' => 'strings', 'status' => 'string' },
|
|
148
|
+
'addTerminalProvider' => {
|
|
149
|
+
'vendorAccountId' => 'string*', 'merchantCode' => 'string*', 'terminalCode' => 'string*', 'productCode' => 'string',
|
|
150
|
+
'label' => 'string'
|
|
151
|
+
},
|
|
152
|
+
'updateTerminalProvider' => { 'rowVersion' => 'rowVersion*', 'label' => 'string?', 'status' => 'string' },
|
|
153
|
+
'changeTerminalDevice' => { 'rowVersion' => 'rowVersion*', 'deviceId' => 'string*', 'reasonCode' => 'string*' },
|
|
154
|
+
'createDevice' => {
|
|
155
|
+
'vendorCode' => 'string*', 'deviceModelId' => 'string*', 'serialNumber' => 'string*', 'displayName' => 'string',
|
|
156
|
+
'externalRef' => 'string', 'storeId' => 'string', 'registerId' => 'string', 'integrationChannel' => 'string*',
|
|
157
|
+
'channelVariant' => 'string', 'appMode' => 'string'
|
|
158
|
+
},
|
|
159
|
+
'updateDevice' => {
|
|
160
|
+
'rowVersion' => 'rowVersion*', 'displayName' => 'string?', 'externalRef' => 'string?', 'integrationChannel' => 'string',
|
|
161
|
+
'channelVariant' => 'string?', 'appMode' => 'string?'
|
|
162
|
+
},
|
|
163
|
+
'assignDevice' => { 'rowVersion' => 'rowVersion*', 'storeId' => 'string*', 'registerId' => 'string?', 'reasonCode' => 'string*' },
|
|
164
|
+
'changeDeviceLifecycle' => { 'rowVersion' => 'rowVersion*', 'target' => 'string*', 'reasonCode' => 'string*' },
|
|
165
|
+
'revokeDeviceKey' => { 'rowVersion' => 'rowVersion*', 'reasonCode' => 'string*' },
|
|
166
|
+
'revertDeviceEnrollment' => { 'reasonCode' => 'string*' },
|
|
167
|
+
'revokeActivationCode' => { 'reasonCode' => 'string*' },
|
|
168
|
+
'setSettlementPolicy' => {
|
|
169
|
+
'mode' => 'string*', 'scheduleTime' => 'string', 'timeZone' => 'string', 'scheduleDays' => 'strings',
|
|
170
|
+
'retryWindowMinutes' => 'int', 'retryIntervalMinutes' => 'int', 'offlineBehavior' => 'string',
|
|
171
|
+
'overdueAlertHours' => 'int', 'expectedRowVersion' => 'rowVersion'
|
|
172
|
+
}
|
|
173
|
+
}.transform_values(&:freeze).freeze
|
|
174
|
+
|
|
175
|
+
physical_pos_page = %w[limit cursor].freeze
|
|
176
|
+
physical_pos_entity_page = (physical_pos_page + ['includeTotal']).freeze
|
|
177
|
+
physical_pos_report = %w[dateFrom dateTo deviceId storeId].freeze
|
|
178
|
+
|
|
179
|
+
# Query parameters per route; anything else is rejected before sending. history covers the audit,
|
|
180
|
+
# link, assignment and key lists.
|
|
181
|
+
PHYSICAL_POS_FILTERS = {
|
|
182
|
+
'listPayments' => physical_pos_page + %w[deviceId paymentStatus createdFrom createdTo merchantReference],
|
|
183
|
+
'listTransactions' => physical_pos_page + %w[deviceId storeId registerId paymentStatus createdFrom createdTo merchantReference
|
|
184
|
+
amountFromMinor amountToMinor origin operation],
|
|
185
|
+
'listAmbiguousPayments' => physical_pos_page + %w[deviceId paymentStatus],
|
|
186
|
+
'getSalesSummary' => physical_pos_report + ['groupBy'],
|
|
187
|
+
'getTaxSummary' => physical_pos_report,
|
|
188
|
+
'listSettlements' => physical_pos_page + %w[deviceId lineStatus createdFrom createdTo],
|
|
189
|
+
'listSettlementRuns' => physical_pos_entity_page + %w[deviceId source runStatus createdFrom createdTo],
|
|
190
|
+
'listDeviceModels' => %w[vendorCode deviceType status],
|
|
191
|
+
'listStores' => physical_pos_entity_page + %w[status q],
|
|
192
|
+
'listRegisters' => physical_pos_entity_page + ['status'],
|
|
193
|
+
'listTerminals' => physical_pos_entity_page + %w[status q],
|
|
194
|
+
'listTerminalAcquirers' => physical_pos_entity_page,
|
|
195
|
+
'listTerminalProviders' => physical_pos_entity_page,
|
|
196
|
+
'listDevices' => physical_pos_entity_page + %w[storeId registerId vendorCode deviceModelId deviceType lifecycleStatus
|
|
197
|
+
ownershipStatus integrationChannel q],
|
|
198
|
+
'history' => physical_pos_page
|
|
199
|
+
}.transform_values { |names| names.dup.freeze }.freeze
|
|
200
|
+
|
|
201
|
+
# Filters scanned for card numbers before sending.
|
|
202
|
+
PHYSICAL_POS_FREE_TEXT_FILTERS = %w[merchantReference q].freeze
|
|
203
|
+
end
|