taler-merchant-manual.rst (74333B)
1 .. 2 This file is part of GNU TALER. 3 4 Copyright (C) 2014-2023 Taler Systems SA 5 6 TALER is free software; you can redistribute it and/or modify it under the 7 terms of the GNU Affero General Public License as published by the Free Software 8 Foundation; either version 2.1, or (at your option) any later version. 9 10 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 12 A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. 13 14 You should have received a copy of the GNU Affero General Public License along with 15 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 16 17 @author Christian Grothoff 18 19 .. _taler-merchant-backend-operator-manual: 20 21 Merchant Backend Operator Manual 22 ################################ 23 24 .. contents:: Table of Contents 25 :depth: 1 26 :local: 27 28 29 Introduction 30 ============ 31 32 About GNU Taler 33 --------------- 34 35 .. include:: frags/about-taler.rst 36 37 38 .. _About-this-manual: 39 40 About this manual 41 ----------------- 42 43 This manual targets system administrators who want to install a GNU 44 Taler merchant *backend*. 45 46 We expect some moderate familiarity with the compilation and 47 installation of Free Software packages. An understanding of cryptography 48 is not required. 49 50 .. _Architecture-overview: 51 52 Architecture overview 53 --------------------- 54 55 .. index:: crypto-currency 56 .. index:: KUDOS 57 58 Taler is a pure payment system, not a new crypto-currency. As such, it 59 operates in a traditional banking context. In particular, this means that in 60 order to receive funds via Taler, the merchant must have a regular bank 61 account, and payments can be executed in ordinary currencies such as USD or 62 EUR. Taler can also be used as a regional currency; for such scenarios, the 63 Taler system also includes its own stand-alone bank. 64 65 .. index:: frontend 66 .. index:: back-office 67 .. index:: backend 68 .. index:: DBMS 69 .. index:: PostgreSQL 70 71 The Taler software stack for a merchant consists of four main components: 72 73 - A *frontend* which interacts with the customer’s browser. The frontend 74 enables the customer to build a shopping cart and place an order. 75 Upon payment, it triggers the respective business logic to satisfy 76 the order. This component is not included with Taler, but rather 77 assumed to exist at the merchant. 78 The `Merchant API Tutorial <https://tutorials.taler.net/dev/merchant-api/>`_ gives an 79 introduction for how to integrate Taler with Web shop frontends. 80 - A *back-office* application that enables the shop operators to view 81 customer orders, match them to financial transfers, and possibly 82 approve refunds if an order cannot be satisfied. This component is 83 not included with Taler, but rather assumed to exist at the 84 merchant. The :ref:`Merchant Backend API <merchant-api>` provides 85 the API specification that should be reviewed to integrate such a 86 back-office with the Taler backend. 87 - A Taler-specific payment *backend* which makes it easy for the frontend 88 to process financial transactions with Taler. This manual primarily 89 describes how to install and configure this backend. 90 - A *DBMS* which stores the transaction history for the Taler backend. 91 For now, the GNU Taler reference implementation only supports 92 PostgreSQL, but the code could be easily extended to support another 93 DBMS. Please review the PostgreSQL documentation for details on 94 how to configure the database. 95 96 The following image illustrates the various interactions of these key 97 components: 98 99 .. image:: images/arch-api.png 100 101 .. index:: RESTful 102 103 Basically, the backend provides the cryptographic protocol support, stores 104 Taler-specific financial information in a DBMS and communicates with the GNU 105 Taler exchange over the Internet. The frontend accesses the backend via a 106 RESTful API. As a result, the frontend never has to directly communicate with 107 the exchange, and also does not deal with sensitive data. In particular, the 108 merchant’s signing keys and bank account information are encapsulated within 109 the Taler merchant backend. 110 111 A typical deployment will additionally include a full-blown Web server (like 112 Apache or Nginx). Such a Web server would be responsible for TLS termination and 113 access control to the ``/private/`` and ``/management/`` API endpoints of the 114 merchant backend. Please carefully review the section on :ref:`secure setup 115 <Secure-setup>` before deploying a Taler merchant backend into production. 116 117 118 Terminology 119 =========== 120 121 This chapter describes some of the key concepts used throughout the manual. 122 123 Instances 124 --------- 125 126 .. index:: instance 127 128 The backend allows a single HTTP server to support multiple independent shops 129 with distinct business entities sharing a single backend. An *instance* is 130 the name or identifier that allows the single HTTP server to determine which 131 shop a request is intended for. Each instance has its own base URL in the 132 REST API of the merchant backend (``/instances/$INSTANCE/``). Each instance 133 can use its own bank accounts and keys for signing contracts. All major 134 accounting functionality is separate per instance. Access to each instance is 135 controlled via a bearer token (to be set in the HTTP "Authorization" header). 136 All instances share the same *database*, top-level HTTP(S) address and the 137 main Taler configuration (especially the accepted *currency* and *exchanges*). 138 139 .. note:: 140 141 This documentation does not use the term "user" or "username" in 142 conjunction with instances as that might create confusion between 143 instances with paying customers using the system. We also do not use the 144 term "account" in conjunction with instances, as that might cause 145 confusion with bank accounts. That said, conceptually it is of course 146 acceptable to consider instances to be the "users" or "accounts" of a 147 merchant backend and the bearer token is equivalent to a passphrase. 148 149 .. _instance-bank-account: 150 151 Instance Bank Accounts 152 ---------------------- 153 154 .. index:: Bank account 155 156 To receive payments, an instance must have configured one or more bank 157 *accounts*. When configuring the bank account of an instance, one should 158 ideally also provide the address and credentials of an HTTP service 159 implementing the :ref:`Taler Bank Revenue HTTP API 160 <taler-bank-merchant-http-api>`. Given such a service, the GNU Taler merchant 161 backend can automatically reconcile wire transfers from the exchange to the 162 merchant's bank account with the orders that are being settled. 163 164 This documentation exclusively uses the term *account* for the bank 165 accounts of a merchant or shop that may be associated with an instance. 166 167 Inventory 168 --------- 169 170 .. index:: inventory 171 .. index:: product 172 .. index:: lock 173 .. index:: unit 174 .. index:: order 175 176 The Taler backend offers inventory management as an optional function. 177 Inventory is tracked per instance and consists of *products* sold in 178 *units*. Inventory can be finite (physical stock) or infinite (for digital 179 products). Products may include previews (images) to be shown to the user as 180 well as other meta-data. Inventory management allows the frontend to *lock* 181 products, reserving a number of units from stock for a particular (unpaid) 182 *order*. The backend can keep track of how many units of a product remain in 183 stock and ensure that the number of units sold does not exceed the number of 184 units in stock. 185 186 Inventory management is optional, and it is possible for the frontend to 187 include products in orders that are not in the inventory. The frontend 188 can also override prices of products in the inventory or set a total price 189 for an order that is different from the price of the sum of the products 190 in the order. 191 192 193 Orders and Contracts 194 -------------------- 195 196 .. index:: order 197 .. index:: terms 198 .. index:: contract 199 .. index:: claim 200 .. index:: pay 201 .. index:: refund 202 .. index:: wire deadline 203 .. index:: lock 204 .. index:: legal expiration 205 206 In Taler, users pay merchants for *orders*. An order is first created by the 207 merchant. To create an order, the merchant must specify the specific *terms* 208 of the order. Order *terms* include details such as the total amount to be 209 paid, payment fees the merchant is willing to cover, the set of products to 210 deliver, a delivery location and many other details. The :ref:`merchant API 211 specification <contract-terms>` specifies the full set of possible order 212 terms. 213 214 After an order is created, it is *claimed* by a wallet. Once an order is 215 claimed by a specific wallet, only that wallet will be able to pay for this 216 order, to the exclusion of other wallets even if they see the same order URL. 217 Sharing order URLs is explicitly allowed: if a user shares an order URL 218 with another user, that other user should be given the opportunity to 219 purchase the same product. 220 221 To prevent unauthorized wallets from claiming an order, merchants can specify 222 that claims require authorization in the form of a *claim token*. This is 223 useful in case the order ID is predictable (say because an existing order ID 224 scheme with predictable order IDs from the merchant frontend is used) and at 225 the same time malicious actors claiming orders is problematic (say because of 226 limited stocks). The use of claim tokens is optional, but if a claim token is 227 used, it must be provided to the wallet as part of the order URI. 228 229 Additionally, when stocks are limited, you can configure Taler to set a 230 *product lock* on items (say, while composing the shopping cart). These 231 locks will ensure that the limited stock is respected when making offers 232 to consumers. 233 234 A wallet may *pay* for a claimed order, at which point the order turns into a 235 (paid) *contract*. Orders have a configurable expiration date (the 236 ``pay_deadline``) after which the commercial offer expires and any stock of 237 products *locked* by the order will be automatically released, allowing the 238 stock to be sold in other orders. When an unpaid order expires, the customer 239 must request a fresh order if they still want to make a purchase. 240 241 Once a contract has been paid, the merchant should fulfill the contract. It 242 is possible for the merchant to *refund* a contract order, for example if the 243 contract cannot be fulfilled after all. Refunds are only possible after the 244 customer paid and before the exchange has *wired* the payment to the 245 merchant. Once the funds have been wired, refunds are no longer allowed by the 246 Taler exchange. The *wire deadline* specifies the latest point in time by 247 which an exchange must wire the funds, while the (earlier) *refund deadline* 248 specifies the earliest point in time when an exchange may wire the funds. 249 Thus, refunds are always possible between the time of purchase and the 250 refund deadline, but may remain possible until the wire deadline. 251 252 Contract information is kept for legal reasons in the merchant database. The 253 main legal reason is typically to provide tax records in case of a tax audit. 254 After the *legal expiration* (by default: a decade), contract information is 255 deleted when running the garbage collector using ``taler-merchant-dbinit``. 256 257 258 .. _template: 259 260 Templates 261 --------- 262 263 .. index:: Template 264 265 Usually, a merchant must use an authenticated endpoint to create an order and 266 then share the link to the order with a wallet. Templates are a mechanism that 267 allows wallets to create their own orders directly, using a public endpoint. 268 The template fixes some properties of the contracts created from it, while 269 other details may be left for the customer to provide. Templates are useful 270 in cases where the point-of-sale of a merchant is offline (and thus cannot 271 setup an order), or even in cases where a simple static QR code is desired to 272 accept payments or donations. 273 274 When generating a template, the "summary" text of the contract and the 275 "amount" to be paid by the customer can be fixed or left for the customer to 276 specify. If the customer is expected to provide either or both of these 277 values, the template link (or QR code) can specify a default value. For 278 example, a cafeteria with a fixed price lunch may use a "lunch" template with 279 both values fixed to the lunch price and the "lunch" product, a bakery might 280 fix the summary to "baked goods" but allow the customer to enter the amount 281 based on the total price of the items being bought, and a charity may allow 282 donating an arbitrary amount and summary message while also suggesting default 283 values. 284 285 If an offline merchant wants to confirm that a customer did actually pay the 286 agreed amount using an order derived from a template, they can associate an 287 OTP device with the template. 288 289 290 .. _otp-device: 291 292 OTP Devices 293 ----------- 294 295 .. index:: OTP 296 .. index:: TOTP 297 298 A One-Time-Password (OTP) generator is a device or application that generates 299 a 4 to 8 digit code typically used for authentication. The widely used TOTP 300 standard is described in `RFC 6238 <https://www.rfc-editor.org/rfc/rfc6238>`_. 301 For GNU Taler merchant backends, OTP devices are used as a way to assure a 302 merchant without network connectivity that a customer made a digital 303 payment. The idea is described in depth in our `SUERF Policy Brief 304 <https://www.suerf.org/suer-policy-brief/69851/practical-offline-payments-using-one-time-passcodes>`_. 305 To use this method, a merchant must configure the OTP device's shared secret 306 in the merchant backend, and then associate the OTP device with a 307 :ref:`template`. Once the customer has paid, they are given a list of OTP 308 codes which must be shown to the merchant who can check that at least one of 309 the codes matches their OTP device, proving that the customer made the 310 payment. 311 312 313 Transfers 314 --------- 315 316 .. index:: transfer 317 .. index:: wire transfer 318 319 The Taler backend can be used to verify that the exchange correctly wired all 320 of the funds to the merchant. However, if no :ref:`Taler Bank Revenue HTTP API 321 <taler-bank-merchant-http-api>` was provided for the respective bank account, 322 the backend does not have access to the incoming wire transfers of the 323 merchant's bank account. In this case, merchants should manually provide the 324 backend with wire *transfer* data that specifies the *wire transfer subject* 325 and the amount that was received. Given this information, the backend can 326 detect and report any irregularities that might arise. 327 328 329 Webhooks 330 -------- 331 332 .. index:: webhook 333 334 A webhook is a pre-defined HTTP request that the GNU Taler merchant backend 335 will make upon certain events, such as an order being paid or refunded. When 336 the configured event happens, the merchant backend will make an HTTP request 337 to the endpoint configured in the webhook configuration, possibly sending 338 selected data about the event to the respective Web service. Webhooks can be 339 used to trigger additional business logic outside of the GNU Taler merchant 340 backend. 341 342 343 Installation 344 ============ 345 346 This chapter describes how to install the GNU Taler merchant backend. 347 348 .. _Generic-instructions: 349 350 Installing the GNU Taler binary packages on Debian 351 -------------------------------------------------- 352 353 .. include:: frags/installing-debian.rst 354 355 .. include:: frags/apt-install-taler-merchant.rst 356 357 358 Installing the GNU Taler binary packages on Trisquel 359 ---------------------------------------------------- 360 361 .. include:: frags/installing-trisquel.rst 362 363 364 Installing the GNU Taler binary packages on Ubuntu 365 -------------------------------------------------- 366 367 .. include:: frags/installing-ubuntu.rst 368 369 .. include:: frags/apt-install-taler-merchant.rst 370 371 372 Installing from source 373 ---------------------- 374 375 The following instructions will show how to install a GNU Taler 376 merchant backend from source. 377 378 The package sources can be find in our 379 `download directory <http://ftpmirror.gnu.org/taler/>`__. 380 381 .. include:: frags/semver.rst 382 383 First, the following packages need to be installed before we can compile the 384 backend: 385 386 .. include:: frags/list-of-dependencies.rst 387 388 .. include:: frags/installing-gnunet.rst 389 390 .. include:: frags/install-before-check.rst 391 392 There is no need to actually run a GNUnet peer to use the Taler merchant 393 backend -- all the merchant needs from GNUnet is a number of headers and 394 libraries! 395 396 .. include:: frags/installing-taler-exchange.rst 397 398 There is no need to actually run a Taler exchange to use the Taler merchant 399 backend -- all the merchant needs from the Taler exchange is a few headers and 400 libraries! 401 402 .. note:: 403 404 There is an additional **optional** dependency that you could install to 405 obtain support for tax-deductable donations. This is only useful for 406 charities and only in countries with tax authorities that operate a Donau to 407 register charities and accept Taler-style digitally signed donation 408 statements. As of right now, we are pretty sure that list is right now 409 empty. But, if you want to experiment with Taler-style donation statmenets, 410 you need to install Donau after the exchange and before the merchant. 411 412 .. include:: frags/install-before-check.rst 413 414 .. include:: frags/installing-taler-merchant.rst 415 416 .. include:: frags/install-before-check.rst 417 418 419 420 How to configure the merchant backend 421 ===================================== 422 423 .. index:: taler-merchant.conf 424 425 The installation already provides reasonable defaults for most of the 426 configuration options. However, some must be provided, in particular the 427 database that the backend should use. By default, the file 428 ``$HOME/.config/taler-merchant.conf`` is where the Web shop administrator specifies 429 configuration values that augment or override the defaults. 430 Note that when using our binary packages, the systemd service files 431 force the use of ``/etc/taler-merchant/taler-merchant.conf`` as the main configuration file. 432 433 434 .. include:: frags/configuration-format.rst 435 436 437 .. _Backend-options: 438 439 Backend options 440 --------------- 441 442 .. index:: DBMS 443 .. index:: PostgreSQL 444 .. index:: UNIX domain socket 445 .. index:: TCP 446 .. index:: port 447 .. index:: currency 448 .. index:: KUDOS 449 .. index:: exchange 450 .. index:: instance 451 .. index:: wire format 452 453 The following table describes the options that commonly need to be 454 modified. Here, the notation ``[$SECTION]/$OPTION`` denotes the option 455 ``$OPTION`` under the section ``[$SECTION]`` in the configuration file. 456 457 458 Service address 459 ^^^^^^^^^^^^^^^ 460 461 The service address specifies where the taler-merchant-httpd should listen for 462 requests. When using the Debian/Ubuntu packages, these options will already be 463 configured correctly for the included Nginx and Apache configurations and will 464 not need any changes. 465 466 The following option sets the transport protocol used by the merchant backend: 467 468 .. code-block:: ini 469 470 [MERCHANT] 471 SERVE = unix # or tcp 472 473 If this option is set to 474 475 - ``tcp`` then we need to set the TCP port in ``[MERCHANT]/PORT``; 476 477 - ``unix`` then we need to set the unix domain socket path and mode 478 in ``[MERCHANT]/UNIXPATH`` and ``[MERCHANT]/UNIXPATH_MODE``. The 479 latter takes the usual permission mask given as a number, e.g. 660 480 for user/group read-write access. 481 482 The frontend can then connect to the backend over HTTP using the specified 483 address. If frontend and backend run within the same operating system, the 484 use of a UNIX domain socket is recommended to avoid accidentally exposing 485 the backend to the network. 486 487 To run the Taler backend on TCP port 9966 (the default), use: 488 489 .. code-block:: ini 490 491 [MERCHANT] 492 SERVE = tcp 493 PORT = 9966 494 495 .. note:: 496 497 If you need to change where the taler-merchant-httpd listens for requests, 498 you should edit ``/etc/taler-merchant/merchant-overrides.conf``. By default, the 499 Taler merchant package will use a UNIX domain socket at 500 ``/run/taler-merchant/merchant-httpd/merchant-http.sock``. For the best possible 501 security it is recommended to leave this in place and configure a reverse 502 proxy (Nginx or Apache) as described below. 503 504 When using the Debian/Ubuntu packages, the use of a UNIX domain socket 505 is already pre-configured in the ``/etc/taler-merchant/conf.d/merchant.conf`` 506 configuration file. Suitable reverse proxy configuration 507 file templates (``taler-merchant``) are be installed in the 508 respective ``sites-available`` directories of Apache and Nginx. 509 510 511 512 Currency 513 ^^^^^^^^ 514 515 Which currency the SPA uses by default is 516 specified using the option: 517 518 .. code-block:: ini 519 520 [MERCHANT] 521 CURRENCY = EUR # or USD, ... 522 523 When testing with the Taler demonstration exchange at 524 https://exchange.demo.taler.net/ you probably want to set this 525 value to ``KUDOS``: 526 527 .. code-block:: ini 528 529 [MERCHANT] 530 CURRENCY = KUDOS 531 532 The merchant backend is already multi-currency capable, and will allow you to 533 create orders in all currencies for which an exchange is configured, not just 534 the default currency. However, the Web interface does not yet offer 535 multi-currency support and often only supports using the default currency. 536 537 .. note:: 538 539 When using the Debian/Ubuntu packages, these options should be 540 configured in the ``/etc/taler-merchant/taler-merchant.conf`` configuration file 541 (alternatively, you can also edit ``/etc/taler-merchant/merchant-overrides.conf``). 542 However, you must edit the ``taler-merchant.conf`` file manually and **must not** 543 use ``taler-merchant-config`` to do this, as that would inline the include 544 directives and destroy the carefully setup path structure. 545 546 547 Database 548 ^^^^^^^^ 549 550 In principle it is possible for the backend to support different DBMSs. 551 The option 552 553 .. code-block:: ini 554 555 [MERCHANT] 556 DB = postgres 557 558 specifies which DBMS is to be used. However, currently only the value 559 ``postgres`` is supported. This is also the default. 560 561 In addition to selecting the DBMS software, the backend requires 562 DBMS-specific options to access the database. 563 564 .. note:: 565 566 The **taler-merchant-dbconfig** tool can be used to automate the database 567 setup. When using the Debian/Ubuntu packages, the user should already have 568 been created, so you can just run the tool without any arguments and should 569 have a working database configuration. 570 571 Please make sure you did not create a taler merchant database manually before running 572 this command or it will fail with SQL errors. 573 574 575 For the ``postgres`` backend, you need to specify: 576 577 .. code-block:: ini 578 579 [merchantdb-postgres] 580 CONFIG = "postgres:///taler-merchant" 581 582 This option specifies a PostgreSQL access path, typically using the format 583 ``postgres:///$DBNAME``, where ``$DBNAME`` is the name of the PostgreSQL 584 database you want to use (here, ``taler-merchant`` on the local machine). 585 Suppose ``$USER`` is the name of the user who will run the backend process 586 (usually ``taler-merchant-httpd``). Then, you need to first run: 587 588 .. code-block:: console 589 590 $ sudo -u postgres createuser -d $USER 591 592 as the PostgreSQL database administrator (usually ``postgres``) to 593 grant ``$USER`` the ability to create new databases. Next, you should 594 as ``$USER`` run: 595 596 .. code-block:: console 597 598 $ createdb $DBNAME 599 600 to create the backend’s database. Here, ``$DBNAME`` must match the 601 database name given in the configuration file. 602 603 Now you should be able to create the tables and indices. To do this, run as 604 ``$USER`` (usually ``taler-merchant-httpd``): 605 606 .. code-block:: console 607 608 $ taler-merchant-dbinit 609 610 You may improve your security posture if you now REVOKE the rights to CREATE, 611 DROP or ALTER tables from ``$USER``. However, if you do so, please be aware 612 that you may have to temporarily GRANT those rights again when you update the 613 merchant backend. For details on how to REVOKE or GRANT these rights, consult 614 the PostgreSQL documentation. 615 616 .. include:: frags/db-stores-sensitive-data.rst 617 618 619 .. index: MASTER_KEY 620 621 Exchange 622 ^^^^^^^^ 623 624 To add an exchange to the list of trusted payment service providers, you 625 create a section with a name that starts with “MERCHANT-EXCHANGE-”. In that 626 section, the following options need to be configured: 627 628 - The ``EXCHANGE_BASE_URL`` option specifies the exchange’s base URL. 629 For example, to use the Taler demonstrator, specify: 630 631 .. code-block:: ini 632 633 [merchant-exchange-kudos] 634 EXCHANGE_BASE_URL = "https://exchange.demo.taler.net/" 635 636 - The KUDOS demo exchange and others are usually enabled by default 637 in the distribution so you can easily test your backend. If you want 638 to disable KUDOS, for example because you only want to support 639 CHF or EUR, do not delete the "kudos.conf", but instead disable 640 it explicitly in your main taler-merchant.conf configuration 641 file using: 642 643 .. code-block:: ini 644 645 [merchant-exchange-kudos] 646 DISABLED = YES 647 648 This is also the preferred way to disable any other exchange that 649 may be enabled by default. You can get a list of all of these 650 exchange configuration sections using 651 ``taler-merchant-config -S | grep merchant-exchange-``. 652 653 - The ``MASTER_KEY`` option specifies the exchange’s master public key 654 in base32 encoding. For the Taler demonstrator, use: 655 656 .. code-block:: ini 657 658 [merchant-exchange-kudos] 659 MASTER_KEY = "GNRJCH0HYKN59939JC0CJ2JDC7ZNEBSATJFF00CVS3WPG4TQEA7G" 660 661 You can find out this key by running ``curl https://exchange.demo.taler.net/keys | jq .master_public_key``. 662 663 - The ``CURRENCY`` option specifies the exchange’s currency. 664 For the Taler demonstrator, use: 665 666 .. code-block:: ini 667 668 [merchant-exchange-kudos] 669 CURRENCY = "KUDOS" 670 671 672 Note that multiple exchanges can be added to the system by using different 673 identifiers in place of ``KUDOS`` in the example above. One exchange will only 674 ever support a single currency; thus, if you need support for multiple 675 currencies, you must add multiple exchanges. 676 677 The merchant already ships with a default configuration that contains the 678 ``merchant-exchange-kudos`` section from above. 679 680 .. note:: 681 682 Manually setting up exchanges is only recommended under special 683 circumstances. In general, GNU Taler distributions will include trustworthy 684 exchanges (for each currency) in the default configuration, and there is 685 rarely a good reason for trusting an exchange that has no relationship 686 with the GNU Taler development team. 687 688 689 .. _Sample-backend-configuration: 690 691 Sample backend configuration 692 ---------------------------- 693 694 .. index:: configuration 695 696 The following is an example for a complete backend configuration: 697 698 .. code-block:: ini 699 700 [taler] 701 CURRENCY = KUDOS 702 703 [merchant] 704 SERVE = TCP 705 PORT = 9966 706 DATABASE = postgres 707 708 [merchantdb-postgres] 709 CONFIG = postgres:///taler-merchant 710 711 [merchant-exchange-kudos] 712 EXCHANGE_BASE_URL = https://exchange.demo.taler.net/ 713 MASTER_KEY = FH1Y8ZMHCTPQ0YFSZECDH8C9407JR3YN0MF1706PTG24Q4NEWGV0 714 # If currency does not match [taler] section, the exchange 715 # will be ignored! 716 CURRENCY = KUDOS 717 718 Given the above configuration, the backend will use a PostgreSQL database 719 named ``donations`` running on the same host. 720 721 The backend will deposit the coins it receives to the exchange at 722 https://exchange.demo.taler.net/, which has the master key 723 ``FH1Y8ZMHCTPQ0YFSZECDH8C9407JR3YN0MF1706PTG24Q4NEWGV0``. 724 725 726 .. _Launching-the-backend: 727 728 Launching the backend 729 --------------------- 730 731 .. index:: backend 732 .. index:: taler-merchant-httpd 733 734 Assuming you have configured everything correctly, you can launch the 735 merchant backend as ``$USER`` using (to provide a trivial example): 736 737 .. code-block:: console 738 739 $ taler-merchant-httpd & 740 $ taler-merchant-webhook & 741 $ taler-merchant-kyccheck & 742 $ taler-merchant-wirewatch & 743 $ taler-merchant-depositcheck & 744 $ taler-merchant-exchangekeyupdate & 745 $ taler-merchant-reconciliation & 746 747 .. note:: 748 749 If you compiled the merchant backend with support for donation 750 statements via Donau, you need to additionally launch 751 ``taler-merchant-donaukeyupdate``. 752 753 To ensure these processes run always in the background and also after 754 rebooting, you should use systemd, cron or some other init system of your 755 operating system to launch the process. You should also periodically re-start 756 these services to prevent them from exhausing the memory utilization of the 757 PostgreSQL database. Consult the documentation of your operating system for 758 how to start and stop daemons. 759 760 .. note:: 761 762 When using the Debian/Ubuntu packages, the systemd configuration 763 will already exist. You only need to enable and start the service 764 using ``systemctl enable taler-merchant.target`` and 765 ``systemctl start taler-merchant.target``. Additionally, you should 766 review the ``/etc/apache2/sites-available/taler-merchant.conf`` 767 or ``/etc/nginx/sites-available/taler-merchant`` (these files 768 contain additional instructions to follow), symlink it to 769 ``sites-enabled/`` and restart your HTTP server. After that, you 770 should be able to visit the merchant backend at the respective 771 HTTP(S) endpoint. 772 773 If everything worked as expected, the command 774 775 .. code-block:: console 776 777 $ wget -O - http://localhost:9966/config 778 779 should return some basic configuration status data about the service. 780 781 Please note that your backend might then be globally reachable without 782 any access control. You can either: 783 784 * Use the ``--auth=$TOKEN`` command-line option to **taler-merchant-httpd** to set an access token to be provided in an ``Authorize: Bearer $TOKEN`` HTTP header. Note that this can be used at anytime to override access control, but remains only in effect until a first instance is created or an existing instance authentication setting is modified. 785 * Set the ``TALER_MERCHANT_TOKEN`` environment variable to ``$TOKEN`` for the same effect. This method has the advantage of ``$TOKEN`` not being visible as a command-line interface to other local users on the same machine. 786 * Set up an instance with an authentication token before some unauthorized person has a chance to access the backend. As the backend is useless without any instance and the chances of remote attackers during the initial configuration is low, this is probably sufficient for most use-cases. Still, keep the first two scenarios in mind in case you ever forget your access token! 787 788 Production systems should additionally be configured to bind to a UNIX domain socket 789 and use TLS for improved network privacy, see :ref:`Secure setup <Secure-setup>`. 790 791 792 Multi-factor authentication 793 ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 794 795 The merchant backend supports multi-factor authentication for critical 796 endpoints, including issuing access token, changing login credentials, 797 modifying the bank account and deleting the instance. To use 798 multi-factor authentication, the merchant backend must be configured 799 with helper programs that can be used to send e-mails or SMS messages. 800 801 802 .. code-block:: ini 803 804 [MERCHANT] 805 HELPER_SMS = sms_helper.sh 806 HELPER_EMAIL = email_helper.sh 807 808 These scripts will be called by the merchant backend with the 809 first argument being the phone number or the e-mail address, and 810 with the message with the TAN code to send to the user on standard 811 input. The shell scripts must exit with a status code of 0 on 812 success. A trivial e-mail helper would look like this: 813 814 .. code-block:: sh 815 816 #!/bin/sh 817 exec mail --subject="TAN code for the Taler merchant backend" "$1" 818 819 Here, ``mail`` refers to the classic UNIX mail command. 820 Example scripts can also be found in the `GNU Anastasis Git 821 <https://git.taler.net/anastasis.git/tree/src/authorization>`_. 822 823 824 Self-provisioning 825 ^^^^^^^^^^^^^^^^^ 826 827 Self-provisioning allows anyone to create a merchant instance. This 828 is useful if a merchant backend is offered as a public service. In this 829 case, you should set: 830 831 .. code-block:: ini 832 833 [MERCHANT] 834 ENABLE_SELF_PROVISIONING = YES 835 836 837 To enable self-provisioned users to reset their passwords if they 838 forgot them, the merchant backend requires two other authentication 839 methods to be available and validated when the instance is 840 self-provisioned. This can be enabled using: 841 842 .. code-block:: ini 843 844 [MERCHANT] 845 MANDATORY_TAN_CHANNELS = sms email 846 847 With this setting, users that self-provision an instance must first 848 demonstrate control over the e-mail address and phone number provided, 849 and can thus later reset their password without needing support from 850 the administrator. 851 852 853 .. index:: instance 854 .. _Instance-setup: 855 856 857 Instance setup 858 ============== 859 860 We recommend the use of the single-page administration application (SPA) that 861 is served by default at the base URL of the merchant backend. You can use it 862 to perform all steps described in this section (and more!), using a simple Web 863 interface. Alternatively, you can also use the ``wget`` commands given below. 864 865 Regardless of which approach you use, the first step for using the backend 866 involves the creation of the ``admin`` instance. The ``admin`` instance can 867 also create, configure or delete other instances, similar to the ``root`` 868 account on UNIX. When no instance exists, then the backend is reachable 869 without any access control (unless you configured some in the reverse proxy). 870 871 .. note:: 872 873 If you created a non-admin instance first, you cannot create an ``admin`` 874 instance via the SPA anymore. In this case, you can only create an 875 administrative account by using the command-line. By invoking 876 ``taler-merchant-passwd --instance=admin $PASSWORD`` you can set both the 877 password and create an ``admin`` instance if it does not yet exist. 878 However, for non-admin instances, you can only set the password with this tool. 879 880 The following documentation shows how to handle any instance. Thus, if you 881 want to have multiple instances, you may need to perform the steps multiple 882 times, once for each instance. 883 884 .. note:: 885 886 A potential security concern is that normal API usage leaks instance existence. 887 This means unauthorized users can distinguish between the case where the 888 instance does not exist (HTTP 404) and the case where access is denied 889 (HTTP 403). 890 This is concern can be addressed using a properly configured 891 :ref:`reverse proxy <reverse-proxy-configuration>`. 892 893 894 Instance setup with the SPA 895 --------------------------- 896 897 In order to setup an instance, you need the merchant backend to already be 898 running, and you must either have the credentials for the ``admin`` instance, 899 or no instance must be configured at all yet. 900 901 To start, point your browser to ``$PROTO://backend.$DOMAIN_NAME/``, replacing 902 "$PROTO" with "https" or (rarely) "http" and "$DOMAIN_NAME" with your 903 organizations DNS domain or subdomain. 904 905 .. note:: 906 907 The label "backend" here is also just a suggestion, your administrator 908 can in principle choose any name. 909 910 You should be welcomed by the following merchant backoffice page: 911 912 .. image:: screenshots/merchant_first_login.png 913 914 After supplying the required fields, primarily the name of your organization 915 and the desired access token, click ``confirm``. You can change the instance 916 settings later via the ``Settings`` entry in the menu on the left. 917 918 919 Instance settings 920 ----------------- 921 922 The settings dialog allows you to select an image to be used as a logo 923 for your shop. Wallets may use that logo when showing contracts to 924 highlight to customers which shop they are buying from. 925 926 The settings dialog allows you to specify the address of your business 927 and the jurisdiction the shop is under. Both will be embedded into the 928 contracts and may be shown by the Taler wallet to customers that want 929 to know these details. 930 931 You must also configure whether you intend to pay transaction fees, 932 or whether the customer is required to pay for any payment fees. If 933 you do not cover the fees, the fees will be shown separately to the 934 customer and added to the total of each order, which may discourage 935 consumers from using the Taler payment method. The specific 936 magnitude of the fees cannot be configured here, as it depends on 937 the amount of the order and is dynamically computed. Regardless of 938 what you specify here, the front-end can override the acceptable 939 fee amount for each order it creates. 940 941 .. note:: 942 943 Details on the acceptable fee calcuation 944 are described in the Taler design document 47. 945 946 Finally, you need to specify several settings relating to default 947 deadlines. 948 949 (1) The "Default payment delay" specifies when an offer expires. The 950 customer basically has this amount of time to pay, or the backend will 951 refuse the payment and require the customer to get a new quote. 952 953 (2) The "Default refund delay" specifies how long the customer may receive 954 refunds. The refund period is cummulative on top of the "Default payment 955 delay". Thus, the refund period ends independently of when the customer 956 actually paid for the order. The exchange will **not** wire the funds to the 957 merchant before the refund deadline lapses, as after the funds have been 958 wired refunds using Taler are no longer possible. 959 960 (3) The "Default wire transfer delay" specifies how soon the exchange 961 **must** wire the funds **after** the refund deadline. The delay is again 962 cummulative on top of the "Default payment delay" and the "Default refund 963 delay". However, the resulting time is still not the actual wire 964 deadline, as first the "Default wire rounding interval" is also considered. 965 966 (4) The "Default wire rounding interval" specifies to what period the 967 wire deadline should be rounded up to. The ultimate wire deadline is 968 computed by adding the default payment, rounding and wire delays to 969 the current time and rounding the resulting timestamp to the 970 "Default wire rounding interval". Typical values include 971 end-of-day, end-of-week, end-of-month, end-of-quarter or end-of-year. 972 973 .. note:: 974 975 The wire deadline is rounded using the local timezone of the Taler merchant 976 backend server, so if you want end-of-day payments make sure to run your 977 merchant backend in your own timezone. 978 979 Specifying larger values for the wire transfer delay and the wire rounding 980 interval allows the exchange to aggregate more payments into larger wire 981 transfers. The exchange is required by the protocol to initiate the wire 982 transfer **before** the wire transfer deadline. 983 984 All of the computed deadlines (payment, refund and wire transfer) 985 are just defaults and can be modified by frontends for any 986 specific order. 987 988 989 Instance setup without the Web interface 990 ---------------------------------------- 991 992 Instances can be created by POSTing a request to ``/management/instances`` 993 without using the Web interface. This could be useful if you want to create 994 many instances programmatically. To create an instance without the Web 995 interface create a file ``instance.json`` with an 996 `InstanceConfigurationMessage`: 997 998 .. code-block:: json 999 1000 { 1001 "id" : "admin", 1002 "name": "Example Inc.", 1003 "address": { "country" : "zz" }, 1004 "auth": { "method" : "external"} , 1005 "jurisdiction": { "country" : "zz" }, 1006 "use_stefan": true, 1007 "default_pay_delay": { "d_ms" : 1209600000 } 1008 "default_refund_delay": { "d_ms" : 1209600000 } 1009 "default_wire_transfer_delay": { "d_ms" : 1209600000 }, 1010 } 1011 1012 The ``name`` field will be shown as the name of your shop. The ``address`` 1013 field is expected to contain your shop's physical address. The various 1014 ``default_*`` values specify defaults for transaction fees your shop is 1015 willing to cover, how long offers made to the customer are valid, and how long 1016 the exchange has before it must wire the funds to your bank account. Those 1017 defaults can be modified for individual orders. For details, see the 1018 :ref:`contract terms <contract-terms>` specification. 1019 1020 You can then create the instance using: 1021 1022 .. code-block:: console 1023 1024 $ wget --post-file=instance.json http://localhost:9966/management/instances 1025 1026 The base URL for the instance will then be ``http://localhost:9966/``. You 1027 can create additional instances, which will then be reachable under 1028 ``http://localhost:9966/instances/$ID`` where ``$ID`` needs to be changed to 1029 the identifier value of the respective instance. 1030 1031 Endpoints to modify (reconfigure), permanently disable (while keeping the data) 1032 or purge (deleting all associated data) instances exist as well and are documented 1033 in the :ref:`Merchant Backend API documentation <merchant-api>`. 1034 1035 .. _instance-account-setup: 1036 1037 Instance bank account setup 1038 =========================== 1039 1040 Before you can use an instance productively, you need to configure one or more 1041 bank accounts. These bank accounts will be provided to the Taler exchange 1042 operator to tell it where to wire the income from your sales. Every bank 1043 account has an associated *wire method* which determines how an exchange can 1044 transfer the funds. The most commonly supported wire method is *iban*, which 1045 implies that bank accounts are identified by IBAN numbers and wire transfers 1046 are to be executed between IBAN accounts. For regional currency setups, the 1047 wire method could also be *x-taler-bank*. 1048 1049 .. note:: 1050 1051 When using a regional currency, you need to first create a bank account at 1052 the regional bank. You may need to contact the respective administrator who 1053 can set one up. After being able to login to the new bank account, you can 1054 see your bank account number by clicking on the ``Welcome, $USERNAME`` 1055 message in the profile page. Next to the bank account number, you can find 1056 a convenient button to copy the number to the clipboard. 1057 1058 Not every exchange will support every *wire method*, and if you do not add a 1059 bank account with a wire method that is supported by a particular exchange, 1060 then you will not be able to receive payments via that exchange even if you 1061 configured the merchant backend to trust that exchange. 1062 1063 The simplest way to configure an account is to use the Web interface which has 1064 specific forms for different wire methods. First, select ``Bank account`` at 1065 the left of the page. The following page should be shown: 1066 1067 .. image:: screenshots/no_default_account_yet.png 1068 1069 Click on the blue "+" sign on the top right of the page to add a new 1070 bank account. The following page should appear: 1071 1072 .. image:: screenshots/enter_instance_details.png 1073 1074 First, you should select the wire method, after which the dialog will show you 1075 additional fields specific to the wire method. For example, if youchoose 1076 ``iban`` as the account type, the following page should appear: 1077 1078 .. image:: screenshots/instance_iban_config.png 1079 1080 Specifying the revenue gateway with username and password is optional and 1081 discussed in section :ref:`automatic-settlement-data-import` below. 1082 1083 After providing the details and confirming, the shop is ready to generate orders 1084 and accept payments. 1085 1086 1087 1088 Detecting Settlement: Manually Adding Transfers 1089 ----------------------------------------------- 1090 1091 The exchange may aggregate many small amounts into one larger wire transfer. 1092 If you want to safely determine for which orders have been settled (final 1093 payment from the exchange has been received), the backend must learn about the 1094 wire transfers made into your bank account. Basically, as a secure system, we 1095 do not simply trust a claim by the exchange that it would transfer the money, 1096 but we allow each merchant to check settlements. 1097 1098 An easy (but somewhat tedious) way to check settlements is to manually add 1099 every wire transfer that a merchant bank account has received from the 1100 exchange with the total amount and the wire transfer subject. Given this 1101 information, the merchant backend will inquire with the exchange which 1102 individual payments were aggregated, check that the total amount is correct, 1103 and will then flag the respective contracts as wired. 1104 1105 You can manually enter wire transfers under ``Transfers``. However, this is 1106 tedious, and so if your banking setup supports it, we highly recommend 1107 using the automatic settlement data import. 1108 1109 .. _automatic-settlement-data-import: 1110 1111 Automatic Settlement Data Import 1112 -------------------------------- 1113 1114 To automatically import settlement data, you need to provide the merchant 1115 backend with the address and access credentials of a 1116 :ref:`taler-bank-merchant-http-api` for each bank account of an instance. The 1117 revenue API endpoint will allow the merchant backend to obtain a list of all 1118 incoming wire transfers into your bank account and automatically import them 1119 into the list of confirmed wire transfers. 1120 1121 Note that setting up a revenue API endpoint will usually require you to first 1122 ask your bank for EBICS access and to set up :ref:`libeufin-nexus` to provide 1123 the revenue API endpoint. The :ref:`libeufin-bank` used by regional currency 1124 setups also provides a revenue API endpoint at 1125 ``$BANK_URL/accounts/$ACCOUNT_NAME/taler-revenue/``. Thus, when using a 1126 regional currency setup, simply use the ``$BANK_URL`` of your bank and specify 1127 your bank login name and password in the :ref:`instance-account-setup` dialog. 1128 1129 1130 Manually creating an order using the SPA 1131 ======================================== 1132 1133 Arbitrary orders can also be created manually using the Web interface of 1134 the GNU Taler merchant backend. For this, log into the single page app (SPA) 1135 of the merchant backend using the authorization token of the respective 1136 instance you want to use. 1137 1138 Click on ``Orders`` at the top left corner of the merchant backoffice page; the 1139 following page should appear 1140 1141 .. image:: screenshots/create_orders.png 1142 1143 You can then set up orders by providing all of the required fields of an 1144 order, in particular an order summary and a price. You can also set various 1145 optional fields or override instance default settings. 1146 1147 After this the interface should show the following page with the related links 1148 to check the status of the order and let wallet pay for it. 1149 1150 .. image:: screenshots/payment_links.png 1151 1152 The order status page also shows you the progress of the order, including when 1153 a wallet has made the payment. You can also use the backend to approve refunds. 1154 1155 In order to test the setup, it should be now possible to use the command line wallet 1156 to withdraw Taler coins and spend them to pay for the order we just created. 1157 1158 In practice, you will rarely if ever setup orders manually like this. Instead, 1159 a `GNU Taler e-commerce front-end 1160 <https://taler.net/en/docs.html#extensions>`_ or the 1161 :ref:`taler-merchant-pos-app` will do this on-demand. Here, you will only need 1162 to provide the respective front-ends with the URL of your instance 1163 (e.g. ``https://backend.$DOMAIN/instances/$NAME``) and your access token. 1164 1165 1166 Paying an order 1167 =============== 1168 1169 The payer simply scans the (dynamic) QR code to initiate the payment. If a 1170 website is interacting with a WebExtension wallet, it may also directly 1171 trigger the GNU Taler wallet without requiring the user to explicitly scan the 1172 QR code. The payer should now review the contract terms and applicable fees. 1173 Selecting "pay" will complete the transaction. Typically, the wallet will 1174 then redirect the user to the fulfillment page where they can track the order 1175 or directly view the digital product that they purchased. 1176 1177 1178 Setting up a template 1179 ===================== 1180 1181 A template provides all or part of the information needed to setup an order 1182 and allows GNU Taler wallets to create an order. Usually, the creation of 1183 orders is a privileged process that requires knowledge of the authorization 1184 code for the respective instance. With templates, a customer's wallet can 1185 directly create an order on-demand. The information of a template can be 1186 partial, in which case the customer is expected to provide the remaining 1187 details, typically the summary and/or amount of the order. 1188 1189 When setting up a template you need to specify all of the fixed inputs that 1190 the customer cannot change. You can then generate a template QR code where 1191 you may additionally specify editable defaults for the order, such as a 1192 default summary or a default amount which may still be changed by the wallet. 1193 The resulting template QR code encodes the specific merchant backend, instance 1194 and template ID as well as the (editable) default values. The resulting 1195 static QR code can then be printed and put on display. 1196 1197 Customers can scan the QR code with their GNU Taler wallet, complete the 1198 missing details or edit the defaults (if any), and pay the resulting order. 1199 1200 To secure template-based payments, you may specify a TOTP secret as part of 1201 the template. In this case, the merchant backend will send a set of TOTP 1202 payment confirmation codes to the GNU Taler wallet upon receiving a payment 1203 for an order created based on the template. If the point-of-sale has a TOTP 1204 generator with the same secret, they can compare their TOTP code with the 1205 codes shown by the customer on their wallet. This provides additional 1206 assurance that the customer actually made the payment instead of just showing 1207 a fake confirmation screen. 1208 1209 1210 Paying with static QR codes 1211 =========================== 1212 1213 The payer simply scans the (static) QR code to initiate the payment. If the 1214 template does not specify a fixed amount, the payer will be prompted to enter 1215 the amount to be paid (and possibly given the opportunity to specify or alter 1216 the summary). Selecting "pay" will complete the transaction. If payment 1217 confirmations are configured by the merchant backend, the wallet will then 1218 display a TOTP confirmation code that can be shown to the merchant as a proof 1219 of payment. 1220 1221 1222 1223 Setting up a webhook 1224 ==================== 1225 1226 To receive notifications when a purchase has been made or a refund was given 1227 to a wallet, you can set up webhooks in the GNU Taler merchant backend. 1228 Webhooks allow you to trigger HTTP(S) requests based on certain events. A 1229 webhook is thus simply an HTTP request that the GNU Taler merchant backend 1230 will make when a certain event (such as a payment) happens. 1231 1232 There are various providers that can send an SMS to a phone number based on an 1233 HTTP request. Thus, by configuring such a provider in a webhook you can 1234 receive an SMS notification whenever a customer makes a payment. 1235 1236 Webhooks are configured per instance. In the Webhook configuration, 1237 you can specify which URL, which HTTP headers, which HTTP method and what HTTP 1238 body to send to the Webhook. Webhooks are automatically retried (with 1239 increasing delays) when the target server returns a temporary error. 1240 1241 `Mustach templates <https://mustache.github.io/mustache.5.html>`__ and limited 1242 version of it are used when defining the contents of Webhooks. 1243 Depending on the triggering event, the templates will be expanded with event-specific 1244 data. Limited in this case means that only a specific string is being replaced 1245 with the event-specific data, no support for parsing conditions or nested structures 1246 is provided. 1247 1248 1249 Order created events 1250 -------------------- 1251 1252 For "order_created" events, the backend will provide the following 1253 information to the Mustache templating engine: 1254 1255 * webhook_type: "order_created". 1256 * order_id: the identifier of the newly created order. 1257 * contract: the full JSON contract for the order (see :ref:`contract_terms <contract-terms>` for the structure). 1258 * instance_id: the merchant instance identifier that created the order. 1259 1260 1261 Order pay events 1262 ---------------- 1263 1264 For "pay" events, the backend will provide the following 1265 information to the Mustache templating engine: 1266 1267 * webhook_type: "pay". 1268 * :ref:`contract_terms <contract-terms>`: the contract terms of the paid order. 1269 * order_id: the ID of the order that received the refund. 1270 1271 1272 Order refund events 1273 ------------------- 1274 1275 For "refund" events which are triggered when a refund is 1276 approved, the backend will provide the following information to the 1277 Mustache templating engine: 1278 1279 * webhook_type: "refund". 1280 * timestamp: time of the refund (using a `Timestamp` with the time in seconds since the UNIX epoch). 1281 * order_id: the ID of the order that received the refund. 1282 * :ref:`contract_terms <contract-terms>`: the full JSON of the contract terms of the refunded order. 1283 * refund_amount: the amount that was being refunded. 1284 * reason: the reason entered by the merchant staff for granting the refund; 1285 be careful, you probably want to inform your staff if a webhook may expose 1286 this information to the consumer. 1287 1288 1289 Order settled events 1290 -------------------- 1291 1292 For "order_settled" events which are triggered when the 1293 **taler-merchant-reconciliation** service is able to map 1294 an incoming wire transfer from the exchange to a paid 1295 order, the backend will provide the following information to the limited 1296 Mustache templating engine: 1297 1298 * webhook_type: "order_settled". 1299 * order_id: The unique identifier of the order that has been fully settled (all payments completed and wired to the merchant). 1300 * wtid: The wire transfer ID of the settlement. 1301 1302 Category added events 1303 --------------------- 1304 1305 For "category_added" events, the backend will provide the following information to the limited 1306 Mustache templating engine: 1307 1308 * webhook_type: "category_added". 1309 * category_serial: The unique identifier of the newly added category. 1310 * category_name: The name of the newly added category. 1311 * merchant_serial: The unique identifier of the merchant associated with the category. 1312 1313 1314 Category updated events 1315 ----------------------- 1316 1317 For "category_updated" events, the backend will provide the following information to the limited 1318 Mustache templating engine: 1319 1320 * webhook_type: "category_updated". 1321 * category_serial: The unique identifier of the updated category. 1322 * old_category_name: The name of the category before the update. 1323 * category_name: The name of the category after the update. 1324 * category_name_i18n: The internationalized name of the category after the update. 1325 * old_category_name_i18n: The internationalized name of the category before the update. 1326 1327 1328 Category deleted events 1329 ----------------------- 1330 1331 For "category_deleted" events, the backend will provide the following information to the limited 1332 Mustache templating engine: 1333 1334 * webhook_type: "category_deleted". 1335 * category_serial: The unique identifier of the deleted category. 1336 * category_name: The name of the deleted category. 1337 1338 1339 Inventory added events 1340 ---------------------- 1341 1342 For "inventory_added" events, the backend will provide the following information to the limited 1343 Mustache templating engine: 1344 1345 * webhook_type: "inventory_added". 1346 * product_serial: The unique identifier of the newly added product. 1347 * product_id: The ID of the newly added product. 1348 * description: The description of the newly added product. 1349 * description_i18n: The internationalized description of the newly added product. 1350 * unit: The unit of the newly added product. 1351 * image: The image of the newly added product. 1352 * taxes: The taxes of the newly added product. 1353 * price: The price of the newly added product. 1354 * total_stock: The total stock of the newly added product. 1355 * total_sold: The total sold of the newly added product. 1356 * total_lost: The total lost of the newly added product. 1357 * address: The address of the newly added product. 1358 * next_restock: The next restock of the newly added product. 1359 * minimum_age: The minimum age for buying the newly added product. 1360 1361 Inventory updated events 1362 ------------------------ 1363 1364 For "inventory_updated" events, the backend will provide the following information to the limited 1365 Mustache templating engine: 1366 1367 * webhook_type: "inventory_updated". 1368 * product_serial: The unique identifier of the updated product. 1369 * product_id: The ID of the product. 1370 * old_description: The description of the product before the update. 1371 * description: The description of the product after the update. 1372 * old_description_i18n: The internationalized description of the product before the update. 1373 * description_i18n: The internationalized description of the product after the update. 1374 * old_unit: The unit of the product before the update. 1375 * unit: The unit of the product after the update. 1376 * old_image: The image of the product before the update. 1377 * image: The image of the product after the update. 1378 * old_taxes: The taxes of the product before the update. 1379 * taxes: The taxes of the product after the update. 1380 * old_price: The price of the product before the update. 1381 * price: The price of the product after the update. 1382 * old_total_stock: The total stock of the product before the update. 1383 * total_stock: The total stock of the product after the update. 1384 * old_total_sold: The total sold of the product before the update. 1385 * total_sold: The total sold of the product after the update. 1386 * old_total_lost: The total lost of the product before the update. 1387 * total_lost: The total lost of the product after the update. 1388 * old_address: The address of the product before the update. 1389 * address: The address of the product after the update. 1390 * old_next_restock: The next restock of the product before the update. 1391 * next_restock: The next restock of the product after the update. 1392 * old_minimum_age: The minimum age for buying the product before the update. 1393 * minimum_age: The minimum age for buying the product after the update. 1394 1395 1396 Inventory deleted events 1397 ------------------------ 1398 1399 For "inventory_deleted" events, the backend will provide the following information to the limited 1400 Mustache templating engine: 1401 1402 * webhook_type: "inventory_deleted". 1403 * product_serial: The unique identifier of the deleted product. 1404 * product_id: The ID of the deleted product. 1405 * description: The description of the deleted product. 1406 * description_i18n: The internationalized description of the deleted product. 1407 * unit: The unit of the deleted product. 1408 * image: The image of the deleted product. 1409 * taxes: The taxes of the deleted product. 1410 * price: The price of the deleted product. 1411 * total_stock: The total stock of the deleted product. 1412 * total_sold: The total sold of the deleted product. 1413 * total_lost: The total lost of the deleted product. 1414 * address: The address of the deleted product. 1415 * next_restock: The next restock of the deleted product. 1416 * minimum_age: The minimum age for buying the deleted product. 1417 1418 1419 .. _Secure-setup: 1420 1421 Secure setup 1422 ============ 1423 1424 .. index:: security 1425 .. index:: TLS 1426 1427 The Taler backend is deliberately simple in terms of support for access 1428 control or transport layer security (TLS). Thus, production setups **must** 1429 deploy the Taler backend behind an HTTP(S) server that acts as a *reverse 1430 proxy*, performs TLS termination and authentication and then forwards requests 1431 to the backend. 1432 1433 1434 Using UNIX domain sockets 1435 ------------------------- 1436 1437 To ensure that the merchant backend is not exposed directly to the network, 1438 you *should* bind the backend to a UNIX domain socket: 1439 1440 .. code-block:: ini 1441 1442 [MERCHANT] 1443 SERVE = unix 1444 UNIXPATH = "/some/path/here.sock" 1445 1446 Do not use a UNIX domain socket path in "/tmp": systemd (or other init 1447 systems) may give Web servers a private "/tmp" thereby hiding UNIX domain 1448 sockets created by other users/processes in "/tmp". 1449 1450 If UNIX domain sockets are for some reason not possible, you *may* use a 1451 host-based firewall to block access to the TCP port of the merchant backend, 1452 but this is *not recommended*. If you do need a TCP socket, you should 1453 instead strongly consider using the "BIND_TO" option to at least bind it only 1454 to "localhost". 1455 1456 .. _reverse-proxy-configuration: 1457 1458 Reverse proxy configuration 1459 --------------------------- 1460 1461 Nginx 1462 ^^^^^ 1463 1464 For Nginx, a possible basic reverse proxy configuration would be: 1465 1466 .. code-block:: nginx 1467 1468 proxy_pass http://unix:/some/path/here.sock; 1469 proxy_redirect off; 1470 proxy_set_header Host $host; 1471 proxy_set_header X-Forwarded-Host "example.com"; 1472 proxy_set_header X-Forwarded-Proto "https"; 1473 1474 Note that the above assumes your domain name is ``example.com`` and that you 1475 have TLS configured. Leave out the last line if your Nginx reverse proxy does 1476 not have HTTPS enabled. Make sure to restart the ``taler-merchant-httpd`` 1477 process after changing the ``SERVE`` configuration. 1478 1479 Apache 1480 ^^^^^^ 1481 1482 In Apache, make sure you have ``mod_proxy``, ``mod_proxy_http`` and 1483 ``mod_headers`` enabled: 1484 1485 .. code-block:: console 1486 1487 $ a2enmod proxy 1488 $ a2enmod proxy_http 1489 $ a2enmod headers 1490 1491 Then configure your Apache reverse proxy like this (you may change the 1492 endpoint): 1493 1494 .. code-block:: apacheconf 1495 1496 <Location "/"> 1497 ProxyPass "unix:/some/path/here.sock|http://example.com/" 1498 RequestHeader add "X-Forwarded-Proto" "https" 1499 </Location> 1500 1501 Note that the above again assumes your domain name is ``example.com`` and that 1502 you have TLS configured. Note that you must add the ``https`` header unless 1503 your site is not available via TLS. 1504 1505 .. _auto-reverse-proxy-configuration: 1506 1507 Automated Reverse Proxy Configuration 1508 ------------------------------------- 1509 1510 GNU Taler provides a helper script, ``taler-merchant-rproxy-setup``, that 1511 automates the most common reverse-proxy configuration tasks for both Nginx 1512 and Apache: 1513 1514 - Detects (or lets you choose) Nginx vs. Apache 1515 - Verifies and enables required modules and packages 1516 - Obtains (or skips) TLS certificates via Certbot (unless ``--httponly``) 1517 - Backs up and populates the stock configuration with your domain 1518 - Optionally forces HTTP → HTTPS redirection (``--httpsonly``) 1519 - Enables the site and reloads the web server 1520 1521 Usage 1522 ^^^^^ 1523 1524 .. code-block:: console 1525 1526 taler-merchant-rproxy-setup \ 1527 --domain <example.com> [--nginx | --apache] [--httponly | --httpsonly] 1528 1529 Options 1530 ^^^^^^^ 1531 1532 ``--domain <name>`` 1533 (Required) The public domain name to configure. 1534 1535 ``--nginx`` 1536 Force use of Nginx (overriding auto-detection). 1537 1538 ``--apache`` 1539 Force use of Apache2 (overriding auto-detection). 1540 1541 ``--httponly`` 1542 Only configure HTTP (no TLS). Skips Certbot entirely. 1543 1544 ``--httpsonly`` 1545 Enable HTTPS and add an HTTP→HTTPS redirect. 1546 1547 ``-h, --help`` 1548 Show this help message and exit. 1549 1550 .. note:: 1551 1552 This script must be run as root (for example via ``sudo``) and requires 1553 that either Nginx or Apache2 (and Certbot for non-HTTP-only modes) be 1554 installed on the system. 1555 1556 1557 Access control 1558 -------------- 1559 1560 All endpoints with ``/private/`` in the URL must be restricted to authorized 1561 users of the respective instance. Specifically, the HTTP server must be 1562 configured to only allow access to ``$BASE_URL/private/`` to the authorized 1563 users of the ``admin`` instance, and to ``$BASE_URL/instances/$ID/private/`` to 1564 the authorized users of the instance ``$ID``. 1565 1566 By default, the GNU Taler merchant backend simply requires the respective 1567 HTTP requests to include an "Authorization" header with a "Bearer" token 1568 set to the respective shared secret which must begin with "secret-token:" 1569 (following RFC 8959). 1570 1571 Note that all of the other endpoints (without ``/private/``) 1572 are expected to be fully exposed to the Internet, and wallets may have to 1573 interact with those endpoints directly without client authentication. 1574 1575 1576 Status code remapping 1577 --------------------- 1578 1579 Normal API usage leaks instance existence information. Distinguishing between 1580 404 (Not found) and 403 (Forbidden) is useful for diagnostics. 1581 1582 For higher security (by leaking less information), you can add the following 1583 fragment, which remaps all 404 response codes to 403. 1584 1585 Nginx 1586 ^^^^^ 1587 1588 .. code-block:: nginx 1589 1590 error_page 404 =403 /empty.gif; 1591 1592 Apache 1593 ^^^^^^ 1594 1595 .. code-block:: apacheconf 1596 1597 cond %{STATUS} =404 1598 set-status 403 1599 1600 1601 Customization 1602 ============= 1603 1604 Legal conditions for using the service 1605 -------------------------------------- 1606 1607 .. include:: frags/legal.rst 1608 1609 .. _MerchantTemplateCustomization: 1610 1611 Template Customization 1612 ---------------------- 1613 1614 The installation process will install various HTML templates to be served to 1615 trigger the wallet interaction. You may change those templates to your own 1616 design. The templating language used is `C implementation of mustache 1617 <https://gitlab.com/jobol/mustach>`__, and the templates are in the 1618 ``share/taler-merchant/templates/`` directory. 1619 1620 The file names must be of the form ``$NAME.$LANG.must`` where ``$NAME`` is the 1621 name of the template and ``$LANG`` is the 2-letter language code of the 1622 template. English templates must exist and will be used as a fallback. If the 1623 browser (user-agent) has provided language preferences in the HTTP header and 1624 the respective language exists, the correct language will be automatically 1625 served. 1626 1627 The following subsections give details about each of the templates. The 1628 subsection titles are the ``$NAME`` of the respective template. 1629 1630 request_payment 1631 ^^^^^^^^^^^^^^^ 1632 1633 Page shown to request the user to make a payment. 1634 1635 This template is instantiated using the following information: 1636 1637 * taler_pay_uri: String; the ``taler://pay/`` URI that must be given 1638 to the wallet to initiate the payment 1639 1640 * taler_pay_qrcode_svg: Image; an SVG image of the QR code with the 1641 ``taler_pay_uri``. 1642 1643 * order_summary: String; a text summarizing the order 1644 1645 * order_status_url: URL of the merchant backend where the order status 1646 can be found, useful for long-polling to check if the order has been paid 1647 1648 1649 offer_refund 1650 ^^^^^^^^^^^^ 1651 1652 Page shown to offer a customer a refund. 1653 1654 This template is instantiated using the following information: 1655 1656 * taler_refund_uri: String; the ``taler://pay/`` URI that must be given 1657 to the wallet to initiate the payment 1658 1659 * taler_refund_qrcode_svg: Image; an SVG image of the QR code with the 1660 ``taler_pay_uri``. 1661 1662 * refund_amount: Amount; how much did the merchant refund 1663 1664 * refund_taken: Amount; how much did the customer already take back in refunds 1665 1666 * order_summary: String; a text summarizing the order 1667 1668 1669 1670 show_order_details 1671 ^^^^^^^^^^^^^^^^^^ 1672 1673 Page shown to the user when they go back to the payment page but 1674 no payment is required and no refund is present. 1675 1676 This template is instantiated using the following information: 1677 1678 * order_summary: String; a text summarizing the order 1679 1680 * contract_terms: Object; the full contract terms (shoud probably 1681 not be shown in full!) 1682 1683 * refund_amount: Amount; how much did the merchant refund 1684 1685 * refund_taken: Amount; how much did the customer already take back in refunds 1686 1687 Static files 1688 ------------ 1689 1690 The merchant backend also has the ability to serve small static files 1691 under the ``/static/{FILENAME}`` endpoint. This is used by the templating 1692 logic to load a CSS file, but you can also put other resources such as 1693 images or JavaScript. 1694 1695 Internationalization 1696 -------------------- 1697 1698 Both templates and static files can be internationalized. This is done 1699 by having the language of the resource be a part of the filename. 1700 For templates the format is ``{BASENAME}.{LANGUAGE}.must``. The 1701 language is mandatory for templates, the default language is English (en). 1702 1703 For static files, the format is ``{BASENAME}.{LANGUAGE}.{EXT}`` for 1704 internationalized files, and ``{BASENAME}.{EXT}`` for resources that do not 1705 support internationalization. The HTTP client will always request 1706 ``/static/{BASENAME}.{EXT}``. If ``{BASENAME}.{EXT}`` exists, that resource is 1707 returned. Otherwise, an internationalized file based on the language 1708 preferences indicated by the browser is returned. 1709 1710 Limitations 1711 ----------- 1712 1713 All of the static files must fit into memory and it must be possible for the 1714 process to hold open file handles for all of these files. You may want 1715 to increase the ``ulimit`` of the ``taler-merchant-httpd`` process if you have 1716 many static files. Note that Mustach templates do not increase the number of 1717 open files. 1718 1719 The backend determines the MIME type based on the file's extension. The list 1720 of supported extensions is hard-coded and includes common text and image 1721 formats. 1722 1723 The current backend only provides a limited set of variables for the Mustach 1724 template expansion, and does not make use of scopes and other Mustach 1725 features. 1726 1727 1728 1729 Upgrade procedure 1730 ================= 1731 1732 This section describes the general upgrade procedure. Please see the release 1733 notes for your specific version to check if a particular release has special 1734 upgrade requirements. 1735 1736 Please note that upgrades are ONLY supported for released version of the 1737 merchant. Attempting to upgrade from or to a version in Git is not supported 1738 and may result in subtle data loss. 1739 1740 To safely upgrade the merchant, you should first stop the existing 1741 ``taler-merchant-httpd`` process, backup your merchant database (see 1742 PostgreSQL manual), and then install the latest version of the code. 1743 1744 If you REVOKED database permissions, ensure that the rights to CREATE, 1745 DROP, and ALTER tables are GRANTed to ``$USER`` again. Then, run: 1746 1747 .. code-block:: console 1748 1749 $ taler-merchant-dbinit 1750 1751 to upgrade the database to the latest schema. After that, you may again 1752 REVOKE the database permissions. Finally, restart the merchant services 1753 processes, either via your systemd or init system, or directly. 1754 1755 1756 1757 1758 Advanced topics 1759 =============== 1760 1761 taler-merchant-config 1762 --------------------- 1763 1764 .. index:: taler-merchant-config 1765 1766 .. include:: frags/using-taler-config.rst 1767 1768 .. _MerchantDatabaseScheme: 1769 1770 Database Scheme 1771 --------------- 1772 1773 The merchant database must be initialized using ``taler-merchant-dbinit``. 1774 This tool creates the tables required by the Taler merchant to operate. 1775 The tool also allows you to reset the Taler merchant database, which is 1776 useful for test cases but should never be used in production. Finally, 1777 ``taler-merchant-dbinit`` has a function to garbage collect a database, 1778 allowing administrators to purge records that are no longer required. 1779 1780 The database scheme used by the merchant looks as follows: 1781 1782 .. image:: images/merchant-db.png 1783 1784 .. _MerchantBenchmarking: 1785 1786 Benchmarking 1787 ------------ 1788 1789 The merchant codebase offers the ``taler-merchant-benchmark`` tool to populate 1790 the database with fake payments. The main goal of the benchmarking tool is to 1791 serve as a starting point (!) for merchants that are interested in developing 1792 stress tests to see how far their infrastructure can scale. As is, it 1793 currently is not actually good at stressing the payment system. 1794 1795 The ``taler-unified-setup.sh`` script can be used to launch all required 1796 services and clients. However, the resulting deployment is simplistic 1797 (everything on the local machine, one single-threaded process per service 1798 type) and not optimized for performance at all. However, this can still be 1799 useful to assess the performance impact of changes 1800 to the code or configuration. 1801 1802 1803 Various configuration files that can be used in the code snippets in this 1804 section can be found in the ``src/merchant-tools/`` directory of the 1805 merchant. These are generally intended as starting points. Note that the 1806 configuration files ending in ``.edited`` are created by 1807 ``taler-unified-setup.sh`` and contain some options that are determined at 1808 runtime by the setup logic provided by ``taler-unified-setup.sh``. 1809 1810 See :ref:`Taler Exchange Manual <Benchmark-choose-bank>` for how to use ``taler-unified-setup.sh`` to setup the system and in particular on how to specify the bank to be used. 1811 1812 1813 Running taler-merchant-benchmark 1814 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1815 1816 You can run the tool as follows: 1817 1818 .. code-block:: console 1819 1820 $ CONF=benchmark-rsa.conf 1821 $ taler-unified-setup.sh -emwt -c "$CONF" -f -u exchange-account-1 1822 $ time taler-merchant-benchmark ordinary -c "$CONF".edited -u exchange-account-1 -f -p 20 1823 1824 The current tool has already a few options, but we expect that to deliver 1825 *relevant* results it will need to be customized to better reflect the 1826 workload of a particular merchant. This customization would at this point 1827 likely involve writing (C) code. We welcome contributions to make it easier 1828 to customize the benchmark and/or to cover more realistic workloads from the 1829 start. 1830 1831 The tool takes all of the values it needs from the command line, with 1832 some of them being common to all subcommands: 1833 1834 - ``--exchange-account-section=SECTION`` Specifies which configuration 1835 section specifies the bank account for the exchange that 1836 should be used for the benchmark. For the example 1837 configuration above, the SECTION value provided must be 1838 ``exchange-account-exchange``. 1839 - ``--fakebank`` Specifies that the benchmark should expect to interact 1840 with a fakebank (instead of libeufin). 1841 1842 The tool comes with two operation modes: *ordinary*, and *corner*. 1843 The first just executes normal payments, meaning that it uses the 1844 ``admin`` instance and make sure that all payments get aggregated. The 1845 second gives the chance to leave some payments unaggregated, and also to 1846 use merchant instances other than ``admin`` (which is, actually, the 1847 one used by default by the tool). 1848 1849 .. note:: 1850 1851 The ability to drive the aggregation policy is useful for testing 1852 the back-office facility. 1853 1854 Any subcommand is also equipped with the canonical ``--help`` option, so 1855 feel free to issue the following command in order to explore all the 1856 possibilities. For example: 1857 1858 .. code-block:: console 1859 1860 $ taler-merchant-benchmark corner --help 1861 1862 will show all the options offered by the *corner* mode. Among the most 1863 interesting, there are: 1864 1865 - ``--two-coins=TC`` This option instructs the tool to perform *TC* 1866 many payments that use two coins, because normally only one coin is 1867 spent per payment. 1868 1869 - ``--unaggregated-number=UN`` This option instructs the tool to 1870 perform *UN* (one coin) payments that will be left unaggregated. 1871 1872 As for the ``ordinary`` subcommand, it is worth explaining the following 1873 option: 1874 1875 - ``--payments-number=PN`` Instructs the tool to perform *PN* payments. 1876 1877 1878 1879 Temporarily Abandoned Features 1880 ============================== 1881 1882 .. [1] 1883 https://docs.docker.com/ 1884 1885 1886 Installing Taler using Docker 1887 ----------------------------- 1888 1889 This section provides instructions for the merchant backend installation 1890 using ‘Docker‘. 1891 1892 For security reasons, we run Docker against a VirtualBox instance, so 1893 the ``docker`` command should connect to a ``docker-machine`` instance 1894 that uses the VirtualBox driver. 1895 1896 Therefore, the needed tools are: “docker“, “docker-machine“, and 1897 “docker-compose“. Please refer to Docker’s official [1]_ documentation 1898 in order to get those components installed, as that is not in this 1899 manual’s scope. 1900 1901 Before starting to build the merchant’s image, make sure a 1902 “docker-machine“ instance is up and running. 1903 1904 Because all of the Docker source file are kept in our “deployment“ 1905 repository, we start by checking out the ``git://git.taler.net/deployment`` 1906 codebase: 1907 1908 .. code-block:: console 1909 1910 $ git clone git://git.taler.net/deployment 1911 1912 Now we actually build the merchant’s image. From the same directory as 1913 above: 1914 1915 .. code-block:: console 1916 1917 $ cd deployment/docker/merchant/ 1918 $ docker-compose build 1919 1920 If everything worked as expected, the merchant is ready to be launched. 1921 From the same directory as the previous step: 1922 1923 .. code-block:: console 1924 1925 # Recall: the docker-machine should be up and running. 1926 $ docker-compose up 1927 1928 You should see some live logging from all the involved containers. At 1929 this stage of development, you should also ignore some (harmless) error 1930 message from postresql about already existing roles and databases. 1931 1932 To test if everything worked as expected, it suffices to issue a simple 1933 request to the merchant, for example: 1934 1935 .. code-block:: console 1936 1937 $ wget -O - http://$(docker-machine ip)/ 1938 # A greeting message should be returned by the merchant.