Solidgate supports two discount flows for subscription products to give you flexible options for applying coupons during checkout.
- Predefined coupon flow
In this flow, the coupon ID is embedded and encrypted in thepaymentIntentduring payment initialization. Once the form is initialized, the applied discount will already be present. - Direct coupon flow
In this flow, the coupon code is applied after the payment form has been initialized using a specialapplyCouponmethod.
Each flow handles coupon application differently, depending on when and how the discount is added to the payment process.
Predefined coupon flow
If you want to apply a discount during form initialization, you can include the coupon_id parameter in the encryption of the paymentIntent, and then call form.init
Description
ID of the coupon which corresponds to the specific product discount, must be passed in UUID v4 format.
The coupon flow is only activated when a product_id is supplied of the subscription workflow.
product_id, the coupon_id is disregarded.Example
eb4c6e93-4c53-447a-b215-5d5786af9844
After a successful form initialization, the discount is already applied. However, in the case of an invalid or expired coupon, you receive an error event with a InitPaymentError when calling form.init.
Direct coupon flow
If you have already initialized the payment form and wish to apply a discount to it, you can do so by calling the applyCoupon method with the specified couponCode string.
|
|
If the coupon is valid and was successfully applied, applyCoupon resolves with ApplyCouponPrices object with schema:
|
|
ApplyCouponPrices to inform users about the original and discounted product prices.
In cases where the coupon application fails due to reasons like an expired coupon code, applyCoupon rejects with an ApplyCouponError. It provides an error details with a specific code and message within error.details.
|
|
ApplyCouponError.details contains original error with a specific code and message