Laravel affiliate tracking with Refficks
Stripe Checkout Sessions your Laravel app creates, credited to the partner whose link brought the buyer.
What it gives you
- A payment through a Checkout Session your app opens is credited to the partner whose link brought the buyer, straight from the payment in your Stripe account.
- A subscription keeps its partner for every renewal, a refund takes the commission back by itself, and partners' codes synced to Stripe work at the checkout as they are.
What it does not
- A visitor who has not accepted cookies, or whose browser sends Global Privacy Control, has no visitor id to pass on. Their sale can still be credited through the partner's discount code.
- Only Checkout Sessions on a Stripe account connected to Refficks are seen. Payments taken some other way need their own guide.
Steps
1. Put the Refficks script on every page
Paste the snippet into the head of every page, in your app's main layout. It records the partner's click when somebody arrives and keeps their visitor id in a first-party cookie, rk_vid.
2. Let Laravel read the visitor cookie
Laravel encrypts its cookies and reads back only the ones it wrote, so the cookie the script wrote reads as empty. Leave it out of encryption in bootstrap/app.php, as below. On Laravel 10 or earlier, add 'rk_vid' to $except in app/Http/Middleware/EncryptCookies.php instead.
->withMiddleware(function (Middleware $middleware) { $middleware->encryptCookies(except: ['rk_vid']); })3. Pass the visitor to Stripe
In the controller that creates the Checkout Session, read the rk_vid cookie and give it to Stripe as refficks_visitor, in the session's metadata and, for a subscription, in subscription_data's metadata. Leave the rest of your checkout as it is.
If the code that creates the session runs on another domain than your site, the cookie does not reach it. Send window.refficks.visitorId() from the page with the request instead, and use that.
// Where your controller creates the session: $visitor = $request->cookie('rk_vid'); $refficks = $visitor ? ['refficks_visitor' => $visitor] : []; $session = $stripe->checkout->sessions->create([ // ...your line items, mode and return URLs, as now... 'metadata' => $refficks, // Only for a subscription: 'subscription_data' => ['metadata' => $refficks], ]); // With Cashier: $user->checkout($prices, ['metadata' => $refficks]), // or newSubscription(...)->withMetadata($refficks)->checkout().4. Make a test purchase
Open your site through any partner's link, copied from their page under Partners, and buy something with Stripe in test mode. The checks on this guide in Refficks turn green as each part is seen. A test payment is never counted as a sale.
Sources
Have an account? Open this guide in Refficks for your own script and the checks that show when it is working. New to Refficks? Create an account.