Payment Redirects: When to Mark an Order as Paid
In this article
- Why the Redirect Itself Is Not Proof of Payment
- How Payment Redirects Work (The Full Flow)
- When to Mark as Paid: The Safe Rule
- What to Do When the Customer Returns but No Webhook Arrives
- Common Mistakes and Misconceptions
- How to Choose the Right Approach for Your Platform
- Costs and Risks of Marking Too Early
- How to Verify a Webhook's Authenticity
- Frequently Asked Questions
This article explains when an online store should mark an order as paid after a customer is redirected from a payment gateway. You enter the payment statuses and redirect behaviors, and you get clear guidance on the safest moment to confirm payment. The answer is: mark an order as paid only after you receive a verified server-side confirmation from the payment provider, never immediately after the customer is redirected back to your site.
Why the Redirect Itself Is Not Proof of Payment
When a customer pays on a hosted payment page (like Stripe, PayPal, or a bank's 3-D Secure page), the gateway redirects them back to your store's success URL. That redirect only tells you the customer finished the payment flow—it does not tell you whether the transaction actually succeeded. The customer might have closed the browser before confirming, the bank might have declined the card after the redirect, or the payment might be pending review. Relying on the redirect alone leads to false "paid" statuses, which cause you to ship goods you never got paid for.
The only reliable signal is a server-to-server notification from the payment provider—commonly called a webhook, IPN (Instant Payment Notification), or callback. This message arrives from the provider's servers directly to your backend, contains a cryptographic signature, and includes the final transaction status (e.g., completed, failed, pending). You should update your order status only when this notification confirms the payment.
How Payment Redirects Work (The Full Flow)
Understanding the sequence helps you see why the redirect is just one step. A typical hosted payment flow looks like this:
- Customer places an order on your site and clicks "Pay".
- Your server creates a payment session with the provider (sending amount, currency, order ID, return URLs).
- Provider returns a payment URL; you redirect the customer to that URL.
- Customer enters card details and confirms on the provider's page.
- Provider processes the transaction (may take seconds to minutes, especially with 3-D Secure or bank transfers).
- Provider redirects the customer back to your
return_url(success or cancel URL). - Provider sends a webhook/IPN to your
notify_urlwith the final status. - Your server verifies the signature and updates the order status.
The redirect (step 6) happens before the webhook (step 7) in most cases, but not always. Sometimes the webhook arrives first. Either way, you should treat the order as "pending" until step 7 confirms it.
When to Mark as Paid: The Safe Rule
Mark an order as paid only when all three conditions are met:
- You receive a verified server-side notification (webhook/IPN) from the payment provider.
- The notification's signature is valid (use the provider's secret key to verify).
- The notification's status field equals "completed", "paid", "succeeded", or the equivalent for your provider.
If the status is "pending", "processing", "authorized", or "failed", do not mark as paid. For "authorized" (e.g., a card pre-authorization), you may want to mark as "authorized" but not "paid" until you capture the funds.
In practice, this means your order statuses should be:
- Pending – created, but no payment confirmation yet.
- Paid – verified webhook received with success status.
- Failed – verified webhook received with failure status.
- Refunded – you issued a refund via the provider's API.
What to Do When the Customer Returns but No Webhook Arrives
Occasionally, the customer is redirected back to your store, but the webhook never arrives (network issues, provider downtime, or the customer closed the browser before the webhook was sent). In that case, you should not mark the order as paid. Instead, implement a fallback:
- Show a "Payment pending" message on the success page, and tell the customer you'll confirm by email.
- On the success page, trigger a background check in your backend: call the provider's API to fetch the transaction status by order ID or session ID.
- If the API says "completed", mark as paid and send confirmation.
- If the API says "pending" or "failed", update accordingly.
- If the API call also fails, schedule a retry (e.g., every 5 minutes for up to 1 hour).
This API lookup is a manual fallback, but it is still server-side and verified—it does not rely on the client redirect.
Common Mistakes and Misconceptions
Several frequent errors cause stores to mark orders as paid incorrectly:
- Trusting the redirect URL's query parameters. Some providers append a transaction ID or status to the return URL. This is not secure—anyone can craft a fake return URL. Never use those parameters to update your database; only use them to display a message.
- Marking as paid on the success page's client-side JavaScript. A user can open the success page without paying (by navigating directly). Client-side code is not reliable for financial decisions.
- Ignoring webhook retries. Providers send webhooks multiple times until they get a 200 OK response. Your endpoint must be idempotent (processing the same webhook twice should not double-charge or double-ship).
- Treating "authorized" as "paid". An authorization holds funds but does not transfer them. You must capture the payment (often via a separate API call) before shipping.
Another misconception: "If the customer sees a success page, the payment must have gone through." Not true—the success page is simply the return URL; it does not carry any financial guarantee.
How to Choose the Right Approach for Your Platform
The exact implementation depends on your stack and payment provider. Here are general guidelines:
- If you use a hosted checkout (Shopify, WooCommerce with Stripe, etc.): The platform handles webhooks for you. You generally don't need to manually set anything—just ensure webhook notifications are enabled in your provider dashboard.
- If you build a custom integration: You must implement a webhook endpoint that verifies the signature, parses the JSON payload, and updates your order status. Most providers have official SDKs that handle verification.
- If you use a payment service provider (PSP) like Adyen or Braintree: They send webhooks with a unique event code (e.g.,
AUTHORISATION). Map those events to your statuses.
Always test in sandbox mode: simulate a successful payment, a failed payment, and a pending payment, and confirm your webhook handler updates statuses correctly.
Costs and Risks of Marking Too Early
Marking an order as paid before confirmation exposes you to financial loss. If you ship goods based on a false "paid" status, you lose the product and the shipping cost. For digital goods, you give away access for free. In addition, you may face chargebacks if the customer disputes a transaction that never actually completed.
On the flip side, delaying the paid status too long (e.g., waiting for a manual check) can lead to delayed order fulfillment and customer frustration. The right balance is to automate the webhook handling so that the status updates within seconds of the provider's confirmation, without human intervention.
How to Verify a Webhook's Authenticity
Security is non-negotiable. To verify a webhook:
- Use the provider's signing secret (a shared key) to compute an HMAC signature of the raw request body.
- Compare it to the signature in the request headers (e.g.,
Stripe-Signaturefor Stripe,Paypal-Transmission-Sigfor PayPal). - Use a constant-time comparison function to avoid timing attacks.
- Optionally, check the event ID to prevent replay attacks (store processed event IDs).
If the signature is invalid, reject the webhook and log the attempt. Never trust a webhook that fails verification, even if it looks like it's from the provider.
Frequently Asked Questions
Can I mark an order as paid if the customer shows me a screenshot of the payment confirmation?
No. Screenshots can be edited or taken from a different transaction. Always rely on your backend's verification, not on what the customer shows you. If you're unsure, ask the customer to check their bank statement or contact the provider.
What if the webhook arrives before the redirect? Is that possible?
Yes, it can happen. The provider may send the webhook immediately after processing, even before the customer's browser is redirected. Your system should handle both orders: if the webhook arrives first, mark as paid; when the redirect follows, just show a success message—do not change the status again.
How long should I wait for a webhook before marking the order as failed?
It depends on the provider, but generally you should wait at least a few minutes. Some payment methods (like bank transfers) can take hours. Instead of timing out, use the provider's API to query the transaction status. Only mark as failed if the API confirms failure.
Do I need to handle webhooks for both success and failure events?
Yes. You should handle all event types: success, failure, pending, refunded, and chargeback. Each event should update the order status accordingly. Ignoring failure events can leave orders stuck in "pending" forever.
Is it safe to use the query parameters in the return URL for anything?
You can use them to display a friendly message ("Payment successful") but never for database updates. Treat them as untrusted input. The only trusted data is the verified webhook or an API response from the provider.
What if my webhook endpoint is down when the provider sends the notification?
Providers retry failed webhook deliveries for a certain period (often 24-72 hours). Your endpoint should be idempotent so that retries don't cause duplicate actions. If you miss the retries, you can manually reconcile by querying the provider's API for recent transactions.