Integrate Stripe to Create Commissions Automatically
This guide will show you how to integrate Stripe with Affast to create commission automatically in just 3 simple steps. It works with both Recurring commissions model and One-time commissions model.
Step 1: Adding Referral ID to Stripe Subscription Metadata?
By adding the referral id to the subscription metadata, Affast will know which marketer is the referrer, and we will create a commission for that marketer automatically.
$stripe->subscriptions->create([
...,
'metadata' => [
'affast_referral' => $customer->refered_by // Add the referral ID here.
]
]);
Note: The metadata key must be
affast_referral
.
Step 2: Handling Stripe Webhooks
To let Affast can adjust the commissions when a customer pays for his/her subscription or cancel the subscription, you need to go to the Stripe webhook panel and enable these following events:
invoice.paid
customer.subscription.deleted
The Endpoint URL should be
https://your-subdomain.affast.app/tenant-webhook/stripe
.
For example, your subdomain is demo
, then the Endpoint URL is https://demo.affast.app/tenant-webhook/stripe
.
Step 3: Adding the Signing Secret to Affast Dashboard
Right below the Webhook details section in Stripe webhook dashboard, click the button "Click to reveal" to get the Signing secret.
Then go to your Affast Integrations dashboard at https://your-subdomain.affast.app/dashboard
to adding the signing secret to Affast.
From here, you can also select the billing reason, Affast will create the commission based on that.
- Subscription Create indicates a Stripe invoice created due to creating a subscription. Only select this option when you just want to implement the One-time commissions model.
- Subscription Cycle indicates a Stripe invoice created by a subscription advancing into a new period. Select this option if you want to implement the Recurring commissions model.
Note: Even the Subscription Cycle option is selected but if the referral's is_recurring attribute is set to false, Affast won't create a commission for that referral.