The idea is simple. Give each visitor an id on your site, put that id on the checkout, and read it back when the payment arrives.
Payment Links
Stripe Payment Links accept client_reference_id in the URL and pass it to the Checkout Session. The DataPenny script sets it on click.
Checkout Sessions
Read the id in the browser, send it to your server, and set it when you create the session:
// browser
const visitorId = window.datapenny?.visitorId?.();
// server
stripe.checkout.sessions.create({
client_reference_id: visitorId,
metadata: { datapenny_visitor_id: visitorId },
// …
});
Subscriptions
Checkout metadata stays on the session, not the subscription. To reach renewals, put it on the subscription too:
subscription_data: { metadata: { datapenny_visitor_id: visitorId } }
A fallback
End your success_url with ?session_id={CHECKOUT_SESSION_ID}. If the metadata goes missing, the thank-you page still links the sale to the visitor.
The rest is in the Stripe guide.