5
2 Comments

How to 'fulfill ' Stripe order after checkout?

I can't seem to figure out the solution from reading the docs, I tried emailing support but it's taking a little while.

I'm working on a little gifting/tipping platform like https://www.buymeacoffee.com. I'm using Stripe Connect with Node. The user enters a Name, Message, and $ Amount and clicks submit. I make an API call with the details to my API endpoint. I save the details into a database record with an fulfilled: false property. Then I created a checkout session like this and redirect the user to it:

    const session = await stripe.checkout.sessions.create({
      payment_method_types: ['card'],
      line_items: [{
        name: `Tip for ${user.name}`,
        amount,
        currency: 'usd',
        quantity: 1,
      }],
      payment_intent_data: {
        application_fee_amount: fee,
        transfer_data: {
          destination: `${user.accountId}`',
        },
      },
      mode: 'payment',
      success_url: 'https://example.com/success',
      cancel_url: ''https://example.com/fail',
    });

At this point I need to find a way to mark the record as fulfilled: true if the payment succeeds. The docs recommend that you listen for the webhook payment_intent.succeeded. However, I don't know how to access the database record from the webhook so that I can fulfill it. Should I pass it through under the line_items.metadata? Is there a simpler way to handle this?

posted to Icon for group Developers
Developers
on July 15, 2021
  1. 4

    You can either put your local database id into the stripe metadata and receive that with the webhook, or you can put the stripe intent id into your database from the stripe API call response. It's up to you, but which one you chooses sort of defines which system is the "source of truth" - either Stripe or your DB.

    1. 1

      Oh wow I missed that attribute in the return value from stripe.checkout.sessions.create(). I haven't really thought about which would 'source of truth' yet but I think it'd make more sense to rely on the database in case I wanted to display "unpaid" objects, I could create a new payment intent for them.

Trending on Indie Hackers
Your build-in-public audience is not your market. I learned the difference the slow way. User Avatar 230 comments Built a "stocks as football cards" thing. 5 days in, my launch tweet got 7 views. What am I missing? User Avatar 33 comments How to automatically turn customer feedback into high-converting testimonials User Avatar 27 comments Why Claude Skills Are Becoming Important for Tech Careers User Avatar 25 comments Spent months building LazyEats AI. Spent 1 day realizing I have no idea how to get users. User Avatar 21 comments Week 10+11: PDF cluster, blog launch, 143 indexed, and a new compression feature User Avatar 19 comments