Re: [Kill Bill users] Creating a subscription with a discount

69 views
Skip to first unread message

stephane brossier

unread,
Jun 10, 2022, 2:04:20 PM6/10/22
to Joseph G, Kill Bill users mailing-list
Joseph,

Do you have a use case where you have a well defined set of discount duration (1 month, 2 months, ...) ? -> If so, you need to define all these plans in your catalog, each plan having one discount phase and (probably) a recurring phase.

If you want to modify the price of the discount on a subscription level, you can reuse these plans but override the price at the time you create the subscription, see api (price override feature).


My first approach was to add a new phase to an existing plan in a catalog every time a discount did not exist. To achieve it, I fetched a catalog and added a new phase to the aimed product. Then, I deleted the product from the catalog and requested an update. Next, I fetched that catalog again, added the product and requested an update. Unfortunately, received an enigmatic error java.lang.IllegalStateException: Failed to de-serialize catalog for tenantRecordId='7'. I dug a little bit deeper and I found another error: java.lang.IllegalStateException: Failed to de-serialize catalog for tenantRecordId='7'.
Do you have any ideas why was the cause?


You cannot fetch and delete entries: As a matter of fact we have no api to delete entries, so did you just tweak the entries in the database - in which case that would explain the error?


Józef Grodzicki

unread,
Jun 10, 2022, 3:12:24 PM6/10/22
to stephane brossier, Kill Bill users mailing-list
That's my plan! I'd like to create discount phases in catalogs. The thing is I don't want to create them upfront and I'm looking for a more flexible solution.

Let's say a customer wants to create a subscription with a 3 month discount. Then, my application checks if a 3 month discount phase already exists in the default plan. If yes, bingo! It would be overridden with a given amount of money and that's it.
If not, the phase must be added to the plan. And this is the tricky part.

I didn't touch the db. I used the "update" (CatalogApi.uploadCatalogXml) method from the kb api like this:
1. fetch the catalog and assign the product to a variable
2. add a new discount phase to the product
3. delete the product from the catalog
4. call the update method
5. fetch the catalog again
6. add the adjusted product
7. call update

stephane brossier

unread,
Jun 10, 2022, 9:04:18 PM6/10/22
to Józef Grodzicki, Kill Bill users mailing-list
On Fri, Jun 10, 2022 at 12:12 PM Józef Grodzicki <jgrod...@griddynamics.com> wrote:
That's my plan! I'd like to create discount phases in catalogs. The thing is I don't want to create them upfront and I'm looking for a more flexible solution.

Are you trying to get flexibility in terms of discount period or pricing or both: If you have a fixed set of discount periods (1 month, 2 month, 30 days, ...), then creating the plans upfront is the best option. For the pricing you can always override when creating the subscription.

If you have 100,000 types of discount, then it will indeed not work well, and then you need to move to a catalog plugin.
 

Let's say a customer wants to create a subscription with a 3 month discount. Then, my application checks if a 3 month discount phase already exists in the default plan. If yes, bingo! It would be overridden with a given amount of money and that's it.
If not, the phase must be added to the plan. And this is the tricky part.

I didn't touch the db. I used the "update" (CatalogApi.uploadCatalogXml) method from the kb api like this:
1. fetch the catalog and assign the product to a variable
2. add a new discount phase to the product
3. delete the product from the catalog
4. call the update method
5. fetch the catalog again
6. add the adjusted product
7. call update


Which apis are you using for step 2. and 4. ?

Józef Grodzicki

unread,
Jun 11, 2022, 7:04:46 AM6/11/22
to stephane brossier, Kill Bill users mailing-list
I need to get flexibility in both discount period and pricing. I agree that the biggest challenge is periods. I will talk to my PO and ask him what to do... Thank you for your input! You confirmed my concerns.

I'm using  https://killbill.github.io/slate/?java#catalog-upload-a-catalog-as-xml (CatalogApi::uploadCatalogXML) for step 4. In step 2, I'm adding DefaultPlanPhase to initialPhases of the product's plan.
It's really strange that the catalog can be corrupted using only the KB api. I couldn't read it anymore and I had to call the "Delete all versions for a tenant catalog" method.

stephane brossier

unread,
Jun 13, 2022, 9:06:42 PM6/13/22
to Józef Grodzicki, Kill Bill users mailing-list
On Sat, Jun 11, 2022 at 4:04 AM Józef Grodzicki <jgrod...@griddynamics.com> wrote:
I need to get flexibility in both discount period and pricing. I agree that the biggest challenge is periods. I will talk to my PO and ask him what to do... Thank you for your input! You confirmed my concerns.


As far as the discount period goes, the question is really how many combinations do you need to support - if it's small number (e.g 1 month, 2 months, ... N months), then hardcoding the combinations in your catalog should not be such a big deal.

I'm using  https://killbill.github.io/slate/?java#catalog-upload-a-catalog-as-xml (CatalogApi::uploadCatalogXML) for step 4. In step 2, I'm adding DefaultPlanPhase to initialPhases of the product's plan.


 If you are using this api to upload a new catalog, then you each time create a new version, and I am not sure what your payload is, but perhaps you create different Plan entries (same id/name) but different content, which is probably not what you want.


It's really strange that the catalog can be corrupted using only the KB api. I couldn't read it anymore and I had to call the "Delete all versions for a tenant catalog" method.


Yes it is, perhaps we are lacking some validation, but I don't know enough of your use case to comment in detail.
Reply all
Reply to author
Forward
0 new messages