Paytrail
Accept Finnish online payments with Paytrail
Paytrail Payment Provider Plugin
Paytrail payment provider plugin for Medusa v2.
This package is published to NPM as Copy to clipboard@solteq-excom/medusa-payment-paytrail.
Install
Add the package to your Medusa backend:
1yarn add @solteq-excom/medusa-payment-paytrail
Register the plugin and payment provider in your Copy to clipboardmedusa-config.ts:
1234567891011121314151617181920plugins: [{resolve: "@solteq-excom/medusa-payment-paytrail",options: {},},],modules: [{resolve: "@medusajs/medusa/payment",options: {providers: [{resolve: "@solteq-excom/medusa-payment-paytrail/providers/paytrail",id: "paytrail",options: {merchantId: Number(process.env.PAYTRAIL_MERCHANT_ID),secretKey: process.env.PAYTRAIL_SECRET_KEY,platformName: process.env.PAYTRAIL_PLATFORM_NAME ?? "MedusaJS",callbackBaseUrl: process.env.PAYTRAIL_CALLBACK_BASE_URL,callbackDelay: process.env.PAYTRAIL_CALLBACK_DELAY
Configuration
Required and supported environment variables:
- Copy to clipboard
PAYTRAIL_MERCHANT_ID - Copy to clipboard
PAYTRAIL_SECRET_KEY - Copy to clipboard
PAYTRAIL_PLATFORM_NAME(optional) - Copy to clipboard
PAYTRAIL_CALLBACK_BASE_URL(recommended, must use HTTPS) - Copy to clipboard
PAYTRAIL_CALLBACK_DELAY(optional, seconds, 0-900, default Copy to clipboard0) - Copy to clipboard
PAYTRAIL_REDIRECT_URL_HOST_WHITELIST(required, comma-separated Copy to clipboardhost[:port]values; Copy to clipboard*wildcard supported) - Copy to clipboard
PAYTRAIL_LANGUAGE(Copy to clipboardFI, Copy to clipboardSV, or Copy to clipboardEN)
Example:
1234567PAYTRAIL_MERCHANT_ID=375917PAYTRAIL_SECRET_KEY=SAIPPUAKAUPPIASPAYTRAIL_PLATFORM_NAME=MedusaJSPAYTRAIL_CALLBACK_BASE_URL=https://your-backend.example.comPAYTRAIL_CALLBACK_DELAY=0PAYTRAIL_REDIRECT_URL_HOST_WHITELIST=localhost:8888,store.example.com,*.foo.bar.baz,pr-*.foo.bar.bazPAYTRAIL_LANGUAGE=EN
If Copy to clipboardPAYTRAIL_CALLBACK_BASE_URL is set, the provider sends Paytrail Copy to clipboardcallbackUrls automatically as:
- success: Copy to clipboard
{PAYTRAIL_CALLBACK_BASE_URL}/hooks/paytrail - cancel: Copy to clipboard
{PAYTRAIL_CALLBACK_BASE_URL}/hooks/paytrail
Copy to clipboardPAYTRAIL_CALLBACK_DELAY maps to Paytrail Copy to clipboardcallbackDelay (seconds). According to Paytrail, when callback URLs are provided, callback delay can be Copy to clipboard0 to Copy to clipboard900 seconds and defaults to Copy to clipboard0.
Paytrail requires HTTPS callback URLs for both success and cancel callbacks. Example uses Paytrail test credentials
When creating payment sessions, Copy to clipboardinput.data.redirect_success and Copy to clipboardinput.data.redirect_cancel must use Copy to clipboardhttp or Copy to clipboardhttps, include only host/path (no query/hash/auth), and the host must match Copy to clipboardPAYTRAIL_REDIRECT_URL_HOST_WHITELIST.
Copy to clipboardPAYTRAIL_REDIRECT_URL_HOST_WHITELIST supports wildcard host patterns with Copy to clipboard*, for example:
- Copy to clipboard
*.foo.bar.baz - Copy to clipboard
pr-*.foo.bar.baz
Features
- Payment session initiation via Paytrail API
- Payment status check for authorization flow
- Refund support
- Callback action parsing and HMAC signature verification
- Custom GET callback route for Paytrail redirect and callback query params
Callback Route
The plugin exposes Copy to clipboardGET /hooks/paytrail for Paytrail redirect and callback handling.
The route forwards callback payloads into Medusa's payment webhook pipeline by emitting Copy to clipboardPaymentWebhookEvents.WebhookReceived after validating the signature.
Behavior
- Currency support is limited to Copy to clipboard
EURby Paytrail. - Payment sessions are created in Copy to clipboard
pendingstatus until Paytrail authorizes them. - Cart completion fails before third-party authorization.
- Standard Paytrail flow is treated as auto-captured after authorization.
Payment Flow
- Store creates a payment session with provider Copy to clipboard
pp_paytrail_paytrail. - Paytrail returns a redirect URL and Copy to clipboard
transactionId. - Customer authorizes the payment in Paytrail checkout.
- Callback updates the payment status to authorized or captured.
- Cart completion succeeds after authorization.
Troubleshooting
No payment providers available in store
- Ensure the Paytrail provider is linked to the region.
Cart completion returns 400 not authorized
- This is expected before the Paytrail authorization callback is processed.
- Complete the payment in Paytrail before completing the cart.
Callback is not triggered
- Verify Copy to clipboard
PAYTRAIL_CALLBACK_BASE_URLis configured with an HTTPS URL. - Paytrail requires HTTPS callback URLs for both success and cancel callbacks.
Contributing
Bug reports and feature requests are welcome.
When submitting an issue, include:
- A clear description of the problem or requested change
- Steps to reproduce, if applicable
- Relevant configuration details, logs, or screenshots
When submitting a pull request:
- Open an issue first for larger changes so the approach can be discussed
- Keep the PR focused on a single fix or feature
- Include tests or updates to existing tests when behavior changes
- Update the README or other documentation if the public behavior changes
Disclaimer
This package is provided as-is, without warranty of any kind. You are responsible for validating the integration, security, and compliance requirements before using it in production.

