Metadata-Version: 2.4
Name: pretix-epay
Version: 0.1.0
Summary: pretix payment provider plugin for epay.eu (card payment, Apple Pay, Google Pay)
Author: ByteServ
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/ByteServIT/pretix-epay
Project-URL: Repository, https://github.com/ByteServIT/pretix-epay
Project-URL: Changelog, https://github.com/ByteServIT/pretix-epay/blob/main/CHANGELOG.rst
Project-URL: Issues, https://github.com/ByteServIT/pretix-epay/issues
Keywords: pretix,epay,payment,apple pay,google pay
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: Django
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Office/Business :: Financial :: Point-Of-Sale
Requires-Python: >=3.10
Description-Content-Type: text/x-rst
License-File: LICENSE
Requires-Dist: requests
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-django; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: responses; extra == "dev"
Requires-Dist: pre-commit; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: license-file

pretix-epay
===========

.. image:: https://github.com/ByteServIT/pretix-epay/actions/workflows/ci.yml/badge.svg
   :target: https://github.com/ByteServIT/pretix-epay/actions/workflows/ci.yml
   :alt: CI

.. image:: https://img.shields.io/pypi/v/pretix-epay.svg
   :target: https://pypi.org/project/pretix-epay/
   :alt: PyPI

A `pretix <https://pretix.eu>`_ plugin that adds
`epay.eu <https://epay.eu>`_ as a payment provider, accepting card
payments, Apple Pay, and Google Pay through the epay.eu Checkout page.

Maintained by `ByteServ <https://github.com/ByteServIT>`_.

Features
--------

* Card payment, Apple Pay, and Google Pay via the epay.eu Checkout page
  (redirect flow, no card data ever touches your pretix server).
* Automatic payment confirmation via a **single, instance-wide webhook**
  — you register it **once** with epay.eu, not per event.
* Refunds can be triggered directly from the pretix backend, using
  epay.eu's transaction refund endpoint.
* German and English translations included (compiled ``.mo`` shipped in
  the package, no build-time translation step required).

Requirements
------------

* pretix >= 2024.5.0
* Python >= 3.10 (CI tests Python 3.10 with pretix 2024.5, and
  Python 3.12/3.13 with the latest pretix release)
* An epay.eu merchant account with at least one Point of Sale configured

Installation
------------

Manual installation (no Docker)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

If pretix runs as a `manual small-scale deployment
<https://docs.pretix.eu/self-hosting/installation/manual_smallscale/>`_
(a Python virtualenv managed by systemd, no Docker involved), plugin
installation follows the same pattern pretix itself documents for any
other plugin — plain ``pip``, no container build step needed:

.. code-block:: bash

   sudo -u pretix -s
   source /var/pretix/venv/bin/activate

   # From PyPI:
   (venv)$ pip3 install pretix-epay
   # ...or from a local checkout:
   (venv)$ pip3 install /path/to/pretix-epay
   # ...or straight from GitHub:
   (venv)$ pip3 install "pretix-epay @ git+https://github.com/ByteServIT/pretix-epay.git"

   (venv)$ python -m pretix migrate    # no-op for this plugin (no DB models), but harmless / standard practice
   (venv)$ python -m pretix rebuild    # rebuilds static files
   exit

   sudo systemctl restart pretix-web pretix-worker

The webhook (see *Configuration* below) needs the ``EPAY_WEBHOOK_TOKEN``
environment variable to be visible to the **pretix-web** process (it is
read directly in the request handler, not by the background worker).
Add it to ``/etc/systemd/system/pretix-web.service``:

.. code-block:: ini

   [Service]
   ...
   Environment="EPAY_WEBHOOK_TOKEN=Bearer xxxxxxxx"

Then:

.. code-block:: bash

   sudo systemctl daemon-reload
   sudo systemctl restart pretix-web

(``pretix-worker`` doesn't need this variable — only the web process
handles the webhook request.)

Docker
^^^^^^

If you run pretix via the official ``pretix/standalone`` Docker image,
you cannot install plugins into a running container — you build a small
custom image on top of it instead:

.. code-block:: dockerfile

   FROM pretix/standalone:stable

   USER root
   RUN pip3 install pretix-epay && \
       rm -rf ~/.cache/pip

   USER pretixuser
   RUN cd /pretix/src && make production

(To build from a local checkout instead, replace the ``pip3 install``
step with ``COPY pretix-epay /pretix-epay`` and
``RUN pip3 install /pretix-epay``.)

Point your ``pretix`` and ``cron`` (or whichever service runs the
scheduled ``pretix cron`` job) services in ``docker-compose.yml`` at
this custom image instead of ``pretix/standalone:stable``, then:

.. code-block:: bash

   docker compose build --no-cache
   docker compose up -d

Here, the ``EPAY_WEBHOOK_TOKEN`` variable goes into the ``pretix``
service's ``environment:`` block in ``docker-compose.yml`` instead of a
systemd unit file.

Configuration
--------------

Per event
^^^^^^^^^

In pretix, open **Event → Settings → Plugins** and enable **epay.eu**.
Then under **Event → Settings → Payment → epay.eu**, fill in:

* **Point of Sale ID** — from your epay.eu backoffice under
  *Point of Sale*.
* **API key** — the API key belonging to that Point of Sale.

Global (once per pretix instance)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The webhook is intentionally **not** scoped per event. It is registered
once for your whole pretix instance and works for every organizer and
event automatically — the specific payment is identified from the
``reference`` field epay.eu sends back, not from the URL.

1. Log in to the epay.eu backoffice and open the **Point of Sale** you
   configured above. Find the **webhook authorization / verification
   value** there (not in a separate generic "Webhooks" section — it is
   tied to the specific Point of Sale).
2. Copy the **complete** value, including its scheme
   (e.g. ``Bearer xxxxxxxx`` or ``Basic xxxxxxxx``).
3. Set it as the ``EPAY_WEBHOOK_TOKEN`` environment variable for your
   pretix web process — see the *systemd* or *Docker* instructions
   above, depending on how you installed the plugin.
4. The webhook endpoint itself is:
   ``https://YOUR-DOMAIN/_epay/webhook/``

We compare the incoming ``Authorization`` header byte-for-byte against
``EPAY_WEBHOOK_TOKEN`` — including the scheme — as recommended by the
`epay.eu webhook documentation
<https://docs.epay.eu/build-and-go-live/handle-payment-results>`_,
which explicitly warns not to assume the scheme is always ``Bearer``.

Architecture notes
-------------------

A few design decisions that aren't obvious from the code alone:

* **Global webhook, not per-event.** ``OrderPayment.full_id`` (e.g.
  ``ABC12-P-1``) is only unique *within* an event, not across the whole
  instance. Since the webhook has no event context, we instead send
  epay.eu the payment's Django primary key (``payment.pk``) as the
  ``reference`` — a plain integer, globally unique, and trivially valid
  against epay.eu's ``reference`` validation regex
  (``^[a-zA-Z0-9\-]{1,36}$``).
* **``@scopes_disabled()`` on the webhook view.** pretix uses
  ``django-scopes`` to scope most queries to an active organizer, for
  multi-tenant safety. Since the global webhook doesn't know the
  organizer in advance, the whole view (not just the lookup) needs
  ``@scopes_disabled()`` — exactly like pretix's own PayPal2 webhook
  does internally.
* **No ``LazyI18nString`` for provider metadata.** It's tempting to use
  ``i18nfield.strings.LazyI18nString`` for translatable strings without
  a compile step. Don't use it for ``verbose_name``, ``public_name``, or
  ``PretixPluginMeta.name``/``description`` — pretix core treats these
  as plain strings internally (``.startswith()`` calls, ``sorted(key=...)``
  comparisons), which ``LazyI18nString`` does not support and which will
  crash the plugin list and payment settings pages. This plugin uses
  ``gettext_lazy`` with a pre-compiled ``.mo`` file instead.
* **Refunds use the transaction ID, not the session ID.** epay.eu's
  refund endpoint is ``POST /transactions/:transactionId/refund``. The
  transaction ID only exists once a payment attempt actually happened,
  so it's captured from the webhook payload (``transaction.id``) and
  stored in ``payment.info``, not from the initial session-creation
  response.

Known limitations
-------------------

* Amounts are converted to minor units using pretix's own list of
  currency decimal places, so zero-decimal currencies (e.g. JPY) are
  handled correctly. pretix has no notion of three-decimal currencies
  (e.g. BHD, KWD) and treats them as two-decimal; these are not supported.
* Does not yet handle refunds initiated directly in the epay.eu
  backoffice (i.e. there's no webhook handling for externally-triggered
  refund events) — refunds must go through the pretix backend to be
  reflected in pretix.

Development
-----------

See `CONTRIBUTING.rst
<https://github.com/ByteServIT/pretix-epay/blob/main/CONTRIBUTING.rst>`_ for the local setup (native or
Docker), running the tests, translations, and the release process.

License
-------

Apache License 2.0. See ``LICENSE`` for the full text.
