Attribute revenue with Stripe PaymentIntent API
Pass the Datasense visitor and session as metadata on a Stripe PaymentIntent, for Stripe Elements and mobile SDKs.
Make sure you've connected your Stripe account first.
With Stripe Elements or the mobile SDKs, pass the visit as metadata when you create the PaymentIntent on your server:
app/api/create-payment-intent/route.js
import { cookies } from "next/headers"
export async function POST() {
const cookieStore = await cookies()
const paymentIntent = await stripe.paymentIntents.create({
amount: 2000,
currency: "usd",
metadata: {
datasense_visitor_id: cookieStore.get("datasense_vid")?.value,
datasense_session_id: cookieStore.get("datasense_sid")?.value,
},
})
return Response.json({ clientSecret: paymentIntent.client_secret })
}Datasense attributes it when Stripe sends payment_intent.succeeded to the webhook it added. No other setup needed.