Coupons
Get in touch
Sign in
Coupons
Dynamic discounts for Payment Form

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 the paymentIntent during 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 special applyCoupon method.

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.

Without a 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.

1
2
3
4
form
  .applyCoupon("exampleCoupon")
  .then((result: ApplyCouponPrices) => { /* success handlers here */ })
  .catch((error: ApplyCouponError) => { /* error handlers here */ })

If the coupon is valid and was successfully applied, applyCoupon resolves with ApplyCouponPrices object with schema:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
interface ApplyCouponPrices {
  productPrice: {  // initial product price
    amount: string;
    currency: string;
    currencyIcon: string;
  };
  discountPrice: { // product price with applied discount
    amount: string;
    currency: string;
    currencyIcon: string;
  };
  trialPrice?: {
    amount: string;
    currency: string;
    currencyIcon: string;
  };
}
If a trial price exists, users are charged at this rate. Future payments may also have the discountPrice applied based on rules established in the HUB. Use data from 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.

1
2
3
4
5
6
interface ApplyCouponError extends Error {
  details?: {
    code: string
    message: string
  };
}

ApplyCouponError.details contains original error with a specific code and message

Looking for help? Contact us
Stay informed with Changelog