chargebee / chargebee-typescript

Typescript library for the Chargebee API.
https://apidocs.chargebee.com/docs/api?lang=typescript
MIT License
22 stars 16 forks source link

Additional fields in hosted_page.checkout_new#subscription #12

Open L2jLiga opened 3 years ago

L2jLiga commented 3 years ago

In chargebee we used additional fields inside subscription like cf_filename which is impossible with this library and we have to cast subscription object as any

ced-mos commented 1 year ago

Here my solution on how I solved this issue while preserving type safety and removing my linting errors.

First of all I extended the existing interface as follows:

interface customSubscriptionListParams extends _subscription.subscription_list_params {
  filename?: filter._string;
}

afterwards I just made a cast to this interface like:

this._chargebeeClient.subscription
        .list(<customSubscriptionListParams>{
          limit: 1,
          cf_filename: { is: filename },
        })

Hence, the type checks exists for the default variables but also for the additional custom field.

The only draw back I see is that this needs to be adapted per request instead of that there would be a central location which is exactly what @jaska120 asked for in https://github.com/chargebee/chargebee-typescript/issues/28.

Hence, Chargebee, if you have a solution to that, please let us know.

dreadjr commented 1 year ago

Could do something like this too, alternative, has it's draw backs

declare module 'chargebee-typescript' {
  namespace _subscription {
    interface subscription_list_params {
      cf_filename?: filter._string;
    }
  }
}
cb-sriramthiagarajan commented 4 months ago

Hi @L2jLiga, I'm sorry for the dealyed response.

Thank you @ced-mos for the solution. I'd also suggest extending the predefined interface to include your custom field. @L2jLiga — were you able to try this and did it help?