lunixi-sdk 1.3.1 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1162b2efebff421ad65d7a57e15f0e224cd65fa70e07cce9fd41f952450f93c6
4
- data.tar.gz: 9a5fa79c17af6872843b6873f50dcd1349532c6564c9154a5d7582a1b09dc3a8
3
+ metadata.gz: 73d1ce64a84a138f96e6544080db54e8fed28926a6f7494de342c526bfe1bd8d
4
+ data.tar.gz: a9317c55a9380c04fc18854cbd9d86dcc228b1f27e1032f34b4eec27e5f0f1fd
5
5
  SHA512:
6
- metadata.gz: caef2d7bd60e3052704d03d13e24d041a4ad9493c72bf62bc75012357e8d271a6502ca7ef3cebf40688a040d4835cdf5870d083dc0d72533d7a5ded040589d3a
7
- data.tar.gz: 8c44e3480d34eb1de8524e3d94a4c7d0691ab3bbdbe77cce78537a0940ac57f0eecae88676d6eb09f9b6a1dd716026c6343750d4f8f0cbe3266a6e2ff2cdf93b
6
+ metadata.gz: 45e22e8ea9fc3bec466ae81ca048f7d1f0a8513c164c934cee2f4d93e8febcd9f93cdd78bf45ca55378b9017033efe404a604d5bbe35eb097684c0ec8de4a18f
7
+ data.tar.gz: d74659f7ecbbcc7c3d95e40e299731ee8264d0f50dae98ad9ff58c548a25ba8e99514e3ced679ef7c83051224c841026e0c87527c0515ffa8261b1a6c59ee2b2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.2 — 2026-11-20
4
+
5
+ - The 2.0.0 and 2.0.1 releases did not reach RubyGems; this version carries the same changes. The Rails sample's development server `puma` moves to 8.0.4 (security advisories in 8.0.2); the gem has no runtime dependency on it.
6
+
7
+ ## 2.0.1 — 2026-11-20
8
+
9
+ - The 2.0.0 release did not reach RubyGems; this version carries the same changes. Test and Rails sample style follow RuboCop.
10
+
11
+ ## 2.0.0 — 2026-11-20
12
+
13
+ - **Breaking — order details required.** Every payment endpoint requires the buyer, the billing address and at least one basket item; a `PHYSICAL` item also requires the shipping address (payment providers do not start a payment without them). `payments.create_intent`, `payments.create_marketplace_intent`, `payments.direct_method_payment`, `payments.split`, `marketplace.create_checkout_intent`, the marketplace card charges and `payments.store_card` (buyer and billing address only) raise `ConfigurationError` naming the missing paths before sending; on the checkout intents `buyer.ip` may be left out (the Lunixi form takes it from the browser). `StoreCardRequest` gains `with_buyer` / `with_billing_address`. New `Lunixi::OrderDetails.missing(body, basket:, checkout_intent:)` / `OrderDetails.check!` and constants `ORDER_DETAILS_REQUIRED_FIELDS`, `BUYER_REQUIRED_FIELDS`, `CHECKOUT_INTENT_BUYER_OPTIONAL_FIELDS`, `ADDRESS_REQUIRED_FIELDS`, `BASKET_ITEM_REQUIRED_FIELDS`, `OrderFieldErrorCode` (`payment.order.field_required`, `payment.order.field_invalid`), `OrderFieldReason`.
14
+ - Split payment bodies carry `buyer`, `billingAddress`, `shippingAddress` and `basketItems`; their field list is `Lunixi::SPLIT_PAYMENT_FIELDS`.
15
+ - Wallet card top-up (`wallet.topups.start_card`): `buyer` and `billingAddress` are required, `shippingAddress` optional; a missing field raises `ConfigurationError` before sending (the gateway answers 400 `payment.order.field_required` with `details.fields`).
16
+ - **Breaking — subscription customers.** `subscriptions.customers.upsert` requires `name`, `surname`, `email`, `gsmNumber`, `identityNumber`, `billingAddress`, `billingCity`, `billingCountry`, `billingZipCode` (renewals take the buyer from this record); `phone`, `locale` and `metadata` were never accepted by the gateway and are removed from the route. New constant `Lunixi::SubscriptionCustomerErrorCode`.
17
+ - **Breaking — payment link buyer fields.** `Lunixi::BuyerFieldRequirement` has only `REQUIRED`: the link page always asks all five buyer fields (the gateway answers `HIDDEN` / `OPTIONAL` with 400).
18
+ - Rails sample: `Order.order_details` (encrypted, migration `20261120000000_add_order_details_to_orders`) carries the buyer, addresses and basket; checkout checks them before reserving an attempt and sends them with the intent outside the reserved request.
19
+
3
20
  ## 1.3.1 — 2026-11-15
4
21
 
5
22
  - Lint (RuboCop) clean and `Gemfile.lock` carries the gem version, so the release builds in CI; no behaviour change.
data/README.md CHANGED
@@ -60,7 +60,13 @@ result = lunixi.payments.create_intent(
60
60
  currency: 'TRY',
61
61
  orderId: order.public_id,
62
62
  callbackUrl: 'https://merchant.example/payments/return',
63
- basketItems: [{ id: 'item-1', name: 'Product', itemType: 'PHYSICAL', price: "10050" }],
63
+ # Order details every payment requires (take them from your checkout, never a placeholder).
64
+ # buyer.ip may be left out on an intent: the Lunixi form takes it from the buyer's browser.
65
+ buyer: { name: 'Ada', surname: 'Yilmaz', identityNumber: '11111111111', email: 'ada@example.com',
66
+ gsmNumber: '+905350000000', city: 'Istanbul', country: 'Turkey', zipCode: '34000' },
67
+ billingAddress: { contactName: 'Ada Yilmaz', address: 'Example Street 1', city: 'Istanbul', country: 'Turkey', zipCode: '34000' },
68
+ shippingAddress: { contactName: 'Ada Yilmaz', address: 'Example Street 1', city: 'Istanbul', country: 'Turkey', zipCode: '34000' },
69
+ basketItems: [{ id: 'item-1', name: 'Product', category1: 'Electronics', itemType: 'PHYSICAL', price: "10050" }],
64
70
  enabledInstallments: [1, 2, 3] # optional: at most 3 installments
65
71
  },
66
72
  idempotency_key: order.persisted_payment_attempt_key
@@ -116,6 +122,8 @@ The shared Lunixi form owns enabled payment methods and supports the methods con
116
122
  | Marketplace | `marketplace.create_checkout_intent`, `charge_marketplace_card2d`, `charge_marketplace_card3d`, sub-dealers, commissions, payouts, audit log |
117
123
  | Other documented endpoints | `request(method, path, body: nil, query: {}, idempotency_key: nil, signed: true, binary: false, accept: 'application/json', max_retries: nil)` |
118
124
 
125
+ Every payment body carries the order details (`Lunixi::OrderDetails`): `buyer` (`name`, `surname`, `identityNumber` — Turkish ID or passport number, `email` — ASCII, `gsmNumber`, `city`, `country`, `zipCode`, `ip` — the buyer's browser IP), `billingAddress` (`contactName`, `address`, `city`, `country`, `zipCode`) and at least one `basketItems` entry (`id`, `name`, `category1`, `itemType`, `price`; the prices add up to the amount); a `PHYSICAL` item also needs `shippingAddress`. On `create_intent`, `create_marketplace_intent` and `marketplace.create_checkout_intent` `ip` may be left out (`Lunixi::CHECKOUT_INTENT_BUYER_OPTIONAL_FIELDS`): the Lunixi form takes it from the buyer's browser. `create_intent`, `create_marketplace_intent`, `direct_method_payment`, `split`, the marketplace intents and card charges, `store_card` (buyer and billing address only) and `wallet.topups.start_card` (buyer and billing address, `shippingAddress` optional) raise `ConfigurationError` naming the missing paths before sending; `Lunixi::OrderDetails.missing(body)` returns the same list (`buyer.email`, `basketItems.0.category1`, `shippingAddress`). The field lists are `Lunixi::ORDER_DETAILS_REQUIRED_FIELDS`, `Lunixi::BUYER_REQUIRED_FIELDS`, `Lunixi::ADDRESS_REQUIRED_FIELDS` and `Lunixi::BASKET_ITEM_REQUIRED_FIELDS`. The gateway answers a missing field with 400 `payment.order.field_required` and an invalid one with `payment.order.field_invalid` (`Lunixi::OrderFieldErrorCode`, `Lunixi::OrderFieldReason`).
126
+
119
127
  `amount`, split `totalAmount` and each leg/item price must be positive canonical minor-unit strings within the signed 64-bit fiat range. Root `price`/`paidPrice` are removed fields and rejected even when null. Basket and split totals must agree. Each `basketItems` entry may carry the optional `productCategory`: the Lunixi product category code (for example `'MOBILE_PHONE'`), used by payment methods with legal installment limits (e.g. shopping loan) and other platform features. Leave it out to keep today's behaviour; the gateway rejects an unknown code with 400. The codes are available as `Lunixi::ProductCategory` constants (`Lunixi::ProductCategory::MOBILE_PHONE`, all 40 in `Lunixi::ProductCategory::ALL`); the list only grows by appending, so the value stays a plain string and the SDK does not check it before sending. Intent installments belong to the checkout form; `installment` is rejected on intent creation. The optional `enabledInstallments` list only narrows the installment counts the form offers for one payment (`[1]` = single payment only); the form shows only the counts your panel settings, the card and the platform maximum also allow. Leave it out for no restriction. The list must hold distinct integers 1–36 that include 1; any other list (an empty list included) raises `ConfigurationError` before sending, and the list is sent in ascending order. Set `preauth: true` for authorization, then capture separately with a new durable operation key. Omitting the capture/refund `amount:` keyword asks the gateway to use the remaining amount; explicit nil, numeric, zero, false and noncanonical string amounts are rejected.
120
128
 
121
129
  ```ruby
@@ -138,6 +146,8 @@ Payments, fraud, payment links, physical POS, wallet, bank accounts, sanctions s
138
146
  request = Lunixi::DirectMethodPaymentRequest.new('10000', 'TRY', order.reference)
139
147
  .with_method_fields(Lunixi::PaymentMethod::MOBILE_BILLING, provider_code,
140
148
  gsmNumber: '+905321234567')
149
+ .with_buyer(buyer).with_billing_address(billing_address) # buyer includes ip here
150
+ .with_basket_items(basket_items)
141
151
  result = lunixi.payments.direct_method_payment(request, idempotency_key: order.payment_operation_key)
142
152
 
143
153
  action = result.dig('data', 'action')
@@ -165,7 +175,7 @@ instruction = Lunixi::BankTransferInstruction.from_response(result)
165
175
 
166
176
  ### Split payments
167
177
 
168
- A non-card split leg carries only one of `Lunixi::SPLIT_LEG_BLOCK_FIELDS` (`mobileBilling`, `wallet`, `promissoryNote`); meal card, open banking, shopping loan and bank transfer cannot be legs and are rejected before sending. `list_splits(status: 'COMPLETED', limit: 25)` lists split payments (`Lunixi::LIST_SPLIT_PAYMENTS_FILTERS`). Webhook names are in `Lunixi::SplitPaymentEvents`; add `Lunixi::SPLIT_LEG_EVENTS_SUBSCRIPTION` to an endpoint's event types to also receive leg events.
178
+ The split body (`Lunixi::SPLIT_PAYMENT_FIELDS`) carries the order details with the legs: `buyer`, `billingAddress`, `basketItems` (adding up to `totalAmount`) and `shippingAddress` for a `PHYSICAL` item. A non-card split leg carries only one of `Lunixi::SPLIT_LEG_BLOCK_FIELDS` (`mobileBilling`, `wallet`, `promissoryNote`); meal card, open banking, shopping loan and bank transfer cannot be legs and are rejected before sending. `list_splits(status: 'COMPLETED', limit: 25)` lists split payments (`Lunixi::LIST_SPLIT_PAYMENTS_FILTERS`). Webhook names are in `Lunixi::SplitPaymentEvents`; add `Lunixi::SPLIT_LEG_EVENTS_SUBSCRIPTION` to an endpoint's event types to also receive leg events.
169
179
 
170
180
  ### BIN, installments and stored cards
171
181
 
@@ -177,7 +187,7 @@ options = lunixi.payments.installment_options(
177
187
  )
178
188
  ```
179
189
 
180
- `payments.store_card(Lunixi::StoreCardRequest.new(card, card_user_key, callback_url), idempotency_key:)` verifies and stores a card (signed); `list_stored_cards(card_user_key)` and `get_stored_card(token)` return masked card data, and `deactivate_stored_card(token, idempotency_key:)` removes it (signed). Both writes require the idempotency key.
190
+ `payments.store_card(Lunixi::StoreCardRequest.new(card, card_user_key, callback_url).with_buyer(buyer).with_billing_address(billing_address), idempotency_key:)` verifies and stores a card (signed; the card holder as the buyer and the billing address are required); `list_stored_cards(card_user_key)` and `get_stored_card(token)` return masked card data, and `deactivate_stored_card(token, idempotency_key:)` removes it (signed). Both writes require the idempotency key.
181
191
 
182
192
  `payments.create_marketplace_intent` takes the intent body plus `sellers` (`[{ subDealerId:, amountMinor:, scenario: }]`) and `multiSellerPolicy`. Each `amountMinor` is a canonical minor-unit string and the sellers must add up to `amount`; any other total raises `ConfigurationError` before sending.
183
193
 
@@ -324,12 +334,16 @@ record_policy(event['insuranceOrderId'], event['policies']) if event.type == Lun
324
334
  ```ruby
325
335
  plan = lunixi.subscriptions.plans.create({ productId: product_id, code: 'pro', name: 'Pro', price: '9900', currency: 'TRY',
326
336
  billing: { frequency: 'MONTHLY' } }, idempotency_key: plan_key)
327
- customer = lunixi.subscriptions.customers.upsert({ externalId: user.id, email: user.email })
337
+ # Renewals take the buyer from the customer record: identity and billing details are required.
338
+ customer = lunixi.subscriptions.customers.upsert({ externalId: user.id, name: user.first_name, surname: user.last_name, email: user.email,
339
+ gsmNumber: user.phone, identityNumber: user.identity_number,
340
+ billingAddress: user.address, billingCity: user.city, billingCountry: user.country,
341
+ billingZipCode: user.zip_code })
328
342
  subscription = lunixi.subscriptions.create({ customerId: customer['id'], planId: plan['id'] }, idempotency_key: signup.key)
329
343
  grant_access! if Lunixi::Subscriptions.active?(subscription)
330
344
  ```
331
345
 
332
- The subscription, plan, customer, card, invoice and audit-log lists return a `Lunixi::ListPage` whose `next_cursor` goes back as `page_token:` (`page_size` is the envelope's `pageSize`); `iterate` walks every page. `portal.create_sdk_session` returns the embedded-portal proof (`portalToken`, `sessionProof`, `proofNonce`, `proofExpiresAt`); `portal.create_portal_link` returns a hosted link, opened with `Lunixi::Subscriptions.portal_url(link)`. Event names are in `Lunixi::SubscriptionEvents`.
346
+ The subscription, plan, customer, card, invoice and audit-log lists return a `Lunixi::ListPage` whose `next_cursor` goes back as `page_token:` (`page_size` is the envelope's `pageSize`); `iterate` walks every page. `portal.create_sdk_session` returns the embedded-portal proof (`portalToken`, `sessionProof`, `proofNonce`, `proofExpiresAt`); `portal.create_portal_link` returns a hosted link, opened with `Lunixi::Subscriptions.portal_url(link)`. Event names are in `Lunixi::SubscriptionEvents`. A missing or invalid customer field is 400 `subscription.customer.field_required` / `subscription.customer.field_invalid` (`Lunixi::SubscriptionCustomerErrorCode`).
333
347
 
334
348
  ## KYC and identity signals
335
349
 
@@ -349,7 +363,8 @@ approved = Lunixi::Kyc.assurance_meets?(achieved_level, Lunixi::KycAssuranceLeve
349
363
 
350
364
  ```ruby
351
365
  intent = lunixi.marketplace.create_checkout_intent(
352
- { amount: '100000', currency: 'TRY', orderId: order.id, callbackUrl: return_url },
366
+ { amount: '100000', currency: 'TRY', orderId: order.id, callbackUrl: return_url,
367
+ buyer: buyer, billingAddress: billing_address, basketItems: basket_items }, # order details as in Start checkout
353
368
  [{ subDealerId: 'd_alice', amountMinor: '60000' }, { subDealerId: 'd_bob', amountMinor: '40000' }],
354
369
  multi_seller_policy: Lunixi::MarketplaceMultiSellerPolicy::ALL_OR_NOTHING, idempotency_key: order.payment_key
355
370
  )
data/README.tr.md CHANGED
@@ -58,7 +58,13 @@ Toplamı sunucuda hesaplayın. Çağrıdan **önce** ödeme denemesine bir UUID
58
58
  result = lunixi.payments.create_intent(
59
59
  { amount: "10050", currency: 'TRY', orderId: order.public_id,
60
60
  callbackUrl: 'https://merchant.example/payments/return',
61
- basketItems: [{ id: 'urun-1', name: 'Product', itemType: 'PHYSICAL', price: "10050" }],
61
+ # Her ödemenin istediği sipariş bilgileri (ödeme sayfanızdan alın, yer tutucu kullanmayın).
62
+ # Intent'te buyer.ip gönderilmeyebilir: Lunixi formu IP'yi alıcının tarayıcısından alır.
63
+ buyer: { name: 'Ada', surname: 'Yilmaz', identityNumber: '11111111111', email: 'ada@example.com',
64
+ gsmNumber: '+905350000000', city: 'Istanbul', country: 'Turkey', zipCode: '34000' },
65
+ billingAddress: { contactName: 'Ada Yilmaz', address: 'Example Street 1', city: 'Istanbul', country: 'Turkey', zipCode: '34000' },
66
+ shippingAddress: { contactName: 'Ada Yilmaz', address: 'Example Street 1', city: 'Istanbul', country: 'Turkey', zipCode: '34000' },
67
+ basketItems: [{ id: 'urun-1', name: 'Product', category1: 'Electronics', itemType: 'PHYSICAL', price: "10050" }],
62
68
  enabledInstallments: [1, 2, 3] }, # isteğe bağlı: en fazla 3 taksit
63
69
  idempotency_key: order.persisted_payment_attempt_key
64
70
  )
@@ -66,6 +72,8 @@ intent_id = result.fetch('data').fetch('paymentId')
66
72
  checkout_token = result.fetch('data').fetch('token')
67
73
  ```
68
74
 
75
+ Her ödeme gövdesi sipariş bilgilerini taşır (`Lunixi::OrderDetails`): `buyer` (`name`, `surname`, `identityNumber` — T.C. kimlik veya pasaport numarası, `email` — ASCII, `gsmNumber`, `city`, `country`, `zipCode`, `ip` — alıcının tarayıcı IP'si), `billingAddress` (`contactName`, `address`, `city`, `country`, `zipCode`) ve en az bir `basketItems` satırı (`id`, `name`, `category1`, `itemType`, `price`; fiyatların toplamı tutara eşittir); `PHYSICAL` bir satır `shippingAddress` de ister. `create_intent`, `create_marketplace_intent` ve `marketplace.create_checkout_intent` çağrılarında `ip` gönderilmeyebilir (`Lunixi::CHECKOUT_INTENT_BUYER_OPTIONAL_FIELDS`): Lunixi formu IP'yi alıcının tarayıcısından alır. `create_intent`, `create_marketplace_intent`, `direct_method_payment`, `split`, pazaryeri intent'leri ve kart tahsilatları, `store_card` (yalnız alıcı ve fatura adresi) ve `wallet.topups.start_card` (alıcı ve fatura adresi, `shippingAddress` isteğe bağlı) eksik alanların yollarını sayan bir `ConfigurationError` ile göndermeden önce durur; `Lunixi::OrderDetails.missing(body)` aynı listeyi döndürür (`buyer.email`, `basketItems.0.category1`, `shippingAddress`). Alan listeleri `Lunixi::ORDER_DETAILS_REQUIRED_FIELDS`, `Lunixi::BUYER_REQUIRED_FIELDS`, `Lunixi::ADDRESS_REQUIRED_FIELDS` ve `Lunixi::BASKET_ITEM_REQUIRED_FIELDS` sabitlerindedir. Gateway eksik alanı 400 `payment.order.field_required`, geçersiz alanı `payment.order.field_invalid` ile yanıtlar (`Lunixi::OrderFieldErrorCode`, `Lunixi::OrderFieldReason`).
76
+
69
77
  `"10050"`, 100,50 TRY’nin kuruş karşılığıdır. Tutarlar pozitif, kanonik alt birim string olmalı ve işaretli 64 bit fiat aralığında kalmalıdır; sayısal değerler kabul edilmez. Eski kök `price`/`paidPrice` alanları null olsa bile reddedilir. Sepet toplamı ve split bacak toplamı ana tutarla aynı olmalıdır. Her `basketItems` satırı isteğe bağlı `productCategory` alanını taşıyabilir: Lunixi ürün kategorisi kodu (ör. `'MOBILE_PHONE'`); yasal taksit sınırı olan ödeme yöntemleri (ör. alışveriş kredisi) ve diğer platform özellikleri tarafından kullanılır. Alanı göndermezseniz mevcut davranış korunur; gateway bilinmeyen kodu 400 ile reddeder. Kodlar `Lunixi::ProductCategory` sabitleri olarak hazırdır (`Lunixi::ProductCategory::MOBILE_PHONE`, 40 kodun tamamı `Lunixi::ProductCategory::ALL` içinde); liste yalnız sona ekleme ile büyüdüğünden değer düz string olarak kalır ve SDK göndermeden önce denetlemez. Intent’te `installment` gönderilmez; taksiti ödeme formu seçtirir. İsteğe bağlı `enabledInstallments` listesi, bir ödeme için formun sunacağı taksit sayılarını yalnızca daraltır (`[1]` = yalnız tek çekim); form, panel ayarlarınızın, kartın ve platform üst sınırının da izin verdiği sayıları gösterir. Kısıt istemiyorsanız alanı göndermeyin. Liste 1–36 arası, tekrarsız ve 1'i içeren tamsayılardan oluşmalıdır; başka bir liste (boş liste dahil) göndermeden önce `ConfigurationError` oluşturur ve liste artan sırada gönderilir. `preauth: true` ile provizyon alınabilir; capture ayrı işlem ve anahtarla yapılır.
70
78
 
71
79
  Varsayılan form mağaza içinde açılır; isteğe bağlı yönlendirme yalnız doğrulanmış backend `paymentPageUrl` adresini kullanır. Token ve adres şifrelenir; iki mod aynı Lunixi form ayarlarını paylaşır. PAN/CVV toplamayın.
@@ -129,6 +137,8 @@ banks = lunixi.request('GET', '/api/v1/bank-connect/banks', query: { limit: 20 }
129
137
  request = Lunixi::DirectMethodPaymentRequest.new('10000', 'TRY', order.reference)
130
138
  .with_method_fields(Lunixi::PaymentMethod::MOBILE_BILLING, provider_code,
131
139
  gsmNumber: '+905321234567')
140
+ .with_buyer(buyer).with_billing_address(billing_address) # buyer burada ip içerir
141
+ .with_basket_items(basket_items)
132
142
  result = lunixi.payments.direct_method_payment(request, idempotency_key: order.payment_operation_key)
133
143
 
134
144
  action = result.dig('data', 'action')
@@ -156,7 +166,7 @@ Yanıtta `DISPLAY` transfer talimatı yoksa `from_response` nil döndürür. Ge
156
166
 
157
167
  ### Parçalı ödeme
158
168
 
159
- Kart dışı bir parça `Lunixi::SPLIT_LEG_BLOCK_FIELDS` alanlarından (`mobileBilling`, `wallet`, `promissoryNote`) yalnız birini taşır; yemek kartı, açık bankacılık, alışveriş kredisi ve Para Transferi parça olamaz ve göndermeden önce reddedilir. `list_splits(status: 'COMPLETED', limit: 25)` parçalı ödemeleri listeler (`Lunixi::LIST_SPLIT_PAYMENTS_FILTERS`). Webhook adları `Lunixi::SplitPaymentEvents` içindedir; parça olaylarını da almak için uç noktanın olay türlerine `Lunixi::SPLIT_LEG_EVENTS_SUBSCRIPTION` ekleyin.
169
+ Çoklu ödeme gövdesi (`Lunixi::SPLIT_PAYMENT_FIELDS`) parçalarla birlikte sipariş bilgilerini taşır: `buyer`, `billingAddress`, `basketItems` (toplamı `totalAmount`) ve `PHYSICAL` bir satır için `shippingAddress`. Kart dışı bir parça `Lunixi::SPLIT_LEG_BLOCK_FIELDS` alanlarından (`mobileBilling`, `wallet`, `promissoryNote`) yalnız birini taşır; yemek kartı, açık bankacılık, alışveriş kredisi ve Para Transferi parça olamaz ve göndermeden önce reddedilir. `list_splits(status: 'COMPLETED', limit: 25)` parçalı ödemeleri listeler (`Lunixi::LIST_SPLIT_PAYMENTS_FILTERS`). Webhook adları `Lunixi::SplitPaymentEvents` içindedir; parça olaylarını da almak için uç noktanın olay türlerine `Lunixi::SPLIT_LEG_EVENTS_SUBSCRIPTION` ekleyin.
160
170
 
161
171
  ### BIN, taksitler ve saklı kartlar
162
172
 
@@ -168,7 +178,7 @@ options = lunixi.payments.installment_options(
168
178
  )
169
179
  ```
170
180
 
171
- `payments.store_card(Lunixi::StoreCardRequest.new(card, card_user_key, callback_url), idempotency_key:)` bir kartı doğrular ve saklar (imzalı); `list_stored_cards(card_user_key)` ve `get_stored_card(token)` maskelenmiş kart verisini döndürür, `deactivate_stored_card(token, idempotency_key:)` kartı kaldırır (imzalı). İki yazım da idempotency anahtarı ister.
181
+ `payments.store_card(Lunixi::StoreCardRequest.new(card, card_user_key, callback_url).with_buyer(buyer).with_billing_address(billing_address), idempotency_key:)` bir kartı doğrular ve saklar (imzalı; alıcı olarak kart sahibi ve fatura adresi zorunludur); `list_stored_cards(card_user_key)` ve `get_stored_card(token)` maskelenmiş kart verisini döndürür, `deactivate_stored_card(token, idempotency_key:)` kartı kaldırır (imzalı). İki yazım da idempotency anahtarı ister.
172
182
 
173
183
  `payments.create_marketplace_intent` intent gövdesine ek olarak `sellers` (`[{ subDealerId:, amountMinor:, scenario: }]`) ve `multiSellerPolicy` alır. Her `amountMinor` kanonik küçük birim string'idir ve satıcıların toplamı `amount` değerine eşit olmalıdır; başka bir toplam göndermeden önce `ConfigurationError` oluşturur.
174
184
 
@@ -315,12 +325,16 @@ record_policy(event['insuranceOrderId'], event['policies']) if event.type == Lun
315
325
  ```ruby
316
326
  plan = lunixi.subscriptions.plans.create({ productId: product_id, code: 'pro', name: 'Pro', price: '9900', currency: 'TRY',
317
327
  billing: { frequency: 'MONTHLY' } }, idempotency_key: plan_key)
318
- customer = lunixi.subscriptions.customers.upsert({ externalId: user.id, email: user.email })
328
+ # Yenilemeler alıcıyı müşteri kaydından alır: kimlik ve fatura bilgileri zorunludur.
329
+ customer = lunixi.subscriptions.customers.upsert({ externalId: user.id, name: user.first_name, surname: user.last_name, email: user.email,
330
+ gsmNumber: user.phone, identityNumber: user.identity_number,
331
+ billingAddress: user.address, billingCity: user.city, billingCountry: user.country,
332
+ billingZipCode: user.zip_code })
319
333
  subscription = lunixi.subscriptions.create({ customerId: customer['id'], planId: plan['id'] }, idempotency_key: signup.key)
320
334
  grant_access! if Lunixi::Subscriptions.active?(subscription)
321
335
  ```
322
336
 
323
- Abonelik, plan, müşteri, kart, fatura ve denetim kaydı listeleri, `next_cursor` değeri `page_token:` olarak geri gönderilen bir `Lunixi::ListPage` döndürür (`page_size` zarfın `pageSize` değeridir); `iterate` bütün sayfaları gezer. `portal.create_sdk_session` gömülü portal kanıtını döndürür (`portalToken`, `sessionProof`, `proofNonce`, `proofExpiresAt`); `portal.create_portal_link` barındırılan bir link döndürür, link `Lunixi::Subscriptions.portal_url(link)` ile açılır. Olay adları `Lunixi::SubscriptionEvents` içindedir.
337
+ Abonelik, plan, müşteri, kart, fatura ve denetim kaydı listeleri, `next_cursor` değeri `page_token:` olarak geri gönderilen bir `Lunixi::ListPage` döndürür (`page_size` zarfın `pageSize` değeridir); `iterate` bütün sayfaları gezer. `portal.create_sdk_session` gömülü portal kanıtını döndürür (`portalToken`, `sessionProof`, `proofNonce`, `proofExpiresAt`); `portal.create_portal_link` barındırılan bir link döndürür, link `Lunixi::Subscriptions.portal_url(link)` ile açılır. Olay adları `Lunixi::SubscriptionEvents` içindedir. Eksik veya geçersiz müşteri alanı 400 `subscription.customer.field_required` / `subscription.customer.field_invalid` ile yanıtlanır (`Lunixi::SubscriptionCustomerErrorCode`).
324
338
 
325
339
  ## KYC ve kimlik sinyalleri
326
340
 
@@ -340,7 +354,8 @@ approved = Lunixi::Kyc.assurance_meets?(achieved_level, Lunixi::KycAssuranceLeve
340
354
 
341
355
  ```ruby
342
356
  intent = lunixi.marketplace.create_checkout_intent(
343
- { amount: '100000', currency: 'TRY', orderId: order.id, callbackUrl: return_url },
357
+ { amount: '100000', currency: 'TRY', orderId: order.id, callbackUrl: return_url,
358
+ buyer: buyer, billingAddress: billing_address, basketItems: basket_items }, # sipariş bilgileri, Ödeme başlatma örneğindeki gibi
344
359
  [{ subDealerId: 'd_alice', amountMinor: '60000' }, { subDealerId: 'd_bob', amountMinor: '40000' }],
345
360
  multi_seller_policy: Lunixi::MarketplaceMultiSellerPolicy::ALL_OR_NOTHING, idempotency_key: order.payment_key
346
361
  )
data/docs/ruby.en.md CHANGED
@@ -62,7 +62,15 @@ result = lunixi.payments.create_intent(
62
62
  currency: 'TRY',
63
63
  orderId: order.public_id,
64
64
  callbackUrl: 'https://merchant.example/payments/return',
65
- basketItems: [{ id: 'item-1', name: 'Product', itemType: 'PHYSICAL', price: "10050" }]
65
+ # Buyer, billing address and basket are required; a PHYSICAL item also needs the shipping address. The buyer IP is optional on an intent: the Lunixi form takes it from the browser.
66
+ buyer: {
67
+ name: 'Ada', surname: 'Yılmaz', identityNumber: '11111111111', email: 'ada@example.com',
68
+ gsmNumber: '+905000000000', city: 'Istanbul', country: 'Turkey', zipCode: '34732'
69
+ },
70
+ billingAddress: {
71
+ contactName: 'Ada Yılmaz', address: 'Altunizade Mah. Örnek Sok. No: 1', city: 'Istanbul', country: 'Turkey', zipCode: '34662'
72
+ },
73
+ basketItems: [{ id: 'item-1', name: 'Consulting service', category1: 'Services', itemType: 'VIRTUAL', price: "10050" }]
66
74
  },
67
75
  idempotency_key: order.persisted_payment_attempt_key
68
76
  )
@@ -77,6 +85,8 @@ checkout_token = result.fetch('data').fetch('token')
77
85
  An intent/token, HTTP 2xx, return URL or intermediate split state does not prove capture. Correlate a verified webhook with the persisted order and authenticate a payment status read; confirm final status, amount and currency before fulfillment.
78
86
 
79
87
 
88
+ Every payment body carries the order details (`Lunixi::OrderDetails`): `buyer` (name, surname, identityNumber, email, gsmNumber, city, country, zipCode and the browser `ip`, optional on the checkout intents), `billingAddress` (contactName, address, city, country, zipCode), at least one `basketItems` entry (id, name, category1, itemType, price) and `shippingAddress` for a `PHYSICAL` item. The SDK raises `ConfigurationError` naming the missing paths before sending; the gateway answers 400 `payment.order.field_required` (`Lunixi::OrderFieldErrorCode`).
89
+
80
90
  Amounts must be positive canonical minor-unit strings within the signed 64-bit fiat range. Root `price` and `paidPrice` are rejected even when null. Basket prices and split leg amounts must equal the relevant total. Each `basketItems` entry may carry the optional `productCategory`: the Lunixi product category code (for example `'MOBILE_PHONE'`), used by payment methods with legal installment limits (e.g. shopping loan) and other platform features. Leave it out to keep today's behaviour; the gateway rejects an unknown code with 400. The codes are available as `Lunixi::ProductCategory` constants (`Lunixi::ProductCategory::MOBILE_PHONE`, all 40 in `Lunixi::ProductCategory::ALL`); the list only grows by appending, so the value stays a plain string and the SDK does not check it before sending. Intent `installment` is rejected because installments are selected in the checkout form; the optional `enabledInstallments` list (distinct integers 1–36 including 1, ascending; `[1]` = single payment only) only narrows the counts the form offers for one payment. `preauth: true` requests authorization; capture is a separate operation.
81
91
 
82
92
  ## Available helpers
data/docs/ruby.tr.md CHANGED
@@ -62,7 +62,15 @@ result = lunixi.payments.create_intent(
62
62
  currency: 'TRY',
63
63
  orderId: order.public_id,
64
64
  callbackUrl: 'https://merchant.example/payments/return',
65
- basketItems: [{ id: 'item-1', name: 'Product', itemType: 'PHYSICAL', price: "10050" }]
65
+ # Alıcı, fatura adresi ve sepet zorunludur; PHYSICAL bir satır teslimat adresi de ister. Intent'te alıcı IP'si isteğe bağlıdır: Lunixi formu IP'yi tarayıcıdan alır.
66
+ buyer: {
67
+ name: 'Ada', surname: 'Yılmaz', identityNumber: '11111111111', email: 'ada@example.com',
68
+ gsmNumber: '+905000000000', city: 'Istanbul', country: 'Turkey', zipCode: '34732'
69
+ },
70
+ billingAddress: {
71
+ contactName: 'Ada Yılmaz', address: 'Altunizade Mah. Örnek Sok. No: 1', city: 'Istanbul', country: 'Turkey', zipCode: '34662'
72
+ },
73
+ basketItems: [{ id: 'item-1', name: 'Consulting service', category1: 'Services', itemType: 'VIRTUAL', price: "10050" }]
66
74
  },
67
75
  idempotency_key: order.persisted_payment_attempt_key
68
76
  )
@@ -77,6 +85,8 @@ checkout_token = result.fetch('data').fetch('token')
77
85
  Intent/token, HTTP 2xx, dönüş sayfası veya ara split durumu tahsilat kanıtı değildir. İmzalı webhook’u kalıcı siparişle eşleştirin; sunucudan ödeme sorgusunda nihai durum, tutar ve para birimi uyuşmadan siparişi tamamlamayın.
78
86
 
79
87
 
88
+ Her ödeme gövdesi sipariş bilgilerini taşır (`Lunixi::OrderDetails`): `buyer` (name, surname, identityNumber, email, gsmNumber, city, country, zipCode ve checkout intent'lerinde isteğe bağlı tarayıcı `ip` değeri), `billingAddress` (contactName, address, city, country, zipCode), en az bir `basketItems` satırı (id, name, category1, itemType, price) ve `PHYSICAL` bir satır için `shippingAddress`. SDK eksik alanların yollarını sayan bir `ConfigurationError` ile göndermeden önce durur; gateway 400 `payment.order.field_required` ile yanıtlar (`Lunixi::OrderFieldErrorCode`).
89
+
80
90
  Tutarlar pozitif, kanonik alt birim string olmalı ve işaretli 64 bit fiat aralığında kalmalıdır. Kök `price`/`paidPrice` null olsa bile reddedilir. Sepet ve split bacak toplamları ana toplamla aynı olmalıdır. Her `basketItems` satırı isteğe bağlı `productCategory` alanını taşıyabilir: Lunixi ürün kategorisi kodu (ör. `'MOBILE_PHONE'`); yasal taksit sınırı olan ödeme yöntemleri (ör. alışveriş kredisi) ve diğer platform özellikleri tarafından kullanılır. Alanı göndermezseniz mevcut davranış korunur; gateway bilinmeyen kodu 400 ile reddeder. Kodlar `Lunixi::ProductCategory` sabitleri olarak hazırdır (`Lunixi::ProductCategory::MOBILE_PHONE`, 40 kodun tamamı `Lunixi::ProductCategory::ALL` içinde); liste yalnız sona ekleme ile büyüdüğünden değer düz string olarak kalır ve SDK göndermeden önce denetlemez. Intent’te `installment` gönderilmez; taksit formda seçilir. İsteğe bağlı `enabledInstallments` listesi (1–36 arası, tekrarsız, 1'i içeren, artan sıralı tamsayılar; `[1]` = yalnız tek çekim) bir ödeme için formun sunacağı sayıları yalnızca daraltır. `preauth: true` provizyon ister; capture ayrı işlemdir.
81
91
 
82
92
  ## Yardımcı API’ler
@@ -52,7 +52,8 @@ module Lunixi
52
52
  data
53
53
  end
54
54
 
55
- # Body of POST /api/v1/payments/cards: card, cardUserKey, an HTTPS callbackUrl and an optional currency.
55
+ # Body of POST /api/v1/payments/cards: card, cardUserKey, an HTTPS callbackUrl, the buyer and the
56
+ # billing address (OrderDetails, no basket) and an optional currency.
56
57
  def store_card_body!(body)
57
58
  data = plain!(body, 'Store card request')
58
59
  raise ConfigurationError, 'Store card request requires the card object' unless data['card'].is_a?(Hash) && !data['card'].empty?
@@ -60,7 +61,7 @@ module Lunixi
60
61
  text!(data['cardUserKey'], 'cardUserKey')
61
62
  callback_url!(data['callbackUrl'])
62
63
  currency!(data['currency']) unless data['currency'].nil?
63
- data
64
+ OrderDetails.check!(data, 'Storing a card', basket: false)
64
65
  end
65
66
 
66
67
  def callback_url!(url)
@@ -124,8 +125,8 @@ module Lunixi
124
125
  end
125
126
  end
126
127
 
127
- # Body of payments.store_card (verify and store a card for cardUserKey). Its inspect output never
128
- # shows the card.
128
+ # Body of payments.store_card (verify and store a card for cardUserKey). with_buyer and
129
+ # with_billing_address are required (no basket). Its inspect output never shows the card.
129
130
  class StoreCardRequest
130
131
  def initialize(card, card_user_key, callback_url)
131
132
  raise ConfigurationError, 'card must be an object' unless card.is_a?(Hash) && !card.empty?
@@ -139,6 +140,18 @@ module Lunixi
139
140
  self
140
141
  end
141
142
 
143
+ # The card holder as the buyer (required; BUYER_REQUIRED_FIELDS).
144
+ def with_buyer(value)
145
+ @payload['buyer'] = object!(value, 'buyer')
146
+ self
147
+ end
148
+
149
+ # The billing address (required; ADDRESS_REQUIRED_FIELDS).
150
+ def with_billing_address(value)
151
+ @payload['billingAddress'] = object!(value, 'billingAddress')
152
+ self
153
+ end
154
+
142
155
  def to_h
143
156
  @payload.dup
144
157
  end
@@ -146,5 +159,13 @@ module Lunixi
146
159
  def inspect
147
160
  "#<#{self.class.name} card=[REDACTED]>"
148
161
  end
162
+
163
+ private
164
+
165
+ def object!(value, field)
166
+ raise ConfigurationError, "#{field} must be an object" unless value.is_a?(Hash)
167
+
168
+ JSON.parse(JsonBody.dump(value))
169
+ end
149
170
  end
150
171
  end
@@ -4,6 +4,8 @@ module Lunixi
4
4
  # Body of POST /api/v1/payments/direct/payment (payments.direct_method_payment). amount is the order
5
5
  # total as a positive canonical minor-unit string. Choose the method with with_method_fields or
6
6
  # with_card; the provider code and the fields of a method come from payments.list_payment_methods.
7
+ # The order details are required: with_buyer, with_billing_address, with_basket_items (at least one
8
+ # item) and with_shipping_address when an item is PHYSICAL (OrderDetails).
7
9
  class DirectMethodPaymentRequest
8
10
  REQUIRED_FIELDS = %w[paymentMethod amount currency orderId].freeze
9
11
 
@@ -147,7 +149,7 @@ module Lunixi
147
149
  # Checks a direct/payment body (a Hash or the result of to_h) before sending and returns a
148
150
  # string-keyed copy: known fields only, the chosen method's block and no other, card fields only
149
151
  # with CARD, block structure, promissory-note plan, shopping-loan basket, no providerCode for
150
- # BANK_TRANSFER.
152
+ # BANK_TRANSFER. payments.direct_method_payment also checks the order details (OrderDetails).
151
153
  def self.payload!(body)
152
154
  raise ConfigurationError, 'A direct method payment needs a body; use DirectMethodPaymentRequest to build it' unless body.is_a?(Hash)
153
155
 
@@ -35,9 +35,12 @@ module Lunixi
35
35
  # orderId, callbackUrl, basketItems ...) plus the seller legs. Returns the answer as it came (token,
36
36
  # checkoutFormContent, paymentId ...); an answer without a token or a form (a seller not eligible
37
37
  # under ALL_OR_NOTHING) raises ApiError instead of leaving the buyer on an empty page. The same route
38
- # as payments.create_marketplace_intent, which takes the legs inside the body.
38
+ # as payments.create_marketplace_intent, which takes the legs inside the body. The order details
39
+ # (buyer, billingAddress, basketItems, shippingAddress for a PHYSICAL item) are required; buyer.ip
40
+ # may be left out (CHECKOUT_INTENT_BUYER_OPTIONAL_FIELDS).
39
41
  def create_checkout_intent(request, sellers, multi_seller_policy: MarketplaceMultiSellerPolicy::ALL_OR_NOTHING, idempotency_key: nil)
40
42
  body = split_body(payload!(request, 'create_checkout_intent request'), sellers, multi_seller_policy)
43
+ OrderDetails.check!(body, 'A marketplace payment intent', checkout_intent: true)
41
44
  response = @routes.call('createCheckoutIntent', body: body, idempotency_key: idempotency_key)
42
45
  intent = RouteResponse.merge_root(response)
43
46
  return response if RouteResponse.text(intent['token']) || RouteResponse.text(intent['checkoutFormContent'])
@@ -49,12 +52,13 @@ module Lunixi
49
52
  # Direct split card charge from a raw body (amount, currency, orderId, card, buyer, billingAddress,
50
53
  # basketItems, sellers, multiSellerPolicy, preauth? ...): POST /payments/marketplace/3d with
51
54
  # three_ds: true, /2d otherwise. Prefer charge_marketplace_card2d / charge_marketplace_card3d, which
52
- # check the body and the legs.
55
+ # check the body and the legs. The order details are checked before sending (OrderDetails).
53
56
  def charge_marketplace_card(payload, three_ds: false, idempotency_key: nil)
54
57
  raise ConfigurationError, "'three_ds' must be true or false." unless [true, false].include?(three_ds)
55
58
 
56
59
  body = payload!(payload, 'charge_marketplace_card payload')
57
60
  charge_amount!(body)
61
+ OrderDetails.check!(body, 'A marketplace card charge')
58
62
  @routes.call(three_ds ? 'chargeMarketplaceCard3d' : 'chargeMarketplaceCard2d', body: body, idempotency_key: idempotency_key)
59
63
  end
60
64
 
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lunixi
4
+ # Order details every payment endpoint requires: the buyer, the billing address and at least one
5
+ # basket item; a basket with a PHYSICAL item also requires the shipping address. Payment providers do
6
+ # not start a payment without them.
7
+ #
8
+ # The gateway refuses a missing field with payment.order.field_required and an invalid one with
9
+ # payment.order.field_invalid; details.field is the dotted path of the first failing field. The SDK
10
+ # checks the same rule before sending and names the same paths. The same values as the Node, PHP and
11
+ # Python SDKs.
12
+
13
+ # Order objects required on every payment endpoint.
14
+ ORDER_DETAILS_REQUIRED_FIELDS = %w[buyer billingAddress basketItems].freeze
15
+
16
+ # buyer fields that must be nonempty strings. identityNumber: Turkish ID or passport number; email:
17
+ # ASCII; ip: the buyer's browser IP (IPv4 or IPv6).
18
+ BUYER_REQUIRED_FIELDS = %w[name surname identityNumber email gsmNumber city country zipCode ip].freeze
19
+
20
+ # buyer fields a checkout intent may leave out (payments.create_intent, payments.create_marketplace_intent,
21
+ # marketplace.create_checkout_intent): the Lunixi form takes the IP from the buyer's browser. A given
22
+ # ip is still sent and wins.
23
+ CHECKOUT_INTENT_BUYER_OPTIONAL_FIELDS = %w[ip].freeze
24
+
25
+ # Fields of billingAddress and shippingAddress that must be nonempty strings.
26
+ ADDRESS_REQUIRED_FIELDS = %w[contactName address city country zipCode].freeze
27
+
28
+ # Fields of each basketItems[] entry the gateway requires.
29
+ BASKET_ITEM_REQUIRED_FIELDS = %w[id name category1 itemType price].freeze
30
+
31
+ # Error codes of a missing or invalid order field.
32
+ module OrderFieldErrorCode
33
+ FIELD_REQUIRED = 'payment.order.field_required'
34
+ FIELD_INVALID = 'payment.order.field_invalid'
35
+
36
+ ALL = [FIELD_REQUIRED, FIELD_INVALID].freeze
37
+ end
38
+
39
+ # details.reason of an order field error.
40
+ module OrderFieldReason
41
+ REQUIRED = 'required'
42
+ REQUIRED_WHEN_PHYSICAL = 'required_when_physical'
43
+ INVALID_TYPE = 'invalid_type'
44
+ INVALID_FORMAT = 'invalid_format'
45
+ TOO_LONG = 'too_long'
46
+ TOO_FEW_ITEMS = 'too_few_items'
47
+
48
+ ALL = [REQUIRED, REQUIRED_WHEN_PHYSICAL, INVALID_TYPE, INVALID_FORMAT, TOO_LONG, TOO_FEW_ITEMS].freeze
49
+ end
50
+
51
+ # The order details check of the payment endpoints.
52
+ module OrderDetails
53
+ PHYSICAL_ITEM_TYPE = 'PHYSICAL'
54
+
55
+ module_function
56
+
57
+ # Paths of the missing order fields of a payment body (String or Symbol keys), in the gateway's
58
+ # format: buyer, buyer.email, billingAddress.city, basketItems.0.category1, shippingAddress. An empty
59
+ # Array means the order details are complete. basket: false checks the buyer and the billing address
60
+ # only (card storage, wallet card top-up); checkout_intent: true does not require
61
+ # CHECKOUT_INTENT_BUYER_OPTIONAL_FIELDS.
62
+ def missing(body, basket: true, checkout_intent: false)
63
+ data = body.is_a?(Hash) ? JSON.parse(JsonBody.dump(body)) : {}
64
+ buyer_fields = checkout_intent ? BUYER_REQUIRED_FIELDS - CHECKOUT_INTENT_BUYER_OPTIONAL_FIELDS : BUYER_REQUIRED_FIELDS
65
+ paths = object_paths(data['buyer'], buyer_fields, 'buyer') +
66
+ object_paths(data['billingAddress'], ADDRESS_REQUIRED_FIELDS, 'billingAddress')
67
+ return paths unless basket
68
+
69
+ items = data['basketItems']
70
+ return paths << 'basketItems' unless items.is_a?(Array) && !items.empty?
71
+
72
+ paths.concat(basket_paths(items))
73
+ shipping = data['shippingAddress']
74
+ if shipping.nil?
75
+ paths << 'shippingAddress' if items.any? { |item| item.is_a?(Hash) && item['itemType'] == PHYSICAL_ITEM_TYPE }
76
+ else
77
+ paths.concat(object_paths(shipping, ADDRESS_REQUIRED_FIELDS, 'shippingAddress'))
78
+ end
79
+ paths
80
+ end
81
+
82
+ # Raises ConfigurationError naming the missing order fields (see missing); label names the request
83
+ # ("A payment intent").
84
+ def check!(body, label, basket: true, checkout_intent: false)
85
+ paths = missing(body, basket: basket, checkout_intent: checkout_intent)
86
+ raise ConfigurationError, "#{label} requires the order details: #{paths.join(', ')}." unless paths.empty?
87
+
88
+ body
89
+ end
90
+
91
+ def object_paths(value, fields, path)
92
+ return [path] unless value.is_a?(Hash)
93
+
94
+ fields.reject { |field| filled?(value[field]) }.map { |field| "#{path}.#{field}" }
95
+ end
96
+
97
+ def basket_paths(items)
98
+ items.each_with_index.flat_map do |item, index|
99
+ next ["basketItems.#{index}"] unless item.is_a?(Hash)
100
+
101
+ BASKET_ITEM_REQUIRED_FIELDS.select { |field| blank?(item[field]) }.map { |field| "basketItems.#{index}.#{field}" }
102
+ end
103
+ end
104
+
105
+ def filled?(value)
106
+ value.is_a?(String) && !value.strip.empty?
107
+ end
108
+
109
+ def blank?(value)
110
+ value.nil? || (value.is_a?(String) && value.strip.empty?)
111
+ end
112
+
113
+ private_class_method :object_paths, :basket_paths, :filled?, :blank?
114
+ end
115
+ end
@@ -54,12 +54,14 @@ module Lunixi
54
54
  ALL = [TEST, LIVE].freeze
55
55
  end
56
56
 
57
+ # Value of a buyerFields entry (name, email, phone, address, identityNumber). Payment providers
58
+ # require the buyer, the identity number and the billing address, so the link page always asks all
59
+ # five fields: REQUIRED is the only value (the gateway answers any other with 400; leaving a field
60
+ # out means REQUIRED).
57
61
  module BuyerFieldRequirement
58
- HIDDEN = 'HIDDEN'
59
- OPTIONAL = 'OPTIONAL'
60
62
  REQUIRED = 'REQUIRED'
61
63
 
62
- ALL = [HIDDEN, OPTIONAL, REQUIRED].freeze
64
+ ALL = [REQUIRED].freeze
63
65
  end
64
66
 
65
67
  module CustomFieldType
@@ -24,24 +24,31 @@ module Lunixi
24
24
  # that include 1; any other list, an empty one included, raises ConfigurationError before sending,
25
25
  # and the list is sent in ascending order.
26
26
  #
27
- # @param body [Hash] gateway body: +amount+ (canonical minor-unit string), +currency+, +orderId+
28
- # 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+
29
34
  # @param idempotency_key [String] the persisted key of this checkout attempt
30
35
  # @return [Hash] Unmodified gateway response envelope; creation is not settlement.
31
36
  def create_intent(body, idempotency_key:)
32
37
  body = payment_body!(body)
33
38
  raise ConfigurationError, 'Intent installments are selected in the checkout form' if body.key?('installment')
34
39
 
40
+ OrderDetails.check!(body, 'A payment intent', checkout_intent: true)
35
41
  client.request('POST', "#{BASE}/intents", body: body, idempotency_key: Client.idempotency_key!(idempotency_key))
36
42
  end
37
43
 
38
44
  # Create a marketplace intent (POST /payments/marketplace/intents, signed): the intent body plus
39
45
  # sellers [{ subDealerId, amountMinor, scenario }] and multiSellerPolicy. Each amountMinor is a
40
46
  # canonical minor-unit string and the sellers must add up to amount; any other total raises
41
- # ConfigurationError before sending.
47
+ # ConfigurationError before sending. The order details follow the rule of create_intent.
42
48
  def create_marketplace_intent(body, idempotency_key:)
43
49
  data = payment_body!(body)
44
50
  sellers!(data['sellers'], data['amount'])
51
+ OrderDetails.check!(data, 'A marketplace payment intent', checkout_intent: true)
45
52
  client.request('POST', "#{BASE}/marketplace/intents", body: data, idempotency_key: Client.idempotency_key!(idempotency_key))
46
53
  end
47
54
 
@@ -64,7 +71,8 @@ module Lunixi
64
71
  end
65
72
 
66
73
  # Verify and store a card for a cardUserKey (POST /payments/cards, signed). Build the body with
67
- # StoreCardRequest or pass a raw Hash; the idempotency key is required.
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).
68
76
  def store_card(body_or_request, idempotency_key: nil)
69
77
  body = CardRules.store_card_body!(body_or_request)
70
78
  client.request('POST', "#{BASE}/cards", body: body, idempotency_key: Client.idempotency_key!(idempotency_key))
@@ -115,11 +123,13 @@ module Lunixi
115
123
  alias list_payment_methods methods
116
124
 
117
125
  # Start a payment with any method from the merchant server (POST /payments/direct/payment). Build
118
- # the body with DirectMethodPaymentRequest or pass a raw Hash; both are checked before sending.
126
+ # the body with DirectMethodPaymentRequest or pass a raw Hash; both are checked before sending,
127
+ # the order details (OrderDetails) included.
119
128
  # When the buyer must act, data.action says how (PaymentActionType); a BANK_TRANSFER payment
120
129
  # answers with a DISPLAY action read by BankTransferInstruction.from_response.
121
130
  def direct_method_payment(body_or_request, idempotency_key: nil)
122
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')
123
133
  client.request('POST', "#{BASE}/direct/payment", body: body, idempotency_key: Client.idempotency_key!(idempotency_key))
124
134
  end
125
135
 
@@ -189,7 +199,9 @@ module Lunixi
189
199
  client.request('POST', "#{BASE}/#{identifier!(payment_id)}/void", idempotency_key: Client.idempotency_key!(idempotency_key))
190
200
  end
191
201
 
192
- # 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.
193
205
  def split(body, idempotency_key:)
194
206
  data = normalize!(body)
195
207
  minor!(data['totalAmount'])
@@ -206,6 +218,7 @@ module Lunixi
206
218
  end
207
219
  raise ConfigurationError, 'Split leg amounts must equal totalAmount' unless total == data['totalAmount'].to_i
208
220
 
221
+ OrderDetails.check!(data, 'A split payment')
209
222
  client.request('POST', "#{BASE}/split", body: data, idempotency_key: Client.idempotency_key!(idempotency_key))
210
223
  end
211
224
 
@@ -5,6 +5,11 @@ module Lunixi
5
5
  # transfer cannot be split payment legs.
6
6
  SPLIT_LEG_BLOCK_FIELDS = %w[mobileBilling wallet promissoryNote].freeze
7
7
 
8
+ # Fields of a split payment body (payments.split). buyer, billingAddress and basketItems are
9
+ # required, shippingAddress when a basket item is PHYSICAL (OrderDetails).
10
+ SPLIT_PAYMENT_FIELDS = %w[totalAmount currency ownerRef legs orderId ownerScope callbackUrl
11
+ buyer billingAddress shippingAddress basketItems].freeze
12
+
8
13
  # Fields of one split leg.
9
14
  SPLIT_PAYMENT_LEG_FIELDS = (%w[paymentMethod cardToken amount force3D installment installmentQuoteToken] + SPLIT_LEG_BLOCK_FIELDS).freeze
10
15
 
@@ -52,7 +52,9 @@ module Lunixi
52
52
  @routes = routes
53
53
  end
54
54
 
55
- # { externalId, email?, name?, phone?, locale?, metadata? }.
55
+ # { externalId, name, surname, email, gsmNumber, identityNumber, billingAddress, billingCity,
56
+ # billingCountry, billingZipCode, billingContactName?, shipping* ? }. Renewals take the buyer from
57
+ # this record; a missing field raises ConfigurationError before sending.
56
58
  def upsert(request, idempotency_key: nil)
57
59
  @routes.data('customers.upsert', body: request, idempotency_key: idempotency_key)
58
60
  end
@@ -41,6 +41,13 @@ module Lunixi
41
41
  ALL = [DRAFT, OPEN, PAID, UNCOLLECTIBLE, VOID].freeze
42
42
  end
43
43
 
44
+ # Errors of customers.upsert: a missing or invalid customer field (details.field).
45
+ module SubscriptionCustomerErrorCode
46
+ FIELD_REQUIRED = 'subscription.customer.field_required'
47
+ FIELD_INVALID = 'subscription.customer.field_invalid'
48
+ ALL = [FIELD_REQUIRED, FIELD_INVALID].freeze
49
+ end
50
+
44
51
  # How invoices are collected (collectionMethod): the saved card is charged each cycle (AUTO_CHARGE,
45
52
  # the default), the invoice is finalised but not charged (SEND_INVOICE), or collection is up to you
46
53
  # (MANUAL).
@@ -157,8 +164,14 @@ module Lunixi
157
164
  'plans.translations' => route.call('GET', "#{subscriptions_base}/plans/:planId/translations"),
158
165
  'plans.upsertTranslation' => route.call('PATCH', "#{subscriptions_base}/plans/:planId/translations/:locale", free: true),
159
166
 
167
+ # Renewals take the buyer from this record: identity and billing details are required (400
168
+ # subscription.customer.field_required).
160
169
  'customers.upsert' => route.call('PUT', "#{subscriptions_base}/customers",
161
- idempotency_key: 'optional', required: %w[externalId], optional: %w[email name phone locale metadata]),
170
+ idempotency_key: 'optional',
171
+ required: %w[externalId name surname email gsmNumber identityNumber billingAddress billingCity billingCountry
172
+ billingZipCode],
173
+ optional: %w[billingContactName shippingContactName shippingAddress shippingCity shippingCountry
174
+ shippingZipCode]),
162
175
  'customers.get' => route.call('GET', "#{subscriptions_base}/customers/:customerId"),
163
176
  'customers.getByExternalId' => route.call('GET', "#{subscriptions_base}/customers/by-external/:externalId"),
164
177
  'customers.list' => route.call('GET', "#{subscriptions_base}/customers", query: %w[search includeArchived] + cursor_query),
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lunixi
4
- VERSION = '1.3.1'
4
+ VERSION = '2.0.2'
5
5
  end
@@ -258,9 +258,14 @@ module Lunixi
258
258
  end
259
259
 
260
260
  # Starts a card top-up. Render checkoutFormContent (or follow redirectUrl / threeDsHtml); the wallet is
261
- # credited when the payment completes (wallet.topup.completed).
261
+ # credited when the payment completes (wallet.topup.completed). buyer and billingAddress are required
262
+ # (OrderDetails, no basket), shippingAddress is optional; a missing field raises ConfigurationError
263
+ # naming its path before sending.
262
264
  def start_card(request, idempotency_key: nil)
263
- @invoker.data('startCardTopup', body: request, idempotency_key: idempotency_key)
265
+ route = WALLET_ROUTES.fetch('startCardTopup')
266
+ body = RouteRequest.fields!(request || {}, route['required'], route['optional'], 'startCardTopup')
267
+ OrderDetails.check!(body, 'A wallet card top-up', basket: false)
268
+ @invoker.data('startCardTopup', body: body, idempotency_key: idempotency_key)
264
269
  end
265
270
 
266
271
  # { operation, history }
@@ -82,9 +82,12 @@ module Lunixi
82
82
  'getOperation' => route.call('GET', '/operations/:operationId', idempotency_key: false),
83
83
  'getOperationReceipt' => route.call('GET', '/operations/:operationId/receipt', idempotency_key: false),
84
84
 
85
+ # The payment provider requires the buyer (buyer.ip: the user's browser IP) and the billing address;
86
+ # a missing field is 400 payment.order.field_required with the paths in details.fields.
85
87
  'startCardTopup' => route.call('POST', '/topups/card',
86
- idempotency_key: true, required: %w[creditWalletAccountId amount currency],
87
- optional: %w[fundingMerchantId savedCardUserKey savedCardToken savedConsumerToken savedPublicCardStorageToken returnUrl]),
88
+ idempotency_key: true, required: %w[creditWalletAccountId amount currency buyer billingAddress],
89
+ optional: %w[fundingMerchantId savedCardUserKey savedCardToken savedConsumerToken savedPublicCardStorageToken
90
+ returnUrl shippingAddress]),
88
91
  'getTopup' => route.call('GET', '/topups/:operationId', idempotency_key: false),
89
92
  # The gateway DTO marks approverPrincipal optional, but the wallet service refuses the refund without
90
93
  # it (400 WALLET_VALIDATION): it is required in practice.
data/lib/lunixi.rb CHANGED
@@ -9,6 +9,7 @@ require_relative 'lunixi/product_category'
9
9
  require_relative 'lunixi/signer'
10
10
  require_relative 'lunixi/transport'
11
11
  require_relative 'lunixi/payment_values'
12
+ require_relative 'lunixi/order_details'
12
13
  require_relative 'lunixi/method_fields'
13
14
  require_relative 'lunixi/promissory_note'
14
15
  require_relative 'lunixi/bank_transfer'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lunixi-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lunixi
@@ -134,6 +134,7 @@ files:
134
134
  - lib/lunixi/marketplace_values.rb
135
135
  - lib/lunixi/method_fields.rb
136
136
  - lib/lunixi/money.rb
137
+ - lib/lunixi/order_details.rb
137
138
  - lib/lunixi/payment_link_filters.rb
138
139
  - lib/lunixi/payment_link_image_rules.rb
139
140
  - lib/lunixi/payment_link_rules.rb