chargebee / chargebee-dotnet

.NET library for the Chargebee API.
https://apidocs.chargebee.com/docs/api?lang=dotnet
MIT License
20 stars 24 forks source link

It's impossible to add `.Header()` to certain types of requests #60

Open nfidirko opened 1 year ago

nfidirko commented 1 year ago

Description

For certain types of requests (e.g. deleting a payment source), when you're trying to add a header via .Header() an exception is thrown.

Affected versions

(Haven't tests earlier version)

Code to reproduce the error

var request = ChargeBee.Models.PaymentSource.Delete("test");
request.Header("test", "test");

Exception

Unhandled exception. System.InvalidCastException: Object must implement IConvertible.
   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
   at ChargeBee.Api.EntityRequest`1.Header(String headerName, String headerValue)
   at Program.<Main>$(String[] args) in ......

Notes

It looks like this error occurs in all requests that have type EntityRequest<Type>. The error is thrown here: (T) Convert.ChangeType((object) this, typeof (T));. It also means that for such requests it's not possible to set idempotency key or add a parameter to such request.