To add referral metadata for a Stripe customer in Webflow when integrating with Rewardful, you'll need to follow a few steps:
Step 1: Set up the Rewardful integration
Before you can add referral metadata, you'll need to integrate Rewardful with your Webflow site. Here's how to do it:
1. Sign up for a Rewardful account and create a referral program.
2. In Rewardful, go to your program settings and copy your Referral tracking code.
3. In Webflow, navigate to your Project Settings and open the Custom Code tab.
4. Paste the Rewardful tracking code in the Footer Code section.
5. Save and publish your site.
Step 2: Retrieve and store the referral information
To add referral metadata to a customer in Stripe, you need to retrieve the referral information from Rewardful and store it in the customer's metadata. Here's an example of how you can achieve this:
1. In your Webflow site, create a referral confirmation page where users land after a successful referral.
2. On this page, include JavaScript code that retrieves the referral information from the URL parameters or from browser cookies.
3. Use the Stripe API to update the customer's metadata with the referral information.
- You'll need to authenticate your Stripe API requests using your API keys.
- Retrieve the customer object from Stripe using the customer's email or ID.
- Add the referral information to the customer's metadata.
- Update the customer object with the new metadata.
Here's some sample JavaScript code to give you an idea:
```
// Retrieve referral information from URL parameters
const urlParams = new URLSearchParams(window.location.search);
const referralCode = urlParams.get('referral_code');
// Store referral information in customer metadata
const customerId = 'your_stripe_customer_id';
const stripe = require('stripe')('your_stripe_api_key');
stripe.customers.update(customerId, {
metadata: {
referralCode,
},
}) .then((customer) => {
console.log('Customer metadata updated:', customer);
}) .catch((error) => {
console.error('Error updating customer metadata:', error);
});
```
Remember to replace `'your_stripe_customer_id'` and `'your_stripe_api_key'` with your actual Stripe customer ID and API key.
Step 3: Test and verify
To ensure that the referral metadata is being properly added to the Stripe customer, test the integration by referring a new customer and checking if the metadata appears in the customer's details on the Stripe dashboard.
By following these steps, you can add referral metadata for a Stripe customer in Webflow when integrating with Rewardful.