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