Start a new topic

Coupons on the fly

Can i create a coupon on the fly with the API?

My problem is i have several user subscriptions and they have discounts based on different criterias that changes over the month. So, when the system charges the users, every user have a different discount. How can i manage this ?


Hello David,

We have some queries to understand your use case better so that we can suggest you the best solution. We currently do not have option to create coupon on the fly using API. We have thought about some ideas to implement this feature.

  • Does the discount change for every user on monthly basis? 
  • Does discount type (i.e. 10% or $3) fall in certain set of values or it changes on every renewal? Like, First month 10%, Second month 20%, then 25% and so on.
  • Can you give an example of the criteria based on which discount changes over the month?

Sorry for my english.

The discounts changes over the month. Suposse a client that has a susbscription of 60€.

He "gains" in the aplication a discount of 10€ while another cliente gains a discount of 15 €.

The discount is calculated in the application by a complex algorithm. 

When the month ends chargebee must charge 60-10=50 € to first client and 60-15=45€ to second client.

The easiest solution for me will be create a coupon of 10€ for first client and a 15€ coupon for second. But this is not possible.

How can i achieve this?

Hello David,

Right now, there is no way to achieve this through our API other than resorting to the coupons created in the admin console. 

However we have in our priority to support for an API which will let you add a discount line item at the time of invoice creation. 

The way it will work is: 

  • Enable the settings for "Notify and wait to close invoices" under setting -> site info. This will put the invoices in pending state and raise invoice_created web-hook to add line item.
  • Add discount line item to the pending invoice. We already have API to add charges in pending state. We will add it for discounts too.
  • Close and collect the invoice.

You can read more about adding lines items in pending invoices at the link given below. This is more like adding charges for metered billing. In your use case, this will become adding discounts on each renewal.

Please let us know if this will work for you? What is the timeline you are looking to go live? It will help us to prioritize this.

This will work.

Now this method only works with charges, not discounts?

My app will be in live about 9 of August of this year.


Hello David,

Yes, this method only works with charges right now, not discounts.

On further thinking I feel 'credits' can be used to handle your requirement. The ability to add credits(to customer) is possible only via UI now. If this approach works out we will prioritize taking up the API support for this. 

Once your invoice gets created ('pending' state), calculate the discount to be given and add that to customer (using the proposed API). Now, on closing the invoice the 'credit adjustment' line item will get added to that invoice.

There will be some limitations of using it :

  1. Credits will be shown as 'credit adjustments' in invoice. You cannot have your own description for now.
  2. If credits are greater than the invoice amount, remaining credits will be carried forward to the next upcoming invoice.
  3. Do you consider pro-rations during upgrade/downgrade ? If so, this discount (captured as credit) will not be taken into account during pro-rations. Say, for a subscription with $60/month and 15$ credit - you would have collected 45$. Now if the plan change happens in mid of term - with pro-rations - the pro-rated credit offered will be $30 and not $22.5 (i.e $45 / 2). If that 15$ was given as discount instead, the prorated credit would have been $22.5.

Please let me know if this will work for you.

This solution of credits will work, but i need the API to make the credit on the fly via API using JAVA.

I will create a credit with the exact amount so that amount never be greater that invoice amount.

No problems with proration.

I think that coupons like discounts is more "beautiful", but what you prefer


@David, we will be releasing API support for creating credits for customers by the second week of August. We will send you the specifications of the proposed API by mid next week so that you can continue your development based on that.

Hope this time frame works for you.


Any news about that?


Hi David,

Sorry for this delay. We are in the final stages of testing. Expecting to release this by tomorrow. Will update you once that is done.

This API will not be open to all. We need to enable this for your site. Can you mail your ChargeBee site details to support[at] ? 

Hello David,

We had released the support for 'Add Credit' API. This is not publicly available now. Kindly mail us your ChargeBee site details and we will enable it for you.

Let us know if you have any further questions.


Login or Signup to post a comment