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

Can't access content of hosted_page #40

Open ayushjaipuriyar opened 1 year ago

ayushjaipuriyar commented 1 year ago
  async acknowledge(id: string): Promise<User> {
    try {
      const result = await this.chargebee.hosted_page.retrieve(id).request();
      this.logger.debug(`${JSON.stringify(result)}`);
      const hosted_page: HostedPage = result?.hosted_page;
      this.logger.debug(`${JSON.stringify(hosted_page)}`);
      if (
        hosted_page.type === 'checkout_new' &&
        hosted_page.state === 'succeeded'
      ) {
        const customer: Customer = result?.customer;
        const invoice: Invoice = result?.invoice;
        const subscription: Subscription = result?.subscription;
        if (!customer && !subscription && !invoice) {
          throw new InternalServerErrorException(
            'There is no data for the given hosted page',
          );
        }
        this.logger.debug(
          `customer: ${JSON.stringify(customer)},invoice: ${JSON.stringify(
            invoice,
          )},subscription:${JSON.stringify(subscription)}`,
        );
        await this.subscriptionService.save(subscription);
        await this.transactionService.saveTransaction({
          customer_id: customer.id,
          subscription_id: subscription.id,
          gateway: customer.payment_method.gateway,
          hosted_page_id: id,
          invoices: [invoice ? invoice : null],
        });
        await this.chargebee.hosted_page.acknowledge(id).request();
      }
      return await this.userService.getUserById(result.customer.id);
    } catch (error) {
      this.logger.error(
        `Something went wrong while retrieving hosted page: ${error.message}`,
        error.stack,
      );
      throw new InternalServerErrorException(
        'Something went wrong while acknowledging hosted page',
      );
    }
  }

there is no content in hosted_page

cb-alish commented 5 months ago

Hi @ayushjaipuriyar , we see you are trying to access content of the response as following

const customer: Customer = result?.customer;
const invoice: Invoice = result?.invoice;
const subscription: Subscription = result?.subscription;

can you please try doing this instead and see if it works?

 const customer: Customer = result?.hosted_page?.content?.customer;
 const invoice: Invoice = result?.hosted_page?.content?.invoice;
 const subscription: Subscription = result?.hosted_page?.content?.subscription;
cb-alish commented 4 months ago

Hi @ayushjaipuriyar, can you please confirm if this works for you?

ayushjaipuriyar commented 4 months ago

I had created a pr for this Now I am not working on that project so you can close this.

On Mon, Apr 22, 2024, 3:44 PM cb-alish @.***> wrote:

Hi @ayushjaipuriyar https://github.com/ayushjaipuriyar, can you please confirm if this works for you?

— Reply to this email directly, view it on GitHub https://github.com/chargebee/chargebee-typescript/issues/40#issuecomment-2069013926, or unsubscribe https://github.com/notifications/unsubscribe-auth/AP4OKXBBQ4KDZHPJBOPV3ADY6TPIVAVCNFSM6AAAAAA4C6MJVCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRZGAYTGOJSGY . You are receiving this because you were mentioned.Message ID: @.***>