Payment attribution API
Link a Stripe payment to the visitor or user who made it, from your server.
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.
Link a payment
curl https://graytower.app/api/v1/payments/attribution \ -H "Authorization: Bearer $GRAYTOWER_STRIPE_ATTRIBUTION_KEY" \ -H "Content-Type: application/json" \ -d '{ "paymentIntentId": "pi_3QxYzAbCdEfGhIjK", "visitorId": "123e4567-e89b-42d3-a456-426614174000", "userId": "user_42" }'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 }),});response = requests.post( "https://graytower.app/api/v1/payments/attribution", headers={"Authorization": f"Bearer {os.environ['GRAYTOWER_STRIPE_ATTRIBUTION_KEY']}"}, json={ "paymentIntentId": intent.id, # or "checkoutSessionId": session.id "visitorId": visitor_id, # the browser's _gt_id cookie "userId": str(user.id), # optional: your own immutable user ID }, timeout=10,)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
| Field | Required | Meaning |
|---|---|---|
paymentIntentId | One of these two | A PaymentIntent (pi_…) on the connected Stripe account. |
checkoutSessionId | One of these two | A Checkout Session (cs_…). Graytower uses its PaymentIntent. |
visitorId | visitorId, userId, or both | The visitor's _gt_id cookie value. Not available on cookieless websites. |
userId | visitorId, userId, or both | Your 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:
{ "data": { "paymentIntentId": "pi_3QxYzAbCdEfGhIjK", "updated": true, "ingested": false } }| Field | Meaning |
|---|---|
updated | true when this request wrote the IDs to Stripe; false when they were already there. Repeating a request is safe. |
ingested | true 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
| Code | What to do |
|---|---|
stripe_not_connected | Connect Stripe for this website, then send again. |
payment_intent_unavailable | Check the ID belongs to the connected Stripe account. For a Checkout Session, wait until it completes. |
metadata_conflict | The payment is already linked to someone else. Graytower keeps the existing link. |
identity_mode_limited | The website is cookieless: send a userId instead of a visitorId. |
unavailable | Stripe 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.