lunixi-sdk 2.0.2 → 2.3.0
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 +28 -0
- data/README.md +43 -4
- data/README.tr.md +28 -3
- data/docs/card-rewards.md +21 -0
- data/lib/lunixi/bank_connect.rb +132 -15
- data/lib/lunixi/bank_connect_filters.rb +13 -3
- data/lib/lunixi/bank_connect_pos.rb +165 -0
- data/lib/lunixi/bank_connect_values.rb +127 -5
- data/lib/lunixi/card_requests.rb +9 -1
- data/lib/lunixi/client.rb +38 -14
- data/lib/lunixi/direct_method_payment_request.rb +24 -2
- data/lib/lunixi/errors.rb +49 -0
- data/lib/lunixi/fraud.rb +3 -2
- data/lib/lunixi/fraud_uk_claims.rb +127 -0
- data/lib/lunixi/fraud_values.rb +46 -0
- data/lib/lunixi/marketplace.rb +2 -0
- data/lib/lunixi/payment_link_rules.rb +13 -1
- data/lib/lunixi/payment_link_values.rb +4 -0
- data/lib/lunixi/payment_links.rb +3 -1
- data/lib/lunixi/payment_values.rb +22 -2
- data/lib/lunixi/payments.rb +62 -6
- data/lib/lunixi/product_webhooks.rb +17 -1
- data/lib/lunixi/refund_to_wallet.rb +94 -0
- data/lib/lunixi/route_table.rb +10 -5
- data/lib/lunixi/routing_pin.rb +247 -0
- data/lib/lunixi/sanction.rb +77 -17
- data/lib/lunixi/sanction_batch.rb +215 -0
- data/lib/lunixi/sanction_values.rb +289 -5
- data/lib/lunixi/split_payment.rb +17 -2
- data/lib/lunixi/subscription_routing.rb +70 -0
- data/lib/lunixi/subscription_values.rb +26 -3
- data/lib/lunixi/subscriptions.rb +22 -2
- data/lib/lunixi/version.rb +1 -1
- data/lib/lunixi/wallet.rb +43 -7
- data/lib/lunixi/wallet_customer_sessions.rb +75 -0
- data/lib/lunixi/wallet_customer_tokens.rb +238 -0
- data/lib/lunixi/wallet_portal.rb +340 -0
- data/lib/lunixi/wallet_portal_routes.rb +171 -0
- data/lib/lunixi/wallet_routes.rb +28 -3
- data/lib/lunixi/wallet_rules.rb +131 -0
- data/lib/lunixi/wallet_values.rb +151 -0
- data/lib/lunixi.rb +12 -0
- metadata +14 -1
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'time'
|
|
5
|
+
|
|
6
|
+
module Lunixi
|
|
7
|
+
# UK APP reimbursement claims (POST /api/v1/fraud/uk-claims). Opening a claim is the only claim action
|
|
8
|
+
# available with an API key; the assessment, approval, milestones and clock stops are done in the panel.
|
|
9
|
+
class FraudUkClaims
|
|
10
|
+
PATH = '/api/v1/fraud/uk-claims'
|
|
11
|
+
# X-Actor-Id: the analyst recording the claim.
|
|
12
|
+
ACTOR_ID = /\A[A-Za-z0-9._@+-]{1,64}\z/
|
|
13
|
+
POSITIVE_MINOR = /\A[1-9][0-9]*\z/
|
|
14
|
+
NONNEGATIVE_MINOR = /\A(0|[1-9][0-9]*)\z/
|
|
15
|
+
PAYMENTS_LIMIT = 200
|
|
16
|
+
LINKED_CLAIMS_LIMIT = 20
|
|
17
|
+
|
|
18
|
+
def initialize(client)
|
|
19
|
+
@client = client
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Records a UK APP reimbursement claim and returns the claim view (id, caseId, regime, claimState,
|
|
23
|
+
# amounts, deadlines, deadlineAlerts, channel: "api"). Keys are the wire names (UK_CLAIM_FIELDS,
|
|
24
|
+
# UK_CLAIM_PAYMENT_FIELDS); amounts are minor-unit strings and the currency is GBP only.
|
|
25
|
+
#
|
|
26
|
+
# actor_id is sent as X-Actor-Id: the analyst recording the claim. It is required with an API key and
|
|
27
|
+
# is stored as your declaration. Sending the same externalClaimRef again returns the existing claim.
|
|
28
|
+
def open(claim, actor_id:)
|
|
29
|
+
actor = actor!(actor_id)
|
|
30
|
+
body = claim!(claim)
|
|
31
|
+
RouteResponse.unwrap(@client.request('POST', PATH, body: body, signed: false, actor_id: actor))
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def actor!(actor_id)
|
|
37
|
+
actor = actor_id.is_a?(String) ? actor_id.strip : ''
|
|
38
|
+
return actor if actor.match?(ACTOR_ID)
|
|
39
|
+
|
|
40
|
+
raise ConfigurationError, 'actor_id (X-Actor-Id) is required: the analyst recording the claim, 1-64 characters of ' \
|
|
41
|
+
'letters, digits and . _ @ + -'
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def claim!(claim)
|
|
45
|
+
raise ConfigurationError, 'UK claim must be an object' unless claim.is_a?(Hash)
|
|
46
|
+
|
|
47
|
+
data = JSON.parse(JsonBody.dump(claim))
|
|
48
|
+
unknown!(data, UK_CLAIM_FIELDS, 'UK claim')
|
|
49
|
+
raise ConfigurationError, 'role is required (sending | receiving).' if data['role'].nil?
|
|
50
|
+
|
|
51
|
+
one_of!(data, 'role', UK_CLAIM_ROLES)
|
|
52
|
+
iso!(data['reportedAt'], 'reportedAt')
|
|
53
|
+
one_of!(data, 'payerType', UK_CLAIM_PAYER_TYPES)
|
|
54
|
+
one_of!(data, 'reportedBy', UK_CLAIM_REPORTED_BY)
|
|
55
|
+
one_of!(data, 'scamType', UK_CLAIM_SCAM_TYPES)
|
|
56
|
+
raise ConfigurationError, 'UK reimbursement claims are GBP only.' if data.key?('currency') && data['currency'] != 'GBP'
|
|
57
|
+
|
|
58
|
+
payer!(data)
|
|
59
|
+
payments!(data['payments'])
|
|
60
|
+
data
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def payer!(data)
|
|
64
|
+
staff = data['payerStaffCount']
|
|
65
|
+
raise ConfigurationError, 'payerStaffCount must be a non-negative integer.' if data.key?('payerStaffCount') && !(staff.is_a?(Integer) && staff >= 0)
|
|
66
|
+
|
|
67
|
+
%w[payerTurnoverOrBalanceEurMinor payerAnnualIncomeGbpMinor].each do |field|
|
|
68
|
+
minor!(data[field], NONNEGATIVE_MINOR, field) if data.key?(field)
|
|
69
|
+
end
|
|
70
|
+
linked = data['linkedClaimIds']
|
|
71
|
+
return unless data.key?('linkedClaimIds') && !(linked.is_a?(Array) && linked.size <= LINKED_CLAIMS_LIMIT)
|
|
72
|
+
|
|
73
|
+
raise ConfigurationError, "linkedClaimIds must be an array of at most #{LINKED_CLAIMS_LIMIT} ids."
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def payments!(payments)
|
|
77
|
+
unless payments.is_a?(Array) && payments.size.between?(1, PAYMENTS_LIMIT)
|
|
78
|
+
raise ConfigurationError, "payments must be an array of 1 to #{PAYMENTS_LIMIT} payments."
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
payments.each_with_index do |payment, index|
|
|
82
|
+
where = "payments[#{index}]"
|
|
83
|
+
raise ConfigurationError, "#{where} must be an object." unless payment.is_a?(Hash)
|
|
84
|
+
|
|
85
|
+
unknown!(payment, UK_CLAIM_PAYMENT_FIELDS, where)
|
|
86
|
+
iso!(payment['executedAt'], "#{where}.executedAt")
|
|
87
|
+
raise ConfigurationError, "#{where}.amountMinor is required." unless payment.key?('amountMinor')
|
|
88
|
+
|
|
89
|
+
minor!(payment['amountMinor'], POSITIVE_MINOR, "#{where}.amountMinor")
|
|
90
|
+
one_of!(payment, 'scheme', UK_CLAIM_SCHEMES, where)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def unknown!(object, allowed, where)
|
|
95
|
+
key = object.keys.find { |name| !allowed.include?(name) }
|
|
96
|
+
raise ConfigurationError, "Unknown #{where} field \"#{key}\"; the gateway rejects it with 400." if key
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def one_of!(object, field, values, where = nil)
|
|
100
|
+
return unless object.key?(field) && !values.include?(object[field])
|
|
101
|
+
|
|
102
|
+
raise ConfigurationError, "#{[where, field].compact.join('.')} must be one of: #{values.join(', ')}."
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def iso!(value, field)
|
|
106
|
+
raise ConfigurationError, "#{field} must be an ISO 8601 date-time string." unless value.is_a?(String) && iso?(value.strip)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def iso?(value)
|
|
110
|
+
Time.iso8601(value)
|
|
111
|
+
true
|
|
112
|
+
rescue ArgumentError
|
|
113
|
+
begin
|
|
114
|
+
Date.iso8601(value)
|
|
115
|
+
true
|
|
116
|
+
rescue ArgumentError
|
|
117
|
+
false
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def minor!(value, pattern, field)
|
|
122
|
+
return if value.is_a?(String) && value.match?(pattern)
|
|
123
|
+
|
|
124
|
+
raise ConfigurationError, "#{field} must be a minor-unit integer string (e.g. \"250000\"), not a number."
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lunixi
|
|
4
|
+
# Fraud webhook event types your endpoint can subscribe to, delivered in the platform's signed envelope
|
|
5
|
+
# and verified with WebhookVerifier. (Lunixi::FraudEvents is the transaction event client.)
|
|
6
|
+
module FraudWebhookEvents
|
|
7
|
+
# Async flow result is ready; correlate with decisionRequestId. Advisory: the synchronous decision stands.
|
|
8
|
+
FLOW_ASYNC_COMPLETED = 'fraud.flow.async_completed'
|
|
9
|
+
# A "Platform Event" node in your flow fired; label and data are the values you defined in the flow.
|
|
10
|
+
FLOW_ACTION_TRIGGERED = 'fraud.flow.action_triggered'
|
|
11
|
+
# Fraud API quota threshold reached, or a request was rejected with 429. Sent once per day and lane.
|
|
12
|
+
QUOTA_THRESHOLD_REACHED = 'fraud.quota.threshold_reached'
|
|
13
|
+
# One of your fraud alert rules fired.
|
|
14
|
+
ALERT_TRIGGERED = 'fraud.alert.triggered'
|
|
15
|
+
# An outage affecting fraud evaluation was detected or declared.
|
|
16
|
+
SERVICE_DEGRADED = 'fraud.service.degraded'
|
|
17
|
+
# The outage closed; carries the duration and how many decisions could not be checked.
|
|
18
|
+
SERVICE_RECOVERED = 'fraud.service.recovered'
|
|
19
|
+
# A scheduled report finished its period and was produced (no download link; download from the console).
|
|
20
|
+
REPORT_READY = 'fraud.report.ready'
|
|
21
|
+
# A UK APP claim obligation (receiving-firm notice, reimbursement, hard close) is due soon or overdue.
|
|
22
|
+
UK_CLAIM_DEADLINE = 'fraud.uk_claim.deadline'
|
|
23
|
+
|
|
24
|
+
ALL = [FLOW_ASYNC_COMPLETED, FLOW_ACTION_TRIGGERED, QUOTA_THRESHOLD_REACHED, ALERT_TRIGGERED, SERVICE_DEGRADED,
|
|
25
|
+
SERVICE_RECOVERED, REPORT_READY, UK_CLAIM_DEADLINE].freeze
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Every fraud webhook event type, in catalog order.
|
|
29
|
+
FRAUD_EVENT_TYPES = FraudWebhookEvents::ALL
|
|
30
|
+
|
|
31
|
+
# UK APP reimbursement claim: wire values of POST /api/v1/fraud/uk-claims. The gateway answers an unknown
|
|
32
|
+
# key with 400; these lists let the SDK fail locally with the offending key name.
|
|
33
|
+
UK_CLAIM_FIELDS = %w[role reportedAt externalClaimRef linkedClaimIds subMerchantRef victimRef payerType payerStaffCount
|
|
34
|
+
payerTurnoverOrBalanceEurMinor payerAnnualIncomeGbpMinor reportedBy scamType currency
|
|
35
|
+
counterpartyPspCode payments].freeze
|
|
36
|
+
UK_CLAIM_PAYMENT_FIELDS = %w[paymentRef fraudDecisionLogId traceId scheme executedAt amountMinor receivingPspCode payeeIban
|
|
37
|
+
payeeSortCode payeeAccountNumber warningRecord delayRecord].freeze
|
|
38
|
+
UK_CLAIM_ROLES = %w[sending receiving].freeze
|
|
39
|
+
UK_CLAIM_PAYER_TYPES = %w[individual micro_enterprise charity business_other].freeze
|
|
40
|
+
UK_CLAIM_REPORTED_BY = %w[victim agent].freeze
|
|
41
|
+
UK_CLAIM_SCAM_TYPES = %w[impersonation_bank_police impersonation_other investment romance purchase advance_fee invoice_mandate
|
|
42
|
+
ceo_fraud other].freeze
|
|
43
|
+
UK_CLAIM_SCHEMES = %w[faster_payments chaps bacs sepa swift on_us card other].freeze
|
|
44
|
+
# Deadline kinds carried by the fraud.uk_claim.deadline webhook event.
|
|
45
|
+
UK_CLAIM_DEADLINE_KINDS = %w[receiving_notify reimburse hard_close].freeze
|
|
46
|
+
end
|
data/lib/lunixi/marketplace.rb
CHANGED
|
@@ -41,6 +41,7 @@ module Lunixi
|
|
|
41
41
|
def create_checkout_intent(request, sellers, multi_seller_policy: MarketplaceMultiSellerPolicy::ALL_OR_NOTHING, idempotency_key: nil)
|
|
42
42
|
body = split_body(payload!(request, 'create_checkout_intent request'), sellers, multi_seller_policy)
|
|
43
43
|
OrderDetails.check!(body, 'A marketplace payment intent', checkout_intent: true)
|
|
44
|
+
RoutingPin.field!(body)
|
|
44
45
|
response = @routes.call('createCheckoutIntent', body: body, idempotency_key: idempotency_key)
|
|
45
46
|
intent = RouteResponse.merge_root(response)
|
|
46
47
|
return response if RouteResponse.text(intent['token']) || RouteResponse.text(intent['checkoutFormContent'])
|
|
@@ -59,6 +60,7 @@ module Lunixi
|
|
|
59
60
|
body = payload!(payload, 'charge_marketplace_card payload')
|
|
60
61
|
charge_amount!(body)
|
|
61
62
|
OrderDetails.check!(body, 'A marketplace card charge')
|
|
63
|
+
RoutingPin.field!(body, payment_method: PaymentMethod::CARD)
|
|
62
64
|
@routes.call(three_ds ? 'chargeMarketplaceCard3d' : 'chargeMarketplaceCard2d', body: body, idempotency_key: idempotency_key)
|
|
63
65
|
end
|
|
64
66
|
|
|
@@ -6,7 +6,7 @@ module Lunixi
|
|
|
6
6
|
# Local checks of the payment-link bodies (list filters: PaymentLinkFilters; image uploads:
|
|
7
7
|
# PaymentLinkImageRules).
|
|
8
8
|
module PaymentLinkRules
|
|
9
|
-
CREATE_FIELDS = (
|
|
9
|
+
CREATE_FIELDS = (PAYMENT_LINK_CREATE_ONLY_FIELDS + PAYMENT_LINK_SPEC_FIELDS).freeze
|
|
10
10
|
UPDATE_FIELDS = PAYMENT_LINK_SPEC_FIELDS
|
|
11
11
|
TIME_FIELDS = %w[startsAt expiresAt eventAt].freeze
|
|
12
12
|
LINK_ACTIONS = %w[pause resume deactivate].freeze
|
|
@@ -18,6 +18,7 @@ module Lunixi
|
|
|
18
18
|
def create_body!(body)
|
|
19
19
|
data = root!(body, 'Payment link request')
|
|
20
20
|
known!(data, CREATE_FIELDS, 'create')
|
|
21
|
+
checkout_routing!(data)
|
|
21
22
|
times(data)
|
|
22
23
|
end
|
|
23
24
|
|
|
@@ -30,9 +31,20 @@ module Lunixi
|
|
|
30
31
|
raise ConfigurationError, "'#{fixed}' is fixed when a payment link is created and cannot be updated; create a new link instead" if fixed
|
|
31
32
|
|
|
32
33
|
known!(data, UPDATE_FIELDS, 'update')
|
|
34
|
+
checkout_routing!(data)
|
|
33
35
|
times(data)
|
|
34
36
|
end
|
|
35
37
|
|
|
38
|
+
# checkout.routing, when given, is a routing pin (routing is not a top-level link field). The pin
|
|
39
|
+
# must be in the link's environment (otherwise 400 payment.routing.pin_mismatch, details.mismatch
|
|
40
|
+
# ENVIRONMENT); a target in maintenance or inactive does not stop the link (a STRICT pin is checked
|
|
41
|
+
# when the buyer pays).
|
|
42
|
+
def checkout_routing!(data)
|
|
43
|
+
return unless data['checkout'].is_a?(Hash)
|
|
44
|
+
|
|
45
|
+
data['checkout'] = RoutingPin.field!(data['checkout'].transform_keys(&:to_s), 'checkout.routing')
|
|
46
|
+
end
|
|
47
|
+
|
|
36
48
|
# pause / resume / deactivate body: expectedRowVersion (optional) and reason.
|
|
37
49
|
def action_body!(action, expected_row_version, reason)
|
|
38
50
|
raise ConfigurationError, "Payment link action must be one of #{LINK_ACTIONS.join(', ')}" unless LINK_ACTIONS.include?(action.to_s)
|
|
@@ -118,6 +118,10 @@ module Lunixi
|
|
|
118
118
|
ALL = [PNG, JPEG, WEBP].freeze
|
|
119
119
|
end
|
|
120
120
|
|
|
121
|
+
# Fields a create body may carry besides PAYMENT_LINK_SPEC_FIELDS: environment. An update does not
|
|
122
|
+
# take it. The routing pin of a link is checkout.routing (create and update).
|
|
123
|
+
PAYMENT_LINK_CREATE_ONLY_FIELDS = %w[environment].freeze
|
|
124
|
+
|
|
121
125
|
# Every field of a payment-link definition in the gateway's spelling. Create and update bodies may
|
|
122
126
|
# carry only these keys (plus environment on create); the gateway rejects any other key with 400.
|
|
123
127
|
PAYMENT_LINK_SPEC_FIELDS = %w[
|
data/lib/lunixi/payment_links.rb
CHANGED
|
@@ -24,7 +24,9 @@ module Lunixi
|
|
|
24
24
|
|
|
25
25
|
# Create a link. The idempotency key is required: the same key with the same body returns the stored
|
|
26
26
|
# link with replayed: true; the same key with another body is 409 payment_link.idempotency.conflict.
|
|
27
|
-
# Only PAYMENT_LINK_SPEC_FIELDS and
|
|
27
|
+
# Only PAYMENT_LINK_SPEC_FIELDS and PAYMENT_LINK_CREATE_ONLY_FIELDS are accepted; amounts are
|
|
28
|
+
# minor-unit strings. checkout.routing pins every payment of the link (create and update; a
|
|
29
|
+
# connection in another environment than the link is refused with 400).
|
|
28
30
|
def create(body, idempotency_key: nil)
|
|
29
31
|
client.request('POST', BASE, body: PaymentLinkRules.create_body!(body), idempotency_key: Client.idempotency_key!(idempotency_key))
|
|
30
32
|
end
|
|
@@ -41,6 +41,26 @@ module Lunixi
|
|
|
41
41
|
ALL = [OTP, REDIRECT, DISPLAY, APP_APPROVAL, INPUT].freeze
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
+
# The envelope code of payments.void on a PROCESSING payment with an open request waiting for the buyer
|
|
45
|
+
# (Request to Pay approval, bank transfer instruction, QR): the request is cancelled through the shared
|
|
46
|
+
# cancellation. Follow the final result with payments.get or the webhook.
|
|
47
|
+
module PaymentPendingActionCode
|
|
48
|
+
# The request was closed, no money moved; the payment is FAILED.
|
|
49
|
+
CANCELLED = 'payment.pending_action.cancelled'
|
|
50
|
+
# The buyer paid during the cancellation; the payment is CAPTURED.
|
|
51
|
+
ALREADY_COMPLETED = 'payment.pending_action.already_completed'
|
|
52
|
+
# The provider does not withdraw the request now; it stays open (the buyer can reject it).
|
|
53
|
+
NOT_CANCELLABLE = 'payment.pending_action.not_cancellable'
|
|
54
|
+
# The result is being verified; the payment is NEEDS_RECONCILIATION.
|
|
55
|
+
CANCEL_UNCONFIRMED = 'payment.pending_action.cancel_unconfirmed'
|
|
56
|
+
# Nothing open to cancel.
|
|
57
|
+
NOT_OPEN = 'payment.pending_action.not_open'
|
|
58
|
+
# The request is being processed; try again in a few seconds.
|
|
59
|
+
BUSY = 'payment.pending_action.busy'
|
|
60
|
+
|
|
61
|
+
ALL = [CANCELLED, ALREADY_COMPLETED, NOT_CANCELLABLE, CANCEL_UNCONFIRMED, NOT_OPEN, BUSY].freeze
|
|
62
|
+
end
|
|
63
|
+
|
|
44
64
|
# providerSelection of a method in payments.list_payment_methods.
|
|
45
65
|
module ProviderSelection
|
|
46
66
|
# Card: routing picks the provider; providerCode is not sent.
|
|
@@ -71,11 +91,11 @@ module Lunixi
|
|
|
71
91
|
# Body fields of POST /payments/direct/payment.
|
|
72
92
|
DIRECT_METHOD_PAYMENT_FIELDS = (%w[
|
|
73
93
|
paymentMethod amount currency orderId paymentChannel paymentGroup callbackUrl locale description customerId
|
|
74
|
-
preauth buyer shippingAddress billingAddress basketItems card installment installmentQuoteToken force3D metadata
|
|
94
|
+
preauth buyer shippingAddress billingAddress basketItems card installment installmentQuoteToken force3D cardRewardSelection routing metadata
|
|
75
95
|
] + METHOD_BLOCK_FIELDS).freeze
|
|
76
96
|
|
|
77
97
|
# Fields that belong to a card payment only (paymentMethod CARD).
|
|
78
|
-
CARD_ONLY_FIELDS = %w[card installment installmentQuoteToken force3D].freeze
|
|
98
|
+
CARD_ONLY_FIELDS = %w[card installment installmentQuoteToken force3D cardRewardSelection].freeze
|
|
79
99
|
|
|
80
100
|
# Body fields of POST /payments/{paymentId}/actions/{actionId}/confirm a merchant server sends.
|
|
81
101
|
# The hosted form's checkout token fields are never sent by this SDK.
|
data/lib/lunixi/payments.rb
CHANGED
|
@@ -3,16 +3,18 @@
|
|
|
3
3
|
module Lunixi
|
|
4
4
|
# Explicit payment routes. The advanced Client#request method covers other
|
|
5
5
|
# documented endpoints without pretending to validate their entire DTO schema.
|
|
6
|
-
class Payments
|
|
6
|
+
class Payments # rubocop:disable Metrics/ClassLength -- one method per catalog operation
|
|
7
7
|
BASE = '/api/v1/payments'
|
|
8
8
|
BIN_BASE = '/api/v1/bin'
|
|
9
9
|
PDF_ACCEPT = 'application/pdf, application/json'
|
|
10
10
|
OMITTED_AMOUNT = Object.new.freeze
|
|
11
11
|
private_constant :OMITTED_AMOUNT
|
|
12
|
-
attr_reader :client
|
|
12
|
+
attr_reader :client, :connections
|
|
13
13
|
|
|
14
14
|
def initialize(client)
|
|
15
15
|
@client = client
|
|
16
|
+
# Your provider connections, the targets of routing.credentialId (connections.list).
|
|
17
|
+
@connections = PaymentConnections.new(client)
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
# Create hosted/embedded checkout using integer minor units and a durable attempt key.
|
|
@@ -29,6 +31,9 @@ module Lunixi
|
|
|
29
31
|
# prices add up to +amount+); +shippingAddress+ when an item is PHYSICAL. A missing field raises
|
|
30
32
|
# ConfigurationError naming its path before sending.
|
|
31
33
|
#
|
|
34
|
+
# Optional +routing+ ({ providerCode:, credentialId:, mode: }, RoutingPinMode) pins the payment to a
|
|
35
|
+
# provider and/or one of your connections; it is written to the intent and the browser never sees it.
|
|
36
|
+
#
|
|
32
37
|
# @param body [Hash] gateway body: +amount+ (canonical minor-unit string), +currency+, +orderId+,
|
|
33
38
|
# the order details and optional fields such as +callbackUrl+ and +enabledInstallments+
|
|
34
39
|
# @param idempotency_key [String] the persisted key of this checkout attempt
|
|
@@ -124,9 +129,24 @@ module Lunixi
|
|
|
124
129
|
|
|
125
130
|
# Start a payment with any method from the merchant server (POST /payments/direct/payment). Build
|
|
126
131
|
# the body with DirectMethodPaymentRequest or pass a raw Hash; both are checked before sending,
|
|
127
|
-
# the order details (OrderDetails) included.
|
|
132
|
+
# the order details (OrderDetails) included. routing (DirectMethodPaymentRequest#with_routing) pins
|
|
133
|
+
# the payment to a provider or one of your connections: STRICT answers 422
|
|
134
|
+
# payment.routing.pin_not_eligible when the target cannot take it, PREFER falls back to normal
|
|
135
|
+
# routing; a pinned payment's response carries data.routing (RoutingPin.result).
|
|
128
136
|
# When the buyer must act, data.action says how (PaymentActionType); a BANK_TRANSFER payment
|
|
129
137
|
# answers with a DISPLAY action read by BankTransferInstruction.from_response.
|
|
138
|
+
# List reward programmes without creating a payment.
|
|
139
|
+
def list_card_rewards(body)
|
|
140
|
+
Money.minor(body.fetch('amount'))
|
|
141
|
+
client.request('POST', "#{BASE}/direct/rewards/options", body: body)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# Query an expiring selection bound to this card and order.
|
|
145
|
+
def query_card_rewards(body)
|
|
146
|
+
Money.minor(body.fetch('amount'))
|
|
147
|
+
client.request('POST', "#{BASE}/direct/rewards/query", body: body)
|
|
148
|
+
end
|
|
149
|
+
|
|
130
150
|
def direct_method_payment(body_or_request, idempotency_key: nil)
|
|
131
151
|
body = body_or_request.is_a?(DirectMethodPaymentRequest) ? body_or_request.to_h : DirectMethodPaymentRequest.payload!(body_or_request)
|
|
132
152
|
OrderDetails.check!(body, 'A direct method payment')
|
|
@@ -194,12 +214,48 @@ module Lunixi
|
|
|
194
214
|
client.request('POST', "#{BASE}/#{payment_id}/refund", body: body, idempotency_key: Client.idempotency_key!(idempotency_key))
|
|
195
215
|
end
|
|
196
216
|
|
|
197
|
-
#
|
|
217
|
+
# Refund a captured LIVE payment to the buyer's wallet in your wallet program instead of the card
|
|
218
|
+
# (POST /payments/{id}/refund-to-wallet, permission payment:refund-to-wallet, signed; the idempotency
|
|
219
|
+
# key is required, as for refund).
|
|
220
|
+
#
|
|
221
|
+
# request takes only REFUND_TO_WALLET_FIELDS (String or Symbol keys, camelCase or snake_case): amount
|
|
222
|
+
# (positive canonical minor-unit string; leave it out to refund the remaining refundable amount),
|
|
223
|
+
# reason, programId (leave it out when you run a single program) and customerId (your own id of the
|
|
224
|
+
# buyer, a STRONG match; without it only the phone recorded on the order is tried, a WEAK match). When
|
|
225
|
+
# no wallet user is found the refund goes to the card. Marketplace / split payments are refused. Any
|
|
226
|
+
# other field raises ConfigurationError before sending; an empty request sends no body. A payment paid
|
|
227
|
+
# WITH the wallet is refunded with refund and only in full (WALLET_PARTIAL_REFUND_UNSUPPORTED).
|
|
228
|
+
# @return [Hash] the payment envelope, as refund answers
|
|
229
|
+
def refund_to_wallet(payment_id, request = {}, idempotency_key:)
|
|
230
|
+
path = "#{BASE}/#{identifier!(payment_id)}/refund-to-wallet"
|
|
231
|
+
body = RefundToWalletRules.body!(request, REFUND_TO_WALLET_FIELDS, 'refund_to_wallet')
|
|
232
|
+
key = Client.idempotency_key!(idempotency_key)
|
|
233
|
+
client.request('POST', path, body: body.empty? ? nil : body, idempotency_key: key)
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
# Read-only: can refund_to_wallet be offered for this payment, to whom (masked) and how strong is the
|
|
237
|
+
# match (POST /payments/{id}/refund-to-wallet/eligibility, same permission, signed, no idempotency key;
|
|
238
|
+
# a POST keeps customerId out of URLs and logs). request takes only REFUND_TO_WALLET_ELIGIBILITY_FIELDS
|
|
239
|
+
# (customerId, programId); an empty request sends {}. Answer data: eligible, matchedBy
|
|
240
|
+
# (RefundToWalletMatchedBy), matchStrength (RefundToWalletMatchStrength), maskedTarget,
|
|
241
|
+
# defaultDestination (always CARD), reason (RefundToWalletEligibilityReason). Nothing moves until
|
|
242
|
+
# refund_to_wallet is called.
|
|
243
|
+
# @return [Hash] the gateway envelope, unmodified
|
|
244
|
+
def refund_to_wallet_eligibility(payment_id, request = {})
|
|
245
|
+
path = "#{BASE}/#{identifier!(payment_id)}/refund-to-wallet/eligibility"
|
|
246
|
+
body = RefundToWalletRules.body!(request, REFUND_TO_WALLET_ELIGIBILITY_FIELDS, 'refund_to_wallet_eligibility')
|
|
247
|
+
client.request('POST', path, body: body)
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
# Void an authorization without inventing a settlement success result. On a PROCESSING payment with an
|
|
251
|
+
# open request waiting for the buyer (Request to Pay, bank transfer instruction, QR) the same call
|
|
252
|
+
# cancels the request; the answer's code is a PaymentPendingActionCode value.
|
|
198
253
|
def void(payment_id, idempotency_key:)
|
|
199
254
|
client.request('POST', "#{BASE}/#{identifier!(payment_id)}/void", idempotency_key: Client.idempotency_key!(idempotency_key))
|
|
200
255
|
end
|
|
201
256
|
|
|
202
|
-
# Start a 1–5 leg split payment; running statuses are returned, never marked paid.
|
|
257
|
+
# Start a 1–5 leg split payment; running statuses are returned, never marked paid. legs[].routing
|
|
258
|
+
# pins one leg (a non-card leg's providerCode must equal it). The body
|
|
203
259
|
# (SPLIT_PAYMENT_FIELDS) carries the order details: buyer, billingAddress, basketItems and
|
|
204
260
|
# shippingAddress for a PHYSICAL item; a missing field raises ConfigurationError before sending.
|
|
205
261
|
def split(body, idempotency_key:)
|
|
@@ -297,7 +353,7 @@ module Lunixi
|
|
|
297
353
|
|
|
298
354
|
validate_basket!(data['basketItems'], data['amount']) if data.key?('basketItems')
|
|
299
355
|
data['enabledInstallments'] = EnabledInstallments.check!(data['enabledInstallments']) if data.key?('enabledInstallments')
|
|
300
|
-
data
|
|
356
|
+
RoutingPin.field!(data)
|
|
301
357
|
end
|
|
302
358
|
|
|
303
359
|
def sellers!(sellers, amount)
|
|
@@ -12,7 +12,7 @@ module Lunixi
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
# Reads product webhooks through the signature check, never around it. Not a public API; use
|
|
15
|
-
# BankConnectWebhook, BankTransferWebhook or InsuranceWebhook.
|
|
15
|
+
# BankConnectWebhook, BankTransferWebhook, BankPosWebhook or InsuranceWebhook.
|
|
16
16
|
module ProductWebhook
|
|
17
17
|
module_function
|
|
18
18
|
|
|
@@ -82,6 +82,22 @@ module Lunixi
|
|
|
82
82
|
end
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
+
# bank_pos.day_closed (BankPosEvents): a POS account's day closed; data holds BANK_POS_DAY_CLOSED_FIELDS
|
|
86
|
+
# (acquiringAccountId is the POS account id; amounts are minor-unit strings, counts integers).
|
|
87
|
+
module BankPosWebhook
|
|
88
|
+
FIELDS = BankPosEvents::ALL.to_h { |type| [type, BANK_POS_DAY_CLOSED_FIELDS] }.freeze
|
|
89
|
+
|
|
90
|
+
module_function
|
|
91
|
+
|
|
92
|
+
def parse(raw_body, headers, secret_or_verifier, tolerance: 300)
|
|
93
|
+
ProductWebhook.parse(raw_body, headers, secret_or_verifier, FIELDS, 'bank POS', tolerance)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def from_event(verified_event)
|
|
97
|
+
ProductWebhook.read(verified_event, FIELDS, 'bank POS')
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
85
101
|
# insurance.* (InsuranceEvents). An order event's data holds INSURANCE_WEBHOOK_FIELDS; the lead event
|
|
86
102
|
# (insurance.lead.submitted) holds INSURANCE_LEAD_WEBHOOK_FIELDS and is not an order. Decide on the
|
|
87
103
|
# order from the webhook; get_order shows its state.
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lunixi
|
|
4
|
+
# Body members of payments.refund_to_wallet (gateway RefundToWalletDto).
|
|
5
|
+
REFUND_TO_WALLET_FIELDS = %w[amount reason programId customerId].freeze
|
|
6
|
+
|
|
7
|
+
# Body members of payments.refund_to_wallet_eligibility (gateway RefundToWalletEligibilityDto).
|
|
8
|
+
REFUND_TO_WALLET_ELIGIBILITY_FIELDS = %w[customerId programId].freeze
|
|
9
|
+
|
|
10
|
+
# A payment paid with the wallet is refunded only in full: a partial payments.refund is answered with this code.
|
|
11
|
+
WALLET_PARTIAL_REFUND_UNSUPPORTED = 'payment.refund.wallet_partial_unsupported'
|
|
12
|
+
|
|
13
|
+
# matchStrength of a refund-to-wallet eligibility answer.
|
|
14
|
+
module RefundToWalletMatchStrength
|
|
15
|
+
# Found by your customerId inside the wallet program.
|
|
16
|
+
STRONG = 'STRONG'
|
|
17
|
+
# Found only by the phone recorded on the order.
|
|
18
|
+
WEAK = 'WEAK'
|
|
19
|
+
NONE = 'NONE'
|
|
20
|
+
|
|
21
|
+
ALL = [STRONG, WEAK, NONE].freeze
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# matchedBy of a refund-to-wallet eligibility answer.
|
|
25
|
+
module RefundToWalletMatchedBy
|
|
26
|
+
CUSTOMER_ID = 'CUSTOMER_ID'
|
|
27
|
+
PHONE = 'PHONE'
|
|
28
|
+
NONE = 'NONE'
|
|
29
|
+
|
|
30
|
+
ALL = [CUSTOMER_ID, PHONE, NONE].freeze
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# reason of a refund-to-wallet eligibility answer.
|
|
34
|
+
module RefundToWalletEligibilityReason
|
|
35
|
+
MATCHED = 'MATCHED'
|
|
36
|
+
# No customerId and no phone on the order.
|
|
37
|
+
NO_CANDIDATE = 'NO_CANDIDATE'
|
|
38
|
+
NOT_FOUND = 'NOT_FOUND'
|
|
39
|
+
# The wallet could not be asked; the refund would go to the card.
|
|
40
|
+
LOOKUP_UNAVAILABLE = 'LOOKUP_UNAVAILABLE'
|
|
41
|
+
# Marketplace / split payments are refunded to the card.
|
|
42
|
+
MARKETPLACE_EXCLUDED = 'MARKETPLACE_EXCLUDED'
|
|
43
|
+
# Only a LIVE payment can be refunded to a wallet.
|
|
44
|
+
WALLET_REQUIRES_LIVE_PAYMENT = 'WALLET_REQUIRES_LIVE_PAYMENT'
|
|
45
|
+
|
|
46
|
+
ALL = [MATCHED, NO_CANDIDATE, NOT_FOUND, LOOKUP_UNAVAILABLE, MARKETPLACE_EXCLUDED, WALLET_REQUIRES_LIVE_PAYMENT].freeze
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Request rules of POST /payments/{id}/refund-to-wallet and …/refund-to-wallet/eligibility. Source of truth:
|
|
50
|
+
# nest-payment-gateway refund-to-wallet.controller.ts and dtos/refund-to-wallet.dto.ts.
|
|
51
|
+
module RefundToWalletRules
|
|
52
|
+
SNAKE_CASE = { 'program_id' => 'programId', 'customer_id' => 'customerId' }.freeze
|
|
53
|
+
|
|
54
|
+
module_function
|
|
55
|
+
|
|
56
|
+
# Only the allowed members (String or Symbol keys, camelCase or snake_case); amount a positive canonical
|
|
57
|
+
# minor-unit string, the others non-empty strings; nil members are dropped.
|
|
58
|
+
def body!(request, allowed, operation)
|
|
59
|
+
raise ConfigurationError, "#{operation} request must be a Hash" unless request.nil? || request.is_a?(Hash)
|
|
60
|
+
|
|
61
|
+
merged = merge!(request || {}, operation)
|
|
62
|
+
unknown = merged.keys - allowed
|
|
63
|
+
unless unknown.empty?
|
|
64
|
+
raise ConfigurationError, "#{operation} does not accept #{unknown.join(', ')} (only #{allowed.join(', ')}; the gateway rejects unknown fields)"
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
allowed.each_with_object({}) do |field, body|
|
|
68
|
+
value = merged[field]
|
|
69
|
+
body[field] = value!(field, value, operation) unless value.nil?
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def merge!(request, operation)
|
|
74
|
+
request.each_with_object({}) do |(key, value), merged|
|
|
75
|
+
wire = SNAKE_CASE.fetch(key.to_s, key.to_s)
|
|
76
|
+
raise ConfigurationError, "#{operation}: #{wire} is given twice" if merged.key?(wire)
|
|
77
|
+
|
|
78
|
+
merged[wire] = value
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def value!(field, value, operation)
|
|
83
|
+
if field == 'amount'
|
|
84
|
+
unless value.is_a?(String) && value.match?(/\A[1-9][0-9]*\z/) && value.to_i <= Money::MAX
|
|
85
|
+
raise ConfigurationError, "#{operation}.amount must be a positive canonical minor-unit string"
|
|
86
|
+
end
|
|
87
|
+
elsif !value.is_a?(String) || value.strip.empty?
|
|
88
|
+
raise ConfigurationError, "#{operation}.#{field} must be a non-empty string"
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
value
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
data/lib/lunixi/route_table.rb
CHANGED
|
@@ -47,13 +47,14 @@ module Lunixi
|
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
# The raw answer of one route. params: path segments by wire name; query: filters; body: the request
|
|
50
|
-
# Hash (wire names, snake_case works too).
|
|
51
|
-
|
|
50
|
+
# Hash (wire names, snake_case works too). A nil body field is left out, except the wire names in
|
|
51
|
+
# null_fields: those are sent as an explicit JSON null (a required one is then present).
|
|
52
|
+
def call(name, params: {}, query: nil, body: nil, idempotency_key: nil, null_fields: [])
|
|
52
53
|
route = @routes.fetch(name) { raise ArgumentError, "Unknown route #{name}." }
|
|
53
54
|
path = RouteRequest.path!(route['path'], params)
|
|
54
55
|
key = key!(name, route['idempotencyKey'] || 'none', idempotency_key)
|
|
55
56
|
filters = query.nil? ? {} : filters!(name, route, query)
|
|
56
|
-
payload = body!(name, route, body)
|
|
57
|
+
payload = body!(name, route, body, null_fields)
|
|
57
58
|
money = path.match?(MONEY_ROUTE)
|
|
58
59
|
if money
|
|
59
60
|
WireMoney.validate_wire(payload)
|
|
@@ -112,9 +113,13 @@ module Lunixi
|
|
|
112
113
|
end
|
|
113
114
|
end
|
|
114
115
|
|
|
115
|
-
def body!(name, route, body)
|
|
116
|
+
def body!(name, route, body, null_fields = []) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity -- mirrors the catalog body rules
|
|
116
117
|
if route.key?('required') || route.key?('optional')
|
|
117
|
-
|
|
118
|
+
explicit_null = null_fields.select { |field| body.is_a?(Hash) && body.key?(field) && body[field].nil? }
|
|
119
|
+
# An explicit null is validated by the caller and re-added below; keep it out of the field check.
|
|
120
|
+
checked = explicit_null.empty? ? (body || {}) : body.except(*explicit_null)
|
|
121
|
+
plain = RouteRequest.fields!(checked, (route['required'] || []) - explicit_null, route['optional'] || [], name)
|
|
122
|
+
explicit_null.each { |field| plain[field] = nil }
|
|
118
123
|
elsif route['free']
|
|
119
124
|
plain = RouteRequest.wire_hash!(body.nil? && route['optionalBody'] ? {} : body, "#{name} body")
|
|
120
125
|
else
|