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