taler-docs

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

api-merchant.rst (50632B)


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