Stripe API Integration

Use the Stripe API directly for promo code tracking

Stripe API Integration

For custom checkout flows or mobile apps, you can use the Stripe API directly to apply affiliate promo codes.

This approach is particularly useful for mobile apps where traditional affiliate link tracking may be restricted by app stores.

Implementation Steps

1. Retrieve the Promo Code ID

When a user enters a promo code on your checkout screen, call the Stripe Promotion Codes API to get the promo code ID. Use stripe.promotionCodes.list with the code parameter set to the entered code.

2. Apply to Subscription

When creating a subscription, include the promotion_code parameter with the promo code ID you retrieved:

const subscription = await stripe.subscriptions.create({
  customer: 'cus_Na6dX7aXxi11N4',
  items: [
    {
      price: 'price_1MowQULkdIwHu7ixraBm864M',
    },
  ],
  promotion_code: 'promo_1MiM6KLkdIwHu7ixrIaX4wgn',
});

Alternative: Update Existing Subscription

You can also apply promo codes to existing subscriptions using the subscription update API with the promotion_code parameter.

Referral attribution works identically whether you apply the code at creation or update time.

On this page