From dbbafc284f61561d62092db595f1e9eb38b9fdd6 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 13 May 2024 09:19:36 -0300 Subject: fix v15 --- packages/taler-util/src/http-client/merchant.ts | 29 ++++++- packages/taler-util/src/http-client/types.ts | 106 ++++++++++++++++++++++-- 2 files changed, 127 insertions(+), 8 deletions(-) (limited to 'packages/taler-util') diff --git a/packages/taler-util/src/http-client/merchant.ts b/packages/taler-util/src/http-client/merchant.ts index d682dcfa0..cad2c839e 100644 --- a/packages/taler-util/src/http-client/merchant.ts +++ b/packages/taler-util/src/http-client/merchant.ts @@ -32,6 +32,7 @@ import { codecForInventorySummaryResponse, codecForMerchantConfig, codecForMerchantOrderPrivateStatusResponse, + codecForMerchantPosProductDetail, codecForMerchantRefundResponse, codecForOrderHistory, codecForOtpDeviceDetails, @@ -122,7 +123,7 @@ export enum TalerMerchantManagementCacheEviction { * Uses libtool's current:revision:age versioning. */ export class TalerMerchantInstanceHttpClient { - public readonly PROTOCOL_VERSION = "10:0:6"; + public readonly PROTOCOL_VERSION = "15:0:0"; readonly httpLib: HttpRequestLibrary; readonly cacheEvictor: CacheEvictor; @@ -858,6 +859,32 @@ export class TalerMerchantInstanceHttpClient { } } + /** + * https://docs.taler.net/core/api-merchant.html#get-[-instances-$INSTANCE]-private-pos + */ + async getPointOfSaleInventory(token: AccessToken | undefined) { + const url = new URL(`private/pos`, this.baseUrl); + + const headers: Record = {}; + if (token) { + headers.Authorization = makeBearerTokenAuthHeader(token); + } + const resp = await this.httpLib.fetch(url.href, { + method: "GET", + headers, + }); + + switch (resp.status) { + case HttpStatusCode.Ok: + return opSuccessFromHttp(resp, codecForMerchantPosProductDetail()); + case HttpStatusCode.NotFound: + return opKnownHttpFailure(resp.status, resp); + default: + return opUnknownFailure(resp, await readTalerErrorResponse(resp)); + } + + } + /** * https://docs.taler.net/core/api-merchant.html#get-[-instances-$INSTANCE]-private-products-$PRODUCT_ID */ diff --git a/packages/taler-util/src/http-client/types.ts b/packages/taler-util/src/http-client/types.ts index c0004a218..fe8a2ff51 100644 --- a/packages/taler-util/src/http-client/types.ts +++ b/packages/taler-util/src/http-client/types.ts @@ -603,6 +603,37 @@ export const codecForInventoryEntry = .property("product_serial", codecForNumber()) .build("TalerMerchantApi.InventoryEntry"); +export const codecForMerchantPosProductDetail = + (): Codec => + buildCodecForObject() + .property("product_serial", codecForNumber()) + .property("product_id", codecOptional(codecForString())) + .property("categories", codecForList(codecForNumber())) + .property("description", codecForString()) + .property("description_i18n", codecForInternationalizedString()) + .property("unit", codecForString()) + .property("price", codecForAmountString()) + .property("image", codecForString()) + .property("taxes", codecOptional(codecForList(codecForTax()))) + .property("total_stock", codecForNumber()) + .property("minimum_age", codecOptional(codecForNumber())) + .build("TalerMerchantApi.MerchantPosProductDetail"); + +export const codecForMerchantCategory = + (): Codec => + buildCodecForObject() + .property("id", codecForNumber()) + .property("name", codecForString()) + .property("name_i18n", codecForInternationalizedString()) + .build("TalerMerchantApi.MerchantCategory"); + +export const codecForFullInventoryDetailsResponse = + (): Codec => + buildCodecForObject() + .property("categories", codecForList(codecForMerchantCategory())) + .property("products", codecForList(codecForMerchantPosProductDetail())) + .build("TalerMerchantApi.FullInventoryDetailsResponse"); + export const codecForProductDetail = (): Codec => buildCodecForObject() @@ -611,9 +642,9 @@ export const codecForProductDetail = .property("unit", codecForString()) .property("price", codecForAmountString()) .property("image", codecForString()) - .property("taxes", codecForList(codecForTax())) - .property("address", codecForLocation()) - .property("next_restock", codecForTimestamp) + .property("taxes", codecOptional(codecForList(codecForTax()))) + .property("address", codecOptional(codecForLocation())) + .property("next_restock", codecOptional(codecForTimestamp)) .property("total_stock", codecForNumber()) .property("total_sold", codecForNumber()) .property("total_lost", codecForNumber()) @@ -2394,7 +2425,7 @@ export namespace TalerCorebankApi { // Is 2FA enabled and what channel is used for challenges? tan_channel?: TanChannel; - + // Current status of the account // active: the account can be used // deleted: the account has been deleted but is retained for compliance @@ -4068,6 +4099,68 @@ export namespace TalerMerchantApi { product_serial: Integer; } + export interface FullInventoryDetailsResponse { + // List of products that are present in the inventory. + products: MerchantPosProductDetail[]; + + // List of categories in the inventory. + categories: MerchantCategory[]; + } + + export interface MerchantPosProductDetail { + // A unique numeric ID of the product + product_serial: number; + + // A merchant-internal unique identifier for the product + product_id?: string; + + // A list of category IDs this product belongs to. + // Typically, a product only belongs to one category, but more than one is supported. + categories: number[]; + + // Human-readable product description. + description: string; + + // Map from IETF BCP 47 language tags to localized descriptions. + description_i18n: { [lang_tag: string]: string }; + + // Unit in which the product is measured (liters, kilograms, packages, etc.). + unit: string; + + // The price for one unit of the product. Zero is used + // to imply that this product is not sold separately, or + // that the price is not fixed, and must be supplied by the + // front-end. If non-zero, this price MUST include applicable + // taxes. + price: AmountString; + + // An optional base64-encoded product image. + image?: ImageDataUrl; + + // A list of taxes paid by the merchant for one unit of this product. + taxes?: Tax[]; + + // Number of units of the product in stock in sum in total, + // including all existing sales ever. Given in product-specific + // units. + // Optional, if missing treat as "infinite". + total_stock?: Integer; + + // Minimum age buyer must have (in years). + minimum_age?: Integer; + } + + export interface MerchantCategory { + // A unique numeric ID of the category + id: number; + + // The name of the category. This will be shown to users and used in the order summary. + name: string; + + // Map from IETF BCP 47 language tags to localized names + name_i18n?: { [lang_tag: string]: string }; + } + export interface ProductDetail { // Human-readable product description. description: string; @@ -4089,7 +4182,7 @@ export namespace TalerMerchantApi { image: ImageDataUrl; // A list of taxes paid by the merchant for one unit of this product. - taxes: Tax[]; + taxes?: Tax[]; // Number of units of the product in stock in sum in total, // including all existing sales ever. Given in product-specific @@ -4104,7 +4197,7 @@ export namespace TalerMerchantApi { total_lost: Integer; // Identifies where the product is in stock. - address: Location; + address?: Location; // Identifies when we expect the next restocking to happen. next_restock?: Timestamp; @@ -4464,7 +4557,6 @@ export namespace TalerMerchantApi { confirmed?: boolean; } - export interface OtpDeviceAddDetails { // Device ID to use. otp_device_id: string; -- cgit v1.2.3