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?
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 variable2. add a new discount phase to the product3. delete the product from the catalog4. call the update method5. fetch the catalog again6. add the adjusted product7. call update
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.