Overview
Icon for MONEI

MONEI

Accept payments with MONEI

medusa-payment-monei

MONEI payment plugin for Medusa v2.

The setup guide with screenshots is in the MONEI documentation.

The plugin contains:

  • Five payment providers: card, Bizum, PayPal, MB WAY and Multibanco. The card provider also takes Apple Pay and Google Pay: on the Hosted Payment Page next to the card form, and through the monei.js Copy to clipboardPaymentRequest component in embedded and express checkout.
  • Store API routes for saved cards and for the live payment status.
  • Subscribers that report orphan payments, release AUTH holds whose cart never became an order, and remove account holders whose MONEI customer was deleted.
  • A job that registers the storefront domains with Apple Pay at startup. See Apple Pay domain.

Upgrade from 0.1.x (breaking changes)

Version 1.0.0 is a full rewrite. Read this section before you upgrade.

  • Set Copy to clipboardcapture: false to keep AUTH. 0.1.x authorized by default (AUTH). 1.0.0 charges at once (SALE) by default. If you used the 0.1.x default, set Copy to clipboardcapture: false before you deploy 1.0.0. See Capture mode.
  • Amounts are Medusa major units. 0.1.x as published sent the Medusa amount as cents. A 19.99 EUR cart was charged 0.20 EUR. 1.0.0 converts 19.99 to 1999 cents.
  • Check the amounts of your 0.1.x orders. Some installations fixed the conversion in their own copy of 0.1.x. Compare the MONEI amount of one 0.1.x payment with its Medusa order total.
    • When they are the same, the amounts are correct. You can refund these orders from Medusa.
    • When the MONEI amount is 1/100 of the total, refund these orders in the MONEI dashboard, not from Medusa. A refund from Medusa asks for 100 times what MONEI took.
  • The package is a Medusa plugin. Add it to Copy to clipboardplugins. The provider Copy to clipboardresolve path is now Copy to clipboardmedusa-payment-monei/providers/monei.
  • The public URL of the Medusa backend is required. Set Copy to clipboardMEDUSA_BACKEND_URL, or the Copy to clipboardbackendUrl option. The plugin registers the callback URL on every payment. You do not need a webhook in the MONEI dashboard.
  • Delete the 0.1.x webhook. If you added a webhook for Medusa in the MONEI dashboard (Settings, Webhooks), delete it. Keeping the dashboard webhook with a Copy to clipboardpk_ key delivers each payment to Medusa twice. See Callbacks.
  • Payments created before the upgrade have no callback URL. 0.1.x did not register one, so MONEI sends no callback for these payments. Only a webhook in the MONEI dashboard sends their events. Capture, cancel and refund from the Medusa admin still work: the plugin fetches each payment from MONEI and does not use the amount or status that 0.1.x stored. Without a dashboard webhook, a checkout that was open at the upgrade completes only when the buyer comes back to the storefront.
  • A checkout whose MONEI amount is not the cart amount cannot complete. 1.0.0 compares the MONEI payment with the Medusa session amount and currency, in cents, before it authorizes. A checkout open at the upgrade with a 0.1.x payment of 1/100 of the cart is refused, and the error log names the payment. Cancel it (Copy to clipboardAUTHORIZED) or refund it (Copy to clipboardSUCCEEDED) in the MONEI dashboard.
  • A checkout with a Copy to clipboardmedusa_ order id cannot complete. 0.1.x made an order id Copy to clipboardmedusa_<time>_<random> when Medusa sent no session id. 1.0.0 completes a cart only for a MONEI payment whose order id is the Medusa payment session id (Copy to clipboardpayses_...). Capture, cancel and refund of existing orders do not check the order id. When a buyer paid such a payment and the cart stayed open, cancel it (Copy to clipboardAUTHORIZED) or refund it (Copy to clipboardSUCCEEDED) in the MONEI dashboard.
  • Copy to clipboardwebhookSecret is removed. With a Copy to clipboardpk_ key, the plugin verifies the Copy to clipboardMONEI-Signature header with that key. See Callbacks.
  • There is one provider per payment method. Enable each provider you want on your regions. See Provider ids.
  • Send Copy to clipboardreturn_url for the hosted payment page. 1.0.0 sends a complete, fail and cancel URL to MONEI only when the create-session request has Copy to clipboardreturn_url in Copy to clipboarddata. Some copies of 0.1.x set Copy to clipboardcompleteUrl in the plugin. If your storefront relied on such a copy, it must send Copy to clipboardreturn_url now. Without it, the buyer stays on the MONEI page after the payment. The MONEI callback still completes the cart. Copy to clipboardreturn_url must be an absolute URL. The plugin adds Copy to clipboardsession_id to it, and Copy to clipboardmonei_canceled=1 on a cancel. See Hosted payment page.
await sdk.store.payment.initiatePaymentSession(cart, {
provider_id: "pp_monei_monei",
data: { return_url: "https://shop.example.com/checkout/monei-return" },
});
  • Session data changed. Copy to clipboardclient_secret is removed. A create-session request whose Copy to clipboarddata holds a key the provider sets (Copy to clipboardid, Copy to clipboardsession_id, Copy to clipboardamount, ...) is refused. See Session data.
  • Partial capture is refused. MONEI payments capture in full only. See Limits.
  • Only five methods. 0.1.x let MONEI offer every method enabled on the account. 1.0.0 offers card, Bizum, PayPal, MB WAY and Multibanco, one per provider. Apple Pay and Google Pay come through the card provider (Hosted Payment Page, or monei.js Copy to clipboardPaymentRequest).

Requirements

  • Medusa Copy to clipboard>=2.17.0 <3. CI runs the full end-to-end suite on 2.22.3, and the Copy to clipboardcapture: false specs (hosted card included) on 2.17.0. Medusa 2.17.0 itself did not start in our tests with the Redis event bus (Copy to clipboard@medusajs/medusa/event-bus-redis) in the default worker mode: use 2.17.1 or later with Redis.
  • Node.js Copy to clipboard>=22.22.0.
  • A MONEI account and its API key. Get the key in the MONEI Dashboard, under Settings, API Access.
  • A backend URL that MONEI can reach from the internet. MONEI sends payment callbacks to it.

Installation

npm install medusa-payment-monei

Configuration

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

import { defineConfig } from "@medusajs/framework/utils";
module.exports = defineConfig({
// ...
plugins: ["medusa-payment-monei"],
modules: [
{
resolve: "@medusajs/medusa/payment",
options: {
providers: [
{
resolve: "medusa-payment-monei/providers/monei",
id: "monei",
options: {
apiKey: process.env.MONEI_API_KEY,
},
},
],
},
},

Set Copy to clipboardMEDUSA_BACKEND_URL to the public URL of your Medusa backend, for example Copy to clipboardhttps://medusa.example.com. MONEI sends the payment callbacks to this URL. Medusa also uses this variable as the default of Copy to clipboardadmin.backendUrl.

The provider Copy to clipboardid must be Copy to clipboard"monei". The callback URL, the store routes and the subscriber use this id. Another id breaks them.

Scoped API key

In the MONEI Dashboard, open API keys and create a scoped key with these permissions.

  • For payments, grant Copy to clipboardpayments:read, Copy to clipboardpayments:create, Copy to clipboardpayments:manage and Copy to clipboardpayments:refund.
  • For customers and saved cards, grant Copy to clipboardcustomers:read and Copy to clipboardcustomers:write.
  • For Apple Pay domain registration, grant Copy to clipboardapplePayDomains:write.

Set Copy to clipboardMONEI_API_KEY=mk_… and Copy to clipboardMONEI_SIGNING_SECRET=mksec_… in the backend environment. Use them in the provider options. Leave Copy to clipboardaccountId unset.

options: {
apiKey: process.env.MONEI_API_KEY,
signingSecret: process.env.MONEI_SIGNING_SECRET,
},

To rotate a scoped key, deploy Copy to clipboardsigningSecret: [newSecret, oldSecret] to every instance and worker before the new key creates any payment. Then set Copy to clipboardMONEI_API_KEY to the new key. Keep the old key and its secret until its payments settle and their callbacks have been processed. Then revoke the old key and remove its secret. Revoking it early removes Copy to clipboardv2 from its callbacks.

Before switching from a Copy to clipboardpk_ key, wait for all open card, Bizum, PayPal, Multibanco and MB WAY payments to settle. Their callbacks have no Copy to clipboardv2 signature, so the plugin refuses them after the switch.

With a scoped key, the plugin refuses dashboard webhooks because they use their own signing secret. Capture and cancel from the Medusa Admin so the changes reach Medusa.

Options

Option Type Required Description Copy to clipboardapiKey Copy to clipboardstring Yes MONEI API key (Copy to clipboardpk_ or Copy to clipboardmk_). A test mode key creates test payments. Copy to clipboardsigningSecret Copy to clipboardstring or Copy to clipboardstring[] With an Copy to clipboardmk_ key Scoped key's Copy to clipboardmksec_ callback secret. Use an array during rotation, with the new secret first. Leave unset with a Copy to clipboardpk_ key. Copy to clipboardbackendUrl Copy to clipboardstring No Public base URL of the Medusa backend. Default: the Copy to clipboardMEDUSA_BACKEND_URL environment variable. One of the two must be set. It must be an absolute Copy to clipboardhttp or Copy to clipboardhttps URL. A trailing slash is removed. Copy to clipboardaccountId Copy to clipboardstring No The merchant account a partner acts for. Leave unset with an Copy to clipboardmk_ key. Copy to clipboardcapture Copy to clipboardboolean No Copy to clipboardtrue (default) charges at once (SALE). Copy to clipboardfalse only authorizes (AUTH), for card and PayPal. Bizum, MB WAY and Multibanco always use SALE. A string such as Copy to clipboard"false" is refused. Copy to clipboardreleaseUnorderedHoldsAfterMinutes Copy to clipboardnumber No Minutes after an Copy to clipboardAUTHORIZED callback after which the plugin cancels the hold when its cart has no order. Default Copy to clipboard30. Copy to clipboard0 turns the release off. Must be a whole number from Copy to clipboard0 to Copy to clipboard10080 (7 days). See Capture mode.

Capture mode

Use Copy to clipboardcapture: false for card and PayPal when stock can run out while the buyer pays. Bizum, MB WAY and Multibanco always use SALE.

In Medusa 2.17 and 2.22.3 (the tested versions), cart completion reserves the stock before it authorizes the payment session. When the stock ran out during payment, Medusa creates no order. Then:

  • With Copy to clipboardcapture: false (AUTH), no money is taken. Medusa does not cancel the Copy to clipboardAUTHORIZED payment. The plugin does: Copy to clipboardreleaseUnorderedHoldsAfterMinutes (default 30) after the Copy to clipboardAUTHORIZED callback, it checks the cart again. When the cart still has no order, the session still holds the payment and MONEI still shows it Copy to clipboardAUTHORIZED, the plugin deletes the session through the Medusa payment module, under the same cart lock that cart completion uses. The provider then cancels the payment, as on any cart change. An order that exists keeps its hold, captured or not.
  • With SALE, the buyer is charged. When the MONEI callback runs cart completion and completion fails, Medusa refunds the payment and gives the cart a new payment session.

When a release does not cancel the payment, the plugin logs an error and emits Copy to clipboardmonei.hold_release_failed:

{
payment_id: string; // MONEI payment id
session_id: string; // Medusa payment session id
cart_id: string | null;
amount: number | null; // major units, null when the release failed before it got the payment from MONEI
currency: string | null;
reason: string;
}

Subscribe to it to alert your team, and cancel the payment in the MONEI dashboard if the cart has no order. The release is not retried.

Costs and limits of the release:

  • A store that completes carts later than the delay loses the hold. For example, a store that places orders from a back office hours after payment. Set a longer delay, or Copy to clipboard0 to turn the release off.
  • A lost callback is not covered. The re-check is scheduled only when the Copy to clipboardAUTHORIZED callback reaches the plugin.
  • The re-check is a delayed event. With the Redis event bus it is a delayed job kept in Redis. With the local event bus it is an in-process timer, and a restart loses it.

Provider ids

Medusa names each provider Copy to clipboardpp_<identifier>_<id>. Enable the providers on your regions in the Medusa Admin.

Method Provider id Callback URL Card (Apple Pay, Google Pay) Copy to clipboardpp_monei_monei Copy to clipboard<backendUrl>/hooks/payment/monei_monei Bizum Copy to clipboardpp_monei-bizum_monei Copy to clipboard<backendUrl>/hooks/payment/monei-bizum_monei PayPal Copy to clipboardpp_monei-paypal_monei Copy to clipboard<backendUrl>/hooks/payment/monei-paypal_monei MB WAY Copy to clipboardpp_monei-mbway_monei Copy to clipboard<backendUrl>/hooks/payment/monei-mbway_monei Multibanco Copy to clipboardpp_monei-multibanco_monei Copy to clipboard<backendUrl>/hooks/payment/monei-multibanco_monei

Each provider offers only its own method.

Event bus

Use the Redis event bus in production. Medusa delivers MONEI callbacks through the event bus. When the plugin cannot fetch a payment from MONEI, it throws, and the Redis event bus retries the event. The local event bus logs the error and drops the event, so the cart of a paid callback can stay open.

Callbacks

The plugin verifies the Copy to clipboardMONEI-Signature header against the raw callback body.

  • The payment. MONEI posts it to the callback URL that the plugin registers on every payment. With a Copy to clipboardpk_ key, the plugin checks Copy to clipboardv1 with the API key. With an Copy to clipboardmk_ key, it checks Copy to clipboardv2 with the configured Copy to clipboardsigningSecret.
  • An account-webhook event (Copy to clipboard{id, type, objectType, objectId, object}), from a webhook in the MONEI dashboard. The plugin accepts these events with a Copy to clipboardpk_ key and verifies Copy to clipboardv1. It uses only Copy to clipboardcharge events and fetches the payment Copy to clipboardobjectId. Copy to clipboardobject.id must be the same id. It ignores events for other objects, such as subscriptions.

In both formats the body is only a pointer. The plugin fetches the payment from MONEI and uses its status. You do not need a dashboard webhook.

If MONEI cannot read a key's signing secret, it sends a callback without Copy to clipboardv2, which a scoped backend refuses. Checkout can still complete through the storefront return. Check the MONEI dashboard for payments that stay open.

How it works

  • Copy to clipboardinitiatePayment creates a MONEI payment. It does not charge. The Copy to clipboardorderId of the MONEI payment is the Medusa payment session id.
  • Every status decision fetches the payment from MONEI. Session data and callback bodies are only pointers.
  • The callback completes the cart when the buyer does not come back to the storefront.
  • When Medusa deletes a session (for example, after a cart total change), the plugin cancels its Copy to clipboardPENDING or Copy to clipboardAUTHORIZED MONEI payment. It does not cancel the payment of a session that Medusa already authorized. This is best effort: a refused cancel is logged as an error for an Copy to clipboardAUTHORIZED payment, and as a warning otherwise.
  • The plugin sends the customer of a signed-in shopper to MONEI, and a billing address. MONEI uses its country to pick the payment processors and methods.
    • The country is Copy to clipboardbilling_country from the session data, when the storefront sends it. Send the cart's billing address country. Without it, the plugin sends the country of the signed-in customer's default billing address. When there is no such address either, MONEI uses the country of the buyer's IP address.
    • The signed-in customer's default billing address is sent in full only when it is in that country (or no Copy to clipboardbilling_country was sent). Otherwise only the country is sent.
    • The country is sent in uppercase.
    • The plugin reads the country when it creates the session. Medusa keeps the session when the cart total does not change, so when the buyer changes the billing country after that, create a new session. The example storefront does this in the embedded flow.
  • Every MONEI request times out after 30 seconds.

Session data

The storefront can send these keys in Copy to clipboarddata when it creates a payment session:

Key Type Description Copy to clipboardreturn_url Copy to clipboardstring Optional. The absolute URL where MONEI sends the buyer back from the hosted page. Without it, the plugin sends no complete, fail or cancel URL. Embedded flows do not need it. Copy to clipboardmonei_session_id Copy to clipboardstring Optional. The monei.js Copy to clipboardsessionId that the card, wallet and express components mount with. MONEI accepts their token only for a payment made with the same value. Copy to clipboardsave_card Copy to clipboardboolean Optional. Card provider and signed-in customers only: Copy to clipboardtrue saves the card to the customer. For a guest, or when the MONEI customer was deleted, the card is not saved and the plugin logs a warning. Copy to clipboardbilling_country Copy to clipboardstring Optional. The ISO 3166-1 alpha-2 code of the cart's billing address, in any case (for example Copy to clipboardes). Any other value is refused. See How it works. Copy to clipboardexpected_amount Copy to clipboardnumber or Copy to clipboardstring Optional. Express checkout: the amount the wallet showed, in major units. Both amounts are rounded to cents, then compared. The plugin refuses the session when they differ.

The plugin refuses (400) a create-session request for a MONEI provider whose Copy to clipboarddata contains a key of the second table, or Copy to clipboard__proto__. Do not send Copy to clipboardsession.data back when you create a session.

Medusa keeps the keys the storefront sent in Copy to clipboardsession.data until authorization replaces it. The payment methods (Copy to clipboardinitiatePayment, Copy to clipboardauthorizePayment, Copy to clipboardgetPaymentStatus, Copy to clipboardretrievePayment, Copy to clipboardcapturePayment, Copy to clipboardcancelPayment, Copy to clipboardrefundPayment) return only these keys, because the store cart API returns Copy to clipboardsession.data. Copy to clipboardupdatePayment returns the data it got unchanged.

Key Description Copy to clipboardid MONEI payment id. Copy to clipboardsession_id Medusa payment session id. Copy to clipboardamount Amount in major units. Copy to clipboardcurrency Currency code in uppercase. Copy to clipboardstatus MONEI payment status. Copy to clipboardredirect_url MONEI hosted payment page URL. Copy to clipboardmonei_customer_missing Copy to clipboardtrue when the saved MONEI customer no longer exists.

The return URL gets a Copy to clipboardsession_id query parameter. The cancel URL also gets Copy to clipboardmonei_canceled=1. MONEI adds nothing to the URL when the buyer cancels on the hosted page, and the payment stays Copy to clipboardPENDING. Without this marker, the return page cannot tell a cancel from a payment in progress.

Storefront flows

The example storefront in Copy to clipboarde2e/storefront implements every flow. It is the Medusa Next.js starter with MONEI modules added. The e2e suite pays with it against the MONEI test API. The links below point to its code.

Hosted payment page

  1. Create the session with Copy to clipboardreturn_url.
  2. On "Place order", send the buyer to Copy to clipboardsession.data.redirect_url.
  3. On the return page, call Copy to clipboardcart.complete. When the cart is not complete yet, poll the cart and Copy to clipboardGET /store/monei/payment-status. Medusa records no failure, so this route is the only way to show a failed payment. A cancelled payment stays Copy to clipboardPENDING: use the Copy to clipboardmonei_canceled=1 query parameter to detect a cancel.

Code: Copy to clipboardredirect-button.tsx, Copy to clipboardreturn.tsx.

The example storefront creates a new session each time the buyer submits the payment step. The old session can point to a payment that the buyer cancelled or failed on the hosted page. Medusa deletes the old session, and the plugin cancels its payment.

Embedded components (monei.js)

  1. Create the session with Copy to clipboardmonei_session_id.
  2. Mount the monei.js components:
    • Card fields and the Apple Pay and Google Pay button (Copy to clipboardPaymentRequest) mount with your public MONEI account id and the Copy to clipboardmonei_session_id. A new session after a cart total change does not remount the card fields, and typed card digits stay. Copy to clipboardPaymentRequest remounts when the cart amount or currency changes: monei.js reads the amount once, at load.
    • Bizum and PayPal mount with Copy to clipboardsession.data.id as Copy to clipboardpaymentId.
  3. On "Place order", get the one-time token and call Copy to clipboardconfirmPayment({ paymentId: session.data.id, paymentToken }). For a card token, also send Copy to clipboardpaymentMethod: { card: { cardholderName } }: MONEI refuses a card confirm without the cardholder name. 3DS and the Bizum approval run in the monei.js modal.
  4. When the payment is Copy to clipboardSUCCEEDED or Copy to clipboardAUTHORIZED, call Copy to clipboardcart.complete. Otherwise go to the return page and let the callback complete the cart. When Copy to clipboardconfirmPayment throws, read Copy to clipboardGET /store/monei/payment-status before you show an error: a lost response can hide a payment that went through.

Code: Copy to clipboardcard-fields.tsx, Copy to clipboardembedded-button.tsx, Copy to clipboarduse-monei-pay.ts. See the monei.js documentation.

PayPal notes:

  • With Copy to clipboardcapture: false, mount every PayPal component (embedded and express) with Copy to clipboardtransactionType: "AUTH". Without it, monei.js loads PayPal with the capture intent, and PayPal cannot pay the AUTH payment. Read the mode from Copy to clipboardGET /store/monei/config.
  • monei.js has no PayPal cancel callback. The example storefront detects that the buyer closed the PayPal popup: it watches for the PayPal overlay element to leave the page without an approval.
  • Do not give a container element the id Copy to clipboardmonei-paypal. Element ids become Copy to clipboardwindow properties, and the PayPal SDK reads Copy to clipboardwindow["monei-paypal"] as its namespace.

Saved cards

The card provider creates a MONEI customer for each signed-in Medusa customer (a Medusa account holder).

  1. Create the card session with Copy to clipboardsave_card: true. After the payment, MONEI saves the card to the customer.
  2. List the saved cards with Copy to clipboardGET /store/monei/payment-methods.
  3. Pay with a saved card through Copy to clipboardPOST /store/monei/confirm. The permanent card token never reaches the browser. The storefront sends only the opaque id from the list.

MONEI charges a saved card as a merchant-initiated payment, without a 3DS challenge. This is MONEI behaviour.

Code: Copy to clipboardactions.ts, Copy to clipboardsaved-cards.

Express checkout

Apple Pay, Google Pay and PayPal express buttons pay a cart without the checkout form.

  1. Mount the buttons with your public MONEI account id and a Copy to clipboardmonei_session_id.
  2. When the buyer approves, the wallet returns a one-time token and the buyer details. Put the details (email, addresses, shipping option) on the cart.
  3. Create the session with Copy to clipboardexpected_amount (the amount the wallet showed) and the same Copy to clipboardmonei_session_id. The plugin refuses a different amount.
  4. Confirm the payment with the wallet token, as in the embedded flow. When the wallet returns a card token (Copy to clipboardpaymentMethod is Copy to clipboardcard), send Copy to clipboardpaymentMethod: { card: { cardholderName } } with the name from the wallet billing details.

The example storefront refuses a wallet result without an email address, because express has no form to collect it.

Code: Copy to clipboardmonei-express.

Apple Pay domain

Apple Pay in embedded and express checkout runs on your storefront domain, and Apple needs that domain registered. The plugin registers it about one minute after the backend starts: every Copy to clipboardhttps origin in Medusa's Copy to clipboardstoreCors (Copy to clipboardSTORE_CORS), except Copy to clipboardlocalhost, IP addresses and Copy to clipboarddocs.medusajs.com. A repeated registration is accepted, so each start registers again.

  1. Serve the domain association file on the storefront at Copy to clipboard/.well-known/apple-developer-merchantid-domain-association, with HTTP 200 and no redirect. The example storefront ships it in Copy to clipboardpublic/.well-known/.
  2. Put the storefront origin in Copy to clipboardSTORE_CORS, for example Copy to clipboardSTORE_CORS=https://shop.example.com.
  3. Check the backend log for Copy to clipboardMONEI Apple Pay: registered shop.example.com. When MONEI refuses a domain, the log has a warning with the reason, and you can register the domain in the MONEI Dashboard: Settings, Payment methods, Apple Pay, then Register domain. See Register your domain with Apple Pay.

Store API routes

All routes are under Copy to clipboard/store, so they need the publishable API key header like every Medusa store route.

Route Auth Body or query Response Copy to clipboardGET /store/monei/payment-methods Customer Copy to clipboard{ payment_methods: [{ id, brand, last4, expires_at }] } Copy to clipboardDELETE /store/monei/payment-methods/:id Customer Copy to clipboard{ id, deleted: true } Copy to clipboardPOST /store/monei/confirm Customer Copy to clipboard{ payment_session_id, payment_method_id } Copy to clipboard{ status, redirect_url } Copy to clipboardGET /store/monei/payment-status None (cart id) Copy to clipboard?cart_id=...&session_id=... Copy to clipboard{ status } Copy to clipboardGET /store/monei/config None Copy to clipboard{ capture }

  • Copy to clipboardid of a saved card is an opaque hash of the MONEI token.
  • Copy to clipboardexpires_at is in seconds since the Unix epoch.
  • Copy to clipboardstatus is a Medusa session status: Copy to clipboardpending, Copy to clipboardauthorized, Copy to clipboardcaptured or Copy to clipboarderror.
  • Copy to clipboardPOST /store/monei/confirm pays only a card session of the signed-in customer's cart.
  • Copy to clipboardcapture is the Copy to clipboardcapture option. PayPal components need it: see the PayPal notes.

Orphan payments

An orphan payment is a MONEI payment that is Copy to clipboardAUTHORIZED or Copy to clipboardSUCCEEDED, but whose Medusa session no longer exists or points to another payment. For example, a buyer pays a Multibanco reference after a cart change.

The subscriber logs an error and emits the Copy to clipboardmonei.orphan_payment event with this data:

{
payment_id: string; // MONEI payment id
session_id: string; // Medusa payment session id
amount: number; // major units
currency: string;
status: string; // AUTHORIZED or SUCCEEDED
}

Subscribe to it to alert your team. If no order was created, cancel an Copy to clipboardAUTHORIZED payment or refund a Copy to clipboardSUCCEEDED payment in the MONEI dashboard. An Copy to clipboardAUTHORIZED payment cannot be refunded.

The event can fire more than once for one payment: for example, once for Copy to clipboardAUTHORIZED and again for Copy to clipboardSUCCEEDED, or again when the event bus retries.

The plugin does not pass a callback for a deleted session to Medusa's core webhook workflow. It logs a warning, Copy to clipboardMONEI webhook ignored, next to the orphan error. This keeps the callback of a deleted session away from Medusa's core workflow.

The same subscriber removes a card account holder whose MONEI customer was deleted. The next session creates a new MONEI customer.

Limits

  • Full capture only. Medusa gives the provider no capture amount. An admin middleware refuses a partial capture amount on Copy to clipboardPOST /admin/payments/:id/capture. Your own code that runs Copy to clipboardcapturePaymentWorkflow with an amount is not checked: MONEI captures in full while Medusa records the amount.
  • Currencies with 2 decimals only. Other currencies are refused.
  • Dashboard refunds are not synced. A refund made in the MONEI dashboard does not update the Medusa order.
  • An authorization expires after about 7 days. Capture an AUTH payment before then.
  • A Multibanco order is created only when the buyer pays. The cart stays open until then. The callback completes it.
  • A sent Multibanco reference or Bizum request stays payable after a cart change. It cannot be canceled. When the buyer pays, it becomes an orphan payment, reported by Copy to clipboardmonei.orphan_payment.
  • Two equal partial refunds sent at almost the same moment can be merged into one at MONEI. The plugin reports this as an error when it can detect it. Check the MONEI dashboard before you retry a refund.
  • A refund retried after an unclear answer can refund twice. A refund can be applied even when its answer is lost or is an error. Then the plugin throws "it may have been applied, check the MONEI dashboard before retrying". Check the dashboard before you retry. For a capture, the plugin checks the payment and accepts it when it is Copy to clipboardSUCCEEDED.
  • Two MONEI customers can appear for one shopper who opens two first checkouts at the same time. Copy to clipboardGET /store/monei/payment-methods lists the cards of both. A saved card pays only a session made with the MONEI customer that holds it; Medusa uses the first one for new sessions.
  • Rarely, a cart change at the moment a payment is authorized can make Medusa complete another cart that needs no payment. No money moves. This applies in AUTH mode (Copy to clipboardcapture: false) and is Medusa core behaviour.
  • The card provider's Copy to clipboardlistPaymentMethods returns opaque ids, not MONEI card tokens. These are the ids of Copy to clipboardGET /store/monei/payment-methods. Copy to clipboarddata holds only Copy to clipboardbrand, Copy to clipboardlast4 and Copy to clipboardexpires_at. Copy to clipboarddeletePaymentMethod takes an opaque id and refuses an id that is not in the customer's list.

Testing

Use a test mode API key. Test cards and test phone numbers are in the MONEI testing documentation.

This repository has two test suites:

  • Unit tests: Copy to clipboardpnpm test. The MONEI API is mocked at the HTTP layer.
  • End-to-end tests: a real Medusa backend and the example storefront in Docker, paying against the MONEI test API. See e2e/README.md.

MB WAY and Multibanco have unit tests only. MONEI test mode has no processor for them.

Development

git clone https://github.com/MONEI/medusa-payment-monei.git
cd medusa-payment-monei
pnpm install
pnpm build # medusa plugin:build
pnpm test # build, then unit tests
pnpm exec vp check # format, lint and type checks

Release

Releases use release-it with the conventional changelog plugin. It runs the unit tests, bumps the version, updates Copy to clipboardCHANGELOG.md, tags Copy to clipboardv<version> and creates the GitHub release. When the GitHub release is published, the publish workflow publishes the package to npm.

pnpm release # the bump the commit types recommend

The rewrite commit has a Copy to clipboardBREAKING CHANGE: footer, so the next Copy to clipboardpnpm release proposes 1.0.0.

To use a local build in a Medusa app, see the Medusa plugin documentation.

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?