taler-docs

Documentation for GNU Taler components, APIs and protocols
Log | Files | Refs | README | LICENSE

post-private-products.rst (6529B)


      1 .. http:post:: [/instances/$INSTANCE]/private/products
      2 
      3   This is used to add a product to the inventory.
      4 
      5   **Required permission:** ``products-write``
      6 
      7   **Request:**
      8 
      9   The request must be a `ProductAddDetailRequest`.
     10 
     11   **Response:**
     12 
     13   :http:statuscode:`204 No content`:
     14     The backend has successfully expanded the inventory.
     15   :http:statuscode:`400 Bad Request`:
     16     The request body is malformed.
     17   :http:statuscode:`404 Not found`:
     18     The instance, category, product group or money pot specified are
     19     unknown. Possible error ``code`` values are thus:
     20     ``TALER_EC_MERCHANT_GENERIC_INSTANCE_UNKNOWN`` (instance unknown),
     21     ``TALER_EC_MERCHANT_GENERIC_PRODUCT_GROUP_UNKNOWN`` (product group unknown)
     22     ``TALER_EC_MERCHANT_GENERIC_MONEY_POT_UNKNOWN`` (money pot unknown),
     23     ``TALER_EC_MERCHANT_GENERIC_CATEGORY_UNKNOWN``
     24     (category unknown, specific category is given in the details).
     25 
     26   :http:statuscode:`409 Conflict`:
     27     The backend already knows a product with this product ID,
     28     but with different details. Returned with a ``code`` of
     29     ``TALER_EC_MERCHANT_PRIVATE_POST_PRODUCTS_CONFLICT_PRODUCT_EXISTS``.
     30   :http:statuscode:`500 Internal Server Error`:
     31     The server experienced an internal failure.
     32     Returned with ``TALER_EC_GENERIC_DB_STORE_FAILED``.
     33 
     34   **Details:**
     35 
     36   .. ts:def:: ProductAddDetailRequest
     37 
     38     interface ProductAddDetailRequest {
     39 
     40       // Product ID to use.
     41       product_id: string;
     42 
     43       // Human-readable product name.
     44       // Since API version **v20**.  Optional only for
     45       // backwards-compatibility, should be considered mandatory
     46       // moving forward!
     47       product_name?: string;
     48 
     49       // Human-readable product description.
     50       description: string;
     51 
     52       // Map from IETF BCP 47 language tags to localized descriptions.
     53       description_i18n?: { [lang_tag: string]: string };
     54 
     55       // Categories into which the product belongs.
     56       // Used in the POS-endpoint.
     57       // Since API version **v16**.
     58       categories?: Integer[];
     59 
     60       // Unit in which the product is measured (liters, kilograms, packages, etc.).
     61       unit: string;
     62 
     63       // Optional override to control whether fractional quantities are permitted.
     64       // Defaults to the policy implied by ``unit``.
     65       unit_allow_fraction?: boolean;
     66 
     67       // Override for the fractional precision level (0-6). Only relevant if
     68       // ``unit_allow_fraction`` is true. Defaults come from ``unit``.
     69       unit_precision_level?: Integer;
     70 
     71       // Preferred way to express inventory counts using "<integer>[.<fraction>]" syntax.
     72       // Use "-1" for unlimited stock. Required unless ``total_stock`` is provided.
     73       unit_total_stock?: DecimalQuantity;
     74 
     75       // Legacy stock counter. Deprecated, use ``unit_total_stock`` instead.
     76       // Still required when ``unit_total_stock`` is omitted.
     77       total_stock?: Integer;
     78 
     79       // Preferred way to express the per-unit price of the product. Supply at least one entry;
     80       // the first entry must match ``price``.
     81       // The price given MUST include applicable taxes if ``price_is_net``
     82       // is false, and MUST exclude applicable taxes if ``price_is_net``
     83       // is true.
     84       // Zero implies that the product is not sold separately or that the price must be supplied
     85       // by the frontend.
     86       // Each entry must use a distinct currency.
     87       // Since API version **v25**.
     88       // Currency uniqueness enforced since protocol **v25**.
     89       unit_price?: Amount[];
     90 
     91       // True if the price(s) given are a net prices, false if they are
     92       // gross prices.
     93       // Since protocol **vTAXES**.
     94       price_is_net?: boolean;
     95 
     96       // Legacy price field.
     97       // Deprecated since **v25**;
     98       // when present it must match the first element of ``unit_price``.
     99       price?: Amount;
    100 
    101       // An optional base64-encoded product image.
    102       image?: ImageDataUrl;
    103 
    104       // A list of taxes paid by the merchant for one unit of this product.
    105       taxes?: Tax[];
    106 
    107       // Identifies where the product is in stock.
    108       address?: Location;
    109 
    110       // Identifies when we expect the next restocking to happen.
    111       next_restock?: Timestamp;
    112 
    113       // Minimum age buyer must have (in years). Default is 0.
    114       minimum_age?: Integer;
    115 
    116       // Product group the product belongs to. 0 and missing both
    117       // means default.
    118       // Since **v25**.
    119       product_group_id?: Integer;
    120 
    121       // Money pot revenue on the product should be accounted in.
    122       // 0 and missing both mean no money pot (revenue accounted
    123       // in money pot of the overall order or not at all).
    124       // Since **v25**.
    125       money_pot_id?: Integer;
    126 
    127     }
    128 
    129   Clients SHOULD migrate to the new ``unit_*`` fields and treat ``total_stock`` and ``price``
    130   as deprecated compatibility shims. If both the legacy and the new representation are supplied,
    131   their values must match. Omitting both ``unit_total_stock`` and ``total_stock`` (or both
    132   ``unit_price`` and ``price``) results in a ``400 Bad Request``. When only ``price`` is given,
    133   the backend treats it as a one-element ``unit_price`` array.
    134 
    135   ``unit_total_stock`` uses a fixed-point decimal string in the form ``INTEGER[.FRACTION]`` with
    136   at most six fractional digits. Scientific notation or special values such as ``NaN`` are not
    137   accepted. Supply ``"-1"`` to represent unlimited stock. See
    138   :ref:`DecimalQuantity <decimal-quantity>`.
    139 
    140   Fractional behaviour defaults to the value of ``unit``. The backend disables fractions for
    141   ``Piece``, ``Set``, ``Custom``, ``WeightUnitMg`` and ``SizeUnitMm``. Other predefined units
    142   allow fractional quantities with the following default precision levels:
    143 
    144   - Precision ``1``: ``WeightUnitG``, ``SizeUnitCm``, ``SurfaceUnitMm2``, ``VolumeUnitMm3``.
    145   - Precision ``2``: ``WeightUnitOunce``, ``SizeUnitInch``, ``SurfaceUnitCm2``,
    146     ``VolumeUnitInch3``, ``VolumeUnitOunce``, ``TimeUnitHour``, ``TimeUnitMonth``.
    147   - Precision ``3``: ``WeightUnitTon``, ``WeightUnitKg``, ``WeightUnitPound``, ``SizeUnitM``,
    148     ``SizeUnitDm``, ``SizeUnitFoot``, ``SurfaceUnitDm2``, ``SurfaceUnitFoot2``, ``VolumeUnitCm3``,
    149     ``VolumeUnitLitre``, ``VolumeUnitGallon``, ``TimeUnitSecond``, ``TimeUnitMinute``,
    150     ``TimeUnitDay``, ``TimeUnitWeek``.
    151   - Precision ``4``: ``SurfaceUnitM2``, ``SurfaceUnitInch2``, ``TimeUnitYear``.
    152   - Precision ``5``: ``VolumeUnitDm3``, ``VolumeUnitFoot3``.
    153   - Precision ``6``: ``VolumeUnitM3``.
    154 
    155   Integrations can override these defaults by explicitly setting ``unit_allow_fraction`` and/or
    156   ``unit_precision_level``.