taler-docs

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

api-merchant.rst (83666B)


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