lunixi-sdk 1.2.2 → 2.0.2

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.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +62 -0
  3. data/README.md +278 -10
  4. data/README.tr.md +282 -8
  5. data/docs/ruby.en.md +11 -1
  6. data/docs/ruby.tr.md +11 -1
  7. data/lib/lunixi/bank_connect.rb +340 -0
  8. data/lib/lunixi/bank_connect_filters.rb +114 -0
  9. data/lib/lunixi/bank_connect_values.rb +205 -0
  10. data/lib/lunixi/bank_transfer.rb +106 -0
  11. data/lib/lunixi/card_requests.rb +171 -0
  12. data/lib/lunixi/client.rb +57 -16
  13. data/lib/lunixi/direct_method_payment_request.rb +245 -0
  14. data/lib/lunixi/enabled_installments.rb +28 -0
  15. data/lib/lunixi/errors.rb +69 -3
  16. data/lib/lunixi/fraud.rb +81 -5
  17. data/lib/lunixi/identity.rb +94 -0
  18. data/lib/lunixi/identity_values.rb +28 -0
  19. data/lib/lunixi/insurance.rb +294 -0
  20. data/lib/lunixi/insurance_request.rb +134 -0
  21. data/lib/lunixi/insurance_values.rb +200 -0
  22. data/lib/lunixi/kyc.rb +189 -0
  23. data/lib/lunixi/kyc_values.rb +158 -0
  24. data/lib/lunixi/marketplace.rb +268 -0
  25. data/lib/lunixi/marketplace_values.rb +86 -0
  26. data/lib/lunixi/method_fields.rb +142 -0
  27. data/lib/lunixi/money.rb +7 -4
  28. data/lib/lunixi/order_details.rb +115 -0
  29. data/lib/lunixi/payment_link_filters.rb +32 -0
  30. data/lib/lunixi/payment_link_image_rules.rb +85 -0
  31. data/lib/lunixi/payment_link_rules.rb +132 -0
  32. data/lib/lunixi/payment_link_values.rb +136 -0
  33. data/lib/lunixi/payment_links.rb +152 -0
  34. data/lib/lunixi/payment_values.rb +86 -0
  35. data/lib/lunixi/payments.rb +170 -8
  36. data/lib/lunixi/physical_pos.rb +183 -0
  37. data/lib/lunixi/physical_pos_card_data.rb +117 -0
  38. data/lib/lunixi/physical_pos_card_number.rb +65 -0
  39. data/lib/lunixi/physical_pos_device_identity.rb +44 -0
  40. data/lib/lunixi/physical_pos_filters.rb +58 -0
  41. data/lib/lunixi/physical_pos_gateway.rb +153 -0
  42. data/lib/lunixi/physical_pos_identifiers.rb +62 -0
  43. data/lib/lunixi/physical_pos_management.rb +326 -0
  44. data/lib/lunixi/physical_pos_money.rb +46 -0
  45. data/lib/lunixi/physical_pos_request.rb +126 -0
  46. data/lib/lunixi/physical_pos_responses.rb +102 -0
  47. data/lib/lunixi/physical_pos_results.rb +52 -0
  48. data/lib/lunixi/physical_pos_settlement_policies.rb +71 -0
  49. data/lib/lunixi/physical_pos_value.rb +43 -0
  50. data/lib/lunixi/physical_pos_values.rb +203 -0
  51. data/lib/lunixi/physical_pos_webhook.rb +147 -0
  52. data/lib/lunixi/product_webhooks.rb +106 -0
  53. data/lib/lunixi/promissory_note.rb +155 -0
  54. data/lib/lunixi/reference.rb +41 -0
  55. data/lib/lunixi/route_request.rb +121 -0
  56. data/lib/lunixi/route_response.rb +101 -0
  57. data/lib/lunixi/route_table.rb +128 -0
  58. data/lib/lunixi/route_value.rb +60 -0
  59. data/lib/lunixi/sanction.rb +244 -0
  60. data/lib/lunixi/sanction_values.rb +132 -0
  61. data/lib/lunixi/split_payment.rb +150 -0
  62. data/lib/lunixi/subscription_resources.rb +357 -0
  63. data/lib/lunixi/subscription_values.rb +233 -0
  64. data/lib/lunixi/subscriptions.rb +202 -0
  65. data/lib/lunixi/version.rb +1 -1
  66. data/lib/lunixi/wallet.rb +153 -0
  67. data/lib/lunixi/wallet_resources.rb +407 -0
  68. data/lib/lunixi/wallet_routes.rb +126 -0
  69. data/lib/lunixi/wallet_values.rb +71 -0
  70. data/lib/lunixi/wire_money.rb +67 -0
  71. data/lib/lunixi.rb +58 -0
  72. metadata +59 -1
@@ -0,0 +1,152 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lunixi
4
+ # Payment links (/api/v1/payments/links). Every gateway call here is signed, reads included: the
5
+ # merchant and the environment come from the signing key, so a TEST key sees and changes only TEST
6
+ # links. The key needs the matching scope (payment-link:create, :view, :manage, :send).
7
+ #
8
+ # Responses are the gateway envelope. Lists carry data.items and the top-level pageInfo
9
+ # (hasMore, nextCursor, totalCount); pass pageInfo.nextCursor as cursor for the next page.
10
+ #
11
+ # The one request that is not sent to the gateway is the image PUT of upload_image: it goes to the
12
+ # storage host behind a presigned URL with only the uploadHeaders, never with the access token or the
13
+ # request signature.
14
+ class PaymentLinks
15
+ BASE = '/api/v1/payments/links'
16
+ IMAGES = "#{BASE}/images".freeze
17
+ QR_ACCEPT = 'image/svg+xml, image/png, application/json'
18
+ attr_reader :client
19
+
20
+ def initialize(client, storage_transport:)
21
+ @client = client
22
+ @storage_transport = storage_transport
23
+ end
24
+
25
+ # Create a link. The idempotency key is required: the same key with the same body returns the stored
26
+ # link with replayed: true; the same key with another body is 409 payment_link.idempotency.conflict.
27
+ # Only PAYMENT_LINK_SPEC_FIELDS and environment are accepted; amounts are minor-unit strings.
28
+ def create(body, idempotency_key: nil)
29
+ client.request('POST', BASE, body: PaymentLinkRules.create_body!(body), idempotency_key: Client.idempotency_key!(idempotency_key))
30
+ end
31
+
32
+ # One page of links, newest first. state, usage and amountMode take an Array; createdFrom /
33
+ # createdTo (a Time or ISO 8601 string) bound a half-open window; query matches a short code or a
34
+ # title/reference prefix.
35
+ def list(**filters)
36
+ client.request('GET', BASE, query: PaymentLinkFilters.list_query!(filters, PaymentLinkFilters::LINK_LIST_FILTERS, 'payment_links.list'))
37
+ end
38
+
39
+ def get(link_id)
40
+ client.request('GET', link_path(link_id))
41
+ end
42
+
43
+ # Change a link (a new version of it). expected_row_version is the link's current rowVersion; a
44
+ # concurrent change is 409 payment_link.link.version_conflict. Only the given keys change, nil clears
45
+ # a field and a nested object is replaced whole. usage, amountMode and currency are fixed.
46
+ def update(link_id, expected_row_version, changes, idempotency_key: nil)
47
+ body = { 'expectedRowVersion' => PaymentLinkRules.row_version!(expected_row_version) }.merge(PaymentLinkRules.update_body!(changes))
48
+ client.request('PATCH', link_path(link_id), body: body, idempotency_key: optional_key(idempotency_key))
49
+ end
50
+
51
+ # Stop accepting payments until resume.
52
+ def pause(link_id, expected_row_version: nil, reason: nil, idempotency_key: nil)
53
+ action(link_id, 'pause', expected_row_version: expected_row_version, reason: reason, idempotency_key: idempotency_key)
54
+ end
55
+
56
+ def resume(link_id, expected_row_version: nil, reason: nil, idempotency_key: nil)
57
+ action(link_id, 'resume', expected_row_version: expected_row_version, reason: reason, idempotency_key: idempotency_key)
58
+ end
59
+
60
+ # Close the link permanently; it cannot be reopened.
61
+ def deactivate(link_id, expected_row_version: nil, reason: nil, idempotency_key: nil)
62
+ action(link_id, 'deactivate', expected_row_version: expected_row_version, reason: reason, idempotency_key: idempotency_key)
63
+ end
64
+
65
+ # pause, resume or deactivate. Without expected_row_version there is no version check.
66
+ def action(link_id, action, expected_row_version: nil, reason: nil, idempotency_key: nil)
67
+ body = PaymentLinkRules.action_body!(action, expected_row_version, reason)
68
+ client.request('POST', "#{link_path(link_id)}/#{action}", body: body, idempotency_key: optional_key(idempotency_key))
69
+ end
70
+
71
+ # Send the link by e-mail or SMS (PaymentLinkDeliveryChannel); without a recipient the link's
72
+ # recipient is used. The idempotency key is required so a retry cannot send twice. An accepted
73
+ # delivery can still fail: read data.delivery.state and failureReason.
74
+ def send_link(link_id, channel: nil, recipient_email: nil, recipient_phone: nil, locale: nil, idempotency_key: nil)
75
+ body = PaymentLinkRules.send_body!(channel, recipient_email, recipient_phone, locale)
76
+ client.request('POST', "#{link_path(link_id)}/send", body: body, idempotency_key: Client.idempotency_key!(idempotency_key))
77
+ end
78
+
79
+ # The link's QR code as frozen image bytes (SVG or PNG, PaymentLinkQrFormat); size is 128–2048 px.
80
+ def qr(link_id, format: PaymentLinkQrFormat::SVG, size: nil)
81
+ client.request('GET', "#{link_path(link_id)}/qr", query: PaymentLinkRules.qr_query!(format, size), binary: true, accept: QR_ACCEPT)
82
+ end
83
+
84
+ # Payment attempts on the link, newest first; state takes an Array.
85
+ def list_attempts(link_id, **filters)
86
+ query = PaymentLinkFilters.list_query!(filters, PaymentLinkFilters::ATTEMPT_LIST_FILTERS, 'payment_links.list_attempts')
87
+ client.request('GET', "#{link_path(link_id)}/attempts", query: query)
88
+ end
89
+
90
+ # Successful payments on the link, with refund totals.
91
+ def list_payments(link_id, **filters)
92
+ query = PaymentLinkFilters.list_query!(filters, PaymentLinkFilters::PAYMENT_LIST_FILTERS, 'payment_links.list_payments')
93
+ client.request('GET', "#{link_path(link_id)}/payments", query: query)
94
+ end
95
+
96
+ # Link image, step 1 of 3: an upload target for a PNG, JPEG or WebP image. data is { assetId,
97
+ # uploadUrl, uploadMethod: 'PUT', uploadHeaders, expiresAt }. Step 2 is a PUT of the bytes to
98
+ # uploadUrl with exactly uploadHeaders before expiresAt; step 3 is confirm_image_upload(assetId).
99
+ # A declared size over the image limit (2 MiB) is refused by the gateway before anything is uploaded.
100
+ def create_image_upload(file_name: nil, content_type: nil, size_bytes: nil)
101
+ body = PaymentLinkImageRules.image_body!(file_name, content_type, size_bytes)
102
+ envelope = client.request('POST', IMAGES, body: body)
103
+ PaymentLinkImageRules.upload_target!(envelope)
104
+ envelope
105
+ end
106
+
107
+ # Link image, step 3 of 3: publish the uploaded image. data is { assetId, url, state: 'PUBLISHED' };
108
+ # use assetId as the imageAssetId of a link or an item. Confirming before the PUT has landed is
109
+ # 400 media.confirm.object_missing and can be retried.
110
+ def confirm_image_upload(asset_id)
111
+ envelope = client.request('POST', "#{IMAGES}/#{PaymentLinkImageRules.asset_id!(asset_id)}/confirm", body: {})
112
+ PaymentLinkImageRules.published_image!(envelope)
113
+ envelope
114
+ end
115
+
116
+ # Upload a link image in one call: create_image_upload, the PUT of content to the storage host and
117
+ # confirm_image_upload. A failed PUT is not retried; it raises ApiError with the storage status (and
118
+ # its error code, e.g. AccessDenied once the URL has expired). Call upload_image again for a new URL.
119
+ def upload_image(file_name: nil, content_type: nil, content: nil)
120
+ bytes = PaymentLinkImageRules.image_content!(content)
121
+ target = PaymentLinkImageRules.upload_target!(create_image_upload(file_name: file_name, content_type: content_type, size_bytes: bytes.bytesize))
122
+ put_to_storage(target, bytes)
123
+ confirm_image_upload(target['assetId'])
124
+ end
125
+
126
+ def inspect
127
+ '#<Lunixi::PaymentLinks>'
128
+ end
129
+
130
+ private
131
+
132
+ # The PUT deliberately does not use Client#request: that adds the bearer token and the signature
133
+ # headers, which must never reach the storage host. Only the headers the URL was signed for are sent.
134
+ def put_to_storage(target, bytes)
135
+ response = @storage_transport.call(method: 'PUT', uri: URI.parse(target['uploadUrl']), headers: target['uploadHeaders'].dup.freeze, body: bytes)
136
+ raise TransportError, 'Image upload to storage returned an invalid response' unless response.is_a?(Response) && response.status.is_a?(Integer)
137
+ return if response.status.between?(200, 299)
138
+
139
+ raise ApiError.new(status: response.status, code: PaymentLinkImageRules.storage_error_code(response.body))
140
+ rescue TransportError
141
+ raise TransportError, 'Image upload to storage failed; call upload_image again for a new upload URL', cause: nil
142
+ end
143
+
144
+ def link_path(link_id)
145
+ "#{BASE}/#{PaymentLinkRules.link_id!(link_id)}"
146
+ end
147
+
148
+ def optional_key(key)
149
+ key.nil? ? nil : Client.idempotency_key!(key)
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lunixi
4
+ # Public payment method codes (paymentMethod). QR is accepted as an alias of QR_CODE.
5
+ module PaymentMethod
6
+ CARD = 'CARD'
7
+ BNPL = 'BNPL'
8
+ SHOPPING_LOAN = 'SHOPPING_LOAN'
9
+ PROMISSORY_NOTE = 'PROMISSORY_NOTE'
10
+ MEAL_CARD = 'MEAL_CARD'
11
+ GIFT_CARD = 'GIFT_CARD'
12
+ CASH = 'CASH'
13
+ CASH_ON_DELIVERY = 'CASH_ON_DELIVERY'
14
+ WALLET = 'WALLET'
15
+ BANK_TRANSFER = 'BANK_TRANSFER'
16
+ OPEN_BANKING = 'OPEN_BANKING'
17
+ # Charge to the buyer's mobile phone bill.
18
+ MOBILE_BILLING = 'MOBILE_BILLING'
19
+ QR_CODE = 'QR_CODE'
20
+ CRYPTO = 'CRYPTO'
21
+ OTHER = 'OTHER'
22
+
23
+ ALL = [CARD, BNPL, SHOPPING_LOAN, PROMISSORY_NOTE, MEAL_CARD, GIFT_CARD, CASH, CASH_ON_DELIVERY, WALLET,
24
+ BANK_TRANSFER, OPEN_BANKING, MOBILE_BILLING, QR_CODE, CRYPTO, OTHER].freeze
25
+ ALIASES = { 'QR' => QR_CODE }.freeze
26
+ end
27
+
28
+ # What the buyer must do when a payment response carries data.action (action.type).
29
+ module PaymentActionType
30
+ # Send the one-time code with payments.confirm_payment_action.
31
+ OTP = 'OTP'
32
+ # Send the buyer to action.redirect.url (for cards: the bank's 3D Secure page).
33
+ REDIRECT = 'REDIRECT'
34
+ # Show the buyer something to act on outside the page (transfer details, a code).
35
+ DISPLAY = 'DISPLAY'
36
+ # The buyer approves in the provider's app; the result arrives by webhook.
37
+ APP_APPROVAL = 'APP_APPROVAL'
38
+ # Send the fields listed in action.input.fields with payments.confirm_payment_action.
39
+ INPUT = 'INPUT'
40
+
41
+ ALL = [OTP, REDIRECT, DISPLAY, APP_APPROVAL, INPUT].freeze
42
+ end
43
+
44
+ # providerSelection of a method in payments.list_payment_methods.
45
+ module ProviderSelection
46
+ # Card: routing picks the provider; providerCode is not sent.
47
+ ROUTED = 'ROUTED'
48
+ # providerCode may be omitted: one provider is connected, or the platform picks it.
49
+ OPTIONAL = 'OPTIONAL'
50
+ # The buyer picks the brand and more than one provider is connected; providerCode must be sent.
51
+ REQUIRED = 'REQUIRED'
52
+
53
+ ALL = [ROUTED, OPTIONAL, REQUIRED].freeze
54
+ end
55
+
56
+ # providerSelectionMode of a method in payments.list_payment_methods: who picks the provider.
57
+ module ProviderSelectionMode
58
+ # The buyer picks the brand; with more than one provider connected providerCode is required.
59
+ BUYER = 'BUYER'
60
+ # The buyer does not pick a brand; without providerCode the platform picks a connected provider.
61
+ PLATFORM = 'PLATFORM'
62
+
63
+ ALL = [BUYER, PLATFORM].freeze
64
+ end
65
+
66
+ # Method blocks POST /payments/direct/payment accepts besides card. The block of the chosen
67
+ # method is required; a block for another method is rejected. A method without a block here
68
+ # cannot be paid through direct/payment yet.
69
+ METHOD_BLOCK_FIELDS = %w[mobileBilling wallet promissoryNote mealCard openBanking shoppingLoan bankTransfer].freeze
70
+
71
+ # Body fields of POST /payments/direct/payment.
72
+ DIRECT_METHOD_PAYMENT_FIELDS = (%w[
73
+ paymentMethod amount currency orderId paymentChannel paymentGroup callbackUrl locale description customerId
74
+ preauth buyer shippingAddress billingAddress basketItems card installment installmentQuoteToken force3D metadata
75
+ ] + METHOD_BLOCK_FIELDS).freeze
76
+
77
+ # Fields that belong to a card payment only (paymentMethod CARD).
78
+ CARD_ONLY_FIELDS = %w[card installment installmentQuoteToken force3D].freeze
79
+
80
+ # Body fields of POST /payments/{paymentId}/actions/{actionId}/confirm a merchant server sends.
81
+ # The hosted form's checkout token fields are never sent by this SDK.
82
+ PAYMENT_ACTION_CONFIRM_FIELDS = %w[otp consentAccepted fields].freeze
83
+
84
+ # Most basket items a SHOPPING_LOAN payment can carry; the basket is required for that method.
85
+ SHOPPING_LOAN_MAX_BASKET_ITEMS = 100
86
+ end
@@ -5,6 +5,8 @@ module Lunixi
5
5
  # documented endpoints without pretending to validate their entire DTO schema.
6
6
  class Payments
7
7
  BASE = '/api/v1/payments'
8
+ BIN_BASE = '/api/v1/bin'
9
+ PDF_ACCEPT = 'application/pdf, application/json'
8
10
  OMITTED_AMOUNT = Object.new.freeze
9
11
  private_constant :OMITTED_AMOUNT
10
12
  attr_reader :client
@@ -18,20 +20,89 @@ module Lunixi
18
20
  # Optional +enabledInstallments+ (an Array of Integer) lists the installment counts the hosted
19
21
  # form may offer for this payment, e.g. <tt>[1, 2, 3]</tt>; <tt>[1]</tt> allows a single payment
20
22
  # only. The form shows only the counts also allowed by the panel settings, the card and the
21
- # platform maximum. Leave it out for no restriction. Send distinct integers 1–36 that include 1,
22
- # in ascending order; the gateway rejects any other list, an empty one included, with 400.
23
+ # platform maximum. Leave it out for no restriction. The list must hold distinct integers 1–36
24
+ # that include 1; any other list, an empty one included, raises ConfigurationError before sending,
25
+ # and the list is sent in ascending order.
23
26
  #
24
- # @param body [Hash] gateway body: +amount+ (canonical minor-unit string), +currency+, +orderId+
25
- # and optional fields such as +callbackUrl+ and +enabledInstallments+
27
+ # The order details are required (OrderDetails): +buyer+ (+ip+ may be left out here: the Lunixi
28
+ # form takes it from the buyer's browser), +billingAddress+ and +basketItems+ (at least one; the
29
+ # prices add up to +amount+); +shippingAddress+ when an item is PHYSICAL. A missing field raises
30
+ # ConfigurationError naming its path before sending.
31
+ #
32
+ # @param body [Hash] gateway body: +amount+ (canonical minor-unit string), +currency+, +orderId+,
33
+ # the order details and optional fields such as +callbackUrl+ and +enabledInstallments+
26
34
  # @param idempotency_key [String] the persisted key of this checkout attempt
27
35
  # @return [Hash] Unmodified gateway response envelope; creation is not settlement.
28
36
  def create_intent(body, idempotency_key:)
29
37
  body = payment_body!(body)
30
38
  raise ConfigurationError, 'Intent installments are selected in the checkout form' if body.key?('installment')
31
39
 
40
+ OrderDetails.check!(body, 'A payment intent', checkout_intent: true)
32
41
  client.request('POST', "#{BASE}/intents", body: body, idempotency_key: Client.idempotency_key!(idempotency_key))
33
42
  end
34
43
 
44
+ # Create a marketplace intent (POST /payments/marketplace/intents, signed): the intent body plus
45
+ # sellers [{ subDealerId, amountMinor, scenario }] and multiSellerPolicy. Each amountMinor is a
46
+ # canonical minor-unit string and the sellers must add up to amount; any other total raises
47
+ # ConfigurationError before sending. The order details follow the rule of create_intent.
48
+ def create_marketplace_intent(body, idempotency_key:)
49
+ data = payment_body!(body)
50
+ sellers!(data['sellers'], data['amount'])
51
+ OrderDetails.check!(data, 'A marketplace payment intent', checkout_intent: true)
52
+ client.request('POST', "#{BASE}/marketplace/intents", body: data, idempotency_key: Client.idempotency_key!(idempotency_key))
53
+ end
54
+
55
+ # Card and bank details of a BIN (6 or 8 digits) or a card number prefix (POST /bin/info). The
56
+ # value is never written to an error message.
57
+ def bin_info(bin_or_pan)
58
+ client.request('POST', "#{BIN_BASE}/info", body: { 'binOrPan' => CardRules.bin_or_pan!(bin_or_pan) }, signed: false)
59
+ end
60
+
61
+ # The installment table (POST /bin/installments) for an InstallmentOptionsRequest or a raw Hash; with
62
+ # a BIN and installment > 1 the answer carries the binding quoteToken. enabledInstallments follows
63
+ # the rule of create_intent and is sent in ascending order.
64
+ def installment_options(body_or_request)
65
+ client.request('POST', "#{BIN_BASE}/installments", body: CardRules.installment_options_body!(body_or_request), signed: false)
66
+ end
67
+
68
+ # Brand, family and bank reference lists (GET /bin/card-taxonomy).
69
+ def card_taxonomy
70
+ client.request('GET', "#{BIN_BASE}/card-taxonomy", signed: false)
71
+ end
72
+
73
+ # Verify and store a card for a cardUserKey (POST /payments/cards, signed). Build the body with
74
+ # StoreCardRequest or pass a raw Hash; the idempotency key is required. The buyer (the card holder)
75
+ # and the billing address are required (OrderDetails, no basket).
76
+ def store_card(body_or_request, idempotency_key: nil)
77
+ body = CardRules.store_card_body!(body_or_request)
78
+ client.request('POST', "#{BASE}/cards", body: body, idempotency_key: Client.idempotency_key!(idempotency_key))
79
+ end
80
+
81
+ # Stored cards of a cardUserKey (GET /payments/cards?cardUserKey=); masked card data only.
82
+ def list_stored_cards(card_user_key)
83
+ client.request('GET', "#{BASE}/cards", query: { cardUserKey: CardRules.text!(card_user_key, 'cardUserKey') }, signed: false)
84
+ end
85
+
86
+ def get_stored_card(stored_card_token)
87
+ client.request('GET', "#{BASE}/cards/#{identifier!(stored_card_token)}", signed: false)
88
+ end
89
+
90
+ # Deactivate a stored card (DELETE /payments/cards/{token}, signed); the idempotency key is required.
91
+ def deactivate_stored_card(stored_card_token, idempotency_key: nil)
92
+ client.request('DELETE', "#{BASE}/cards/#{identifier!(stored_card_token)}", idempotency_key: Client.idempotency_key!(idempotency_key))
93
+ end
94
+
95
+ # Payments rescued by provider failover retries (GET /payments/analytics/failover-recovery).
96
+ # Filters such as from, to or range are sent as the query.
97
+ def failover_recovery_analytics(**filters)
98
+ client.request('GET', "#{BASE}/analytics/failover-recovery", query: filters, signed: false)
99
+ end
100
+
101
+ # Performance of one provider credential (GET /payments/analytics/provider-credentials/{id}).
102
+ def provider_credential_analytics(credential_id, **filters)
103
+ client.request('GET', "#{BASE}/analytics/provider-credentials/#{identifier!(credential_id)}", query: filters, signed: false)
104
+ end
105
+
35
106
  # @return [Hash] Authenticated payment status envelope for reconciliation.
36
107
  def get(payment_id)
37
108
  client.request('GET', "#{BASE}/#{identifier!(payment_id)}", signed: false)
@@ -42,11 +113,71 @@ module Lunixi
42
113
  client.request('GET', BASE, query: filters, signed: false)
43
114
  end
44
115
 
45
- # Return merchant-enabled methods; the shared Lunixi form owns the final available list.
116
+ # Return merchant-enabled methods; the shared Lunixi form owns the final available list. Each method
117
+ # lists its blockName, providerSelection, providerSelectionMode and providers with the inputFields
118
+ # of the method block. payment_method narrows the list to one method code (QR is sent as QR_CODE).
46
119
  def methods(payment_method: nil)
47
- query = payment_method ? { paymentMethod: payment_method } : {}
120
+ query = payment_method.nil? ? {} : { paymentMethod: MethodFields.normalize_payment_method(payment_method) }
48
121
  client.request('GET', "#{BASE}/methods", query: query)
49
122
  end
123
+ alias list_payment_methods methods
124
+
125
+ # Start a payment with any method from the merchant server (POST /payments/direct/payment). Build
126
+ # the body with DirectMethodPaymentRequest or pass a raw Hash; both are checked before sending,
127
+ # the order details (OrderDetails) included.
128
+ # When the buyer must act, data.action says how (PaymentActionType); a BANK_TRANSFER payment
129
+ # answers with a DISPLAY action read by BankTransferInstruction.from_response.
130
+ def direct_method_payment(body_or_request, idempotency_key: nil)
131
+ body = body_or_request.is_a?(DirectMethodPaymentRequest) ? body_or_request.to_h : DirectMethodPaymentRequest.payload!(body_or_request)
132
+ OrderDetails.check!(body, 'A direct method payment')
133
+ client.request('POST', "#{BASE}/direct/payment", body: body, idempotency_key: Client.idempotency_key!(idempotency_key))
134
+ end
135
+
136
+ # Complete the open action of a payment with { otp:, consentAccepted:, fields: } (at least one).
137
+ def confirm_payment_action(payment_id, action_id, input)
138
+ client.request('POST', action_path(payment_id, action_id, 'confirm'), body: MethodFields.confirm_body!(input))
139
+ end
140
+
141
+ # Send a new one-time code; the previous action is closed, confirm with the new data.action.id.
142
+ def resend_payment_action(payment_id, action_id)
143
+ client.request('POST', action_path(payment_id, action_id, 'resend'))
144
+ end
145
+
146
+ # The notes of a promissory-note payment with their status (PromissoryNoteStatus).
147
+ def get_promissory_notes(payment_id)
148
+ client.request('GET', promissory_notes_path(payment_id))
149
+ end
150
+
151
+ # Cancel notes; without serial_numbers every open note is cancelled. cancelResults[] gives the
152
+ # result per note (PromissoryNoteCancelResult, PromissoryNoteCancelErrorCode).
153
+ def cancel_promissory_notes(payment_id, serial_numbers: nil, idempotency_key: nil)
154
+ body = serial_numbers.nil? ? nil : { 'serialNumbers' => PromissoryNotePlan.serial_numbers!(serial_numbers) }
155
+ key = idempotency_key.nil? ? nil : Client.idempotency_key!(idempotency_key)
156
+ client.request('POST', "#{promissory_notes_path(payment_id)}/cancel", body: body, idempotency_key: key)
157
+ end
158
+
159
+ # The printable notes as PDF bytes (a frozen binary String), one note per page. Not stored by the
160
+ # gateway: download it when you need it. locale is one of PromissoryNoteDocumentLocale::ALL.
161
+ def download_promissory_note_document(payment_id, locale: nil)
162
+ query = locale.nil? ? {} : { locale: PromissoryNotePlan.document_locale!(locale) }
163
+ client.request('GET', "#{promissory_notes_path(payment_id)}/document", query: query, binary: true, accept: PDF_ACCEPT)
164
+ end
165
+
166
+ # Late, short and excess transfers of BANK_TRANSFER payments; data.items[] of the envelope.
167
+ def list_bank_transfer_exceptions(environment: nil, status: nil, limit: nil)
168
+ query = BankTransferExceptions.query!(environment: environment, status: status, limit: limit)
169
+ client.request('GET', "#{BASE}/bank-transfer/exceptions", query: query)
170
+ end
171
+
172
+ # Accept a LATE or UNDERPAID exception; data is the exception or nil.
173
+ def accept_bank_transfer_exception(exception_id)
174
+ client.request('POST', "#{BASE}/bank-transfer/exceptions/#{BankTransferExceptions.exception_id!(exception_id)}/accept")
175
+ end
176
+
177
+ # Report that you refunded the money of an exception to the sender from your own bank.
178
+ def mark_bank_transfer_exception_refunded(exception_id)
179
+ client.request('POST', "#{BASE}/bank-transfer/exceptions/#{BankTransferExceptions.exception_id!(exception_id)}/refunded")
180
+ end
50
181
 
51
182
  # Omit amount to capture the remaining authorization; explicit nil is invalid.
52
183
  def capture(payment_id, idempotency_key:, amount: OMITTED_AMOUNT)
@@ -68,7 +199,9 @@ module Lunixi
68
199
  client.request('POST', "#{BASE}/#{identifier!(payment_id)}/void", idempotency_key: Client.idempotency_key!(idempotency_key))
69
200
  end
70
201
 
71
- # Start a 1–5 leg split payment; running statuses are returned, never marked paid.
202
+ # Start a 1–5 leg split payment; running statuses are returned, never marked paid. The body
203
+ # (SPLIT_PAYMENT_FIELDS) carries the order details: buyer, billingAddress, basketItems and
204
+ # shippingAddress for a PHYSICAL item; a missing field raises ConfigurationError before sending.
72
205
  def split(body, idempotency_key:)
73
206
  data = normalize!(body)
74
207
  minor!(data['totalAmount'])
@@ -77,13 +210,15 @@ module Lunixi
77
210
  legs = data['legs']
78
211
  raise ConfigurationError, 'Split payment requires 1–5 legs' unless legs.is_a?(Array) && legs.size.between?(1, 5)
79
212
 
80
- total = legs.sum do |leg|
213
+ total = legs.each_with_index.sum do |leg, index|
81
214
  raise ConfigurationError, 'Split legs must be objects' unless leg.is_a?(Hash)
82
215
 
216
+ SplitPaymentRules.leg!(leg, "legs[#{index}]")
83
217
  minor!(leg['amount']).to_i
84
218
  end
85
219
  raise ConfigurationError, 'Split leg amounts must equal totalAmount' unless total == data['totalAmount'].to_i
86
220
 
221
+ OrderDetails.check!(data, 'A split payment')
87
222
  client.request('POST', "#{BASE}/split", body: data, idempotency_key: Client.idempotency_key!(idempotency_key))
88
223
  end
89
224
 
@@ -92,6 +227,12 @@ module Lunixi
92
227
  client.request('GET', "#{BASE}/split/#{identifier!(split_id)}", signed: false)
93
228
  end
94
229
 
230
+ # Split payments, newest first. Filters: LIST_SPLIT_PAYMENTS_FILTERS; status and currency take a
231
+ # value or a list, limit is 1–100 and after is the pageInfo.endCursor of the previous page.
232
+ def list_splits(**filters)
233
+ client.request('GET', "#{BASE}/split", query: SplitPaymentRules.list_query!(filters), signed: false)
234
+ end
235
+
95
236
  # Refund a split session using the documented partial/full amount in minor units.
96
237
  def refund_split(split_id, amount:, idempotency_key:, reason: nil)
97
238
  body = { 'amount' => minor!(amount) }
@@ -102,6 +243,14 @@ module Lunixi
102
243
 
103
244
  private
104
245
 
246
+ def action_path(payment_id, action_id, operation)
247
+ "#{BASE}/#{identifier!(payment_id)}/actions/#{identifier!(action_id)}/#{operation}"
248
+ end
249
+
250
+ def promissory_notes_path(payment_id)
251
+ "#{BASE}/#{identifier!(payment_id)}/promissory-notes"
252
+ end
253
+
105
254
  def identifier!(value)
106
255
  raise ConfigurationError, 'Invalid resource identifier' unless value.is_a?(String) && value.match?(/\A[a-zA-Z0-9_-]{1,256}\z/)
107
256
 
@@ -147,9 +296,22 @@ module Lunixi
147
296
  raise ConfigurationError, 'preauth must be a JSON boolean' if data.key?('preauth') && ![true, false].include?(data['preauth'])
148
297
 
149
298
  validate_basket!(data['basketItems'], data['amount']) if data.key?('basketItems')
299
+ data['enabledInstallments'] = EnabledInstallments.check!(data['enabledInstallments']) if data.key?('enabledInstallments')
150
300
  data
151
301
  end
152
302
 
303
+ def sellers!(sellers, amount)
304
+ raise ConfigurationError, 'Marketplace intent requires a nonempty sellers array' unless sellers.is_a?(Array) && !sellers.empty?
305
+
306
+ total = sellers.each_with_index.sum do |seller, index|
307
+ raise ConfigurationError, "sellers[#{index}] must be an object" unless seller.is_a?(Hash)
308
+
309
+ text!(seller['subDealerId'])
310
+ Money.minor(seller['amountMinor'], positive: false).to_i
311
+ end
312
+ raise ConfigurationError, 'sellers[].amountMinor must add up to amount' unless total == amount.to_i
313
+ end
314
+
153
315
  def validate_callback!(url)
154
316
  uri = URI.parse(url)
155
317
  raise ConfigurationError, 'callbackUrl must use HTTPS' unless uri.is_a?(URI::HTTPS) && uri.host && !uri.userinfo && !uri.fragment && url.bytesize <= 2048