Overview
Icon for zahls.ch

zahls.ch

TWINT, cards and PostFinance (Switzerland)

@zahls/medusa-plugin

zahls.ch payment provider for Medusa v2.

This plugin lets a Medusa application create and manage zahls.ch Gateway checkouts from the backend. It supports:

  • Hosted checkout, where the customer is redirected to the zahls.ch payment page (Copy to clipboardsession.data.link)
  • Swiss payment methods such as TWINT, cards, and PostFinance
  • Captures for authorized / reserved transactions
  • Refunds through zahls.ch transactions
  • Medusa's built-in payment webhook route for asynchronous status updates, with optional HMAC signature verification

The plugin never handles raw card data directly. zahls.ch credentials remain on the Medusa backend.

Compatibility

  • Medusa v2.18.x
  • zahls.ch Gateway API

Install

npm install @zahls/medusa-plugin

Configure Medusa

Register the plugin and payment provider in Copy to clipboardmedusa-config.ts:

import { defineConfig } from "@medusajs/framework/utils"
export default defineConfig({
plugins: [
{
resolve: "@zahls/medusa-plugin",
options: {},
},
],
modules: [
{
resolve: "@medusajs/medusa/payment",
options: {
providers: [
{
resolve: "@zahls/medusa-plugin/providers/zahls",
id: "zahls",
options: {
apiKey: process.env.ZAHLS_API_KEY,
instance: process.env.ZAHLS_INSTANCE,

After the application starts, enable zahls.ch for the relevant region in Medusa Admin → Settings → Regions. Per Medusa's payment-provider model, the resulting provider identifier is Copy to clipboardpp_zahls_zahls when the service identifier is Copy to clipboardzahls and the configured provider Copy to clipboardid is Copy to clipboardzahls.

Configuration Options

Option Required Description Copy to clipboardapiKey Yes Instance API secret from zahls.ch → API & Integrations. Keep it server-side. Copy to clipboardinstance Yes Instance name (Copy to clipboardexample for Copy to clipboardexample.zahls.ch). Copy to clipboardwebhookSecret Yes Signing key for Copy to clipboardX-Webhook-Signature verification. Webhooks are rejected without it. Copy to clipboardsuccessRedirectUrl No Storefront URL after a successful payment. Copy to clipboardfailedRedirectUrl No Storefront URL after a failed payment. Copy to clipboardcancelRedirectUrl No Storefront URL after the customer cancels. Copy to clipboardskipResultPage No Skip the zahls.ch result page (default Copy to clipboardtrue).

Auth uses the Copy to clipboardX-API-KEY header (recommended by the zahls.ch / Payrexx REST API).

Hosted Checkout

The plugin creates a zahls.ch Gateway and stores the returned checkout Copy to clipboardlink in the payment-session data. The storefront should redirect the customer to that URL:

const link = paymentSession.data?.link
if (typeof link === "string") {
window.location.href = link
}

Use backend / webhook state as the source of truth. The storefront should not treat the redirect alone as proof of payment success.

When available, customer name, email, company, and billing address from the Medusa payment context are prefilled on the Gateway.

Webhooks

Medusa provides a built-in webhook listener route for payment providers at:

/hooks/payment/[identifier]_[provider]

For this plugin, with service identifier Copy to clipboardzahls and provider Copy to clipboardid: "zahls", add this URL in the zahls.ch merchant backend (Webhooks), with JSON content type:

https://your-medusa-backend.com/hooks/payment/zahls_zahls

The plugin verifies Copy to clipboardX-Webhook-Signature when Copy to clipboardwebhookSecret is set, loads the Gateway from zahls.ch, maps the status to a Medusa payment action, and returns the payment session reference (Copy to clipboardreferenceId) back to Medusa.

zahls.ch status Medusa webhook action Copy to clipboardconfirmed Copy to clipboardcaptured Copy to clipboardauthorized / Copy to clipboardreserved Copy to clipboardauthorized Copy to clipboardwaiting Copy to clipboardpending_authorization Copy to clipboardcancelled Copy to clipboardcanceled Copy to clipboardfailed / Copy to clipboarddeclined Copy to clipboardfailed

Copy to clipboardreferenceId on the Gateway is set to the Medusa payment session id so webhooks can resolve the session.

What the Plugin Stores

The payment-session data returned by the provider includes:

  • Copy to clipboardid — zahls.ch Gateway id
  • Copy to clipboardhash
  • Copy to clipboardlink — hosted checkout URL
  • Copy to clipboardreferenceId — Medusa payment session id
  • Copy to clipboardstatus
  • Copy to clipboardamount and Copy to clipboardcurrency
  • Copy to clipboardtransactionId when available
  • Copy to clipboardlastRefundId after a refund

Current Behavior and Limitations

  • Checkout is hosted-redirect only. There is no embedded card widget mode.
  • Copy to clipboardauthorizePayment checks the remote zahls.ch Gateway status rather than performing a separate authorization step.
  • Copy to clipboardcapturePayment succeeds immediately when the Gateway is already Copy to clipboardconfirmed. For Copy to clipboardauthorized / Copy to clipboardreserved / Copy to clipboarduncaptured, it calls zahls.ch capture (and falls back to charge if needed).
  • Copy to clipboardupdatePayment recreates the Gateway when amount or currency changes before payment.
  • Refunds require a successful zahls.ch transaction id on the session.
  • Copy to clipboardwebhookSecret is required; unsigned webhooks are rejected.

Sandbox Checklist

  • Create a Gateway and complete one successful hosted checkout (e.g. TWINT or card).
  • Confirm the storefront redirect to Copy to clipboardsession.data.link works.
  • Verify at least one webhook-driven status update to Medusa.
  • Verify Copy to clipboardX-Webhook-Signature rejection when the secret is wrong.
  • Capture an authorized / reserved payment if your zahls.ch flow supports it.
  • Verify one full refund and one partial refund.
  • Verify canceled and failed checkouts map cleanly back into Medusa session state.

Local Development

npm run build
npm run dev
npm run test:unit
npm run test:integration:modules

Module integration tests need PostgreSQL (Copy to clipboardDB_HOST, Copy to clipboardDB_USERNAME, Copy to clipboardDB_PASSWORD, Copy to clipboardDB_PORT). Defaults: Copy to clipboardlocalhost:5432, user Copy to clipboardpostgres.

Publish locally with Copy to clipboardnpx medusa plugin:publish, then in a Medusa app:

npx medusa plugin:add @zahls/medusa-plugin

License

MIT

You may also like

Browse all integrations

Build your own

Develop your own custom integration

Build your own integration with our API to speed up your processes. Make your integration available via npm for it to be shared in our Library with the broader Medusa community.

gift card interface

Ready to build your custom commerce setup?