Introducing the Chargebee CLI

How to retrieve the value of a coupon applied to subscriptions using the API?

Scope

I want to display the coupon values for each subscription on my website (portal). How can I fetch them?

How can I get the value of every coupon applied to a subscription?

Summary

To fetch the coupons applied to a subscription, use the Retrieve a subscription API.

You can also use the Estimates API, which shows the estimated amount for creation or renewal of a subscription.

Solution

Coupons applied to a subscription

To fetch the coupons applied to a subscription, use the Retrieve a subscription API for current subscriptions. For subscriptions that have scheduled changes, use the Retrieve with scheduled changes API.

Estimate of a coupon's value for a new subscription or a subscription change

When you sign customers up for subscriptions, use the Estimates API to review the purchase before you sign them up.

These Estimate APIs return coupon details:

Sample estimate cURL:

CURL Command
curl https://videoclikz-test.chargebee.com/api/v2/customers/AzqYVYT2JWr1B33u/create_subscription_for_items_estimate
    -X POST
    -u {site_api_key}
    -d subscription_items[item_price_id][0]="Plan300-USD-Monthly"
    -d subscription_items[billing_cycles][0]=2
    -d coupon_ids[0]=cbdemo_launchoffer

Response:

JSON Response
{
  "estimate": {
    "created_at": 1653303899,
    "object": "estimate",
    "subscription_estimate": {
      "status": "active",
      "next_billing_at": 1655922600,
      "object": "subscription_estimate",
      "currency_code": "USD"
    },
    "invoice_estimate": {
      "recurring": true,
      "date": 1653303899,
      "price_type": "tax_exclusive",
      "sub_total": 71000,
      "total": 71000,
      "credits_applied": 0,
      "amount_paid": 0,
      "amount_due": 71000,
      "object": "invoice_estimate",
      "customer_id": "AzqYVYT2JWr1B33u",
      "line_items": [{
        "id": "li_169lhnT6ecftf16W8",
        "date_from": 1653244200,
        "date_to": 1655922599,
        "unit_amount": 30000,
        "quantity": 1,
        "amount": 30000,
        "pricing_model": "flat_fee",
        "is_taxed": false,
        "tax_amount": 0,
        "object": "line_item",
        "customer_id": "AzqYVYT2JWr1B33u",
        "description": "Plan300",
        "entity_type": "plan_item_price",
        "entity_id": "Plan300-USD-Monthly",
        "metered": false,
        "tax_exempt_reason": "export",
        "discount_amount": 9000,
        "item_level_discount_amount": 9000
      }, {
        "id": "li_169lhnT6ecfth16W9",
        "date_from": 1653244200,
        "date_to": 1655922599,
        "unit_amount": 50000,
        "quantity": 1,
        "amount": 50000,
        "pricing_model": "tiered",
        "is_taxed": false,
        "tax_amount": 0,
        "object": "line_item",
        "customer_id": "AzqYVYT2JWr1B33u",
        "description": "Additional Users - Monthly Addon",
        "entity_type": "addon_item_price",
        "entity_id": "cbdemo_additional-users-USD-monthly",
        "metered": false,
        "tax_exempt_reason": "export",
        "discount_amount": 0,
        "item_level_discount_amount": 0
      }],
      "discounts": [{
        "object": "discount",
        "entity_type": "item_level_coupon",
        "description": "Special Launch Offer",
        "amount": 9000,
        "entity_id": "cbdemo_launchoffer",
        "discount_type": "percentage"
      }],
      "taxes": [],
      "line_item_taxes": [],
      "line_item_tiers": [{
        "starting_unit": 1,
        "ending_unit": 10,
        "quantity_used": 1,
        "unit_amount": 50000,
        "object": "line_item_tier",
        "line_item_id": "li_169lhnT6ecfth16W9"
      }],
      "currency_code": "USD",
      "round_off_amount": 0,
      "line_item_discounts": [{
        "object": "line_item_discount",
        "line_item_id": "li_169lhnT6ecftf16W8",
        "discount_type": "item_level_coupon",
        "discount_amount": 9000,
        "coupon_id": "cbdemo_launchoffer",
        "entity_id": "cbdemo_launchoffer"
      }]
    }
  }
}