Open MercatoDocsSearch docsAPI reference

User guide

Tpay Payment Gateway

Configure the Tpay integration for the account that will receive payments. Check the connection before sending customers through the payment flow.

This guide explains how to connect Tpay to Open Mercato and accept PLN payments through Tpay's hosted payment page. The payer is redirected to Tpay, chooses a payment method there (online transfer, BLIK, and other methods enabled on your Tpay account), and returns to your checkout page.

Before you start

Configure the integration

  1. Navigate to External Systems → Integrations and click Configure on the Tpay card.
  2. Fill in the credentials:
    • Client ID and Client Secret – from the Tpay API key.
    • Environment – Sandbox for sandbox credentials, Production for live credentials. Open Mercato uses Tpay's fixed sandbox or production API address for the selected environment.
    • Notification URL (optional) – the public HTTPS address Tpay will notify about payment results. It must not contain credentials, a query string, or a fragment, and production requires port 443. Leave it empty if the Tpay Merchant Panel already defines the notification address.
    • Notification Security Code – the security code from Tpay Merchant Panel → Settings → Notifications → Security. Required for payment notifications; without it every notification is rejected.
  3. Save and run the health check. A healthy result means Open Mercato obtained an access token from Tpay with these credentials.
  4. Enable the integration.

Optional env preconfiguration

OM_INTEGRATION_TPAY_CLIENT_ID=...
OM_INTEGRATION_TPAY_CLIENT_SECRET=...
OM_INTEGRATION_TPAY_ENVIRONMENT=sandbox
OM_INTEGRATION_TPAY_NOTIFICATION_URL=
OM_INTEGRATION_TPAY_NOTIFICATION_SECURITY_CODE=
OM_INTEGRATION_TPAY_ENABLED=true
OM_INTEGRATION_TPAY_FORCE_PRECONFIGURE=false

Client ID and Client Secret are required together. In standalone apps created with create-mercato-app, the module is opt-in: uncomment gateway_tpay in src/modules.ts. New tenants pick the preset up automatically. To apply it to an existing tenant:

yarn mercato gateway_tpay configure-from-env --tenant <tenantId> --org <organizationId> [--force]

Without --force, existing Tpay credentials or integration state are left untouched.

Using Tpay in checkout

Select Tpay as the payment provider of a checkout link and keep customer details collection enabled: Tpay requires the payer's email address and name, and checkout forwards the values the payer enters. Payments without an email address or name are rejected before anything is sent to Tpay.

The email, first name, and last name customer fields must be marked as required. Until they are, the Payment section of the template or link editor shows a warning and saving is rejected. A link saved before this rule keeps working, but you must fix its customer fields the next time you save it.

After paying, the payer returns to the checkout success page, which reads the transaction status from Tpay. A paid transaction becomes captured.

Payment notifications

Tpay confirms each paid transaction with a server-to-server notification. Open Mercato settles the payment from that notification, so a payment is captured even when the payer closes the browser on Tpay's page.

  1. In the Tpay Merchant Panel, set the notification address to https://<your-domain>/api/payment_gateways/webhook/tpay (or fill Notification URL in the integration, which Tpay uses when overriding is allowed). The address must be public HTTPS on port 443, without redirects.
  2. Copy the notification security code (Tpay Merchant Panel → Settings → Notifications → Security) into Notification Security Code. Without it every notification is rejected and the integration health check reports a degraded status.
  3. Save the integration.

Each notification is checked before anything changes:

SituationResponse to TpayEffect
Verified and processed200 TRUEPayment captured (or refunded for a chargeback) once, even if Tpay repeats the notification
Transaction not found yet, certificate download or validation failed, or processing failed503 FALSETpay retries later
Invalid checksum or signature, amount/currency mismatch, underpayment400 FALSENothing changes; Tpay keeps retrying – check the security code and the integration environment

An overpayment still captures the expected amount; the paid amount is kept in the transaction details.

Scheduled status check

When the Tpay integration is enabled for an organization, Open Mercato registers a scheduled job (Tpay payment status reconciliation, every 5 minutes) that asks Tpay for the current status of that organization's Tpay transactions that are still open (pending, authorized, or partially captured). It repairs payments whose notification never arrived, for example because the notification address was misconfigured or Tpay exhausted its retries.

Testing with the Tpay sandbox

Tpay signs every notification with its own certificate, so notifications cannot be simulated locally. To test the whole flow, use a Tpay sandbox account and a public HTTPS address that reaches your local application.

  1. In the Tpay sandbox panel, copy the API Client ID and Secret and the notification security code. Configure the integration with Environment set to Sandbox.

  2. Expose only the notification endpoint, not the whole application. For example, a Cloudflare named tunnel whose ingress allows only the webhook path:

    ingress:
      - hostname: <your-test-host>
        path: ^/api/payment_gateways/webhook/tpay$
        service: http://127.0.0.1:<app-port>
      - service: http_status:404
    

    Set Notification URL to https://<your-test-host>/api/payment_gateways/webhook/tpay.

  3. Create a published PLN checkout link with Tpay and pay on the sandbox page. To test notifications, close the Tpay tab after paying instead of returning to the checkout page: the success page reads the status from Tpay and would capture the payment before the notification arrives.

  4. To test the scheduled status check, make the endpoint unreachable (for example, stop the tunnel) before paying. The payment stays pending until the next run of Tpay payment status reconciliation captures it. The scheduler must be running.

Tpay e-mails the merchant when the endpoint does not answer TRUE. These e-mails are expected while you test a missing notification. The sandbox payment page may block automated (headless) browsers, so complete test payments in a regular browser. Remove the tunnel and its DNS record when you finish.

Limitations

Previous: Teams and team members · Next: Extend users with custom fields