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