taler-docs

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

api-merchant.rst (85558B)


      1 ..
      2   This file is part of GNU TALER.
      3   Copyright (C) 2014-2026 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU Affero General Public License as published by the Free Software
      7   Foundation; either version 3.0, or (at your option) any later version.
      8 
      9   TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     10   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11   A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
     12 
     13   You should have received a copy of the GNU Affero General Public License along with
     14   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 
     16   @author Marcello Stanisci
     17   @author Florian Dold
     18   @author Christian Grothoff
     19   @author Priscilla Huang
     20   @author Martin Schanzenbach
     21 
     22 .. _merchant-api:
     23 
     24 ============================
     25 Merchant Backend RESTful API
     26 ============================
     27 
     28 ---------------
     29 Version History
     30 ---------------
     31 
     32 The currently implemented protocol version is **v44**.
     33 
     34 * The Android PoS app is currently targeting **v20**.
     35 * The SPA is currently targeting **vXX**.
     36 * taler-mdb is currently targeting **v27**.
     37 * anastasis is currently targeting **v27**.
     38 * taler-woocommerce is currently targeting **v29**.
     39 * taler-drupal-turnstile is currently targeting **v29**.
     40 * taler-drupal-commerce is currently targeting **vXX**.
     41 * paivana is currently targeting **v29**.
     42 
     43 **Version history:**
     44 
     45 * ``v21``: Added self-provisioning and two factor authentication
     46 * ``v22``: Added various defaults
     47 * ``v23``: Added various defaults, fields and some new filters
     48 * ``v24``: Make minor changes to refund semantics
     49 * ``v25``: adds features to group amounts internally (say to
     50   separate tips, taxes and revenue in reporting), endpoints
     51   for periodic report generation and inventory-based templates,
     52   new long-polling for KYC and features for templates to support
     53   session-based payments
     54 * ``v26``: adds unclaim endpoint, enhanced settlement reporting
     55 * ``v27``: adds various fields to a few endpoints
     56 * ``v28``: adds the ``/kycauth`` endpoint for wire transfer subject
     57   shortening during KYC Auth wire transfers and expands :http:get:`/config </config>`.
     58 * ``v29``: adds ``max_pickup_duration`` to templates (for Paivana)
     59 * ``v30``: adds ``debit_restrictions`` to GET /exchanges (for SPA)
     60 * ``v31``: adds ``/private/accept-tos-early`` and related API changes
     61 * ``v32``: adds "force" argument for locked product deletion
     62 * ``v33``: adds ``build_version`` to :http:get:`/config </config>` and
     63   ``max_age_s`` to ``[/instances/$INSTANCE]/private/orders``, deprecating
     64   the ``max_age`` query parameter of that endpoint
     65 * ``v34``: adds ``editable_amount`` to the choices of a Paivana template
     66   together with the ``choice_amounts`` request field to instantiate them,
     67   and ``min_amount``/``max_amount`` to bound client-chosen amounts for
     68   templates of any type
     69 * ``v35``: adds ``exchange_payto_uri`` to
     70   :http:get:`[/instances/$INSTANCE]/private/transfers`,
     71   passing on the exchange account reported by exchange protocol **v39**
     72 * ``v36``: allows token families with indefinite validity
     73 * ``v37``: adds expiration filtering to the private order history
     74 * ``v38``: adds reporting and repair of an order's wired status
     75 * ``v39``: returns a login token after a successful password reset
     76 * ``v40``: requires the current password when changing merchant credentials
     77 * ``v41``: returns merchant details and compatible exchange candidates for
     78   wallet templates
     79 * ``v42``: adds the additive ``amount_external`` field for orders settled
     80   partly outside of Taler, the ``/private/orders/$ORDER_ID/collect`` endpoint
     81   for completing zero-Taler orders without a wallet, the
     82   ``/private/orders/$ORDER_ID/refund-external`` endpoint for recording
     83   externally settled refunds, and exposes both through order status
     84   (see :doc:`DD 96 </design-documents/096-partial-payments>`)
     85 * ``v43``: adds ECDSA and EdDSA challenge-based payment confirmations.
     86   The OTP-device API generates signing keys and exposes the public key.
     87   Order creation and template instantiation accept a ``challenge``; after
     88   successful payment, the backend returns its signature in ``pos_confirmation``
     89   (see :doc:`DD 97 </design-documents/097-challenge-confirmations>`).
     90   Also adds token fountain management and wallet APIs for retrieving grants
     91   and withdrawing blind-signed promotional tokens without creating an order
     92   (see :doc:`DD 98 </design-documents/098-token-fountains>`)
     93 * ``v44``: adds unauthenticated :http:get:`[/instances/$INSTANCE]/units`
     94   to retrieve all active measurement units for one merchant instance,
     95   including built-in units with instance overrides and custom units.
     96   Also adds ``limit``/``offset`` pagination to
     97   :http:get:`[/instances/$INSTANCE]/private/fountains`, using the new
     98   ``fountain_serial`` response field as an exclusive cursor
     99 
    100 **Upcoming versions:**
    101 
    102 * ``vTAXES``: adds features to manage taxes
    103 * ``vDonauReceipts``: returns donation receipts from ``/pay`` in the new
    104   ``donau_sigs`` field instead of inside ``token_sigs`` (breaking for orders
    105   with a donation receipt output), answers a Donau failure after a
    106   successful payment with a 502 that carries the payment confirmation, and
    107   refuses to replay ``/pay`` after a refund
    108 
    109 **Ideas for future version:**
    110 
    111 * ``vXXX``: marker for features not yet targeted for release
    112 
    113 -----------------------
    114 Base URLs and Instances
    115 -----------------------
    116 
    117 A single merchant backend installation can host multiple merchant instances.
    118 This is useful when multiple businesses want to share the same payment
    119 infrastructure.
    120 
    121 Merchant backends have one special ``admin`` instance.  This ``admin``
    122 instance is used when no explicit instance is specified.  Note that using
    123 ``/instances/admin/$ANYTHING`` is deprecated and will result in a permanent
    124 redirect (HTTP status 308) to ``$ANYTHING``. Despite its name, this instance
    125 must be created after the installation.
    126 
    127 Each instance (admin and others) has a base URL.  The resources under
    128 this base URL are divided into the following categories:
    129 
    130 * Public endpoints that are exposed to the Internet
    131 * Private endpoints (under ``/private/*``) that are only supposed to be exposed
    132   to the merchant internally, and must not be exposed on the
    133   Internet.
    134 * Management endpoints (under ``/management/*``) are also private and dedicated
    135   to CRUD operation over instances and reset authentication settings over all
    136   instances. Only accessible with the admin instance authentication token.
    137 
    138 Examples:
    139 
    140 .. code-block:: none
    141 
    142    Base URL of the merchant (admin instance) at merchant-backend.example.com:
    143    https://merchant-backend.example.com/
    144 
    145    A private endpoint (admin instance):
    146    https://merchant-backend.example.com/private/orders
    147 
    148    A public endpoint (admin instance and order id "ABCD"):
    149    https://merchant-backend.example.com/orders/ABCD
    150 
    151    A private endpoint ("myinst" instance):
    152    https://merchant-backend.example.com/instances/myinst/private/orders
    153 
    154    A public endpoint ("myinst" instance and order id "ABCD"):
    155    https://merchant-backend.example.com/instances/myinst/orders/ABCD
    156 
    157    A private endpoint (explicit "admin" instance):
    158    https://merchant-backend.example.com/private/orders
    159 
    160    A public endpoint (explicit "admin" instance):
    161    https://merchant-backend.example.com/orders
    162 
    163    Endpoints to manage other instances (ONLY for implicit "admin" instance):
    164    https://merchant-backend.example.com/management/instances
    165    https://merchant-backend.example.com/management/instances/$ID
    166 
    167    Endpoints to manage own instance:
    168    https://merchant-backend.example.com/private
    169    https://merchant-backend.example.com/private/auth
    170    https://merchant-backend.example.com/instances/$ID/private
    171    https://merchant-backend.example.com/instances/$ID/forgot-password
    172    https://merchant-backend.example.com/instances/$ID/private/auth
    173 
    174    Unavailabe endpoints (will return 404):
    175    https://merchant-backend.example.com/instances/myinst/private/instances
    176 
    177 .. _merchant-session-id:
    178 
    179 -----------
    180 Session IDs
    181 -----------
    182 
    183 Payments can be bound to a *session*, which is identified by a session ID.
    184 Session IDs are chosen by the merchant's frontend (or by the client device,
    185 as is the case for the Paivana IDs given to
    186 :http:post:`[/instances/$INSTANCE]/templates/$TEMPLATE_ID`); the backend
    187 merely stores them and uses them to match a payment against the session it
    188 was made for.
    189 
    190 .. ts:def:: SessionID
    191 
    192   // Identifier of the session a payment is bound to.  Like a `Slug`,
    193   // a session ID must only use ASCII alphanumeric characters
    194   // ("A-Z", "a-z", "0-9") and the punctuation characters "-", ".",
    195   // "_", ":" and "~", and must not be "." or "..".  Unlike a slug, a
    196   // session ID may also contain "=" and may be empty.
    197   // Session IDs are case-sensitive.
    198   type SessionID = string;
    199 
    200 A session ID is thus *not* a slug.  It additionally permits ``=`` because
    201 session IDs are frequently base64-encoded identifiers, which may end in
    202 padding.  And it may be empty: the empty session ID means that a payment is
    203 not bound to any session.  Clients must expect to encounter it, as the
    204 backend itself puts an empty session ID into the ``taler://pay/`` URI of an
    205 order that has no session (the session is the last path component of that
    206 URI and thus cannot simply be omitted), and wallets send back what they were
    207 given.  Endpoints for which only an actual session makes sense say so
    208 explicitly and reject the empty session ID.
    209 
    210 -----------------
    211 Generic Responses
    212 -----------------
    213 
    214 The following (error) responses are applicable to all endpoints
    215 unless specified otherwise.
    216 
    217 .. include:: merchant/any-star.rst
    218 
    219 .. _merchant-api-authentication:
    220 
    221 --------------
    222 Authentication
    223 --------------
    224 
    225 Each merchant instance has separate authentication settings for the private API resources
    226 of that instance.
    227 
    228 Currently, the ``/private/auth/`` API supports two main authentication methods in the `InstanceAuthConfigurationMessage`:
    229 
    230 * ``external``: (@deprecated since **v20**) With this method, no checks are done by the merchant backend.
    231   Instead, a reverse proxy / API gateway must do all authentication/authorization checks.
    232 * ``token`` (**@since v19**): With this method, the client must provide an authorization header
    233   that contains a bearer token  when accessing a protected endpoint in the form
    234   ``Authorization: Bearer secret-token:$TOKEN``.
    235   ``$TOKEN`` is an authentication token retrieved from the ``/private/token`` endpoint using basic authorization.
    236   The respective username is the instance ``$ID``, and the password the instance password (``$INSTANCE_PASSWORD``).
    237   A login token is commonly only valid for a limited period of time and scoped to specific permissions.
    238   A login token that is unknown or has expired is rejected with a ``401 Unauthorized``
    239   and ``TALER_EC_GENERIC_TOKEN_UNKNOWN`` or ``TALER_EC_GENERIC_TOKEN_EXPIRED`` respectively.
    240   If the ``$INSTANCE_PASSWORD`` is lost, the administrator can set a password
    241   using the ``taler-merchant-passwd`` command-line tool.
    242 * ``token`` (@deprecated since **v19**): With this method, the client must provide an authentication token in
    243   the format ``secret-token: $INSTANCE_PASSWORD``.
    244   The behaviour is then equivalent to the ``token`` method above.
    245   Any API may be accessed using the bearer authentication ``secret-token: $INSTANCE_PASSWORD``.
    246   Notice that this behaviour is deprecated and will be phased out in favor of login tokens.
    247   The bearer token is only interpreted as the instance password if it is not a well-formed login token.
    248   The backend refuses the instance password as a bearer token if the instance has a usable MFA channel
    249   (a validated e-mail address with ``HELPER_EMAIL`` configured, or a validated phone number
    250   with ``HELPER_SMS`` configured), as it would bypass the MFA required by ``/private/token``,
    251   and always if the backend runs with ``STRICT_PROTOCOL_V19 = YES``.
    252   Such requests fail with a ``401 Unauthorized`` and ``TALER_EC_MERCHANT_GENERIC_UNAUTHORIZED``.
    253   Clients must then obtain a login token from ``/private/token`` using basic authorization;
    254   for instances with MFA, that request requires solving MFA challenges.
    255 
    256 For testing, the service may be started with the configuration option ``DISABLE_AUTHENTICATION = YES``
    257 in section ``[merchant]`` (@since **v20**).
    258 
    259 .. _merchant-api-scopes:
    260 
    261 Scopes and permissions
    262 ^^^^^^^^^^^^^^^^^^^^^^
    263 
    264 Authorization in the merchant backend is expressed with *permissions*.  Every
    265 endpoint that requires authorization requires exactly one permission, which is
    266 stated as **Required permission** in the documentation of that endpoint.
    267 Permission names have the form ``$RESOURCE-$ACTION``, where ``$ACTION`` is
    268 usually ``read`` (for operations that only inspect state) or ``write`` (for
    269 operations that change it).
    270 
    271 Clients do not request individual permissions.  Instead, an access token is
    272 issued for a *scope*, which is a fixed, named set of permissions.  A request is
    273 authorized if the permission required by the endpoint is covered by the scope
    274 of the access token that was used.
    275 
    276 Permissions
    277 """""""""""
    278 
    279 The following permissions exist:
    280 
    281 .. list-table::
    282   :widths: 25 75
    283   :header-rows: 1
    284 
    285   * - Permission
    286     - Grants access to
    287   * - ``accounts-read``
    288     - Listing and inspecting the bank accounts of the instance, and starting
    289       KYC authentication for one of them.
    290   * - ``accounts-write``
    291     - Adding, modifying and deleting bank accounts of the instance, and
    292       accepting the terms of service of an exchange ahead of time.
    293   * - ``auth-write``
    294     - Changing the authentication settings of the instance itself
    295       (via the instance's own ``/private/auth`` endpoint).
    296   * - ``categories-read``
    297     - Listing and inspecting product categories.
    298   * - ``categories-write``
    299     - Creating, modifying and deleting product categories.
    300   * - ``donau-read``
    301     - Listing the linked Donau charity instances.
    302   * - ``donau-write``
    303     - Adding and removing Donau charity instance links.
    304   * - ``fountains-read``
    305     - Listing and inspecting token fountains.  Since **v43**.
    306   * - ``fountains-write``
    307     - Creating, modifying and deleting token fountains.
    308       Since **v43**.
    309   * - ``groups-read``
    310     - Listing product groups.
    311   * - ``groups-write``
    312     - Creating, modifying and deleting product groups.
    313   * - ``instances-auth-write``
    314     - Changing the authentication settings of *any* instance via the
    315       ``/management/`` API.  Only the ``admin`` instance can hold this
    316       permission in a useful way.
    317   * - ``instances-kyc-read``
    318     - Querying the KYC status of *any* instance via the ``/management/`` API.
    319   * - ``instances-read``
    320     - Reading the configuration of the instance itself.
    321   * - ``instances-write``
    322     - Creating, inspecting, modifying and deleting instances.  Note that this
    323       permission is required for *all* operations on the ``/management/``
    324       instance API, including the ``GET`` operations that merely list or
    325       inspect instances, as well as for modifying or deleting the instance
    326       itself via its own private API.
    327   * - ``kyc-read``
    328     - Querying the KYC status of the instance itself.
    329   * - ``orders-read``
    330     - Listing orders and checking their payment, refund and wire transfer
    331       status.
    332   * - ``orders-write``
    333     - Creating orders, forgetting parts of a contract, collecting zero-amount
    334       orders and deleting orders.
    335   * - ``orders-refund``
    336     - Granting refunds and recording externally settled refunds.
    337   * - ``otp-devices-read``
    338     - Listing and inspecting one-time-password (OTP) devices.
    339   * - ``otp-devices-write``
    340     - Creating, modifying and deleting OTP devices.
    341   * - ``pos-read``
    342     - Downloading the full point-of-sale configuration
    343       (:http:get:`[/instances/$INSTANCE]/private/pos`).
    344   * - ``pots-read``
    345     - Listing and inspecting money pots.
    346   * - ``pots-write``
    347     - Creating, modifying and deleting money pots.
    348   * - ``products-read``
    349     - Listing and inspecting products in the inventory.
    350   * - ``products-write``
    351     - Adding, modifying and deleting products in the inventory.
    352   * - ``products-lock``
    353     - Locking products in the inventory
    354       (:http:post:`[/instances/$INSTANCE]/private/products/$PRODUCT_ID/lock`).
    355   * - ``reports-read``
    356     - Listing and inspecting reports.
    357   * - ``reports-write``
    358     - Creating, modifying and deleting reports.
    359   * - ``statistics-read``
    360     - Reading counter, amount and transaction statistics.
    361   * - ``templates-read``
    362     - Listing and inspecting order templates.
    363   * - ``templates-write``
    364     - Creating, modifying and deleting order templates.
    365   * - ``tokenfamilies-read``
    366     - Listing and inspecting token families.
    367   * - ``tokenfamilies-write``
    368     - Creating, modifying and deleting token families.
    369   * - ``tokens-read``
    370     - Listing the access tokens that were issued for the instance.
    371   * - ``tokens-write``
    372     - Revoking access tokens of the instance by serial.
    373   * - ``token-refresh``
    374     - Obtaining a new access token from
    375       :http:post:`[/instances/$INSTANCE]/private/token` using an existing
    376       access token.  This permission is special: it is *not* part of any
    377       scope's permission set and is not implied by ``*``.  It is granted
    378       exactly if the access token used is refreshable (see below).
    379   * - ``transfers-read``
    380     - Listing expected and actual wire transfers, including incoming
    381       transfers.
    382   * - ``transfers-write``
    383     - Informing the backend about wire transfers and deleting such records.
    384   * - ``units-read``
    385     - Listing and inspecting measurement units.
    386   * - ``units-write``
    387     - Creating, modifying and deleting measurement units.
    388   * - ``webhooks-read``
    389     - Listing and inspecting webhooks.
    390   * - ``webhooks-write``
    391     - Creating, modifying and deleting webhooks.
    392 
    393 Endpoints of the wallet-facing (public) API, such as those used to claim, pay
    394 for or abort an order, require no permission at all and are documented as
    395 "**Required permission:** none".
    396 
    397 Scopes
    398 """"""
    399 
    400 Access tokens can be requested with a (limiting) scope.  The available scopes
    401 and the permissions they grant are:
    402 
    403 .. list-table::
    404   :widths: 15 45 40
    405   :header-rows: 1
    406 
    407   * - Scope
    408     - Permissions
    409     - Remarks
    410   * - ``readonly``
    411     - ``*-read``
    412     - Every permission ending in ``-read``.  Note that this does *not* include
    413       the ``/management/`` instance API, which requires ``instances-write``
    414       even for ``GET`` requests.
    415   * - ``all``
    416     - ``*``
    417     - Every permission.  Tokens with this scope are always refreshable.
    418       @since **v19**
    419   * - ``write``
    420     - ``*``
    421     - @deprecated since **v19**, identical to ``all``.
    422   * - ``spa``
    423     - ``*``
    424     - Every permission; used by the merchant backoffice SPA.  Unlike ``all``,
    425       this scope is not implicitly refreshable.  @since **v20**
    426   * - ``order-simple``
    427     - ``orders-read``, ``orders-write``
    428     - Allows the creation of orders and checking of payment status.
    429       @since **v19**
    430   * - ``order-pos``
    431     - ``orders-read``, ``orders-write``, ``pos-read``, ``products-lock``,
    432       ``products-read``, ``orders-refund``
    433     - Same as ``order-simple`` and allows inventory locking (@since **v19**),
    434       ``products-read`` since **v32**, and granting refunds.
    435   * - ``order-mgmt``
    436     - ``orders-read``, ``orders-write``, ``pos-read``, ``orders-refund``
    437     - Same as ``order-simple``, plus reading the point-of-sale configuration
    438       and granting refunds.  @since **v19**
    439   * - ``order-full``
    440     - ``orders-read``, ``orders-write``, ``pos-read``, ``products-lock``,
    441       ``orders-refund``
    442     - ``order-pos`` and ``order-mgmt`` combined.  @since **v19**
    443 
    444 .. note::
    445 
    446    The ``products-lock`` permission granted by ``order-pos`` and ``order-full``
    447    is only required for explicitly locking products via
    448    :http:post:`[/instances/$INSTANCE]/private/products/$PRODUCT_ID/lock`.
    449    Creating an order (which locks inventory as a side effect) requires only
    450    ``orders-write``.
    451 
    452 .. ts:def:: TokenScope
    453 
    454   // Scope of an access token.  Since **v19**, the scope may be
    455   // suffixed with ":refreshable" (see below), for example
    456   // "order-pos:refreshable".  "write" is deprecated since **v19**
    457   // and is equivalent to "all".
    458   type TokenScope = "readonly" | "all" | "spa" | "order-simple" | "order-pos" | "order-mgmt" | "order-full" | "write";
    459 
    460 Matching rules
    461 """"""""""""""
    462 
    463 Given the permission ``$P`` required by an endpoint and the permission set of
    464 the scope of the access token used, access is granted if any of the following
    465 holds:
    466 
    467 * the scope contains ``*``;
    468 * the scope contains ``*-read`` and ``$P`` ends in ``-read``;
    469 * the scope contains ``*-write`` and ``$P`` ends in ``-write``;
    470 * the scope contains ``$P`` literally.
    471 
    472 The permission ``token-refresh`` is handled separately and is granted if and
    473 only if the access token is refreshable, regardless of the scope's permission
    474 set.
    475 
    476 Refreshable tokens
    477 """"""""""""""""""
    478 
    479 Since **v19** the scope may be suffixed with ``:refreshable``, e.g.
    480 ``order-pos:refreshable``.
    481 This allows the token to be refreshed at the token endpoint.
    482 This behaviour replaces the deprecated ``refreshable`` field in the `LoginTokenRequest`.
    483 Tokens with the ``all`` (or the deprecated ``write``) scope are always
    484 refreshable.
    485 
    486 When requesting a token from
    487 :http:post:`[/instances/$INSTANCE]/private/token` with an existing access
    488 token, the requested scope must be a subset of the scope of the token used,
    489 and a non-refreshable token can never be used to obtain a refreshable one.
    490 
    491 -----------------
    492 Configuration API
    493 -----------------
    494 
    495 The configuration API exposes basic information about a merchant backend,
    496 such as the implemented version of the protocol and the currency used.
    497 
    498 .. include:: merchant/get-config.rst
    499 
    500 .. include:: tos.rst
    501 
    502 -------------------
    503 Exchange Status API
    504 -------------------
    505 
    506 The exchange status API exposes basic information about the exchanges
    507 configured for a merchant backend, in particular the acceptable
    508 currencies, master public keys and the status of the merchant backend's
    509 download of the :http:get:`/keys </keys>` from the exchange.  This is mostly useful
    510 to diagnose configuration problems.
    511 
    512 .. include:: merchant/get-exchanges.rst
    513 
    514 ---------------
    515 Two Factor Auth
    516 ---------------
    517 
    518 202 Challenge Responses
    519 ^^^^^^^^^^^^^^^^^^^^^^^
    520 
    521 Various APIs generate ``202 Accepted`` HTTP status codes when multi-factor
    522 authentication (MFA) is required.  In this case, the response will be a
    523 `ChallengeResponse`.  In these cases, the client must first request and solve
    524 one or more challenges before repeating the request. When repeating the
    525 request, they must include a list of comma-separated challenge IDs of the
    526 solved challenges in a ``Taler-Challenge-Ids`` HTTP header. The body must
    527 remain absolutely unchanged.
    528 
    529 Challenge IDs are bound to the merchant instance, the critical operation,
    530 the required authentication factor, and the exact request body for which
    531 they were issued.  A solved challenge is therefore authorization to retry
    532 that particular transaction.  It is not proof of a generic privilege
    533 elevation or merely of an MFA authentication performed recently, and it
    534 MUST NOT authorize an operation for another instance.  Binding challenges
    535 to their merchant instance is required since protocol **v39**.
    536 
    537 Clients should retain challenge IDs only while transmitting or confirming
    538 the challenges and completing or retrying the protected request.  They must
    539 not attach challenge IDs to unrelated requests or reuse them for another
    540 instance, operation, or request body.
    541 
    542   .. note::
    543 
    544     If all allowed attempts to solve the MFA challenge(s) fail, the endpoint
    545     may start to return ``403 Forbidden`` until the issued challenges expire,
    546     preventing the request from being completed for a while.  In this case,
    547     repeating the request with a different body may still be allowed!
    548 
    549 .. ts:def:: ChallengeResponse
    550 
    551   // @since v21
    552   interface ChallengeResponse {
    553     // List of challenge IDs that must be solved before the
    554     // client may proceed.
    555     challenges: Challenge[];
    556 
    557     // True if **all** challenges must be solved (AND), false if
    558     // it is sufficient to solve one of them (OR).
    559     combi_and: boolean;
    560 
    561   }
    562 
    563 .. ts:def:: Challenge
    564 
    565   interface Challenge {
    566     // Unique identifier of the challenge to solve to run this protected
    567     // operation.
    568     challenge_id: Slug;
    569 
    570     // Channel of the last successful transmission of the TAN challenge.
    571     tan_channel: TanChannel;
    572 
    573     // Info of the last successful transmission of the TAN challenge.
    574     // Hint to show to the user as to where the challenge was
    575     // sent or what to use to solve the challenge. May not
    576     // contain the full address for privacy.
    577     tan_info: string;
    578 
    579   }
    580 
    581 Requesting challenges
    582 ^^^^^^^^^^^^^^^^^^^^^
    583 
    584 .. include:: merchant/post-challenge-CHALLENGE_ID.rst
    585 
    586 Solving challenges
    587 ^^^^^^^^^^^^^^^^^^
    588 
    589 .. include:: merchant/post-challenge-CHALLENGE_ID-confirm.rst
    590 
    591 ----------
    592 Wallet API
    593 ----------
    594 
    595 This section describes (public) endpoints that wallets must be able
    596 to interact with directly (without HTTP-based authentication). These
    597 endpoints are used to process payments (claiming an order, paying
    598 for the order, checking payment/refund status and aborting payments),
    599 and to process refunds (checking refund status, obtaining the refund).
    600 
    601 
    602 Claiming an order
    603 ^^^^^^^^^^^^^^^^^
    604 
    605 The first step of processing any Taler payment consists of the
    606 (authorized) wallet claiming the order for itself. In this process,
    607 the wallet provides a wallet-generated nonce that is added
    608 into the contract terms.  This step prevents two different
    609 wallets from paying for the same contract, which would be bad
    610 especially if the merchant only has finite stocks.
    611 
    612 A claim token can be used to ensure that the wallet claiming an
    613 order is actually authorized to do so. This is useful in cases
    614 where order IDs are predictable and malicious actors may try to
    615 claim orders (say in a case where stocks are limited).
    616 
    617 
    618 .. include:: merchant/post-orders-ORDER_ID-claim.rst
    619 
    620 .. include:: merchant/post-orders-ORDER_ID-unclaim.rst
    621 
    622 
    623 Making the payment
    624 ^^^^^^^^^^^^^^^^^^
    625 
    626 .. include:: merchant/post-orders-ORDER_ID-pay.rst
    627 
    628 
    629 Querying payment status
    630 ^^^^^^^^^^^^^^^^^^^^^^^
    631 
    632 .. include:: merchant/get-orders-ORDER_ID.rst
    633 
    634 .. include:: merchant/get-sessions-SESSION_ID.rst
    635 
    636 
    637 Demonstrating payment
    638 ^^^^^^^^^^^^^^^^^^^^^
    639 
    640 In case a wallet has already paid for an order, this is a fast way of proving
    641 to the merchant that the order was already paid. The alternative would be to
    642 replay the original payment, but simply providing the merchant's signature
    643 saves bandwidth and computation time.
    644 
    645 Demonstrating payment is useful in case a digital good was made available
    646 only to clients with a particular session ID: if that session ID expired or
    647 if the user is using a different client, demonstrating payment will allow
    648 the user to regain access to the digital good without having to pay for it
    649 again.
    650 
    651 .. include:: merchant/post-orders-ORDER_ID-paid.rst
    652 
    653 
    654 Aborting incomplete payments
    655 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    656 
    657 In rare cases (such as a wallet restoring from an outdated backup) it is possible
    658 that a wallet fails to complete a payment because it runs out of e-cash in the
    659 middle of the process. The abort API allows the wallet to abort the payment for
    660 such an incomplete payment and to regain control over the coins that were spent
    661 so far. Aborts are not permitted for payments that have completed.  In contrast to
    662 refunds, aborts do not require approval by the merchant because aborts always
    663 are for incomplete payments for an order and never for established contracts.
    664 
    665 
    666 .. _order-abort:
    667 .. include:: merchant/post-orders-ORDER_ID-abort.rst
    668 
    669 
    670 Obtaining refunds
    671 ^^^^^^^^^^^^^^^^^
    672 
    673 Refunds allow merchants to fully or partially restitute e-cash to a wallet,
    674 for example because the merchant determined that it could not actually fulfill
    675 the contract. Refunds must be approved by the merchant's business logic.
    676 
    677 .. include:: merchant/post-orders-ORDER_ID-refund.rst
    678 
    679 
    680 -------------------
    681 Instance management
    682 -------------------
    683 
    684 Instances allow one merchant backend to be shared by multiple merchants.
    685 Every backend must have at least one instance, typically the "admin"
    686 instance setup before it can be used to manage inventory or process payments.
    687 
    688 
    689 Setting up instances
    690 ^^^^^^^^^^^^^^^^^^^^
    691 
    692 .. include:: merchant/post-instances.rst
    693 
    694 .. include:: merchant/post-instances-INSTANCE-forgot-password.rst
    695 
    696 .. include:: merchant/post-management-instances.rst
    697 
    698 .. include:: merchant/post-management-instances-INSTANCE-auth.rst
    699 
    700 Access control tokens
    701 ^^^^^^^^^^^^^^^^^^^^^
    702 
    703 .. include:: merchant/post-private-token.rst
    704 
    705 .. include:: merchant/get-private-tokens.rst
    706 
    707 .. include:: merchant/delete-private-tokens-SERIAL.rst
    708 
    709 .. include:: merchant/delete-private-token.rst
    710 
    711 .. include:: merchant/patch-management-instances-INSTANCE.rst
    712 
    713 
    714 Inspecting instances
    715 ^^^^^^^^^^^^^^^^^^^^
    716 
    717 .. _instances:
    718 .. include:: merchant/get-management-instances.rst
    719 
    720 .. include:: merchant/get-management-instances-INSTANCE.rst
    721 
    722 
    723 Getting statistics
    724 ^^^^^^^^^^^^^^^^^^
    725 
    726 .. include:: merchant/get-private-statistics-amount-SLUG.rst
    727 
    728 .. include:: merchant/get-private-statistics-counter-SLUG.rst
    729 
    730 .. include:: merchant/get-private-statistics-report-NAME.rst
    731 
    732 
    733 Deleting instances
    734 ^^^^^^^^^^^^^^^^^^
    735 
    736 .. include:: merchant/delete-management-instances-INSTANCE.rst
    737 
    738 
    739 KYC status checks
    740 ^^^^^^^^^^^^^^^^^
    741 
    742 .. _merchantkycstatus:
    743 
    744 .. include:: merchant/get-private-kyc.rst
    745 
    746 .. include:: merchant/post-private-accept-tos-early.rst
    747 
    748 
    749 -------------
    750 Bank Accounts
    751 -------------
    752 
    753 One or more bank accounts must be associated with an instance
    754 so that the instance can receive payments.  Payments may be made
    755 into any of the active bank accounts of an instance.
    756 
    757 .. include:: merchant/post-private-accounts.rst
    758 
    759 .. include:: merchant/patch-private-accounts-H_WIRE.rst
    760 
    761 .. include:: merchant/get-private-accounts.rst
    762 
    763 .. include:: merchant/get-private-accounts-H_WIRE.rst
    764 
    765 .. include:: merchant/delete-private-accounts-H_WIRE.rst
    766 
    767 .. include:: merchant/post-private-accounts-H_WIRE-kycauth.rst
    768 
    769 
    770 --------------------
    771 Inventory management
    772 --------------------
    773 
    774 .. _inventory:
    775 
    776 Inventory management is an *optional* backend feature that can be used to
    777 manage limited stocks of products and to auto-complete product descriptions in
    778 contracts (such that the frontends have to do less work).  You can use the
    779 Taler merchant backend to process payments *without* using its inventory
    780 management.
    781 
    782 .. _decimal-quantity:
    783 
    784 Decimal quantities
    785 ^^^^^^^^^^^^^^^^^^
    786 
    787 .. ts:def:: DecimalQuantity
    788 
    789   // Fixed-point decimal string in the form "<integer>[.<fraction>]".
    790   // Fractional part has up to six digits.
    791   // "-1" is only valid for fields that explicitly allow "infinity".
    792   // Since protocol **v25**; used in template selection since **v25**.
    793   type DecimalQuantity = string;
    794 
    795 
    796 Managing measurement units
    797 ^^^^^^^^^^^^^^^^^^^^^^^^^^
    798 
    799 .. include:: merchant/get-units.rst
    800 
    801 .. include:: merchant/get-private-units.rst
    802 
    803 .. include:: merchant/get-private-units-UNIT.rst
    804 
    805 .. include:: merchant/post-private-units.rst
    806 
    807 .. include:: merchant/patch-private-units-UNIT.rst
    808 
    809 .. include:: merchant/delete-private-units-UNIT.rst
    810 
    811 
    812 Managing product categories
    813 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    814 
    815 .. include:: merchant/get-private-categories.rst
    816 
    817 .. include:: merchant/get-private-categories-CATEGORY_ID.rst
    818 
    819 .. include:: merchant/post-private-categories.rst
    820 
    821 .. include:: merchant/patch-private-categories-CATEGORY_ID.rst
    822 
    823 .. include:: merchant/delete-private-categories-CATEGORY_ID.rst
    824 
    825 
    826 Managing products in the inventory
    827 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    828 
    829 .. include:: merchant/post-private-products.rst
    830 
    831 .. include:: merchant/patch-private-products-PRODUCT_ID.rst
    832 
    833 .. include:: merchant/get-private-products.rst
    834 
    835 .. include:: merchant/get-private-products-PRODUCT_ID.rst
    836 
    837 .. include:: merchant/delete-private-products-PRODUCT_ID.rst
    838 
    839 
    840 
    841 Providing configuration data for point-of-sale terminals
    842 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    843 
    844 .. include:: merchant/get-private-pos.rst
    845 
    846 
    847 Fetching product images
    848 ^^^^^^^^^^^^^^^^^^^^^^^
    849 
    850 .. include:: merchant/get-products-IMAGE_HASH-image.rst
    851 
    852 
    853 
    854 Reserving inventory
    855 ^^^^^^^^^^^^^^^^^^^
    856 
    857 .. include:: merchant/post-private-products-PRODUCT_ID-lock.rst
    858 
    859 
    860 ------------------
    861 Payment processing
    862 ------------------
    863 
    864 To process Taler payments, a merchant must first set up an order with
    865 the merchant backend. The order is then claimed by a wallet, and
    866 paid by the wallet. The merchant can check the payment status of the
    867 order. Once the order is paid, the merchant may (for a limited time)
    868 grant refunds on the order.
    869 
    870 Creating orders
    871 ^^^^^^^^^^^^^^^
    872 
    873 .. _post-order:
    874 
    875 .. include:: merchant/post-private-orders.rst
    876 
    877 Inspecting orders
    878 ^^^^^^^^^^^^^^^^^
    879 
    880 .. include:: merchant/get-private-orders.rst
    881 
    882 .. include:: merchant/get-private-orders-ORDER_ID.rst
    883 
    884 
    885 .. _collect-order:
    886 
    887 Collecting zero-Taler orders
    888 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    889 
    890 Orders whose Taler ``amount`` is zero, for example because the full total
    891 was settled through ``amount_external``, can be completed by the merchant
    892 backend itself instead of a customer wallet.
    893 
    894 .. include:: merchant/post-private-orders-ORDER_ID-collect.rst
    895 
    896 
    897 .. _private-order-data-cleanup:
    898 
    899 Private order data cleanup
    900 ^^^^^^^^^^^^^^^^^^^^^^^^^^
    901 
    902 Some orders may contain sensitive information that the merchant may not want
    903 to retain after fulfillment, such as the customer's shipping address.  By
    904 initially labeling these order components as forgettable, the merchant can
    905 later tell the backend to forget those details (without changing the hash of
    906 the contract!) to minimize risks from information leakage.
    907 
    908 A member is marked as forgettable by adding its name to the
    909 ``$forgettable`` object in the same parent object.  The value is a random salt
    910 encoded using upper-case Crockford Base32.  Order-creation requests may use
    911 ``true`` instead of a salt; the merchant backend then generates the random
    912 salt before producing the final contract terms.  The boolean form is not valid
    913 in final contract terms.
    914 
    915 Forgetting a member removes both its value and its salt and adds an entry with
    916 the same name to ``$forgotten``.  The entry is a 64-byte HKDF-SHA-512 result,
    917 encoded using upper-case Crockford Base32.  The HKDF input key material is the
    918 RFC 8785 canonical JSON representation of the recursively scrubbed member
    919 value followed by one zero byte.  The HKDF salt is the UTF-8 representation of
    920 the salt string followed by one zero byte, and the HKDF context is empty.  Scrubbing an object
    921 recursively forgets all members marked by ``$forgettable``.  These rules make
    922 the hash of the contract terms invariant under authorized forgetting.
    923 
    924 Objects that participate in this mechanism may use ordinary member names
    925 matching ``^[-0-9A-Za-z_]+$`` and the two reserved names ``$forgettable`` and
    926 ``$forgotten``.  Numbers must be safe integers; floating-point values are not
    927 permitted.
    928 
    929 The following object is the interoperability reference vector::
    930 
    931   {
    932     "k1": 1,
    933     "$forgettable": { "k1": "SALT" },
    934     "k2": {
    935       "n1": true,
    936       "$forgettable": { "n1": "salt" }
    937     },
    938     "k3": { "n1": "string" }
    939   }
    940 
    941 Its Crockford-Base32-encoded contract hash is
    942 ``VDE8JPX0AEEE3EX1K8E11RYEWSZQKGGZCV6BWTE4ST1C8711P7H850Z7F2Q2HSSYETX87ERC2JNHWB7GTDWTDWMM716VKPSRBXD7SRR``.
    943 
    944 .. include:: merchant/patch-private-orders-ORDER_ID-forget.rst
    945 
    946 .. include:: merchant/delete-private-orders-ORDER_ID.rst
    947 
    948 
    949 .. _merchant_refund:
    950 
    951 -----------------
    952 Approving Refunds
    953 -----------------
    954 
    955 .. include:: merchant/post-private-orders-ORDER_ID-refund.rst
    956 
    957 .. include:: merchant/post-private-orders-ORDER_ID-refund-external.rst
    958 
    959 
    960 -----------------------
    961 Tracking Wire Transfers
    962 -----------------------
    963 
    964 This API is used by merchants that want to track the payments from the
    965 exchange to be sure that they have been paid on time. By telling the merchant
    966 backend about all incoming wire transfers, the backend can detect if an
    967 exchange failed to perform a wire transfer that was due.
    968 
    969 
    970 Informing the backend about incoming wire transfers
    971 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    972 
    973 .. include:: merchant/post-private-transfers.rst
    974 
    975 
    976 Querying known wire transfers
    977 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    978 
    979 .. include:: merchant/get-private-transfers.rst
    980 
    981 
    982 
    983 Querying expected wire transfers
    984 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    985 
    986 .. include:: merchant/get-private-incoming.rst
    987 
    988 
    989 .. include:: merchant/get-private-incoming-ID.rst
    990 
    991 
    992 Deleting confirmed wire transfer
    993 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    994 
    995 Deleting a wire transfer can be useful in case of a data entry
    996 mistake. In particular, if the exchange base URL was entered
    997 badly, deleting the old entry and adding a correct one is a
    998 good idea. Note that deleting wire transfers is not possible
    999 if they were expected.
   1000 
   1001 .. include:: merchant/delete-private-transfers-TID.rst
   1002 
   1003 
   1004 .. _merchant-otp-device-api:
   1005 
   1006 -----------
   1007 OTP Devices
   1008 -----------
   1009 
   1010 OTP devices can be used to allow offline merchants
   1011 to validate that a customer made a payment.
   1012 
   1013 
   1014 .. include:: merchant/post-private-otp-devices.rst
   1015 
   1016 
   1017 .. include:: merchant/patch-private-otp-devices-DEVICE_ID.rst
   1018 
   1019 
   1020 .. include:: merchant/get-private-otp-devices.rst
   1021 
   1022 .. include:: merchant/get-private-otp-devices-DEVICE_ID.rst
   1023 
   1024 .. include:: merchant/delete-private-otp-devices-DEVICE_ID.rst
   1025 
   1026 
   1027 .. _merchant-template-api:
   1028 
   1029 ---------
   1030 Templates
   1031 ---------
   1032 
   1033 The template is a backend feature that is used to allow wallets to create an
   1034 order. This is useful in cases where a store does not have Internet
   1035 connectivity or where a Web site wants to enable payments on a purely static
   1036 Web page (for example to collect donations). In these cases, the GNU Taler
   1037 wallet can be used to setup an order (and then of course pay for it).
   1038 
   1039 Templates can describe a fixed contract (``fixed-order``), an inventory-backed
   1040 cart where the wallet picks products and quantities (``inventory-cart``), or a
   1041 session-based template (``paivana``). The template type controls which fields
   1042 appear in the contract and which inputs are required during instantiation.
   1043 
   1044 The template itself primarily provides order details that cannot be changed
   1045 by the customer when the wallet creates the order.  The idea is that the user
   1046 *may* be prompted to enter certain information, such as the amount to be paid,
   1047 or the order summary (as a reminder to themselves or a message to the store),
   1048 while the template provides all of the other contract details.
   1049 
   1050 The typical user-experience with templates is that the user first scans a QR
   1051 code or clicks on a taler://-URI which contains a ``pay-template`` (see `LSD
   1052 0006 <https://lsd.gnunet.org/lsd0006/>`__). The URI specifies which values the
   1053 user should supply, currently either nothing, the amount, the order summary or
   1054 both.  The URI may also specify defaults or partial defaults for those
   1055 values. After the user has supplied those values, the wallet will use the
   1056 public template API to create the order, then fetch the order details, and
   1057 proceed as if it had been given the respective ``pay`` URI in the first place:
   1058 show the full contract details and allow the user to make a payment.  If the
   1059 user chooses to abort the payment, the wallet should give the user the
   1060 opportunity to edit the values and create another order with different values.
   1061 If the template does not include any values that the user is allowed to edit
   1062 (so it is basically a fixed contract), the wallet should directly create the
   1063 order and immediately proceed to the contract acceptance dialog.
   1064 
   1065 The business process for the templating API is also pretty simple. First, the
   1066 private API is used to setup (or edit) the template, providing all of the
   1067 contract terms that subsequently cannot be changed by the customer/wallet.
   1068 This template data is then stored under the template ID which can be freely
   1069 chosen and must be in URL-encoded format. The SPA should also make it easy
   1070 for the merchant to convert the template ID into a taler://-URI and/or QR code.
   1071 Here, the merchant must additionally specify the defaults (if any) for the
   1072 customer-editable values. Afterwards, the merchant can print out the QR code
   1073 for display at the store, add a link to the taler://-URI and/or embed the
   1074 respective QR-code image into their Web page.
   1075 
   1076 To receive a payment confirmation, the mechant may choose to configure a
   1077 webhook in the merchant backend on the ``pay`` action, for example to send an
   1078 SMS to their mobile phone.  For points-of-sale without a mobile phone or
   1079 Internet connectivity, the OTP mechanism can also be used to confirm payments.
   1080 
   1081 
   1082 Adding templates
   1083 ^^^^^^^^^^^^^^^^
   1084 
   1085 .. include:: merchant/post-private-templates.rst
   1086 
   1087 
   1088 Editing templates
   1089 ^^^^^^^^^^^^^^^^^
   1090 
   1091 .. include:: merchant/patch-private-templates-TEMPLATE_ID.rst
   1092 
   1093 
   1094 Inspecting template
   1095 ^^^^^^^^^^^^^^^^^^^
   1096 
   1097 .. include:: merchant/get-private-templates.rst
   1098 
   1099 .. include:: merchant/get-private-templates-TEMPLATE_ID.rst
   1100 
   1101 
   1102 Removing template
   1103 ^^^^^^^^^^^^^^^^^
   1104 
   1105 .. include:: merchant/delete-private-templates-TEMPLATE_ID.rst
   1106 
   1107 
   1108 Using template
   1109 ^^^^^^^^^^^^^^
   1110 
   1111 .. include:: merchant/get-templates-TEMPLATE_ID.rst
   1112 
   1113 .. include:: merchant/post-templates-TEMPLATE_ID.rst
   1114 
   1115 .. _merchant-webhooks:
   1116 
   1117 --------
   1118 Webhooks
   1119 --------
   1120 
   1121 The webhook is a backend feature that is used to trigger an HTTP request
   1122 to some business logic of the merchant in real-time whenever a specified
   1123 type of event happens.  Depending on the type of the event, webhooks
   1124 may include additional meta-data, such as the amount or contract paid
   1125 by the customer. For details on setup and supported event payloads, see the
   1126 `Merchant manual – Setting up a webhook <https://docs.taler.net/taler-merchant-manual.html#setting-up-a-webhook>`_.
   1127 
   1128 Each webhook is bound to an ``event_type``. The backend currently recognizes the following types, which are mirrored in the `WebhookEventType` enum so API clients can
   1129 validate their payloads without guesswork:
   1130 
   1131 .. ts:def:: WebhookEventType
   1132 
   1133    enum WebhookEventType {
   1134       ORDER_CREATED = "order_created",
   1135       PAY = "pay",
   1136       REFUND = "refund",
   1137       ORDER_SETTLED = "order_settled",
   1138       CATEGORY_ADDED = "category_added",
   1139       CATEGORY_UPDATED = "category_updated",
   1140       CATEGORY_DELETED = "category_deleted",
   1141       INVENTORY_ADDED = "inventory_added",
   1142       INVENTORY_UPDATED = "inventory_updated",
   1143       INVENTORY_DELETED = "inventory_deleted"
   1144    }
   1145 
   1146 - ``order_created``: fired whenever a new order is created and exposes the ``order_id``, contract, and owning ``instance_id``.
   1147 - ``pay``: emitted after a payment succeeds; the payload contains the paid contract terms and ``order_id``.
   1148 - ``refund``: triggered when a refund is approved and includes timestamp, refunded amount, and reason.
   1149 - ``order_settled``: sent when reconciliation links a wire transfer to an order (includes ``order_id`` and ``wtid``).
   1150 - ``category_added`` / ``category_updated`` / ``category_deleted``: cover lifecycle changes to product categories.
   1151 - ``inventory_added`` / ``inventory_updated`` / ``inventory_deleted``: cover lifecycle changes to inventory items, including descriptive fields and stock state.
   1152 
   1153 For the full payloads associated with each event consult the merchant manual section linked above.
   1154 
   1155 
   1156 Adding webhooks
   1157 ^^^^^^^^^^^^^^^
   1158 
   1159 .. include:: merchant/post-private-webhooks.rst
   1160 
   1161 
   1162 Editing webhooks
   1163 ^^^^^^^^^^^^^^^^
   1164 
   1165 .. include:: merchant/patch-private-webhooks-WEBHOOK_ID.rst
   1166 
   1167 
   1168 Inspecting webhook
   1169 ^^^^^^^^^^^^^^^^^^
   1170 
   1171 .. include:: merchant/get-private-webhooks.rst
   1172 
   1173 .. include:: merchant/get-private-webhooks-WEBHOOK_ID.rst
   1174 
   1175 
   1176 Removing webhook
   1177 ^^^^^^^^^^^^^^^^
   1178 
   1179 .. include:: merchant/delete-private-webhooks-WEBHOOK_ID.rst
   1180 
   1181 
   1182 -------
   1183 Reports
   1184 -------
   1185 
   1186 Reports are a backend feature that is used to send periodic
   1187 reports to the merchant. Reports are sent using notification
   1188 helper programs which must be configured for each merchant backend.
   1189 
   1190 Since protocol **v25**.
   1191 
   1192 Generating reports
   1193 ^^^^^^^^^^^^^^^^^^
   1194 
   1195 .. include:: merchant/post-reports-REPORT_ID.rst
   1196 
   1197 
   1198 Scheduling periodic reports
   1199 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   1200 
   1201 .. include:: merchant/post-private-reports.rst
   1202 
   1203 
   1204 Editing scheduled reports
   1205 ^^^^^^^^^^^^^^^^^^^^^^^^^
   1206 
   1207 .. include:: merchant/patch-private-reports-REPORT_ID.rst
   1208 
   1209 
   1210 Inspecting reporting schedules
   1211 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   1212 
   1213 .. include:: merchant/get-private-reports.rst
   1214 
   1215 .. include:: merchant/get-private-reports-REPORT_ID.rst
   1216 
   1217 
   1218 Removing scheduled reports
   1219 ^^^^^^^^^^^^^^^^^^^^^^^^^^
   1220 
   1221 .. include:: merchant/delete-private-reports-REPORT_ID.rst
   1222 
   1223 
   1224 --------------
   1225 Product groups
   1226 --------------
   1227 
   1228 Product groups are used to manage taxes. Each product is in
   1229 exactly one group and that group is typically used to determine
   1230 the applicable tax rules. Products that are not assigned explicitly
   1231 to a group are considered to be in the *default* product group.
   1232 
   1233 Product groups are different from categories as a product can be
   1234 in multiple categories. Furthermore, categories are used to make
   1235 it easier to find products in user interfaces, while product
   1236 groups are used to make it easier to manage taxes.
   1237 
   1238 Since protocol **v25**.
   1239 
   1240 Adding groups
   1241 ^^^^^^^^^^^^^
   1242 
   1243 .. include:: merchant/post-private-groups.rst
   1244 
   1245 
   1246 Editing groups
   1247 ^^^^^^^^^^^^^^
   1248 
   1249 .. include:: merchant/patch-private-groups-GROUP_ID.rst
   1250 
   1251 
   1252 Inspecting groups
   1253 ^^^^^^^^^^^^^^^^^
   1254 
   1255 .. include:: merchant/get-private-groups.rst
   1256 
   1257 
   1258 Removing groups
   1259 ^^^^^^^^^^^^^^^
   1260 
   1261 .. include:: merchant/delete-private-groups-GROUP_ID.rst
   1262 
   1263 
   1264 ----
   1265 Pots
   1266 ----
   1267 
   1268 Pots are a backend feature that is used for accounting. Transacted
   1269 amounts can be assigned into pots, for example to separate out
   1270 tips and taxes from revenue for reporting.
   1271 
   1272 Since protocol **v25**.
   1273 
   1274 Adding pots
   1275 ^^^^^^^^^^^
   1276 
   1277 .. include:: merchant/post-private-pots.rst
   1278 
   1279 
   1280 Editing pots
   1281 ^^^^^^^^^^^^
   1282 
   1283 .. include:: merchant/patch-private-pots-POT_ID.rst
   1284 
   1285 
   1286 Inspecting pots
   1287 ^^^^^^^^^^^^^^^
   1288 
   1289 .. include:: merchant/get-private-pots.rst
   1290 
   1291 .. include:: merchant/get-private-pots-POT_ID.rst
   1292 
   1293 
   1294 Removing pots
   1295 ^^^^^^^^^^^^^
   1296 
   1297 .. include:: merchant/delete-private-pots-POT_ID.rst
   1298 
   1299 
   1300 ----------------------------------------
   1301 Token Families: Subscriptions, Discounts
   1302 ----------------------------------------
   1303 
   1304 This API provides functionalities for the issuance, management, and revocation
   1305 of token families. Tokens facilitate the implementation of subscriptions and
   1306 discounts, engaging solely the merchant and the user. Each token family
   1307 encapsulates details pertaining to its respective tokens, guiding the merchant's
   1308 backend on the appropriate processing and handling.
   1309 
   1310 
   1311 Creating token families
   1312 ^^^^^^^^^^^^^^^^^^^^^^^
   1313 
   1314 .. include:: merchant/post-private-tokenfamilies.rst
   1315 
   1316 
   1317 Updating token families
   1318 ^^^^^^^^^^^^^^^^^^^^^^^
   1319 
   1320 .. include:: merchant/patch-private-tokenfamilies-TOKEN_FAMILY_SLUG.rst
   1321 
   1322 
   1323 
   1324 Inspecting token families
   1325 ^^^^^^^^^^^^^^^^^^^^^^^^^
   1326 
   1327 .. include:: merchant/get-private-tokenfamilies.rst
   1328 
   1329 .. include:: merchant/get-private-tokenfamilies-TOKEN_FAMILY_SLUG.rst
   1330 
   1331 
   1332 
   1333 Deleting token families
   1334 ^^^^^^^^^^^^^^^^^^^^^^^
   1335 
   1336 .. include:: merchant/delete-private-tokenfamilies-TOKEN_FAMILY_SLUG.rst
   1337 
   1338 
   1339 .. _merchant-fountain-api:
   1340 
   1341 -----------------------------------------
   1342 Fountains: Promotional Token Distribution
   1343 -----------------------------------------
   1344 
   1345 A fountain is a bearer credential that entitles a wallet to withdraw
   1346 blind-signed promotional tokens for a set of token families without
   1347 creating an order per withdrawal.  An institution can distribute a fountain
   1348 to one recipient or share it for a campaign
   1349 (see :doc:`DD 98 </design-documents/098-token-fountains>`).
   1350 
   1351 Wallets receive the credential as a
   1352 ``taler://fountain/$MERCHANT_HOST[/$INSTANCE_PATH]/$FOUNTAIN_ID/$FOUNTAIN_SECRET``
   1353 URI. All fountain endpoints are available since protocol
   1354 **v43**.
   1355 
   1356 Managing fountains
   1357 ^^^^^^^^^^^^^^^^^^
   1358 
   1359 .. include:: merchant/post-private-fountains.rst
   1360 
   1361 .. include:: merchant/patch-private-fountains-FOUNTAIN_ID.rst
   1362 
   1363 .. include:: merchant/get-private-fountains.rst
   1364 
   1365 .. include:: merchant/get-private-fountains-FOUNTAIN_ID.rst
   1366 
   1367 .. include:: merchant/delete-private-fountains-FOUNTAIN_ID.rst
   1368 
   1369 
   1370 Wallet fountain API
   1371 ^^^^^^^^^^^^^^^^^^^
   1372 
   1373 .. include:: merchant/get-fountain-info.rst
   1374 
   1375 .. include:: merchant/post-fountain-withdraw.rst
   1376 
   1377 
   1378 -----------------------
   1379 Donau Charity Instances
   1380 -----------------------
   1381 
   1382 A merchant instance can link one or more **Donau charity instances**.
   1383 Each link associates the instance’s own public key with a charity registered
   1384 at some Donau service.  These links are managed under the private API.
   1385 
   1386 Permissions
   1387 ^^^^^^^^^^^
   1388 
   1389 * ``donau-read``  — list linked charities.
   1390 * ``donau-write`` — add or remove charity links.
   1391 
   1392 See :ref:`Scopes <merchant-api-scopes>` for how permissions relate to the
   1393 scope of an access token.
   1394 
   1395 Listing charity instances
   1396 ^^^^^^^^^^^^^^^^^^^^^^^^^
   1397 
   1398 .. include:: merchant/get-private-donau.rst
   1399 
   1400 Adding a charity instance
   1401 ^^^^^^^^^^^^^^^^^^^^^^^^^
   1402 
   1403 .. include:: merchant/post-private-donau.rst
   1404 
   1405 Deleting a charity instance
   1406 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   1407 
   1408 .. include:: merchant/delete-private-donau-DONAU_SERIAL.rst
   1409 
   1410 
   1411 ------------------
   1412 The Contract Terms
   1413 ------------------
   1414 
   1415 This section describes the overall structure of templates, orders and contract
   1416 terms that are the foundation for Taler payments.
   1417 
   1418 .. _template-contract-details:
   1419 
   1420 Templates
   1421 ^^^^^^^^^
   1422 
   1423 The template contract is like the most raw form where many choices are still
   1424 open or deferred.
   1425 
   1426 
   1427   .. ts:def:: TemplateContractDetails
   1428 
   1429     type TemplateContractDetails = (TemplateContractFixedOrder | TemplateContractInventoryCart | TemplateContractPaivana) & TemplateContractCommon;
   1430 
   1431   .. ts:def:: TemplateContractCommon
   1432 
   1433     interface TemplateContractCommon {
   1434       // Template type to apply. Defaults to "fixed-order" if omitted.
   1435       // Prescribes which interface has to be followed
   1436       // Since protocol **v25**.
   1437       template_type?: TemplateType;
   1438 
   1439       // Human-readable summary for the template.
   1440       summary?: string;
   1441 
   1442       // Required currency for payments to the template.
   1443       // This parameter is optional and should not be present
   1444       // if "amount" is given.
   1445       currency?: string;
   1446 
   1447       // Lower bound (inclusive) on amounts the client gets to choose
   1448       // when instantiating this template.  Excludes any tip.  Only
   1449       // amounts the client had an influence on are checked against
   1450       // this bound: the amount given in the request for a "fixed-order"
   1451       // template, the total of the selected products for an
   1452       // "inventory-cart" template, and the amount of an editable choice
   1453       // for a "paivana" template.  Requires "currency" to be given and
   1454       // to match, must be in the same currency as "max_amount", and
   1455       // must not exceed it.
   1456       // Since protocol **v34**.
   1457       min_amount?: Amount;
   1458 
   1459       // Upper bound (inclusive) on amounts the client gets to choose
   1460       // when instantiating this template.  Excludes any tip.  Checked
   1461       // against the same amounts as "min_amount".  Requires "currency"
   1462       // to be given and to match.
   1463       // Since protocol **v34**.
   1464       max_amount?: Amount;
   1465 
   1466       // Time available to pay before the order expires unpaid.  If omitted or
   1467       // zero, the instance's default pay delay is used.  "forever" is invalid.
   1468       pay_duration?: RelativeTime;
   1469 
   1470       // How long will customers have to access / read / pick-up
   1471       // the resource they are buying? Will turn into
   1472       // max_pickup_time in the contract for every template type,
   1473       // measured from order creation (not from payment or a repeat visit).
   1474       // Optional; if omitted or "forever", access has no deadline.
   1475       // Zero gives an immediately expired access window.
   1476       // Since protocol **v29**.
   1477       max_pickup_duration?: RelativeTime;
   1478 
   1479       // Minimum age buyer must have (in years). Default is 0.
   1480       minimum_age?: Integer;
   1481 
   1482       // Inventory-cart: request a tip during instantiation.
   1483       // Since protocol **v25**.
   1484       request_tip?: boolean;
   1485     }
   1486 
   1487   .. ts:def:: TemplateType
   1488 
   1489     enum TemplateType {
   1490       FIXED_ORDER = "fixed-order",
   1491       INVENTORY_CART = "inventory-cart",
   1492       PAIVANA = "paivana"
   1493     }
   1494 
   1495   .. ts:def:: TemplateContractFixedOrder
   1496 
   1497     interface TemplateContractFixedOrder {
   1498 
   1499       // The price is imposed by the merchant and cannot be changed by the customer.
   1500       // This parameter is optional.
   1501       amount?: Amount;
   1502 
   1503     }
   1504 
   1505   .. ts:def:: TemplateContractInventoryCart
   1506 
   1507     interface TemplateContractInventoryCart {
   1508 
   1509       // Inventory-cart: allow any inventory item to be selected.
   1510       // Since protocol **v25**.
   1511       selected_all?: boolean;
   1512 
   1513       // Inventory-cart: only products in these categories are selectable.
   1514       // Since protocol **v25**.
   1515       selected_categories?: Integer[];
   1516 
   1517       // Inventory-cart: only these products are selectable.
   1518       // Since protocol **v25**.
   1519       selected_products?: string[];
   1520 
   1521       // Inventory-cart: require exactly one selection entry.
   1522       // Since protocol **v25**.
   1523       choose_one?: boolean;
   1524 
   1525       // Inventory-cart: backend-provided payload with selectable data.
   1526       // Only present in ``GET /templates/$TEMPLATE_ID`` responses.
   1527       // Since protocol **v25**.
   1528       inventory_payload?: InventoryPayload;
   1529    }
   1530 
   1531   .. ts:def:: TemplateContractPaivana
   1532 
   1533     interface TemplateContractPaivana {
   1534 
   1535       // POSIX extended regular expression over URLs for which
   1536       // this template is valid.  Matched against the absolute
   1537       // URL, and anchored: it must match that URL in its
   1538       // entirety, not merely occur within it.
   1539       // Optional, if not given all URLs are accepted.
   1540       // Since protocol **v25**.
   1541       website_regex?: string;
   1542 
   1543       // Methods to pay for the contract.
   1544       choices: TemplateOrderChoice[];
   1545    }
   1546 
   1547   The backend only stores ``website_regex``; it is the paywall proxy
   1548   reading these templates that evaluates it.  ``paivana-httpd`` matches
   1549   it against the **absolute** URL of the request (``BASE_URL`` or the
   1550   scheme and ``Host`` of the request, followed by the path) and anchors
   1551   it, so an expression written against the path alone, or meant as a
   1552   substring rule, will not apply.  See :ref:`Paivana-Templates` in the
   1553   :doc:`Paivana operator manual <../taler-paivana-manual>` for the
   1554   matching rules and worked examples.
   1555 
   1556   If exactly one of the ``choices`` of a Paivana template has
   1557   ``editable_amount`` set, the template may also carry an ``amount`` in its
   1558   ``editable_defaults`` to tell the user interface to offer a single amount
   1559   field with that default; the client then submits it as the ``amount`` of
   1560   the `UsingTemplateCommonRequest`.  With more than one editable choice, the
   1561   defaults are the ``amount`` values of the choices themselves and the client
   1562   must use ``choice_amounts``.
   1563 
   1564 .. _template-choice:
   1565 
   1566 Template Choices
   1567 ^^^^^^^^^^^^^^^^
   1568 
   1569   The `OrderChoice` object describes a possible choice within an order. The
   1570   choice is done by the wallet and consists of in- and outputs. In the example
   1571   of buying an article, the merchant could present the customer with the
   1572   choice to use a valid subscription token or pay using a gift
   1573   voucher. Available since protocol **v21**.
   1574 
   1575   .. ts:def:: OrderChoice
   1576 
   1577     interface OrderChoice {
   1578       // Total price for the choice. The exchange will subtract deposit
   1579       // fees from that amount before transferring it to the merchant.
   1580       amount: Amount;
   1581 
   1582       // Optional tip amount. Must match the currency of ``amount``.
   1583       // Since protocol **v25**.
   1584       tip?: Amount;
   1585 
   1586       // Human readable description of the semantics of the choice
   1587       // within the contract to be shown to the user at payment.
   1588       description?: string;
   1589 
   1590       // Map from IETF 47 language tags to localized descriptions.
   1591       description_i18n?: { [lang_tag: string]: string };
   1592 
   1593       // Inputs that must be provided by the customer, if this choice is selected.
   1594       // Defaults to empty array if not specified.
   1595       inputs?: OrderInput[];
   1596 
   1597       // Outputs provided by the merchant, if this choice is selected.
   1598       // Defaults to empty array if not specified.
   1599       outputs?: OrderOutput[];
   1600 
   1601       // Maximum total deposit fee accepted by the merchant for this contract.
   1602       // Overrides defaults of the merchant instance.
   1603       max_fee?: Amount;
   1604     }
   1605 
   1606   A choice of a *template* contract may additionally allow the client to
   1607   replace the amount when the template is instantiated.
   1608 
   1609   .. ts:def:: TemplateOrderChoice
   1610 
   1611     interface TemplateOrderChoice extends OrderChoice {
   1612       // If true, the client may replace "amount" when instantiating
   1613       // the template; "amount" then merely provides the default.  The
   1614       // client may only change the value, never the currency.  The
   1615       // resulting amount is subject to the "min_amount" and
   1616       // "max_amount" bounds of the template (if any).
   1617       // Defaults to false, in which case the amount is fixed by the
   1618       // merchant.
   1619       // Since protocol **v34**.
   1620       editable_amount?: boolean;
   1621     }
   1622 
   1623   .. ts:def:: OrderInput
   1624 
   1625     // For now, only token inputs are supported.
   1626     type OrderInput = OrderInputToken;
   1627 
   1628   .. ts:def:: OrderInputToken
   1629 
   1630     interface OrderInputToken {
   1631 
   1632       // Token input.
   1633       type: "token";
   1634 
   1635       // Token family slug as configured in the merchant backend. Slug is unique
   1636       // across all configured tokens of a merchant.
   1637       token_family_slug: Slug;
   1638 
   1639       // How many units of the input are required.
   1640       // Defaults to 1 if not specified. Output with count == 0 are ignored by
   1641       // the merchant backend.
   1642       count?: Integer;
   1643 
   1644     }
   1645 
   1646   .. ts:def:: OrderOutput
   1647 
   1648     type OrderOutput = OrderOutputToken | OrderOutputTaxReceipt;
   1649 
   1650   .. ts:def:: OrderOutputToken
   1651 
   1652     interface OrderOutputToken {
   1653 
   1654       // Token output.
   1655       type: "token";
   1656 
   1657       // Token family slug as configured in the merchant backend. Slug is unique
   1658       // across all configured tokens of a merchant.
   1659       token_family_slug: Slug;
   1660 
   1661       // How many units of the output are issued by the merchant.
   1662       // Defaults to 1 if not specified. Output with count == 0 are ignored by
   1663       // the merchant backend.
   1664       count?: Integer;
   1665 
   1666       // When should the output token be valid. Can be specified if the
   1667       // desired validity period should be in the future (like selling
   1668       // a subscription for the next month). Optional. If not given,
   1669       // the validity is supposed to be "now" (time of order creation).
   1670       valid_at?: Timestamp;
   1671 
   1672     }
   1673 
   1674   .. ts:def:: OrderOutputTaxReceipt
   1675 
   1676     interface OrderOutputTaxReceipt {
   1677 
   1678       // Tax receipt output.
   1679       type: "tax-receipt";
   1680 
   1681       // Donation amount. Useful if the donation is only for
   1682       // part of the total.
   1683       // Optional, if not given the purchase total amount is
   1684       // assumed to be the donation amount.
   1685       amount?: Amount;
   1686     }
   1687 
   1688 .. _contract-base-terms:
   1689 
   1690 Contract base terms
   1691 ^^^^^^^^^^^^^^^^^^^
   1692 
   1693 These are the basic terms that are shared terms between orders and contracts
   1694 and basically present (or optional) all the time.
   1695 
   1696 .. ts:def:: ContractBaseTerms
   1697 
   1698   interface ContractBaseTerms {
   1699     // Human-readable description of the whole purchase.
   1700     summary: string;
   1701 
   1702     // Map from IETF BCP 47 language tags to localized summaries.
   1703     summary_i18n?: { [lang_tag: string]: string };
   1704 
   1705     // Unique, free-form identifier for the proposal.
   1706     // Must be unique within a merchant instance.
   1707     // For merchants that do not store proposals in their DB
   1708     // before the customer paid for them, the ``order_id`` can be used
   1709     // by the frontend to restore a proposal from the information
   1710     // encoded in it (such as a short product identifier and timestamp).
   1711     order_id: Slug;
   1712 
   1713     // URL where the same contract could be ordered again (if
   1714     // available). Returned also at the public order endpoint
   1715     // for people other than the actual buyer (hence public,
   1716     // in case order IDs are guessable).
   1717     public_reorder_url?: WebURL;
   1718 
   1719     // URL that will show that the order was successful after
   1720     // it has been paid for.  Optional, but either ``fulfillment_url``
   1721     // or ``fulfillment_message`` must be specified in every
   1722     // contract terms.
   1723     //
   1724     // If a non-unique fulfillment URL is used, a customer can only
   1725     // buy the order once and will be redirected to a previous purchase
   1726     // when trying to buy an order with the same fulfillment URL a second
   1727     // time, while the previous purchase's max_pickup_time still permits
   1728     // access. This is useful for digital goods that a customer should
   1729     // be able to repeatedly download during the purchased access period.
   1730     //
   1731     // For orders where the customer is expected to be able to make
   1732     // repeated purchases (for equivalent goods), the fulfillment URL
   1733     // should be made unique for every order. The easiest way to do
   1734     // this is to include a unique order ID in the fulfillment URL.
   1735     //
   1736     // When POSTing to the merchant, the placeholder text "${ORDER_ID}"
   1737     // is be replaced with the actual order ID (useful if the
   1738     // order ID is generated server-side and needs to be
   1739     // in the URL). Note that this placeholder can only be used once.
   1740     // Front-ends may use other means to generate a unique fulfillment URL.
   1741     // Because of that placeholder, the value given here is merely a
   1742     // string and not yet a `WebURL`; only after the substitution has
   1743     // been performed is the result a `WebURL`.
   1744     fulfillment_url?: string;
   1745 
   1746     // Message shown to the customer after paying for the order.
   1747     // Either fulfillment_url or fulfillment_message must be specified.
   1748     fulfillment_message?: string;
   1749 
   1750     // Map from IETF BCP 47 language tags to localized fulfillment
   1751     // messages.
   1752     fulfillment_message_i18n?: { [lang_tag: string]: string };
   1753 
   1754     // Delivery location for (all!) products.
   1755     delivery_location?: Location;
   1756 
   1757     // Time indicating when the order should be delivered.
   1758     // May be overwritten by individual products.
   1759     delivery_date?: Timestamp;
   1760 
   1761     // Specifies for how long the wallet should try to get an
   1762     // automatic refund for the purchase. If this field is
   1763     // present, the wallet should wait for a few seconds after
   1764     // the purchase and then automatically attempt to obtain
   1765     // a refund.  The wallet should probe until "delay"
   1766     // after the payment was successful (i.e. via long polling
   1767     // or via explicit requests with exponential back-off).
   1768     //
   1769     // In particular, if the wallet is offline
   1770     // at that time, it MUST repeat the request until it gets
   1771     // one response from the merchant after the delay has expired.
   1772     // If the refund is granted, the wallet MUST automatically
   1773     // recover the payment.  This is used in case a merchant
   1774     // knows that it might be unable to satisfy the contract and
   1775     // desires for the wallet to attempt to get the refund without any
   1776     // customer interaction.  Note that it is NOT an error if the
   1777     // merchant does not grant a refund.
   1778     auto_refund?: RelativeTime;
   1779 
   1780     // Extra data that is only interpreted by the merchant frontend.
   1781     // Useful when the merchant needs to store extra information on a
   1782     // contract without storing it separately in their database.
   1783     // Must really be an Object (not a string, integer, float or array).
   1784     extra?: Object;
   1785 
   1786     // Minimum age the buyer must have (in years). Default is 0.
   1787     // This value is at least as large as the maximum over all
   1788     // mimimum age requirements of the products in this contract.
   1789     // It might also be set independent of any product, due to
   1790     // legal requirements.
   1791     minimum_age?: Integer;
   1792 
   1793     // Default money pot to use for this order, applies to the
   1794     // amount remaining that was not claimed by money pots of
   1795     // products or taxes.  Not useful to wallets, only for
   1796     // merchant-internal accounting.  If not given, the remaining
   1797     // account is simply not accounted for in any money pot.
   1798     // Since **v25**.
   1799     order_default_money_pot?: Integer;
   1800 
   1801     // Latest time until which the good or service specified in the
   1802     // contract may be picked up by the customer. This is usually
   1803     // for digital goods where the customer has a finite window
   1804     // for downloading the resource(s). Absent or "never" means unlimited.
   1805     // Once this time is reached, wallets must not reuse the purchase to
   1806     // satisfy a new order with the same fulfillment_url. A new payment
   1807     // requires the customer's confirmation.
   1808     max_pickup_time?: Timestamp;
   1809 
   1810   }
   1811 
   1812 .. _order-details:
   1813 
   1814 Orders
   1815 ^^^^^^
   1816 
   1817   The `Order` object represents the starting point for new `ContractTerms`.
   1818   After validating and sanitizing all inputs, the merchant backend will add
   1819   additional information to the order and create a new `ContractTerms` object
   1820   that will be stored in the database.
   1821 
   1822   .. ts:def:: Order
   1823 
   1824     type Order = ContractBaseTerms & (OrderV0 | OrderV1) & OrderCommon;
   1825 
   1826   .. ts:def:: OrderV0
   1827 
   1828     interface OrderV0 {
   1829       // Optional, defaults to 0 if not set.
   1830       version?: 0;
   1831 
   1832       // Total price for the transaction, including tip. The exchange will
   1833       // subtract deposit fees from that amount before transferring it to
   1834       // the merchant.
   1835       amount: Amount;
   1836 
   1837       // Optional tip amount. Must match the currency of ``amount``.
   1838       // Since protocol **v25**.
   1839       tip?: Amount;
   1840 
   1841       // Maximum total deposit fee accepted by the merchant for this contract.
   1842       // Overrides defaults of the merchant instance.
   1843       max_fee?: Amount;
   1844     }
   1845 
   1846   .. ts:def:: OrderV1
   1847 
   1848     interface OrderV1 {
   1849       // Version 1 order support discounts and subscriptions.
   1850       // https://docs.taler.net/design-documents/046-mumimo-contracts.html
   1851       // @since protocol **v21**
   1852       version: 1;
   1853 
   1854       // List of contract choices that the customer can select from.
   1855       // @since protocol **v21**
   1856       choices: OrderChoice[];
   1857     }
   1858 
   1859 
   1860   .. ts:def:: OrderCommon
   1861 
   1862     interface OrderCommon {
   1863 
   1864       // List of products that are part of the purchase.
   1865       products?: ProductEntry[];
   1866 
   1867       // After this deadline has passed, no refunds will be accepted.
   1868       // Overrides deadline calculated from ``refund_delay`` in
   1869       // `PostOrderRequest`.
   1870       // A value of "never" is not allowed.
   1871       refund_deadline?: Timestamp;
   1872 
   1873       // After this deadline, the merchant won't accept payments for the contract.
   1874       // Overrides deadline calculated from default pay delay configured in
   1875       // merchant backend.
   1876       // A value of "never" is not allowed.
   1877       pay_deadline?: Timestamp;
   1878 
   1879       // Transfer deadline for the exchange. Must be in the deposit permissions
   1880       // of coins used to pay for this order.
   1881       // Overrides deadline calculated from default wire transfer delay
   1882       // configured in merchant backend. Must be after refund deadline.
   1883       // A value of "never" is not allowed.
   1884       wire_transfer_deadline?: Timestamp;
   1885 
   1886       // Payments for this order that were settled outside of Taler,
   1887       // for example in cash or by card. The ``amount`` field above (or
   1888       // the selected choice's ``amount`` for v1 orders) remains the
   1889       // amount paid with Taler; the full order total is the sum of that
   1890       // amount and all entries here. If present, all entries and (for
   1891       // v1 orders) all choices must use the currency of the Taler
   1892       // ``amount``. Never contains a ``taler`` entry.
   1893       // @since protocol **v42**.
   1894       amount_external?: ExternalPaymentInfo[];
   1895 
   1896     }
   1897 
   1898   .. ts:def:: ExternalPaymentInfo
   1899 
   1900     interface ExternalPaymentInfo {
   1901       // External payment method, for example "cash" or "card".
   1902       // Must be a stable, non-empty identifier of ASCII
   1903       // alphanumerics and "-", and must never be "taler".
   1904       method: string;
   1905 
   1906       // Identifier of the payment action within the order, unique
   1907       // among the entries of this ``amount_external`` array.
   1908       // Examples: "cash1", "card1", "card2".
   1909       id: string;
   1910 
   1911       // Amount covered by this payment action. Must use the same
   1912       // currency as the Taler ``amount`` of the order.
   1913       amount: Amount;
   1914 
   1915       // Additional method-specific fields for reconciliation or audit,
   1916       // for example a cashier number, terminal identifier or
   1917       // authorization code. These must be flat scalar values (no
   1918       // nested objects or arrays) so that the merchant portal can
   1919       // render ``amount_external`` as a generic table.
   1920       [field: string]: string | Amount | Integer | boolean | null;
   1921     }
   1922 
   1923 .. _product-entry:
   1924 
   1925 Product entries
   1926 ^^^^^^^^^^^^^^^
   1927 
   1928   .. ts:def:: ProductEntry
   1929 
   1930     type ProductEntry = (ProductSold | MinimalInventoryProduct);
   1931 
   1932 
   1933 The following `MinimalInventoryProduct` can be provided if the parts of the
   1934 order are inventory-based, that is if the `PostOrderRequest` uses
   1935 ``inventory_products``. For such products, which must be in the backend's
   1936 inventory, the backend can automatically fill in the amount and other details
   1937 about the product that are known to it from its ``products`` table.  Note that
   1938 the ``inventory_products`` will be appended to the list of ``products`` that
   1939 the frontend already put into the ``order``.  So the frontend can sell
   1940 additional non-inventory products together with ``inventory_products``.  Note
   1941 that the backend will NOT update the ``amount`` of the ``order``, so the
   1942 frontend must already have calculated the total price --- including the
   1943 ``inventory_products``.
   1944 
   1945   .. ts:def:: MinimalInventoryProduct
   1946 
   1947     // Note that if the frontend does give details beyond these,
   1948     // it will override those details (including price or taxes)
   1949     // that the backend would otherwise fill in via the inventory.
   1950     interface MinimalInventoryProduct {
   1951 
   1952       // Which product is requested (here mandatory!).
   1953       product_id: Slug;
   1954 
   1955       // Legacy integer quantity.
   1956       // Deprecated since **v25**;
   1957       // defaults to 1 if both ``quantity`` and ``unit_quantity`` are absent.
   1958       quantity?: Integer;
   1959 
   1960       // Preferred quantity string using "<integer>[.<fraction>]" syntax.
   1961       // @since **v25**;
   1962       unit_quantity?: string
   1963 
   1964       // Money pot to use for this product, overrides value from
   1965       // the inventory if given.
   1966       // Since **v25**.
   1967       product_money_pot?: Integer;
   1968 
   1969     }
   1970 
   1971 Clients must supply either ``quantity`` or ``unit_quantity`` when referencing
   1972 inventory products. If both are missing the backend assumes a quantity of
   1973 one. ``unit_quantity`` follows the same decimal-string rules as
   1974 ``unit_total_stock``.
   1975 
   1976 
   1977 .. _contract-token-family:
   1978 
   1979 Contract token family
   1980 ^^^^^^^^^^^^^^^^^^^^^
   1981 
   1982 The contract token family provides additional meta-data about
   1983 input and output tokens associated with a particular choice of
   1984 payment.
   1985 
   1986 .. ts:def:: ContractTokenFamily
   1987 
   1988   interface ContractTokenFamily {
   1989     // Human-readable name of the token family.
   1990     name: string;
   1991 
   1992     // Human-readable description of the semantics of
   1993     // this token family (for display).
   1994     description: string;
   1995 
   1996     // Map from IETF BCP 47 language tags to localized descriptions.
   1997     description_i18n?: { [lang_tag: string]: string };
   1998 
   1999     // Public keys used to validate tokens issued by this token family.
   2000     keys: TokenIssuePublicKey[];
   2001 
   2002     // Kind-specific information of the token
   2003     details: ContractTokenDetails;
   2004 
   2005     // Must a wallet understand this token type to
   2006     // process contracts that use or issue it?
   2007     critical: boolean;
   2008   };
   2009 
   2010 .. ts:def:: TokenIssuePublicKey
   2011 
   2012   type TokenIssuePublicKey =
   2013     | TokenIssueRsaPublicKey
   2014     | TokenIssueCsPublicKey;
   2015 
   2016 .. ts:def:: TokenIssueRsaPublicKey
   2017 
   2018   interface TokenIssueRsaPublicKey {
   2019     cipher: "RSA";
   2020 
   2021     // RSA public key.
   2022     rsa_pub: RsaPublicKey;
   2023 
   2024     // Start time of this key's signatures validity period.
   2025     signature_validity_start: Timestamp;
   2026 
   2027     // End time of this key's signatures validity period.
   2028     signature_validity_end: Timestamp;
   2029 
   2030   }
   2031 
   2032 .. ts:def:: TokenIssueCsPublicKey
   2033 
   2034   interface TokenIssueCsPublicKey {
   2035     cipher: "CS";
   2036 
   2037     // CS public key.
   2038     cs_pub: Cs25519Point;
   2039 
   2040     // Start time of this key's signatures validity period.
   2041     signature_validity_start: Timestamp;
   2042 
   2043     // End time of this key's signatures validity period.
   2044     signature_validity_end: Timestamp;
   2045 
   2046   }
   2047 
   2048 .. ts:def:: ContractTokenDetails
   2049 
   2050   type ContractTokenDetails =
   2051     | ContractSubscriptionTokenDetails
   2052     | ContractDiscountTokenDetails;
   2053 
   2054 .. ts:def:: ContractSubscriptionTokenDetails
   2055 
   2056   interface ContractSubscriptionTokenDetails {
   2057     class: "subscription";
   2058 
   2059     // Array of domain names where this subscription
   2060     // can be safely used (e.g. the issuer warrants that
   2061     // these sites will re-issue tokens of this type
   2062     // if the respective contract says so).  May contain
   2063     // "*" for any domain or subdomain.
   2064     trusted_domains: string[];
   2065   };
   2066 
   2067 .. ts:def:: ContractDiscountTokenDetails
   2068 
   2069   interface ContractDiscountTokenDetails {
   2070     class: "discount";
   2071 
   2072     // Array of domain names where this discount token
   2073     // is intended to be used.  May contain "*" for any
   2074     // domain or subdomain.  Users should be warned about
   2075     // sites proposing to consume discount tokens of this
   2076     // type that are not in this list that the merchant
   2077     // is accepting a coupon from a competitor and thus
   2078     // may be attaching different semantics (like get 20%
   2079     // discount for my competitors 30% discount token).
   2080     expected_domains: string[];
   2081   };
   2082 
   2083 
   2084 .. _proto-contract-terms:
   2085 
   2086 Proto contract terms
   2087 ^^^^^^^^^^^^^^^^^^^^
   2088 
   2089 The proto-contract terms are the proposed contract that a merchant
   2090 is about to present to a wallet, but that lacks the wallet's *nonce*
   2091 and is thus not yet buyer-specific.
   2092 
   2093 
   2094 
   2095 .. ts:def:: ProtoContractTerms
   2096 
   2097   type ProtoContractTerms = ContractBaseTerms & (ContractTermsV0 | ContractTermsV1) & ContractTermsCommon;
   2098 
   2099 
   2100 .. ts:def:: ContractTermsV0
   2101 
   2102   interface ContractTermsV0 {
   2103     // Defaults to version 0.
   2104     version?: 0;
   2105 
   2106     // Total price for the transaction, including tip.
   2107     // The exchange will subtract deposit fees from that amount
   2108     // before transferring it to the merchant.
   2109     amount: Amount;
   2110 
   2111     // Optional tip amount. Must match the currency of ``amount``.
   2112     // Since protocol **v25**.
   2113     tip?: Amount;
   2114 
   2115     // Maximum total deposit fee accepted by the merchant for this contract.
   2116     // Overrides defaults of the merchant instance.
   2117     max_fee: Amount;
   2118   }
   2119 
   2120 .. ts:def:: ContractTermsV1
   2121 
   2122   interface ContractTermsV1 {
   2123     // Version 1 supports the ``choices`` array, see
   2124     // https://docs.taler.net/design-documents/046-mumimo-contracts.html.
   2125     // @since protocol **v21**
   2126     version: 1;
   2127 
   2128     // List of contract choices that the customer can select from.
   2129     // @since protocol **v21**
   2130     choices: ContractChoice[];
   2131 
   2132     // Map of storing metadata and issue keys of
   2133     // token families referenced in this contract.
   2134     // @since protocol **v21**
   2135     token_families: { [token_family_slug: Slug]: ContractTokenFamily };
   2136   }
   2137 
   2138 .. ts:def:: ContractTermsCommon
   2139 
   2140   interface ContractTermsCommon {
   2141 
   2142     // Time when this contract was generated.
   2143     timestamp: Timestamp;
   2144 
   2145     // After this deadline has passed, no refunds will be accepted.
   2146     refund_deadline: Timestamp;
   2147 
   2148     // After this deadline, the merchant won't accept payments for the contract.
   2149     pay_deadline: Timestamp;
   2150 
   2151     // Transfer deadline for the exchange.  Must be in the
   2152     // deposit permissions of coins used to pay for this order.
   2153     wire_transfer_deadline: Timestamp;
   2154 
   2155     // Merchant's public key used to sign this proposal; this information
   2156     // is typically added by the backend. Note that this can be an ephemeral key.
   2157     merchant_pub: EddsaPublicKey;
   2158 
   2159     // Base URL of the (public!) merchant backend API.
   2160     // Must be an absolute URL that ends with a slash.
   2161     merchant_base_url: WebURL;
   2162 
   2163     // More info about the merchant, see below.
   2164     merchant: Merchant;
   2165 
   2166     // List of products that are part of the purchase (see `ProductSold`).
   2167     products: ProductSold[];
   2168 
   2169     // The hash of the merchant instance's wire details.
   2170     h_wire: HashCode;
   2171 
   2172     // Wire transfer method identifier for the wire method associated with ``h_wire``.
   2173     // The wallet may only select exchanges via a matching auditor if the
   2174     // exchange also supports this wire method.
   2175     // The wire transfer fees must be added based on this wire transfer method.
   2176     wire_method: string;
   2177 
   2178     // Exchanges that the merchant accepts even if it does not accept any auditors that audit them.
   2179     exchanges: Exchange[];
   2180 
   2181     // Payments for this order that were settled outside of Taler,
   2182     // for example in cash or by card. The ``amount`` field (or the
   2183     // selected choice's ``amount`` for v1 contracts) remains the amount
   2184     // paid with Taler; the full order total is the sum of that amount
   2185     // and all entries here. See `ExternalPaymentInfo`.
   2186     // @since protocol **v42**.
   2187     amount_external?: ExternalPaymentInfo[];
   2188 
   2189   }
   2190 
   2191 .. ts:def:: ContractChoice
   2192 
   2193   interface ContractChoice {
   2194     // Price to be paid for this choice. Could be 0.
   2195     // The price is in addition to other instruments,
   2196     // such as rations and tokens.
   2197     // The exchange will subtract deposit fees from that amount
   2198     // before transferring it to the merchant.
   2199     amount: Amount;
   2200 
   2201     // Optional tip amount. Must match the currency of ``amount``.
   2202     // Since protocol **v25**.
   2203     tip?: Amount;
   2204 
   2205     // Human readable description of the semantics of the choice
   2206     // within the contract to be shown to the user at payment.
   2207     description?: string;
   2208 
   2209     // Map from IETF 47 language tags to localized descriptions.
   2210     description_i18n?: { [lang_tag: string]: string };
   2211 
   2212     // List of inputs the wallet must provision (all of them) to
   2213     // satisfy the conditions for the contract.
   2214     inputs: ContractInput[];
   2215 
   2216     // List of outputs the merchant promises to yield (all of them)
   2217     // once the contract is paid.
   2218     outputs: ContractOutput[];
   2219 
   2220     // Maximum total deposit fee accepted by the merchant for this contract.
   2221     max_fee: Amount;
   2222   }
   2223 
   2224 .. ts:def:: ContractInput
   2225 
   2226   // For now, only tokens are supported as inputs.
   2227   type ContractInput = ContractInputToken;
   2228 
   2229 .. ts:def:: ContractInputToken
   2230 
   2231   interface ContractInputToken {
   2232     type: "token";
   2233 
   2234     // Slug of the token family in the
   2235     // ``token_families`` map on the order.
   2236     token_family_slug: Slug;
   2237 
   2238     // Number of tokens of this type required.
   2239     // Defaults to one if the field is not provided.
   2240     count?: Integer;
   2241   };
   2242 
   2243 .. ts:def:: ContractOutput
   2244 
   2245   // For now, only tokens are supported as outputs.
   2246   type ContractOutput = ContractOutputToken | ContractOutputTaxReceipt;
   2247 
   2248 .. ts:def:: ContractOutputToken
   2249 
   2250   interface ContractOutputToken {
   2251     type: "token";
   2252 
   2253     // Slug of the token family in the
   2254     // 'token_families' map on the top-level.
   2255     token_family_slug: Slug;
   2256 
   2257     // Number of tokens to be issued.
   2258     // Defaults to one if the field is not provided.
   2259     count?: Integer;
   2260 
   2261     // When should the output token be valid. Can be specified if the
   2262     // desired validity period should be in the future (like selling
   2263     // a subscription for the next month). Optional. If not given,
   2264     // the validity is supposed to be "now" (time of order creation).
   2265     valid_at?: Timestamp;
   2266 
   2267     // Index of the public key for this output token
   2268     // in the `ContractTokenFamily` ``keys`` array.
   2269     key_index: Integer;
   2270 
   2271   }
   2272 
   2273 .. ts:def:: ContractOutputTaxReceipt
   2274 
   2275   interface ContractOutputTaxReceipt {
   2276 
   2277     // Tax receipt output.
   2278     type: "tax-receipt";
   2279 
   2280     // Array of base URLs of donation authorities that can be
   2281     // used to issue the tax receipts. The client must select one.
   2282     donau_urls: WebURL[];
   2283 
   2284     // Total amount that will be on the tax receipt.
   2285     amount: Amount;
   2286 
   2287   }
   2288 
   2289 
   2290 Product listing
   2291 ^^^^^^^^^^^^^^^
   2292 
   2293 The `ProductSold` object describes a product and the quantity
   2294 being purchased from the merchant as well as possibly the price
   2295 and applicable taxes.
   2296 It has the following structure:
   2297 
   2298 .. ts:def:: ProductSold
   2299 
   2300   interface ProductSold {
   2301 
   2302     // Merchant-internal identifier for the product.
   2303     product_id?: Slug;
   2304 
   2305     // Name of the product.
   2306     // Since API version **v20**.  Optional only for
   2307     // backwards-compatibility, should be considered mandatory
   2308     // moving forward!
   2309     product_name?: string;
   2310 
   2311     // Human-readable product description.
   2312     description: string;
   2313 
   2314     // Map from IETF BCP 47 language tags to localized descriptions.
   2315     description_i18n?: { [lang_tag: string]: string };
   2316 
   2317     // Legacy integer portion of the quantity to deliver defaults to 1 if not specified.
   2318     quantity?: Integer;
   2319 
   2320     // Preferred quantity string using "<integer>[.<fraction>]" syntax with up to six fractional digits.
   2321     unit_quantity?: string;
   2322 
   2323     // Unit in which the product is measured (liters, kilograms, packages, etc.).
   2324     unit?: Slug;
   2325 
   2326     // The price of the product;
   2327     // Deprecated since **v25**;
   2328     // this is the total price
   2329     // for ``quantity`` times ``unit`` of this product.
   2330     price?: Amount;
   2331 
   2332     // Price of ``unit_quantity`` units of the product in various currencies.
   2333     // Zero or absent implies that the product is not sold
   2334     // separately.
   2335     // Since API version **v25**.
   2336     prices?: Amount[];
   2337 
   2338     // True if the ``prices`` given are the net price,
   2339     // false if they are the gross price.  Note that even ``prices`` are the
   2340     // gross price, ``taxes`` may be missing if the merchant configured
   2341     // gross ``prices`` but did not configure any ``taxes``.
   2342     // Similarly, the merchant may have configured net ``prices``
   2343     // for products but deals with taxes on a per-order basis. Thus, it
   2344     // may not always be possible to compute the gross price from the net
   2345     // price for an individual product, necessitating this flag.
   2346     // Since protocol **vTAXES**.
   2347     prices_are_net: boolean;
   2348 
   2349     // An optional base64-encoded product image.
   2350     image?: ImageDataUrl;
   2351 
   2352     // A list of taxes paid by the merchant for this product. Can be empty.
   2353     // Will likely change soon!
   2354     taxes?: Tax[];
   2355 
   2356     // Time indicating when this product should be delivered.
   2357     delivery_date?: Timestamp;
   2358 
   2359     // Money pot to use for this product, overrides value from
   2360     // the inventory if given.  Not useful to wallets, only for
   2361     // merchant-internal accounting.
   2362     // Since **v25**.
   2363     product_money_pot?: Integer;
   2364 
   2365   }
   2366 
   2367 .. ts:def:: Tax
   2368 
   2369   interface Tax {
   2370     // The name of the tax.
   2371     name: string;
   2372 
   2373     // Amount paid in tax.
   2374     tax: Amount;
   2375   }
   2376 
   2377 .. ts:def:: Merchant
   2378 
   2379   interface Merchant {
   2380     // The merchant's legal name of business.
   2381     name: string;
   2382 
   2383     // Email address for contacting the merchant.
   2384     email?: string;
   2385 
   2386     // Merchant public website.
   2387     website?: WebURL;
   2388 
   2389     // An optional base64-encoded product image.
   2390     logo?: ImageDataUrl;
   2391 
   2392     // Label for a location with the business address of the merchant.
   2393     address?: Location;
   2394 
   2395     // Label for a location that denotes the jurisdiction for disputes.
   2396     // Some of the typical fields for a location (such as a street address) may be absent.
   2397     jurisdiction?: Location;
   2398   }
   2399 
   2400 
   2401 .. ts:def:: Location
   2402 
   2403   // Delivery location, loosely modeled as a subset of
   2404   // ISO20022's PostalAddress25.
   2405   interface Location {
   2406     // Nation with its own government.
   2407     country?: string;
   2408 
   2409     // Identifies a subdivision of a country such as state, region, county.
   2410     country_subdivision?: string;
   2411 
   2412     // Identifies a subdivision within a country sub-division.
   2413     district?: string;
   2414 
   2415     // Name of a built-up area, with defined boundaries, and a local government.
   2416     town?: string;
   2417 
   2418     // Specific location name within the town.
   2419     town_location?: string;
   2420 
   2421     // Identifier consisting of a group of letters and/or numbers that
   2422     // is added to a postal address to assist the sorting of mail.
   2423     post_code?: string;
   2424 
   2425     // Name of a street or thoroughfare.
   2426     street?: string;
   2427 
   2428     // Name of the building or house.
   2429     building_name?: string;
   2430 
   2431     // Number that identifies the position of a building on a street.
   2432     building_number?: string;
   2433 
   2434     // Free-form address lines, should not exceed 7 elements.
   2435     address_lines?: string[];
   2436   }
   2437 
   2438 
   2439 Exchanges
   2440 ^^^^^^^^^
   2441 
   2442 The wallet must select an exchange that the merchant accepts by
   2443 listing it in the exchanges array.
   2444 
   2445 .. ts:def:: Exchange
   2446 
   2447   interface Exchange {
   2448     // The exchange's base URL.
   2449     url: WebURL;
   2450 
   2451     // How much would the merchant like to use this exchange.
   2452     // The wallet should use a suitable exchange with high
   2453     // priority. The following priority values are used, but
   2454     // it should be noted that they are NOT in any way normative.
   2455     //
   2456     // 0: likely it will not work (recently seen with account
   2457     //    restriction that would be bad for this merchant)
   2458     // 512: merchant does not know, might be down (merchant
   2459     //    did not yet get /wire response).
   2460     // 1024: good choice (recently confirmed working)
   2461     priority: Integer;
   2462 
   2463     // Master public key of the exchange.
   2464     master_pub: EddsaPublicKey;
   2465 
   2466     // Maximum amount that the merchant could be paid
   2467     // using this exchange (due to legal limits).
   2468     // New in protocol **v17**.
   2469     // Optional, no limit if missing.
   2470     max_contribution?: Amount;
   2471   }
   2472 
   2473 In addition to the fields described above,
   2474 each object (from `ContractTerms` down)
   2475 can mark certain fields as "forgettable" by listing the names of those fields
   2476 in a special peer field ``$forgettable``.
   2477 (See :ref:`Private order data cleanup <private-order-data-cleanup>`.)
   2478 
   2479 
   2480 .. _contract-terms:
   2481 
   2482 Final contract terms
   2483 ^^^^^^^^^^^^^^^^^^^^
   2484 
   2485 The contract terms are the final object that is signed by both
   2486 parties to finalize a purchase. It must have the following structure:
   2487 
   2488 .. ts:def:: ContractTerms
   2489 
   2490   type ContractTerms = ProtoContractTerms & ContractTermsNonce;
   2491 
   2492 .. ts:def:: ContractTermsNonce
   2493 
   2494   interface ContractTermsNonce {
   2495 
   2496     // Nonce generated by the wallet and echoed by the merchant
   2497     // in this field when the order is claimed and converted
   2498     // into a contract that is bound to a wallet.
   2499     nonce: EddsaPublicKey;
   2500   }