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

Modified on: Thu, 15 Sep, 2022 at 12:28 PM

Scope

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

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


Summary

If you are trying to fetch the coupons that are applied to a subscription, you can make use of the Retrieve Subscription API.

Alternatively, you can also make use of the Estimates API which would show the estimated amount on creation/renewal for a subscription.


Solution

Coupons applied to a subscription


To fetch the coupons that are applied to a subscription, you can make use of the Retrieve Subscription API for current subscriptions and for subscriptions that are scheduled for changes using Retrieve with scheduled changes API.


Estimate of Coupons value to a new or a subscription Change:


During the process of signing up customers to subscriptions, use the Estimates API to evaluate the details of the purchase before actually signing them up. 


Below is the list of Estimate APIs to fetch Coupon details:


Sample Estimate CURL:


curl  https://videoclikz-test.chargebee.com/api/v2/customers/AzqYVYT2JWr1B33u/create_subscription_for_items_estimate \

     -X POST  \

     -u test_Mu99gW9wCf6kKeiUTP5bcduMEjGYMscuqA:\

     -d subscription_items[item_price_id][0]="Plan300-USD-Monthly" \

     -d subscription_items[billing_cycles][0]=2 \

     -d coupon_ids[0]=cbdemo_launchoffer


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"

            }]

        }

    }

}


Related Articles

How to add coupons to an existing subscription in PC2.0?

What is the order type in which coupons are applied?

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.
×