Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️
PHP attendize-alternativedoor-managementevent-check-inevent-managementevent-registrationevent-ticketingeventbrite-alternativeeventslaravelopen-sourcephpreactself-hostedsell-ticketssell-tickets-onlineticket-sellingticketing-systemtickettailor-alternativetito-alternative
Report each embedded checkout order to the host page once (#1441)
Dave Earley766bd7d0dca9
diff --git a/e2e/tests/widget/widget-modes.spec.ts b/e2e/tests/widget/widget-modes.spec.tsindex a8c77d7cc..ca68aa488 100644--- a/e2e/tests/widget/widget-modes.spec.ts+++ b/e2e/tests/widget/widget-modes.spec.ts@@ -100,6 +100,37 @@ test.describe('widget modes', () => {.toEqual([expect.objectContaining({ eventId: String(event.eventId), quantity: 1, status: 'COMPLETED' })]);});+ test('reloading a completed checkout does not tell the host page about the order again', async ({ page, api, account, baseURL }) => {+ const event = await createLiveEventWithFreeTicket(api, account.organizerId);+ const buyer = { firstName: 'Reload', lastName: 'Buyer', email: uniqueEmail('reload-buyer') };++ await openEmbedHost(page, baseURL!, widgetMarkup({ id: String(event.eventId), 'widget-type': 'button', 'button-text': 'Book now' }));+ await page.evaluate(() => {+ const log: unknown[] = [];+ (window as unknown as { hieventsOrders: unknown[] }).hieventsOrders = log;+ window.addEventListener('hievents:order-completed', (event) => log.push((event as CustomEvent).detail));+ });++ await page.getByRole('button', { name: 'Book now' }).click();+ const widget = await resolveWidgetFrame(page);+ await setWidgetQuantity(widget, 1);+ await widget.getByTestId('checkout-continue-button').click();+ const checkoutFrame = await resolveCheckoutFrame(page);+ await checkoutFrame.waitForURL(/\/checkout\/\d+\/[^/]+\/details/);+ const checkout = new CheckoutPage(page, checkoutFrame);+ await checkout.fillOrderDetails(buyer);+ await checkout.fillFirstAttendee(buyer);+ await checkout.completeFreeOrder();+ const hostOrders = () => page.evaluate(() => (window as unknown as { hieventsOrders: unknown[] }).hieventsOrders.length);+ await expect.poll(hostOrders).toBe(1);++ await checkoutFrame.goto(checkoutFrame.url());+ await expect(checkoutFrame.getByText(`You're going to ${event.title}`)).toBeVisible();+ await page.waitForTimeout(1000);++ expect(await hostOrders()).toBe(1);+ });+test('a paid order through the ticket button tells the host page its total and currency', async ({ page, api, account, baseURL }) => {const event = await createLiveEventWithPaidTicket(api, account.organizerId, 20);await api.updateEventSettings(event.eventId, { pass_platform_fee_to_buyer: false });diff --git a/frontend/src/components/layouts/Checkout/index.tsx b/frontend/src/components/layouts/Checkout/index.tsxindex 5e72307b5..7000bed7c 100644--- a/frontend/src/components/layouts/Checkout/index.tsx+++ b/frontend/src/components/layouts/Checkout/index.tsx@@ -19,7 +19,7 @@ import {withLoadingNotification} from "../../../utilites/withLoadingNotificationimport {useAbandonOrderPublic} from "../../../mutations/useAbandonOrderPublic.ts";import {showError, showInfo} from "../../../utilites/notifications.tsx";import {isDateInFuture, utcDateToEpochMs} from "../../../utilites/dates.ts";-import {getCheckoutSessionIdentifier} from "../../../utilites/checkoutSession.ts";+import {claimOrderCompletionReport, getCheckoutSessionIdentifier} from "../../../utilites/checkoutSession.ts";import {PoweredByFooter} from "../../common/PoweredByFooter";import {detectMode} from "../../../utilites/themeUtils.ts";import {CheckoutThemeProvider} from "./CheckoutThemeProvider.tsx";@@ -166,6 +166,9 @@ const Checkout = () => {return;}reportedOrderRef.current = order.short_id;+ if (!claimOrderCompletionReport(order.short_id)) {+ return;+ }postToParent('hievents:order-completed', {eventId,currency: order.currency,diff --git a/frontend/src/utilites/checkoutSession.ts b/frontend/src/utilites/checkoutSession.tsindex 85ca76ed6..e147cbf1e 100644--- a/frontend/src/utilites/checkoutSession.ts+++ b/frontend/src/utilites/checkoutSession.ts@@ -1,6 +1,7 @@import {isSsr, safeSessionStorageGet, safeSessionStorageSet} from "./helpers.ts";const SESSION_KEY_PREFIX = 'hievents.checkout.session.';+const COMPLETION_REPORTED_KEY_PREFIX = 'hievents.checkout.completionReported.';const readSessionIdentifierFromUrl = (): string | null => {if (isSsr()) return null;@@ -24,3 +25,11 @@ export const getCheckoutSessionIdentifier = (orderShortId: string): string | nulreturn safeSessionStorageGet(SESSION_KEY_PREFIX + orderShortId);};++export const claimOrderCompletionReport = (orderShortId: string): boolean => {+ if (safeSessionStorageGet(COMPLETION_REPORTED_KEY_PREFIX + orderShortId)) {+ return false;+ }+ safeSessionStorageSet(COMPLETION_REPORTED_KEY_PREFIX + orderShortId, '1');+ return true;+};