I just finished setting up payments through stripe on PHP using their payment intents API and forgot about having to add the products/items the user has just purchased.
Looking through the API Reference I didn't see anything where I could add items to the payment intent so I could retreive what was purchased later on in the webhook.
Do I need to do my own magic and somehow add the items to the metadata array or is there something that i'm missing here?
PaymentIntents do not track any sort of product that's connected to the purchase (just an amount). In order to link Products to a payment, you'd want to use Invoices which will generate a PaymentIntent as part of the process.
I'm using node.js. Here's what worked for me:
Step #5 response will contain the client_secret value that can be sent to the client for payment capture.
const customer = ...
const invoiceItem = await stripe.invoiceItems.create({
customer: ...
price_data: { ... }
})
const invoice = await stripe.invoices.create({
customer: ...
})
const finalInvoice = await stripe.invoices.finalizeInvoice(
invoice.id
)
const paymentIntent = await stripe.paymentIntents.retrieve(
finalInvoice.payment_intent
)
res.send({ secret: paymentIntent.client_secret })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With