# Common mistakes

> The mistakes that break payment integrations on NorthechPay, from marking orders paid too early to unsafe retries, and how to avoid each one.

Each item below has caused real bugs in payment integrations. Check your code against all of them.

## Payment state

**Marking the order paid when the buyer comes back.** Moov payment links have no return URL, and nothing in the browser proves payment. Mark paid only from a verified `checkout.paid` webhook or your own server-side read showing `paid: true`.

**Marking the order paid on the `201` from create.** A new checkout is `open`. Nobody has paid yet.

**Treating `authorized` as paid.** `authorized` means the card was approved and funds are settling. It can still fail. Ship on `paid` only.

**Reading `paid: true` as "not refunded".** `paid` stays `true` after a refund or dispute. Check `status` for `partially_refunded`, `refunded` and `disputed`.

**Not checking the amount.** Before fulfilling, compare `amount.amount` and `amount.currency` with the order.

**Moving an order backwards on an old event.** Events can arrive out of order. A late `checkout.authorized` must not undo `paid`. Re-read the checkout and only move forward.

**Adding up refund events.** Each refund sends its own `checkout.refunded` with that refund's amount. A redelivered event has the same `id`, so deduplicate by `id`, and store the payment's `refunded_amount` (Moov's total) instead of adding event amounts yourself.

**Fulfilling from the checkout status on a reusable link.** A payment link's `status` describes the whole link. Act on `data.payment` (one event per payment), not on `data.status`.

## Idempotency

**Leaving out `Idempotency-Key`.** Refunds and payouts through the API are refused without one (`422`). For checkouts NorthechPay generates a key and returns it in the response header, but if the request times out you never see it, and a blind retry creates a second checkout. Always send your own.

**Sending an invalid key.** Keys must be 8 to 128 characters from `A-Z a-z 0-9 . _ : -`. A key with a space or `#`, or one shorter than 8 characters, is rejected with `422 validation_failed`.

**Using a new key after a timeout.** A timeout is an unknown outcome. Retry with the same key, or read the resource. A new key can charge, refund or pay out twice.

**Reusing a key for a changed request.** The same key with a different amount or title returns `409 idempotency_conflict`. Start a new attempt with a new key when the order changes.

**Generating the key inside the retry loop.** Create the key once, save it with the order, then call the API.

**Trusting a refund replay.** A replayed refund returns the transaction, even if Moov rejected the first attempt. Confirm with `refunded_amount`.

## Keys and security

**Calling the API from the browser.** The API key is a secret. Every call must come from your server.

**Granting every ability.** A website checkout needs `merchant:read`, `checkouts:read`, `checkouts:write` and `transactions:read`. Keep `refunds:write` and `payouts:write` off public web servers.

**Logging the key or the webhook secret.** Log `X-Request-Id` and error codes instead.

## Webhooks

**Verifying the signature against parsed JSON.** Re-encoding changes bytes and breaks the signature. Use the raw request body.

**Comparing signatures with `==`.** Use a constant-time comparison: `hash_equals` in PHP, `crypto.timingSafeEqual` in Node.js.

**Skipping the timestamp check.** Reject signatures whose `t` is more than 300 seconds from your clock. Keep your server clock in sync.

**Doing slow work before answering.** NorthechPay waits 10 seconds. Answer `2xx` first, then process in the background. A slow handler gets retried and may run twice.

**Not deduplicating.** The same event can arrive more than once. Store event IDs with a unique index.

**Redirecting the webhook URL.** Redirects are not followed and count as failures. Register the final HTTPS URL.

**Counting on webhooks alone.** Deliveries stop after 8 attempts. Run a reconciliation job.

## Requests

**Sending dollars instead of cents.** `amount` is an integer in cents. `24.50` fails validation; send `2450`.

**Line items that do not add up.** When you send `line_items`, `amount` must equal the sum of `quantity × unit_amount`.

**Expecting `search` to match exactly.** `search` matches `merchant_reference` partially. Store the checkout `id` and read it directly.

**Polling `refresh` in a loop.** Each refresh calls Moov and counts toward your limit. Use webhooks, `GET` in scheduled jobs, and refresh only when a person asks.

**Ignoring `checkout_url: null`.** A checkout in `creating` has no URL yet. Wait and re-read, do not redirect to `null`.

**Using payment links for orders.** A reusable link is not tied to one order. Use one checkout per order.

## Business rules

**Refunding a disputed payment.** It is blocked with `409 not_refundable`. Respond to the dispute instead.

**Refunding before the payment completes.** Only `completed` card payments can be refunded. An `authorized` payment cannot.

**Computing the balance yourself.** Read it from `GET /merchant/wallets`. Moov holds the money.

**Offering instant payouts, ACH debit checkout or embedded card fields.** They are not available in this build.

**Telling buyers or merchants that live payments work.** This build is test mode only. Passing tests is not production approval.
