Skip to content

Payment Webhook Trip

Run the Payment Webhook Trip MicroSim Fullscreen

About This MicroSim

When Dana buys a pack of 5 scans, the payment happens on Stripe's servers, not the app's. Stripe knows the moment the card goes through. A webhook is how the app finds out: Stripe sends a POST request to the app's endpoint, /api/webhooks/stripe. For this one conversation the roles flip. Stripe is the client, and the app's back end is the server.

The picture shows three parties as columns, with one row for each message. You first watch the normal five-step trip. Then you get five scenarios, each changing one part of the trip. You predict what happens to Dana, and the trip plays with the changed rows shaded orange.

Scenarios 2 to 5 are marked "illustrative scenario." The 20 minutes in scenario 2, the 5 scans per pack and the fifteen dollars are made up for the example.

How to Use

  1. Press Play and watch the normal trip once. Notice who sends each message.
  2. Scenario 1 appears, with the normal trip shown in gray for reference. Pick one of the three outcomes. Your first pick counts.
  3. The trip plays with that scenario's change. Rows that differ from normal are shaded orange, and the feedback shows the result for Dana.
  4. Press Replay this trip to watch it again, or Next scenario to go on.
  5. After scenario 5, press See summary to list the five scenarios and which ones you got right.
  6. Click any party, the webhook arrow or the 200 answer at any time to read what it is.

Iframe Embed Code

You can add this MicroSim to any web page by adding this to your HTML:

<iframe src="https://arunbatchu.github.io/good-enough-engineering/sims/payment-webhook-trip/main.html"
        height="674px"
        width="100%"
        scrolling="no"></iframe>

Lesson Plan

Learning Objective

The learner will infer the outcome for the member when one part of a Stripe payment webhook trip goes wrong, for five scenarios, with at least 4 of 5 correct.

Bloom level: Understand (infer)

Grade Level

Adult professional (Good Enough Engineering)

Duration

10-15 minutes

Prerequisites

Webhook, HTTP request, API endpoint, HTTP status codes, JSON, and client and server, all from Chapter 2: How a Web App Works.

Activities

  1. Watch (3 min): Play the normal trip. Name the direction of each message: who calls whom.
  2. Predict (7 min): Work through the five scenarios. Before you pick, say which of three things the scenario changes: the direction of the call, the status code, or the signature check.
  3. Connect (3 min): In the summary, pick the scenario that worries you most for a real app. Say what you would ask your agent to check.

Assessment

  • Mastery is 4 of 5 scenarios correct on the first pick.
  • Ask the learner: "The server was down when Stripe called. Is the payment lost? Why not?"
  • Ask the learner: "Why can Dana end up with 10 scans after paying for 5?"

Common Misconceptions

  • The app asks Stripe whether the payment went through.
  • If the app is down when Stripe calls, the payment is lost forever.
  • Any request to the webhook address is from Stripe.
  • The app's server sees the card number.

References

  1. Receive Stripe events in your webhook endpoint - Stripe Documentation - Signature checks, retries and duplicate events.
  2. Chapter 2: How a Web App Works - Good Enough Engineering - The section "Webhooks: When the Server Gets a Call."