chargebee / chargebee-node

Node.js library for the Chargebee API.
https://apidocs.chargebee.com/docs/api?lang=node
MIT License
46 stars 29 forks source link

estimate.invoiceEstimate should return undefined instead of empty {} if none are found #43

Open julianCast opened 3 weeks ago

julianCast commented 3 weeks ago

Description of the Bug

I believe we should get null instead of { } in the cases of no invoices estimate. That object can cause trouble for notNullable fields. That would make the field invoice_estimate.sub_total be undefined, when it's not an optional parameter in your documentation.

Steps to reproduce

Check the output for a subscription which has no next invoice, so no invoice_estimate

const response = await chargebee.estimate.renewal_estimate(subscriptionId).request();
console.log(response.estimate.invoice_estimate) // {}, instead of undefined

Expected Behavior

Estimate {
  created_at: 1718879521,
  object: 'estimate',
  subscription_estimate: SubscriptionEstimate {
    id: '12C9UGDmLHI2CC',
    status: 'non_renewing',
    object: 'subscription_estimate',
    currency_code: 'EUR',
    shipping_address: ShippingAddress {
      first_name: 'John',
      last_name: 'Doe',
     ...
      validation_status: 'not_validated',
      object: 'shipping_address'
    }
  },
  invoice_estimate: undefined <---- Shouldn't this be the response?
  next_invoice_estimate: null
}

Code Snippets (if applicable)

Estimate {
  created_at: 1718879521,
  object: 'estimate',
  subscription_estimate: SubscriptionEstimate {
    id: '12C9UGDmLHI2CC',
    status: 'non_renewing',
    object: 'subscription_estimate',
    currency_code: 'EUR',
    shipping_address: ShippingAddress {
      first_name: 'John',
      last_name: 'Doe',
      validation_status: 'not_validated',
      object: 'shipping_address'
    }
  },
  invoice_estimate: InvoiceEstimate {},<---- CB response instead of undefined ?
  next_invoice_estimate: InvoiceEstimate {}
}

Operating System

macOS

Language version

Node 18.17.0

Library version

2.32.1

Additional context

This incurs in error if we are returning estimate via graphql where the field invoice_estimate.sub_total was set as NonNegativeInt!.

cb-sriramthiagarajan commented 2 weeks ago

Hi @julianCast, I just checked this and this looks to be returning undefined when there's no invoice_estimate as expected.

Could you confirm if you see the empty object when you hit the API via curl or any other REST client?

julianCast commented 2 weeks ago

Hi @julianCast, I just checked this and this looks to be returning undefined when there's no invoice_estimate as expected.

Could you confirm if you see the empty object when you hit the API via curl or any other REST client?

Here's the thing. To reproduce it, I create a subscription, with a yearly plan, modify the price to 0 and after that I cancel it (end of term)

❌ Using this library node js (Got the {})

image

✅ Using regular HHTP in Postman (Doesn't return the attribute since is undefined)

image
cb-sriramthiagarajan commented 2 weeks ago

Thanks for sharing this @julianCast. I don't seem to be able to reproduce this with the same flow & code snippet 😕

Just to be sure, is the chargebee object in the code sample you shared coming directly from our SDK or do you have any wrapper on top? Also, is there any layer that could possibly modify the response?

julianCast commented 1 week ago

Hi! Thanks for following this: Yes, I'm actually just using the SDK.

import { ChargeBee } from 'chargebee-typescript';

const chargebee = new ChargeBee();