← Lessons

quiz vs the machine

Gold1440

System Design

Payment Integration

Connecting to a payment provider with authorize, capture, and webhook handling.

5 min read · core · beat Gold to climb

Talking to a payment provider

Most stores never touch raw card data. They integrate a payment provider that handles cards and returns a token. This keeps sensitive data out of your systems and reduces compliance scope.

Authorize then capture

  • Authorize checks that funds exist and places a hold, but does not move money.
  • Capture actually transfers the held funds, often done when the order ships.

Separating these lets you reserve money at checkout but only charge when you can fulfill.

Handling async results

Payment results often arrive asynchronously through a webhook from the provider. Your endpoint must be idempotent, because the provider may deliver the same event more than once. Verify the webhook signature to ensure it really came from the provider.

Reliability

  • Use an idempotency key per payment attempt so retries do not double charge.
  • Store each payment state so you can reconcile against the provider if a response is lost.

Key idea

Tokenize cards, split authorize from capture, and make webhook handling idempotent and signature verified.

Check yourself

Answer to earn rating on the learn ladder.

1. What is the difference between authorize and capture?

2. Why must a payment webhook handler be idempotent?

3. Why integrate a provider instead of storing raw card numbers?