How to implement and apply Stripe coupons and promo codes in your Embeddable
Stripe offers two ways to provide discounts to your customers: Coupons and Promo Codes. While they’re related, they serve different purposes and are implemented differently.
A1b2C3d4
or an ID chosen by you.promo_1A2B3C4D5E6F7G8H9I0J
.Both coupons and promo codes are environment-specific - they exist either in test mode or live mode in Stripe, but not both.
Make sure you’re using the correct mode for your Embeddable. If you want to test coupons or promo codes in both modes, you’ll need to create equivalent coupons and promo codes in both modes.
There are two ways to implement promo codes in your Embeddable:
To let customers enter their own promo codes:
Add Input and Button Components
new_promo_code
.{{promo_code_success_message}}
and {{promo_code_error_message}}
respectively.Style the components
Create an Action
Create an Action that will be triggered when the button is clicked:
Register User Data Keys
promo_code_success_message
promo_code_error_message
Add a Trigger to the Action
Recommended: Reset Messages on Page Load
Since the Stripe checkout session is refreshed when the user refreshes or changes pages, you’ll want to reset the success and error messages when the page loads, to avoid the user thinking that their promo code is still applied.
Use this method to automatically apply a promo code for all customers.
A UI for handling this without editing the JSON is coming soon!
In your Stripe component Options, open the JSON editor and add the following to the checkout session configuration:
Tips:
YOUR_PROMO_CODE_ID
or YOUR_COUPON_ID
with your actual promo code ID from Stripe.{{promo_code_id}}
or {{coupon_id}}
to use an ID calculated from a Computed Field or Action.promotion_code
or coupon
key, not both.// ...
) since JSON doesn’t support comments.// ... other checkout session configuration ...
line, since you’re only adding the discounts section.When using automatic application, make sure you’re using the correct promo code for your environment (test vs live mode).
Error: Invalid promo code
This usually means one of the following:
Error: Promo code already applied
This means the customer has already applied a promo code to their checkout session. Only one promo code can be applied at a time.
Error: Coupon ID instead of Promo Code
If you’re getting errors when trying to apply a discount, make sure you’re using a promo code (customer-facing code) and not a coupon ID. The applyPromotionCode
function expects a promo code, not a coupon ID.
Test Both Modes: Always test your promo codes in both test and live modes to ensure they work as expected.
Clear Messaging: Make sure your UI clearly communicates:
Error Handling: Implement proper error handling in your Action to provide a good user experience when:
Security: Remember that promo codes are public-facing. Don’t include sensitive information in them, and consider implementing rate limiting if you’re concerned about brute force attempts.
Data Management:
How to implement and apply Stripe coupons and promo codes in your Embeddable
Stripe offers two ways to provide discounts to your customers: Coupons and Promo Codes. While they’re related, they serve different purposes and are implemented differently.
A1b2C3d4
or an ID chosen by you.promo_1A2B3C4D5E6F7G8H9I0J
.Both coupons and promo codes are environment-specific - they exist either in test mode or live mode in Stripe, but not both.
Make sure you’re using the correct mode for your Embeddable. If you want to test coupons or promo codes in both modes, you’ll need to create equivalent coupons and promo codes in both modes.
There are two ways to implement promo codes in your Embeddable:
To let customers enter their own promo codes:
Add Input and Button Components
new_promo_code
.{{promo_code_success_message}}
and {{promo_code_error_message}}
respectively.Style the components
Create an Action
Create an Action that will be triggered when the button is clicked:
Register User Data Keys
promo_code_success_message
promo_code_error_message
Add a Trigger to the Action
Recommended: Reset Messages on Page Load
Since the Stripe checkout session is refreshed when the user refreshes or changes pages, you’ll want to reset the success and error messages when the page loads, to avoid the user thinking that their promo code is still applied.
Use this method to automatically apply a promo code for all customers.
A UI for handling this without editing the JSON is coming soon!
In your Stripe component Options, open the JSON editor and add the following to the checkout session configuration:
Tips:
YOUR_PROMO_CODE_ID
or YOUR_COUPON_ID
with your actual promo code ID from Stripe.{{promo_code_id}}
or {{coupon_id}}
to use an ID calculated from a Computed Field or Action.promotion_code
or coupon
key, not both.// ...
) since JSON doesn’t support comments.// ... other checkout session configuration ...
line, since you’re only adding the discounts section.When using automatic application, make sure you’re using the correct promo code for your environment (test vs live mode).
Error: Invalid promo code
This usually means one of the following:
Error: Promo code already applied
This means the customer has already applied a promo code to their checkout session. Only one promo code can be applied at a time.
Error: Coupon ID instead of Promo Code
If you’re getting errors when trying to apply a discount, make sure you’re using a promo code (customer-facing code) and not a coupon ID. The applyPromotionCode
function expects a promo code, not a coupon ID.
Test Both Modes: Always test your promo codes in both test and live modes to ensure they work as expected.
Clear Messaging: Make sure your UI clearly communicates:
Error Handling: Implement proper error handling in your Action to provide a good user experience when:
Security: Remember that promo codes are public-facing. Don’t include sensitive information in them, and consider implementing rate limiting if you’re concerned about brute force attempts.
Data Management: