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