Update user billing flow and improve error handling
Updated the user billing process to add a return to home function and redirect users to their specific account page after payment. Enhanced error handling in the billing event handler to handle scenarios where no account id is found in the subscription. Removed unused billing page object from the stripe page object.
This commit is contained in:
@@ -20,8 +20,11 @@ test.describe('User Billing', () => {
|
|||||||
await po.billing.stripe.submitForm();
|
await po.billing.stripe.submitForm();
|
||||||
|
|
||||||
await expect(po.billing.successStatus()).toBeVisible();
|
await expect(po.billing.successStatus()).toBeVisible();
|
||||||
|
await po.billing.returnToHome();
|
||||||
|
|
||||||
await page.goto('/home/billing');
|
await page.locator('a', {
|
||||||
|
hasText: 'Billing',
|
||||||
|
}).click();
|
||||||
|
|
||||||
await expect(await po.billing.getStatus()).toContainText('active');
|
await expect(await po.billing.getStatus()).toContainText('active');
|
||||||
await expect(po.billing.manageBillingButton()).toBeVisible();
|
await expect(po.billing.manageBillingButton()).toBeVisible();
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ export class BillingPageObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async returnToHome() {
|
async returnToHome() {
|
||||||
|
await this.page.waitForTimeout(500);
|
||||||
await this.successStatus().locator('button').click();
|
await this.successStatus().locator('button').click();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
import { Page, expect } from '@playwright/test';
|
import { Page, expect } from '@playwright/test';
|
||||||
import { BillingPageObject } from './billing.po';
|
|
||||||
|
|
||||||
export class StripePageObject {
|
export class StripePageObject {
|
||||||
private readonly page: Page;
|
private readonly page: Page;
|
||||||
public readonly billing: BillingPageObject;
|
|
||||||
|
|
||||||
constructor(page: Page) {
|
constructor(page: Page) {
|
||||||
this.page = page;
|
this.page = page;
|
||||||
this.billing = new BillingPageObject(page);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getStripeCheckoutIframe() {
|
getStripeCheckoutIframe() {
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ interface SessionPageProps {
|
|||||||
searchParams: {
|
searchParams: {
|
||||||
session_id: string;
|
session_id: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
params: {
|
||||||
|
account: string;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const LazyEmbeddedCheckout = dynamic(
|
const LazyEmbeddedCheckout = dynamic(
|
||||||
@@ -27,7 +31,10 @@ const LazyEmbeddedCheckout = dynamic(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
async function ReturnCheckoutSessionPage({ searchParams }: SessionPageProps) {
|
async function ReturnCheckoutSessionPage({
|
||||||
|
searchParams,
|
||||||
|
params,
|
||||||
|
}: SessionPageProps) {
|
||||||
const sessionId = searchParams.session_id;
|
const sessionId = searchParams.session_id;
|
||||||
|
|
||||||
if (!sessionId) {
|
if (!sessionId) {
|
||||||
@@ -45,12 +52,17 @@ async function ReturnCheckoutSessionPage({ searchParams }: SessionPageProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const redirectPath = pathsConfig.app.accountHome.replace(
|
||||||
|
'[account]',
|
||||||
|
params.account,
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={'fixed left-0 top-48 z-50 mx-auto w-full'}>
|
<div className={'fixed left-0 top-48 z-50 mx-auto w-full'}>
|
||||||
<BillingSessionStatus
|
<BillingSessionStatus
|
||||||
customerEmail={customerEmail ?? ''}
|
customerEmail={customerEmail ?? ''}
|
||||||
redirectPath={pathsConfig.app.home}
|
redirectPath={redirectPath}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -68,6 +68,15 @@ export class BillingEventHandlerService {
|
|||||||
|
|
||||||
logger.info(ctx, 'Processing subscription updated event ...');
|
logger.info(ctx, 'Processing subscription updated event ...');
|
||||||
|
|
||||||
|
if (!subscription.target_account_id) {
|
||||||
|
logger.info(
|
||||||
|
`No account id found in subscription. This event may have arrived before we created a subscription. Exiting...`,
|
||||||
|
subscription,
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Handle the subscription updated event
|
// Handle the subscription updated event
|
||||||
// here we update the subscription in the database
|
// here we update the subscription in the database
|
||||||
const { error } = await client.rpc('upsert_subscription', subscription);
|
const { error } = await client.rpc('upsert_subscription', subscription);
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ export class StripeWebhookHandlerService
|
|||||||
case 'customer.subscription.updated': {
|
case 'customer.subscription.updated': {
|
||||||
return this.handleSubscriptionUpdatedEvent(
|
return this.handleSubscriptionUpdatedEvent(
|
||||||
event,
|
event,
|
||||||
params.onCheckoutSessionCompleted,
|
params.onSubscriptionUpdated,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user