commit fce333a3ca5fe640bcf11126245ef42e99f800de
parent 95f6b5cad01ef09f152fb5771c151e5d263866bf
Author: Florian Dold <dold@taler.net>
Date: Sun, 9 Aug 2026 15:45:04 +0200
Fix merchant product codec fields
Diffstat:
2 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/packages/taler-util/src/types-taler-merchant.ts b/packages/taler-util/src/types-taler-merchant.ts
@@ -4274,15 +4274,28 @@ export interface ProductSold {
// Map from IETF BCP 47 language tags to localized descriptions.
description_i18n?: { [lang_tag: string]: string };
- // The number of units of the product to deliver to the customer.
+ // Legacy integer portion of the quantity to deliver. Defaults to 1 if not
+ // specified.
quantity?: Integer;
+ // Preferred quantity string using "<integer>[.<fraction>]" syntax with up
+ // to six fractional digits. Since API version **v25**.
+ unit_quantity?: DecimalQuantity;
+
// Unit in which the product is measured (liters, kilograms, packages, etc.).
unit?: string;
- // The price of the product; this is the total price for quantity times unit of this product.
+ // The price of the product; this is the total price for quantity times unit
+ // of this product. Deprecated since API version **v25**.
price?: AmountString;
+ // Price of unit_quantity units of the product in various currencies. Since
+ // API version **v25**.
+ prices?: AmountString[];
+
+ // Whether prices are net prices. Since protocol **vTAXES**.
+ prices_are_net: boolean;
+
// An optional base64-encoded product image.
image?: ImageDataUrl;
@@ -5124,8 +5137,11 @@ export const codecForProductSold = (): Codec<ProductSold> =>
codecOptional(codecForInternationalizedString()),
)
.property("quantity", codecOptional(codecForNumber()))
+ .property("unit_quantity", codecOptional(codecForString()))
.property("unit", codecOptional(codecForString()))
.property("price", codecOptional(codecForAmountString()))
+ .property("prices", codecOptional(codecForList(codecForAmountString())))
+ .property("prices_are_net", codecForBoolean())
.property("image", codecOptional(codecForString()))
.property("taxes", codecOptional(codecForList(codecForTax())))
.property("delivery_date", codecOptional(codecForTimestamp))
diff --git a/packages/taler-util/src/types.test.ts b/packages/taler-util/src/types.test.ts
@@ -38,14 +38,25 @@ test("contract terms validation", (t) => {
pay_deadline: { t_s: 42 },
wire_transfer_deadline: { t_s: 42 },
merchant_base_url: "https://example.com/pay",
- products: [],
+ products: [
+ {
+ description: "Coffee",
+ unit_quantity: "0.25",
+ unit: "kg",
+ prices: ["EUR:2.5", "USD:3"],
+ prices_are_net: false,
+ },
+ ],
refund_deadline: { t_s: 42 },
summary: "hello",
timestamp: { t_s: 42 },
wire_method: "test",
} satisfies MerchantContractTerms;
- codecForMerchantContractTerms().decode(c);
+ const decoded = codecForMerchantContractTerms().decode(c);
+ assert.strictEqual(decoded.products?.[0]?.unit_quantity, "0.25");
+ assert.deepStrictEqual(decoded.products?.[0]?.prices, ["EUR:2.5", "USD:3"]);
+ assert.strictEqual(decoded.products?.[0]?.prices_are_net, false);
const c1 = JSON.parse(JSON.stringify(c));
c1.pay_deadline = "foo";