Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

portal_session.create returning invalid response #49

Open
ankero opened this issue Mar 22, 2024 · 2 comments
Open

portal_session.create returning invalid response #49

ankero opened this issue Mar 22, 2024 · 2 comments

Comments

@ankero
Copy link

ankero commented Mar 22, 2024

Hi,

The client.portal_session.create().request() is returning an invalid response. It is only including the responseHeaders to the response. The server is returning the portal session, but the library has a bug in core.js responseHandler on line response = new result_1.Result(response, responseHeaders); that causes the response to be dropped and only the responseHeaders get returned.

Reproduce just by calling that API with this library.

Here's the request I made to produce this issue:

const response = await chargebeeClient.portal_session.create({
        customer: {
          id: customerId,
        },
      }).request()

Workaround can be done with direct API call, for example:

  private async createPortalSession(
    customerId: string,
  ): Promise<PortalSession> {
    try {
      /**
       * this.chargebeeClient.portal_session.create().request() is
       * broken. So we'll use axios until its fixed.
       */
      const { data } = await axios.post(
        `https://${this.apiAuth?.site}.chargebee.com/api/v2/portal_sessions?customer[id]=${customerId}`,
        {},
        {
          headers: {
            Authorization: `Basic ${Buffer.from(
              `${this.apiAuth?.api_key}:`,
            ).toString("base64")}`,
            "Content-Type": "application/json",
          },
        },
      );
      // @ts-ignore response
      return data.portal_session as PortalSession;
    } catch (error) {
      console.error("Failed to create portal session", error);
      throw error;
    }
  }
@cb-sriramthiagarajan
Copy link
Collaborator

Hi @ankero, I'm sorry about the delay in responding to this. I'm able to see this working correctly using the SDK. Sharing the code snipped that works for me:

const response = await chargebee.portal_session
      .create({
        customer: {
          id: "customer_id"
        }
      })
      .request();
console.log(response.portal_session);

Could you give this a try and let us know if it works for you? Please share the error details if you see any.

@cb-sriramthiagarajan
Copy link
Collaborator

Hi @ankero, did you get a chance to try this out? Let me know if you're still facing any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants