Punchcommerce medusa plugin
PunchOut in minutes — no prior experience required. Connects Medusa v2 to procurement systems via OCI, cXML and IDS-Connect.
PunchCommerce Plugin for Medusa
A Medusa v2 plugin that integrates with PunchCommerce to enable cXML/PunchOut procurement gateway functionality. Procurement systems redirect buyers to your Medusa storefront where they can browse and add items to a cart, then transfer the cart back to the procurement system.
How It Works
- Buyer clicks a PunchOut link in their ERP → PunchCommerce redirects to your storefront's entry route with and query parameters
- Storefront authenticates the buyer via the Medusa SDK using the auth provider ()
- Storefront creates a fresh cart for the session and stores in . The buyer shops normally — items are added through the standard Store API.
- On checkout, the storefront calls to receive the PunchOut basket payload + a , then submits the basket as a form to that URL.
Installation
Requires Medusa v2.13.6 or newer (any 2.x release).
Configuration
The plugin requires you to add two entries to your : the plugin itself and an auth provider inside the Auth module.
Add the plugin to :
Register the punchcommerce-auth-Provider:
Options
| Option | Required | Default | Description |
|---|---|---|---|
| No | Base URL of the PunchCommerce gateway. Override for staging or self-hosted instances. Pass to both the plugin entry and the auth-provider entry. | ||
| No | Auth-provider option. When , skips the call to and accepts any well-formed . Intended for local development without a live PunchCommerce instance — never enable in production. |
Note: the gateway version is currently pinned to (see ).
Customer Setup
Customers are linked to PunchCommerce via an identity in Medusa's Auth module.
- In PunchCommerce: create a customer and copy the Customer identification — this is the .
- In Medusa admin: open the customer's detail page. On the right sidebar, the PunchCommerce widget shows the current link.
- Click Add (or the pencil icon) and paste the .
- If the same is already linked to another customer, the API returns an error and the widget displays it.
- Use the trash icon to unlink. The link is also auto-removed when the customer is deleted.
PunchCommerce Configuration
In the PunchCommerce dashboard, configure each customer with:
- Entry address: your storefront's PunchOut landing route, e.g.
- Customer identification: the same you entered in the Medusa admin
PunchCommerce will redirect buyers to the entry address with appended (plus any action parameters).
Storefront Requirements
The plugin is backend-only. The storefront must orchestrate the PunchOut flow.
1. Authentication route
Create a route that PunchCommerce redirects to. It must call the Medusa SDK with the provider and persist the auth token + .
All examples use the Next.js Starter Template: https://github.com/medusajs/nextjs-starter-medusa
What this triggers in the backend (see ):
- The is validated against (unless is set).
- The provider identity is looked up by . If no customer has that linked, the request fails with .
- On success, Medusa returns an auth token scoped to the linked customer.
2. Session-scoped cart
After authentication, create a new cart for the PunchOut session and attach the to its metadata. All Store API operations referencing this cart inherit the link.
Existing carts the customer owns outside of PunchOut are untouched. enforces that the cart used for any transfer/action has set.
3. PunchOut Page (replaces checkout)
Instead of the normal checkout, render a dedicated page that loads the prepared basket from the backend, shows it to the buyer for review, and submits it to PunchCommerce via a form on click. The buyer never sees the JSON payload — only the cart summary and a "Submit to procurement" button.
Data loader (server action that hits the Store API):
PunchOut Page:
4. PunchOut Actions (optional)
PunchCommerce can append to the entry URL to ask the storefront to perform additional steps right after authentication. The backend exposes to process them and the storefront decides what to do with the response.
| Action | Required params | Effect |
|---|---|---|
| Adds the listed items to the current cart. Missing SKUs return as warning notifications. | ||
| Looks up the product handle for the SKU. Storefront redirects to the product-detail page. | ||
| Storefront redirects to its own search results page. | ||
| Backend builds a basket from search results and returns it together with a (for inline PunchOut sessions that submit search results back). |
A few things to keep in mind before implementing:
- always runs when present, regardless of other actions. It mutates the cart and may add notifications for missing SKUs. It never sets a navigation response.
- Only the first result-producing action wins. If contains both and , the backend processes the first one and skips the rest.
- The input action name is (hyphen) but the response discriminant is (underscore) — always branch on , not the raw input string.
- (e.g. "SKU X not found") survive the action call even when a redirect follows. Store them in a cookie or flash session to surface them to the buyer after the redirect.
Data loader (add alongside in ):
Note: In the authenticate route the auth token and cart were just created, so / may not yet read the freshly-set cookies. Pass both values explicitly from the route; the defaults still work for other callers (e.g. loading the loader from the page after the session is established).
Extended authenticate route — after and cart creation (Steps 1–2), check for actions and branch on the result:
Also see https://www.punchcommerce.de/swagger#/E-Commerce-Integration/post_punchcommerce_authenticate
Cart Mapping
The plugin maps each Medusa cart line item to a ():
- = the line (net), = (gross), = (net unit price)
- is forwarded from the cart line (decimal, e.g. )
- is truncated to 39 characters (OCI/cXML constraint)
- is hardcoded to ; per-variant unit mapping (, , , …) is not yet implemented
- The basket is submitted to as by the storefront
Cart Lifecycle
After a successful transfer, the Medusa cart is not automatically marked complete, archived, or deleted — it remains in its current state. Recommended storefront behavior:
- Start the next PunchOut session by creating a brand-new cart with the new in its metadata
(The actual purchase order is created later through PunchCommerce / the ERP — Medusa is only the catalog browsing surface.)
Parallel Sessions
Carts are scoped per , not per customer, so a single PunchCommerce-linked customer can have multiple independent PunchOut sessions in flight.
REST API Reference
Customer-authenticated (bearer or session). Builds a PunchOut basket from a session-scoped Medusa cart.
| Query | Required | Description |
|---|---|---|
| Yes | Cart whose metadata contains . |
Response:
Customer-authenticated. Processes one or more PunchOut entry actions.
| Query | Required | Description |
|---|---|---|
| Yes | Cart to operate on. | |
| Yes | One or more of , , , . | |
| For | Comma-separated pairs. | |
| For | SKU to look up. | |
| For / | Free-text search term. |
Response: — see .
Admin-authenticated. Backs the customer-detail widget.
- GET →
- POST body — upserts the link.
- DELETE — removes the link.
Types Reference
All types are exported from .
A single line in the PunchOut basket. The plugin builds one position per Medusa cart line item.
Product-Data embedded in each PunchOutPosition. Sent to PunchCommerce so the procurement system can store/display the product even if the buyer's catalog doesn't have it.
Top-level basket wrapper. This is the shape the PunchCommerce endpoint expects — when submitting the form, wrap the position array in .
Item passed to the action. The route parses the query string into an array of these.
Warning / info message returned alongside an action response (e.g. when a SKU in was not found).
Discriminated union returned by . The storefront branches on to decide what to do next.

