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

Can't access content of hosted_page #40

Open
ayushjaipuriyar opened this issue Aug 29, 2023 · 4 comments · May be fixed by #41
Open

Can't access content of hosted_page #40

ayushjaipuriyar opened this issue Aug 29, 2023 · 4 comments · May be fixed by #41

Comments

@ayushjaipuriyar
Copy link

ayushjaipuriyar commented Aug 29, 2023

  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

@ayushjaipuriyar ayushjaipuriyar changed the title Getting response headers as result Chargebee.hosted_page.retrieve(id).request(); Can't access content of hosted_page Aug 29, 2023
@ayushjaipuriyar ayushjaipuriyar linked a pull request Aug 30, 2023 that will close this issue
@cb-alish
Copy link
Collaborator

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
Copy link
Collaborator

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

@ayushjaipuriyar
Copy link
Author

ayushjaipuriyar commented Apr 22, 2024 via email

@karan925
Copy link

karan925 commented Oct 2, 2024

@cb-alish @ayushjaipuriyar I am running into the same issue. It seems like PR #41 was created but never checked in.

This content type is being sent when the conditions are met, but there is no context type. Can we add this?

your previous reply " result?.hosted_page?.content?.customer" wouldn't work if there is no content declared

export declare class HostedPage extends Model {
    id?: string;
    type?: string;
    url?: string;
    state?: string;
    failure_reason?: string;
    pass_thru_content?: string;
    embed: boolean;
    created_at?: number;
    expires_at?: number;
    updated_at?: number;
    resource_version?: number;
    checkout_info?: any;
    business_entity_id?: string;
    ...
    ```

[API Docs for Retrieve](https://apidocs.chargebee.com/docs/api/hosted_pages?lang=typescript#retrieve_a_hosted_page)

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

Successfully merging a pull request may close this issue.

3 participants