When a Medusa v2 Payment Succeeds but No Order Is Created
A hosted payment can be captured before its order exists. Trace the original Medusa v2 checkout attempt and recover it without taking a second payment.
When a provider shows a capture and Medusa has no order, I trace the original payment before taking any action on the cart. A storefront timeout can leave the customer on the checkout screen after the provider has taken the money.
Check the cart-to-order link
Start with the transaction reference from the provider. Check the provider account and environment, the actual payment state, amount, and currency. An authorization reserves funds. Capture initiates collection of the authorized amount. A hosted checkout page can also return while authorization is pending. Pause new payment requests while the status of the original attempt is unknown.
In Medusa, find the cart, its payment collection and session, and any order linked to the cart. Check the webhook delivery log around the same time. A delivery marked successful tells you the endpoint acknowledged the request. Check the handler or job logs to see what happened next. For a standard Medusa checkout, the payment provider can return an authorized or captured action from a webhook and Medusa can complete the associated cart. Medusa payment webhook events
An existing order can still be awaiting payment. Medusa added deferred authorization in v2.17.2, so a payment session in pending_authorization can already have an order attached. If you find one, check its payment record before creating anything. Medusa payment flow
Reconcile a webhook and a browser return
I used this pattern for one hosted provider in a Medusa v2.18.0 checkout with several providers. The checkout records an attempt before sending the shopper away. That record ties the cart and its payment collection to the merchant account, amount, currency, and provider reference. It survives a missing or cleared local payment session. The wider checkout is documented in my payment-provider case study, with other examples on my Medusa development page.
The webhook handler stores a receipt under a unique key. A worker fetches the transaction from the provider, matches it to one local attempt, and then checks that the cart still matches the original checkout. A signed return from the browser can trigger the same check for that attempt. A change of cart total or an unexpected second capture goes to review. In this adapter, the local capture step records money the provider has already taken. It sends no new charge.
This simplified example covers an unresolved lookup and a verified capture. It chooses a next step before any order or payment write.
function nextStep(verifiedCapture: boolean, matchingCart: boolean, orderId?: string) {
if (!verifiedCapture) return "wait_for_provider"
if (!matchingCart) return "send_for_review"
if (orderId) return "reconcile_existing_order"
return "resume_original_cart"
}The workflow checks for an existing order while it holds a cart lock. If the order is there, the workflow reconciles its payment record. If the order is missing and the verified capture still matches the cart, it can resume completion for the original cart. A scheduled job revisits pending receipts and attempts even when the browser never comes back. Medusa cart completion
Test what the customer sees while recovery runs
I check that the storefront still shows the processing screen when an order exists but its capture record is incomplete. The regression tests also cover a shopper returning before the webhook, an older failure alongside a newer pending attempt, and a captured payment whose order still cannot be finalized. The last case needs a message like “We received your payment and are checking your order.” A generic failure screen can send the shopper back to a pay button.
When testing a payment integration in a sandbox, replay a confirmed callback after cart completion. Check that the order ID stays the same and the capture count stays at one. Repeat without the browser return to simulate a shopper closing the provider tab after paying.