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?
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.
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.