Theme

Start for free
DocsOther Stripe payments

03 · Revenue

Link the rest of your Stripe payments

Not every Stripe payment starts at a checkout. Each kind has a place the visitor's id can ride, or an email to match it by.

01PaymentIntents you create

With the Payment Element, or any flow where your server creates the PaymentIntent, put the visitor's id in the PaymentIntent's metadata:

Node.js
// Where your server creates the PaymentIntent (the Payment Element, Elements).
const visitorId = req.cookies['_tally_vid'];
const paymentIntent = await stripe.paymentIntents.create({
  amount: 4900,
  currency: 'usd',
  automatic_payment_methods: { enabled: true },
  metadata: visitorId ? { 'tally_visitor_id': visitorId } : {},
});

02Subscriptions you create

A subscription made through the API passes its metadata to every invoice, so the first payment and each renewal carry the id:

Node.js
// A subscription your server creates: its invoices carry its metadata.
const visitorId = req.cookies['_tally_vid'];
const subscription = await stripe.subscriptions.create({
  customer: customerId,
  items: [{ price: 'price_123' }],
  metadata: visitorId ? { 'tally_visitor_id': visitorId } : {},
});

03On the customer

The customer's metadata is read too, so an id saved on the customer reaches every payment they make, invoices included:

Node.js
// When you create the customer (or later, with stripe.customers.update).
const visitorId = req.cookies['_tally_vid'];
const customer = await stripe.customers.create({
  email: user.email,
  metadata: visitorId ? { 'tally_visitor_id': visitorId } : {},
});

04Invoices and manual charges

An invoice you send by hand or a charge made in the Stripe dashboard has no checkout to carry an id. Once the customer is signed in (or on your success page), identify them with the email they pay with: a payment whose customer email matches is linked, with medium confidence. The email is hashed when it arrives and only the hash is kept.

JavaScript
// Once the customer is signed in (or on your success page), with the email they pay with.
// It is hashed when it arrives; only the hash is kept.
window.tally = window.tally || function () { (tally.q = tally.q || []).push(arguments); };
tally('identify', { email: user.email });

05Renewals, upgrades and refunds

These follow on their own: a renewal or upgrade is linked as the subscription's first payment was, and a refund or chargeback as the payment it reverses, with the same confidence.

06Check it worked

Something missing, or not what you see? Write to support@tallybyoutpost.com and say which page.