Can't access content of hosted_page
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
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;
Hi @ayushjaipuriyar, can you please confirm if this works for you?
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: @.***>
@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)