Search documentation

Search titles, headings, and page summaries.

Payment attribution API

Link a Stripe payment to the visitor or user who made it, from your server.

Updated 2026-12-05

POST https://graytower.app/api/v1/payments/attribution tells Graytower who made a Stripe payment, so its revenue is credited to the right source. Stripe stays the source of truth for the amount, refunds, and status: this endpoint only records who paid.

Authenticate with a Stripe attribution server key (see Server authentication). The website must have Stripe connected.

JavaScript
const response = await fetch("https://graytower.app/api/v1/payments/attribution", {  method: "POST",  headers: {    Authorization: `Bearer ${process.env.GRAYTOWER_STRIPE_ATTRIBUTION_KEY}`,    "Content-Type": "application/json",  },  body: JSON.stringify({    paymentIntentId: intent.id, // or checkoutSessionId: session.id    visitorId, // the browser's _gt_id cookie    userId: user.id, // optional: your own immutable user ID  }),});

Call it once a PaymentIntent exists: right after you create a PaymentIntent, or after a Checkout Session completes. A Checkout Session that was just created may not have a PaymentIntent yet, which returns payment_intent_unavailable.

Request fields

FieldRequiredMeaning
paymentIntentIdOne of these twoA PaymentIntent (pi_…) on the connected Stripe account.
checkoutSessionIdOne of these twoA Checkout Session (cs_…). Graytower uses its PaymentIntent.
visitorIdvisitorId, userId, or bothThe visitor's _gt_id cookie value. Not available on cookieless websites.
userIdvisitorId, userId, or bothYour own user ID, at most 256 characters. Use an ID that never changes, not an email.

Send exactly one Stripe ID. Graytower writes the IDs into the payment's Stripe metadata (graytower_visitor_id, graytower_user_id), and the userId onto the Stripe Customer when it has none. It never overwrites a different value that is already there.

Response

A successful request returns 200:

JSON
{ "data": { "paymentIntentId": "pi_3QxYzAbCdEfGhIjK", "updated": true, "ingested": false } }
FieldMeaning
updatedtrue when this request wrote the IDs to Stripe; false when they were already there. Repeating a request is safe.
ingestedtrue when the payment has already succeeded and is now recorded with this attribution. false for a payment that hasn't succeeded yet: Graytower attributes it when Stripe reports the payment.

Errors

CodeWhat to do
stripe_not_connectedConnect Stripe for this website, then send again.
payment_intent_unavailableCheck the ID belongs to the connected Stripe account. For a Checkout Session, wait until it completes.
metadata_conflictThe payment is already linked to someone else. Graytower keeps the existing link.
identity_mode_limitedThe website is cookieless: send a userId instead of a visitorId.
unavailableStripe or Graytower is briefly unavailable. Retry after Retry-After.

These 409 errors are permanent for that request. See Errors and retries for the codes every endpoint shares.

The earlier endpoint

POST /api/stripe/attribution/server keeps working with its earlier response format. New integrations should use /api/v1/payments/attribution. The earlier endpoint will be retired with at least six months' notice.