Polar Integration
Automatically track subscriptions and calculate commissions with Polar
Overview
Refgrow integrates with Polar to automatically track subscriptions and calculate commissions for your affiliates.
- Automatic tracking of subscription creation and renewals
- Support for product-specific commission rates
- Support for affiliate-specific commission overrides
- Secure webhook implementation for real-time tracking
- Works with Polar's subscription management system
Setting Up Polar Integration
Step 1: Configure Webhook
- Go to your project's "Integration" tab
- Select "Polar Webhook" as your tracking method
- Copy the provided webhook URL
- In your Polar dashboard, go to Settings → Webhooks
- Create a new webhook with the copied URL
- Enable these events:
subscription.created
,subscription.updated
,subscription.canceled
,subscription.renewed
- Copy the webhook signing secret from Polar
- Paste the signing secret in Refgrow and click "Save Secret"
Step 2: Choose Your User Flow
Select the appropriate user conversion flow for your business:
- Click → Signup → Subscribe: Users create an account before subscribing
- Click → Subscribe: Users can subscribe directly without signing up first
- Both: Your platform supports both flows
Passing Referral Codes to Polar
For Polar Subscriptions
When creating a subscription on your server, pass the referral code in the metadata:
// Example (Node.js Server-Side)
const refCode = req.cookies.refgrow_ref_code; // Get code from cookie
const subscription = await polar.subscriptions.create({
// ... other subscription parameters
metadata: {
referral_code: refCode || null // Pass the code here
}
});
For Polar Checkout
For checkout sessions, include the referral code in the metadata:
// Example (Node.js Server-Side)
const refCode = req.cookies.refgrow_ref_code; // Get code from cookie
const checkout = await polar.checkouts.create({
// ... other checkout parameters
metadata: {
referral_code: refCode || null // Pass the code here
}
});
Commission Configuration
Default Commission Settings
Configure your default commission structure in your project settings:
- Commission Type: Percentage or Fixed Amount
- Commission Value: The percentage or fixed amount
- Commission Duration: Lifetime, First Purchase, or Limited Period
Product-Specific Commissions
Override commission rates for specific products:
- Go to your project's "Integration" tab
- Scroll to "Product-Specific Commissions"
- Click "Add Product Commission"
- Select a Polar product and set its unique commission rate
Affiliate-Specific Overrides
Set custom commission rates for individual affiliates:
- Go to your "Affiliates" tab
- Find the affiliate you want to customize
- Click "Manage Override"
- Set a custom commission type and value
How It Works
1. Referral Click
User clicks an affiliate link and the refgrow_ref_code
cookie is set.
2. Polar Subscription
The referral code is passed to Polar, and the user completes subscription.
3. Webhook Processing
Refgrow receives the webhook, attributes the subscription, and calculates the commission.
Supported Webhook Events
Refgrow automatically listens for these webhook events:
subscription.created
- When a new subscription is createdsubscription.updated
- When a subscription is updatedsubscription.canceled
- When a subscription is canceledsubscription.renewed
- When a subscription is renewed
Troubleshooting
- Verify your webhook signing secret is correctly set in your project settings
- Check that the webhook endpoint was created with the correct URL:
https://refgrow.com/webhook/polar/{your-project-id}
- Confirm all required events are enabled for the webhook
- Check your Polar dashboard for webhook delivery logs
- Ensure the webhook is active and not paused
- Ensure the referral code is being passed in the subscription metadata
- Check that the affiliate with that referral code exists and is active
- Verify the referral code format matches exactly (case-sensitive)
- Check that the user hasn't been attributed to another affiliate already
- Review the webhook payload to confirm the referral code is present
- Check your default commission settings in project configuration
- Verify product-specific commission overrides if applicable
- Check affiliate-specific commission overrides
- Ensure the subscription amount is greater than zero
- Review the webhook payload for correct currency and amount values
- Check that the same subscription isn't being processed multiple times
- Verify webhook retry logic isn't causing duplicates
- Review your subscription creation flow to prevent duplicate webhooks
- Check the conversion logs for duplicate subscription IDs
API Reference
Webhook Endpoint
POST https://refgrow.com/webhook/polar/{project-id}
Required Headers
Content-Type: application/json
polar-signature: {hmac-sha256-signature}
Webhook Payload Example
{
"type": "subscription.created",
"data": {
"subscription": {
"id": "sub_123456789",
"customer": {
"email": "customer@example.com"
},
"price": {
"amount": 2900,
"currency": "USD"
},
"product": {
"id": "prod_123456789"
},
"metadata": {
"referral_code": "ABC123"
}
}
}
}
Best Practices
Security
- Always verify webhook signatures
- Use HTTPS for all webhook endpoints
- Keep your webhook secrets secure
- Monitor webhook delivery logs
Reliability
- Implement webhook retry logic
- Handle webhook failures gracefully
- Monitor webhook delivery status
- Test webhooks in development first
Need Help?
If you're experiencing issues with your Polar integration:
- Check the Troubleshooting Guide for common solutions
- Review your webhook delivery logs in your Polar dashboard
- Contact our support team with your project ID and specific error details
- Join our Discord community for help from other users