Customer referrals through the API
A walkthrough for a SaaS to run its own referral program inside the product: turn customers into affiliates, say on the checkout session who referred the sale, show the panel with a sign-in link, define what a qualified conversion is and pay through the API.
This walkthrough is for the SaaS that wants a "refer and earn" inside its own product: the user gets a link, a friend subscribes, and the user earns a commission. Vipter keeps who referred, computes the commission and tracks what is owed. You pay, outside Vipter, and record the payment.
Before you start, the store needs its affiliate program created and open in the dashboard, and an API key with the write scope. The fields and errors of each call are in the API reference.
1. Turn the customer into an affiliate
Create the affiliate from the store's customer. They are linked to that customer and active at once. Nobody is e-mailed: your product is what shows the link. Because the store put them in the program, they start with confirmed: false (see step 5).
curl https://api.vipter.com/v1/affiliates \
-H "Authorization: Bearer vk_live_…" \
-H "Idempotency-Key: aff-user_8213" \
-d customer=cust_9f2c1a7b{
"id": "5f0c8a52-6d3e-4f6b-9a1c-2b7d4e8f9a10",
"object": "affiliate",
"code": "marina",
"status": "active",
"name": null,
"email": "marina@example.com",
"confirmed": false,
"commission": null,
"customer": "cust_9f2c1a7b",
"joined_through": "api",
"approved_at": 1794571200,
"livemode": true,
"created": 1794571200
}Keep id and code with your user. If you would rather not call the API for every customer, turn on Every paying customer becomes an affiliate in the Program tab (or auto_enroll_customers through the API): every customer becomes an affiliate on their first paid order (an order of zero, like a free trial's, does not count), and the affiliate.approved event carries the id, the code and the customer to your system. If the person already was an affiliate of the store under the same e-mail, they are only linked to the customer and no event is sent: find them with GET /v1/affiliates?customer=cust_….
To find a customer's affiliate later, use GET /v1/affiliates?customer=cust_….
2. Show the referral link
GET /v1/affiliates/{id}/links returns what the affiliate shares: short_url and one link per offer. Show whatever makes sense in your product. If the referral happens inside your app (a "who referred you?" field), you need no link at all: use the code in step 3.
3. Say who referred when you create the checkout
When you create the new user's checkout session, send referral_code (the code they typed or that came in your link) or affiliate (the ID).
curl https://api.vipter.com/v1/checkout/sessions \
-H "Authorization: Bearer vk_live_…" \
-d offer=ofr_4b1e9c27 \
-d client_reference_id=user_9001 \
-d referral_code=marina \
-d success_url="https://app.exemplo.com/bem-vindo?session={CHECKOUT_SESSION_ID}"What the API guarantees:
- The affiliate you name wins over an affiliate coupon and a click remembered by the browser.
- A code that does not exist, or an affiliate that is not active, refuses the call (
400 referral_code_invalidor400 affiliate_not_active), and so does a program that is closed or still a draft (400 program_not_open). A sale is never silently left without an owner: decide in your code whether to go on without a referral. - The affiliate's own purchase earns no commission when the program blocks self-purchases.
4. Define what a qualified conversion is
Under Qualified conversion, in the Program tab, or through the API:
curl https://api.vipter.com/v1/affiliate_program \
-H "Authorization: Bearer vk_live_…" \
-d auto_enroll_customers=true \
-d "qualification[first_purchase_only]=true" \
-d "qualification[subscription_active_days]=14"| Rule | Effect |
|---|---|
first_purchase_only | Only the customer's first paid purchase in the store earns a commission. |
minimum_order_amount | The order total, in minor units of the store's currency, must reach the amount. |
subscription_active_days | The commission of a subscription's first charge only comes to exist once the subscription has been active for this many days. If it is cancelled or refunded before that, there is no commission. A subscription whose charge is being retried, or that is paused, when the period ends does not lose the commission: Vipter looks again the next day, for up to 90 days. |
The rules apply to the sale that starts a purchase. An upsell and a renewal follow that sale: they earn a commission only if it did. An order is only judged once paid: a PIX or boleto still open waits. An order of zero is not judged, so on a subscription with a free trial the first real charge decides. Subscriptions that already earned commissions before you created the rule keep earning on renewals. Sending null for a key removes the rule.
5. Show the panel without asking for a login
For a "see my referrals" in your product, create a sign-in link and redirect the user:
curl https://api.vipter.com/v1/affiliate_portal/sessions \
-H "Authorization: Bearer vk_live_…" \
-d affiliate=5f0c8a52-6d3e-4f6b-9a1c-2b7d4e8f9a10{
"id": "aps_3c9a1f0b7e2d4a6c8b10",
"object": "affiliate_portal.session",
"url": "https://affiliate.vipter.com/verify?token=…",
"affiliate": "5f0c8a52-6d3e-4f6b-9a1c-2b7d4e8f9a10",
"expires_at": 1794572100,
"livemode": true,
"created": 1794571200
}The link is valid for 15 minutes, works once, and opens only the panel of your store's program: links, sales, statement and payouts. The affiliate's profile, with their payout details, attaching an invoice and their panels in other stores ask for the code sent to their e-mail.
The first time, the panel shows a notice: the store put the person in the program, and they need to confirm their e-mail and accept the terms. That code is how they accept the terms and fill in their PIX key or bank account. Only then does confirmed become true, Vipter starts sending them e-mail notices, and you can open payouts for them. Say so in your product, next to the panel button: someone who does not confirm accrues commissions but is not paid.
6. Track and pay
The commission.created, commission.released, commission.reversed events and the others arrive by webhook: store the state that comes in the object instead of adding up amounts.
To pay, open the payouts, pay outside (the payout carries payee, with the PIX key or the bank details, in full for a key with the write scope) and record it. Whoever has not confirmed taking part yet comes in skipped with not_confirmed:
curl https://api.vipter.com/v1/payouts \
-H "Authorization: Bearer vk_live_…" \
-H "Idempotency-Key: payout-2026-11" \
-d "affiliates[]=5f0c8a52-6d3e-4f6b-9a1c-2b7d4e8f9a10"
curl https://api.vipter.com/v1/payouts/8a1d…/mark_paid \
-H "Authorization: Bearer vk_live_…" \
-d method=pix -d reference=E2E123 -d expected_amount=4480expected_amount protects against a refund that changes what is owed between reading and recording: in that case nothing is written and the answer carries the new amount.
SaaS: from sign-up to dashboard
A guide with code to charge a user of your SaaS through Vipter: create the checkout session with the user's ID, redirect, confirm the payment through the API or the checkout.session.completed webhook, handle PIX, idempotency, bill the month's usage on the saved card, cancel and change plans, what to store and how to coexist with Stripe.
Metered usage (Meters)
How to bill by consumption while Vipter keeps the count, in the shape of Stripe's Billing Meters: create a meter, price the usage on the offer or on the subscription, send usage events, read the open period and what happens when the cycle closes, with curl and Node.js examples, allowances, graduated tiers, billing thresholds and the differences from Stripe.