paymos 1.6.1 → 1.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7bfc8552db30245323684620dc4db5b8e206de6c2cae9eddeab9f80f68c583a7
4
- data.tar.gz: eb8c7eace8288653d5beb401e498c279124891fbe0f8a1f448c4b845644c6b7d
3
+ metadata.gz: b4b2825ca7de83a212ccb05ee60ca1a00456d4e8db3a87517a3ec9f48601a578
4
+ data.tar.gz: e997c75cd1c6f4ba28856d7d0028c233238f62dbc67d3fe1218cd7094ea9a764
5
5
  SHA512:
6
- metadata.gz: 6200473cb3bb0d8f98403bfa9ed512e27e042ea33cfee95cbdfd09662e323bc3a388931caeda284501832c446b6f9aa937338a6fcaf4098aa945f3732bdbb9d0
7
- data.tar.gz: 53c7e6389ad62f2cc2bc59242c41e49fb096bb2ec565789ea2608e74f0b79decce504be7ec0719f97a1485428879ffa23a561fe5dabae10fc16d038c3a6b3cff
6
+ metadata.gz: a5400d64070f388f4aa881655cc0e3bd7bec28873e74e9464071415e4303a9363853f9462c14772b547f6467a34add12cda5858c963018998cd81161c1948459
7
+ data.tar.gz: '0364786fcc8214ae4d109feab9f8d9b363efff7810cbfa2514f1b07b707865ded95e6971b043eeb2be33c99255a562010b0969a4b360b5f1368fbe632a771051'
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [1.7.0] - 2026-11-16
6
+
7
+ - docs(sdk,drupal): document invoice products[] and update OpenAPI snapshot
8
+ - feat(sdk): support invoice products in Ruby SDK and RBS types (8.3)
9
+ - feat(sdk): add products wire conformance fixtures (7.1)
10
+
5
11
  ## [1.6.1] - 2026-11-13
6
12
 
7
13
  - fix(plugins,publicweb): SDK webhook credit recipes, CMS recovery, redirects and CSP logs (audit 2026-11-13)
data/README.md CHANGED
@@ -16,6 +16,7 @@ paymos = Paymos::Client.new(
16
16
  api_secret: ENV.fetch("PAYMOS_API_SECRET")
17
17
  )
18
18
 
19
+ # Compatible amount-only call (products omitted or nil)
19
20
  invoice = paymos.invoices.create(
20
21
  project_id: "prj_...",
21
22
  amount: "10.00",
@@ -28,7 +29,49 @@ end
28
29
  balances = paymos.balances.get
29
30
  ```
30
31
 
31
- Responses are immutable Ruby objects with documented RBS signatures; request
32
+ ### Product line items (`products[]`)
33
+
34
+ Pass optional `products:` (`1..50` `Paymos::InvoiceProduct` instances or Hashes) to display purchase context on hosted checkout, or omit `products:` / pass `products: nil` for a compatible `amount-only` invoice. Each `Paymos::InvoiceProduct` requires `title:` (<= 200 Unicode scalar values), positive integer `quantity:`, and decimal string `unit_amount:` (in the invoice currency); `description:` (plain text, <= 2000 scalars) and `image_url:` (HTTPS URL, <= 2048 scalars) are optional keywords and are omitted on the wire when `nil`.
35
+
36
+ ```ruby
37
+ # 1-item invoice with optional description and image_url
38
+ studio_pro = Paymos::InvoiceProduct.new(
39
+ title: "Studio Pro",
40
+ description: "One-month access",
41
+ image_url: "https://shop.example/images/studio-pro.webp",
42
+ quantity: 2,
43
+ unit_amount: "24.50"
44
+ )
45
+ single_invoice = paymos.invoices.create(
46
+ project_id: "prj_...",
47
+ amount: "47.00",
48
+ currency: "USD",
49
+ external_order_id: "order_product_single",
50
+ products: [studio_pro]
51
+ )
52
+
53
+ # Multi-item cart including a minimal 3-field item (no description / image_url)
54
+ cart_invoice = paymos.invoices.create(
55
+ project_id: "prj_...",
56
+ amount: "59.00",
57
+ currency: "USD",
58
+ external_order_id: "order_product_multi",
59
+ products: [
60
+ studio_pro,
61
+ Paymos::InvoiceProduct.new(title: "Priority Support", quantity: 1, unit_amount: "12.00")
62
+ ]
63
+ )
64
+
65
+ (cart_invoice.order.products || []).each do |item|
66
+ puts "#{item.title} x#{item.quantity} @ #{item.unit_amount}"
67
+ end
68
+ ```
69
+
70
+ - **Authoritative `amount`:** `amount` is the exact order total and is never recomputed from `sum(quantity * unit_amount)`.
71
+ - **First-success replay:** the first successful create freezes `order.products` on the invoice. Replaying the same `external_order_id` with unchanged `(amount, currency, network)` returns HTTP 200 with the original `Paymos::Invoice` and `order.products`, even if `products` changed; changing `(amount, currency, network)` raises `Paymos::ConflictError` (`409 invoice_idempotency_conflict`). Legacy and `amount-only` invoices return `order.products == nil`.
72
+ - **Image/product fallback & webhooks:** invoice creation stores `image_url` without fetching it server-side; if the buyer's browser fails to load an image or an item omits `description`/`image_url`, checkout hides only the missing media/description and keeps payment active. Signed invoice webhooks omit `products`.
73
+
74
+ Responses are immutable Ruby objects with documented RBS signatures (`sig/paymos.rbs`); request
32
75
  keywords remain idiomatic `snake_case` and are converted directly to the Paymos
33
76
  wire contract.
34
77
 
@@ -1133,6 +1133,174 @@
1133
1133
  }
1134
1134
  ]
1135
1135
  }
1136
+ },
1137
+ "invoices": {
1138
+ "authentication": "Payment key with verified HMAC",
1139
+ "create_single_product": {
1140
+ "method": "POST",
1141
+ "path": "/v1/invoices",
1142
+ "body": {
1143
+ "project_id": "prj_1",
1144
+ "amount": "47.00",
1145
+ "currency": "USD",
1146
+ "external_order_id": "order-product-single",
1147
+ "products": [
1148
+ {
1149
+ "title": "Studio Pro",
1150
+ "description": "One-month access",
1151
+ "image_url": "https://shop.example/images/studio-pro.webp",
1152
+ "quantity": 2,
1153
+ "unit_amount": "24.50"
1154
+ }
1155
+ ]
1156
+ },
1157
+ "response": {
1158
+ "invoice_id": "inv_prod_1",
1159
+ "project_id": "prj_1",
1160
+ "status": "awaiting_client",
1161
+ "is_final": false,
1162
+ "is_test": true,
1163
+ "payment_url": "https://pay.paymos.io/i/inv_prod_1",
1164
+ "order": {
1165
+ "external_id": "order-product-single",
1166
+ "amount": "47.00",
1167
+ "currency": "USD",
1168
+ "products": [
1169
+ {
1170
+ "title": "Studio Pro",
1171
+ "description": "One-month access",
1172
+ "image_url": "https://shop.example/images/studio-pro.webp",
1173
+ "quantity": 2,
1174
+ "unit_amount": "24.50"
1175
+ }
1176
+ ]
1177
+ },
1178
+ "created_at": 1700000000,
1179
+ "updated_at": 1700000000
1180
+ }
1181
+ },
1182
+ "create_multi_product": {
1183
+ "method": "POST",
1184
+ "path": "/v1/invoices",
1185
+ "body": {
1186
+ "project_id": "prj_1",
1187
+ "amount": "59.00",
1188
+ "currency": "USD",
1189
+ "external_order_id": "order-product-multi",
1190
+ "products": [
1191
+ {
1192
+ "title": "Studio Pro",
1193
+ "description": "One-month access",
1194
+ "image_url": "https://shop.example/images/studio-pro.webp",
1195
+ "quantity": 2,
1196
+ "unit_amount": "24.50"
1197
+ },
1198
+ {
1199
+ "title": "Priority Support",
1200
+ "quantity": 1,
1201
+ "unit_amount": "12.00"
1202
+ }
1203
+ ]
1204
+ },
1205
+ "response": {
1206
+ "invoice_id": "inv_prod_2",
1207
+ "project_id": "prj_1",
1208
+ "status": "awaiting_client",
1209
+ "is_final": false,
1210
+ "is_test": true,
1211
+ "payment_url": "https://pay.paymos.io/i/inv_prod_2",
1212
+ "order": {
1213
+ "external_id": "order-product-multi",
1214
+ "amount": "59.00",
1215
+ "currency": "USD",
1216
+ "products": [
1217
+ {
1218
+ "title": "Studio Pro",
1219
+ "description": "One-month access",
1220
+ "image_url": "https://shop.example/images/studio-pro.webp",
1221
+ "quantity": 2,
1222
+ "unit_amount": "24.50"
1223
+ },
1224
+ {
1225
+ "title": "Priority Support",
1226
+ "quantity": 1,
1227
+ "unit_amount": "12.00"
1228
+ }
1229
+ ]
1230
+ },
1231
+ "created_at": 1700000000,
1232
+ "updated_at": 1700000000
1233
+ }
1234
+ },
1235
+ "legacy_without_products": {
1236
+ "method": "POST",
1237
+ "path": "/v1/invoices",
1238
+ "body": {
1239
+ "project_id": "prj_1",
1240
+ "amount": "30.00",
1241
+ "currency": "USD",
1242
+ "external_order_id": "order-legacy-1"
1243
+ },
1244
+ "response": {
1245
+ "invoice_id": "inv_legacy_1",
1246
+ "project_id": "prj_1",
1247
+ "status": "awaiting_client",
1248
+ "is_final": false,
1249
+ "is_test": true,
1250
+ "payment_url": "https://pay.paymos.io/i/inv_legacy_1",
1251
+ "order": {
1252
+ "external_id": "order-legacy-1",
1253
+ "amount": "30.00",
1254
+ "currency": "USD"
1255
+ },
1256
+ "created_at": 1700000000,
1257
+ "updated_at": 1700000000
1258
+ }
1259
+ },
1260
+ "null_products": {
1261
+ "method": "POST",
1262
+ "path": "/v1/invoices",
1263
+ "body": {
1264
+ "project_id": "prj_1",
1265
+ "amount": "30.00",
1266
+ "currency": "USD",
1267
+ "external_order_id": "order-null-products-1",
1268
+ "products": null
1269
+ },
1270
+ "response": {
1271
+ "invoice_id": "inv_null_1",
1272
+ "project_id": "prj_1",
1273
+ "status": "awaiting_client",
1274
+ "is_final": false,
1275
+ "is_test": true,
1276
+ "payment_url": "https://pay.paymos.io/i/inv_null_1",
1277
+ "order": {
1278
+ "external_id": "order-null-products-1",
1279
+ "amount": "30.00",
1280
+ "currency": "USD"
1281
+ },
1282
+ "created_at": 1700000000,
1283
+ "updated_at": 1700000000
1284
+ }
1285
+ },
1286
+ "products_wire": {
1287
+ "min_items": 1,
1288
+ "max_items": 50,
1289
+ "required_item_fields": [
1290
+ "title",
1291
+ "quantity",
1292
+ "unit_amount"
1293
+ ],
1294
+ "optional_item_fields": [
1295
+ "description",
1296
+ "image_url"
1297
+ ],
1298
+ "omit_null_optional_item_fields": true,
1299
+ "quantity_type": "integer",
1300
+ "unit_amount_type": "decimal string",
1301
+ "amount_independent_of_products_sum": true,
1302
+ "excluded_from_webhooks": true
1303
+ }
1136
1304
  }
1137
1305
  }
1138
1306
  }
data/lib/paymos/client.rb CHANGED
@@ -211,7 +211,7 @@ module Paymos
211
211
 
212
212
  class Invoices < Resource
213
213
  def create(project_id:, amount:, currency:, external_order_id:, network: nil,
214
- customer_fee_percent: nil, client_id: nil)
214
+ customer_fee_percent: nil, client_id: nil, products: nil)
215
215
  required_keywords(project_id:, amount:, currency:, external_order_id:)
216
216
  if !customer_fee_percent.nil? && !(customer_fee_percent.is_a?(Integer) && customer_fee_percent.between?(0, 100))
217
217
  raise ArgumentError, 'customer_fee_percent must be between 0 and 100'
@@ -219,6 +219,7 @@ module Paymos
219
219
 
220
220
  payload = { project_id:, amount:, currency:, external_order_id:, network:,
221
221
  customer_fee_percent:, client_id: }.compact
222
+ payload[:products] = serialize_products(products) unless products.nil?
222
223
  Invoice.from(@client.request('POST', '/v1/invoices', payload:))
223
224
  end
224
225
 
@@ -261,6 +262,18 @@ module Paymos
261
262
  missing = values.select { |_name, value| !value.is_a?(String) || value.strip.empty? }.keys
262
263
  raise ArgumentError, "Required values are missing: #{missing.join(', ')}" unless missing.empty?
263
264
  end
265
+
266
+ def serialize_products(products)
267
+ raise ArgumentError, 'products must be an array' unless products.is_a?(Array)
268
+
269
+ products.map do |item|
270
+ raise ArgumentError, 'products items must respond to to_h' unless item.respond_to?(:to_h)
271
+
272
+ item.to_h.transform_keys(&:to_sym).reject do |key, value|
273
+ %i[description image_url].include?(key) && value.nil?
274
+ end
275
+ end
276
+ end
264
277
  end
265
278
 
266
279
  class Withdrawals < Resource
data/lib/paymos/models.rb CHANGED
@@ -79,9 +79,28 @@ module Paymos
79
79
  end
80
80
  end
81
81
 
82
+ class InvoiceProduct < Model
83
+ fields :title, :description, :image_url, :quantity, :unit_amount,
84
+ required: %i[title quantity unit_amount]
85
+
86
+ def to_h
87
+ super.reject { |key, value| %i[description image_url].include?(key) && value.nil? }
88
+ end
89
+ end
90
+
82
91
  class Order < Model
83
- fields :external_id, :client_id, :amount, :currency, :network,
92
+ fields :external_id, :client_id, :amount, :currency, :network, :products,
84
93
  required: %i[external_id amount currency]
94
+
95
+ def self.from(value)
96
+ model = super
97
+ return model if model.products.nil?
98
+
99
+ raise Error, 'Paymos API order products must be an array' unless model.products.is_a?(Array)
100
+
101
+ products = model.products.map { |item| InvoiceProduct.from(item) }
102
+ new(**model.to_h, products: products)
103
+ end
85
104
  end
86
105
 
87
106
  class Transfer < Model
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Paymos
4
- VERSION = '1.6.1'
4
+ VERSION = '1.7.0'
5
5
  end
data/sig/paymos.rbs CHANGED
@@ -73,12 +73,23 @@ module Paymos
73
73
  def to_h: () -> Hash[Symbol, untyped]
74
74
  end
75
75
 
76
+ class InvoiceProduct < Model
77
+ attr_reader title: String
78
+ attr_reader description: String?
79
+ attr_reader image_url: String?
80
+ attr_reader quantity: Integer
81
+ attr_reader unit_amount: String
82
+
83
+ def initialize: (title: String, quantity: Integer, unit_amount: String, ?description: String?, ?image_url: String?) -> void
84
+ end
85
+
76
86
  class Order < Model
77
87
  attr_reader external_id: String
78
88
  attr_reader client_id: String?
79
89
  attr_reader amount: String
80
90
  attr_reader currency: String
81
91
  attr_reader network: String?
92
+ attr_reader products: Array[InvoiceProduct]?
82
93
  end
83
94
 
84
95
  class Transfer < Model
@@ -280,7 +291,7 @@ module Paymos
280
291
  end
281
292
 
282
293
  class Invoices
283
- def create: (project_id: String, amount: String, currency: String, external_order_id: String, ?network: String?, ?customer_fee_percent: Integer?, ?client_id: String?) -> Invoice
294
+ def create: (project_id: String, amount: String, currency: String, external_order_id: String, ?network: String?, ?customer_fee_percent: Integer?, ?client_id: String?, ?products: Array[InvoiceProduct | Hash[Symbol | String, untyped]]?) -> Invoice
284
295
  def get: (String invoice_id) -> Invoice
285
296
  def list: (?limit: Integer?, ?cursor: String?, ?status: String | Array[String]?, ?external_order_id: String?, ?project_id: String?, ?created_from: Integer?, ?created_to: Integer?) -> Page[InvoiceListItem]
286
297
  def cancel: (String invoice_id, reason: String) -> Invoice
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paymos
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paymos Labs