taler-docs

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

api-merchant.rst (62818B)


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