Connect
- In Stripe, go to Developers → API keys → Create restricted key. Give it Write on Webhook Endpoints, and Read on Charges, Invoices, Checkout Sessions and Refunds.
- Paste the key (
rk_live_…) into Setup → Payments → Stripe.
DataPenny creates the webhook and never stores the key.
By hand
Add a destination under Developers → Webhooks, pointing at https://YOUR-DATAPENNY-URL/api/webhooks/stripe/YOUR_SITE_ID. Listen for checkout.session.completed, checkout.session.async_payment_succeeded, invoice.paid and charge.refunded, then paste the signing secret (whsec_…) under Connect by hand.
Checkouts
Payment Links are tagged by the script. It sets client_reference_id to the visitor id, unless you’ve already set one.
Checkout Sessions you create need the id passed in:
const session = await stripe.checkout.sessions.create({
mode: 'subscription',
client_reference_id: visitorId, // from datapenny.visitorId()
subscription_data: { metadata: { datapenny_visitor_id: visitorId } },
success_url: 'https://yourapp.com/welcome?session_id={CHECKOUT_SESSION_ID}',
// …
});
The session_id on your success page is a fallback: if metadata is missing, the script links the sale from there.
Import past sales
The import needs a key with Read on Checkout Sessions, Invoices, Charges and Refunds, and the key from above works. It’s used while the import runs and isn’t stored. Sales from before you installed the script have no visit to credit, and show as Before tracking.