Medusa
How to connect zahls.ch as a payment provider in Medusa v2 with the official @zahls/medusa-plugin npm package.
Overview
Medusa is an open-source commerce framework for headless shops. With the zahls.ch plugin you accept TWINT, credit and debit cards, PostFinance, and more via the hosted checkout.
Links
Features
- ✅ Hosted checkout (redirect to the zahls.ch payment page)
- ✅ Captures for authorized / reserved transactions
- ✅ Refunds through zahls.ch transactions
- ✅ Webhooks for asynchronous status updates
- ✅ Optional HMAC signature verification
- ✅ No raw card data in the Medusa backend
Compatibility
- Medusa v2.18.x
- zahls.ch Gateway API
Setup
1. Install the plugin
npm install @zahls/medusa-plugin
2. Activate payment methods in zahls.ch
- In the dashboard, go to Payment providers.
- Activate Payrexx Pay and/or Payrexx Pay Plus plus the payment methods you need.
- We recommend at least TWINT, Mastercard, Visa, Apple Pay, Google Pay, and PostFinance.
Details: Activating payment services.
3. Create an API key
- In the dashboard, go to API and integrations.
- Click Add API key.
- Choose a name (e.g. “Medusa”) and click Add.
- Copy the API key — you need it in the next step.
More information: API and integrations.
4. Configure Medusa
Register the plugin and payment provider in medusa-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,
webhookSecret: process.env.ZAHLS_WEBHOOK_SECRET,
successRedirectUrl: process.env.ZAHLS_SUCCESS_URL,
failedRedirectUrl: process.env.ZAHLS_FAILED_URL,
cancelRedirectUrl: process.env.ZAHLS_CANCEL_URL,
},
},
],
},
},
],
})
Set the environment variables in your Medusa backend:
| Variable | Required | Description |
|---|---|---|
ZAHLS_API_KEY | Yes | Instance API secret from API & Integrations |
ZAHLS_INSTANCE | Yes | Instance name (example for example.zahls.ch) |
ZAHLS_WEBHOOK_SECRET | No | Secret for HMAC verification |
ZAHLS_SUCCESS_URL | No | Redirect after successful payment |
ZAHLS_FAILED_URL | No | Redirect after failed payment |
ZAHLS_CANCEL_URL | No | Redirect after cancellation |
5. Enable the provider for a region
After the application starts, enable zahls.ch under Medusa Admin → Settings → Regions for the relevant region. The provider identifier is typically pp_zahls_zahls.
6. Test payment
- Place a test order in the storefront.
- Choose zahls.ch as the payment method — the customer is redirected to the hosted checkout.
- Check status and transaction in the zahls.ch dashboard.
Webhooks
Medusa uses its built-in payment webhook route for asynchronous status updates. Optionally the plugin verifies the HMAC signature when webhookSecret is set.
More: Webhooks.
Marketing and combo pages
- Medusa integration
- Example: TWINT for Medusa