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
6 weeks solo, 2 rejections, finally live but nobody told me marketing would be this hard User Avatar 118 comments Building ExpenseSpy solo, no funding — launching June 17 on iOS & Android User Avatar 46 comments I built a $5/1k-listing CRE data API because CoStar is overkill for first-pass scans User Avatar 18 comments Building LinkCover – Day 3: Payment is live. No more building, time to sell. User Avatar 15 comments I just wanted to taste AI coding tools. A week passed. User Avatar 14 comments I Was Bypassing Every App Blocker, So I Built One That Fights Back User Avatar 11 comments