taler-docs

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

api-merchant.rst (82798B)


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