@coras-io/embed 0.12.0 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +18 -8
  3. package/dist/components/attraction-card/base/attraction-card.mixin.js +3 -3
  4. package/dist/components/attraction-card/base/attraction-card.styles.js +8 -0
  5. package/dist/components/button/button.component.d.ts +6 -0
  6. package/dist/components/button/button.component.js +31 -8
  7. package/dist/components/button/button.styles.js +8 -1
  8. package/dist/contexts/basket/basket.provider.js +1 -17
  9. package/dist/core/color-scheme.d.ts +0 -1
  10. package/dist/core/color-scheme.js +4 -6
  11. package/dist/core/utils/mount-root.d.ts +1 -0
  12. package/dist/core/utils/mount-root.js +15 -0
  13. package/dist/core/utils/redaction.js +5 -0
  14. package/dist/errors.js +2 -2
  15. package/dist/mixins/coinbase.mixin.d.ts +12 -2
  16. package/dist/mixins/coinbase.mixin.js +23 -20
  17. package/dist/sdk/mount.js +15 -13
  18. package/dist/sdk/redaction.d.ts +7 -1
  19. package/dist/sdk/redaction.js +32 -1
  20. package/dist/sdk/url.d.ts +44 -2
  21. package/dist/sdk/url.js +54 -6
  22. package/dist/sdk/validation.d.ts +1 -6
  23. package/dist/sdk/validation.js +7 -7
  24. package/dist/views/details-page/partials/location-categories/location-categories.component.d.ts +2 -1
  25. package/dist/views/details-page/partials/location-categories/location-categories.component.js +18 -5
  26. package/dist/views/payment-page/controllers/crypto-auth.controller.js +4 -4
  27. package/dist/views/payment-page/controllers/crypto-transfer.controller.d.ts +4 -4
  28. package/dist/views/payment-page/controllers/crypto-transfer.controller.js +9 -6
  29. package/dist/views/payment-page/controllers/stripe-payment.controller.d.ts +4 -1
  30. package/dist/views/payment-page/controllers/stripe-payment.controller.js +38 -10
  31. package/dist/views/payment-page/partials/activity-details/activity-details.component.js +1 -1
  32. package/dist/views/payment-page/partials/confirmation/confirmation.component.d.ts +2 -0
  33. package/dist/views/payment-page/partials/confirmation/confirmation.component.js +26 -6
  34. package/dist/views/payment-page/partials/confirmation/confirmation.styles.js +4 -0
  35. package/dist/views/payment-page/partials/hotel-pickup-field/hotel-pickup-field.component.js +3 -1
  36. package/dist/views/payment-page/partials/hotel-pickup-list/hotel-pickup-list.component.js +1 -1
  37. package/dist/views/payment-page/payment-page.component.d.ts +2 -1
  38. package/dist/views/payment-page/payment-page.component.js +45 -25
  39. package/dist/views/payment-page/payment-page.utils.d.ts +2 -0
  40. package/dist/views/payment-page/payment-page.utils.js +5 -0
  41. package/dist/views/suggestion-widget/suggestion-widget.component.d.ts +1 -1
  42. package/dist/views/suggestion-widget/suggestion-widget.component.js +11 -4
  43. package/package.json +1 -1
package/dist/sdk/url.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { SupportedCurrencies } from "../core/types/core/currency.js";
2
2
  import type { SupportedLocales } from "../core/types/core/locale.js";
3
- import type { CorasPageName, CorasPageParams } from "./types.js";
3
+ import type { CorasHrefFor, CorasNavigateDetail, CorasPageName, CorasPageParams, CorasStateChangeDetail } from "./types.js";
4
4
  /**
5
5
  * Framework-neutral URL helpers for host-controlled routing. The host owns the
6
6
  * URL; these helpers translate between a Coras state and a canonical URL so each
@@ -47,8 +47,19 @@ export type CorasUrlStrategy = {
47
47
  * collide with real ids.
48
48
  */
49
49
  reservedSegments?: Partial<Record<CorasRoutablePage, string>>;
50
+ /**
51
+ * How a built URL writes the locale segment: the canonical `en-IE` by
52
+ * default, or `"lower"` for `en-ie`. Parsing accepts either case.
53
+ */
54
+ localeCase?: "canonical" | "lower";
55
+ /**
56
+ * A currency a built URL leaves out, as a code or as a function of the
57
+ * state's locale. A parsed URL without a currency has `currency: undefined`,
58
+ * so the host supplies the same default when it reads one.
59
+ */
60
+ defaultCurrency?: SupportedCurrencies | ((locale?: SupportedLocales) => SupportedCurrencies | undefined);
50
61
  };
51
- export declare const DEFAULT_URL_STRATEGY: Required<Omit<CorasUrlStrategy, "reservedSegments">> & {
62
+ export declare const DEFAULT_URL_STRATEGY: Required<Omit<CorasUrlStrategy, "reservedSegments" | "localeCase" | "defaultCurrency">> & {
52
63
  reservedSegments: Partial<Record<CorasRoutablePage, string>>;
53
64
  };
54
65
  /** Parse a (relative or absolute) URL into a Coras state. */
@@ -66,3 +77,34 @@ export declare function createCorasUrlState(strategy?: CorasUrlStrategy): {
66
77
  normalize: typeof normalizeCorasUrlState;
67
78
  isSame: typeof isSameCorasUrlState;
68
79
  };
80
+ /**
81
+ * What the routing glue needs from a URL helper: `createCorasUrlState()`
82
+ * itself, or a wrapper around its `build` for a host whose URL shape differs
83
+ * from the strategy (a lower-case locale segment, a currency left out).
84
+ */
85
+ export type CorasUrlBuilder = Pick<ReturnType<typeof createCorasUrlState>, "build">;
86
+ export type CorasRoutingOptions = {
87
+ /** The URL helper to build with, or the strategy to bind one to. */
88
+ url: CorasUrlBuilder | CorasUrlStrategy;
89
+ /** Shows `href` as a new history entry; `intent` is the detail it was built from. */
90
+ navigate: (href: string, intent: CorasNavigateDetail) => void;
91
+ /** Shows `href` in place of the current history entry. */
92
+ replace: (href: string, state: CorasStateChangeDetail) => void;
93
+ /** Opens an external link. By default a new tab that cannot reach the opener. */
94
+ external?: (href: string, intent: CorasNavigateDetail) => void;
95
+ };
96
+ export type CorasRouting = {
97
+ hrefFor: CorasHrefFor;
98
+ onNavigate: (intent: CorasNavigateDetail) => void;
99
+ onStateChange: (state: CorasStateChangeDetail) => void;
100
+ };
101
+ /**
102
+ * The three mount options that connect Coras to a host router, built from one
103
+ * URL helper so the link a control renders (`hrefFor`) and the route a click
104
+ * takes (`onNavigate`) are always the same URL. `onNavigate` pushes a history
105
+ * entry through `navigate`, `onStateChange` replaces the current one through
106
+ * `replace`, and an intent carrying `href` is an external link: it gets no
107
+ * `hrefFor` and is opened by `external` instead of routed. Spread the result
108
+ * into `mount()`.
109
+ */
110
+ export declare function createCorasRouting({ url: urlOrStrategy, navigate, replace, external, }: CorasRoutingOptions): CorasRouting;
package/dist/sdk/url.js CHANGED
@@ -141,6 +141,15 @@ export function parseCorasUrl(url, strategy = {}) {
141
141
  ...(currency ? { currency } : {}),
142
142
  };
143
143
  }
144
+ // The state's currency, unless the strategy leaves that one out as the default.
145
+ function currencyToWrite(state, defaultCurrency) {
146
+ if (!state.currency)
147
+ return undefined;
148
+ const omitted = typeof defaultCurrency === "function"
149
+ ? defaultCurrency(state.locale)
150
+ : defaultCurrency;
151
+ return state.currency === omitted ? undefined : state.currency;
152
+ }
144
153
  /** Build a canonical URL from a Coras state. */
145
154
  export function buildCorasUrl(state, strategy = {}) {
146
155
  const resolved = resolveStrategy(strategy);
@@ -156,10 +165,14 @@ export function buildCorasUrl(state, strategy = {}) {
156
165
  const base = trimSlashes(resolved.basePath);
157
166
  if (base)
158
167
  segments.push(base);
159
- if (resolved.localeInPath && state.locale)
160
- segments.push(state.locale);
161
- if (resolved.currencyInPath && state.currency)
162
- segments.push(state.currency);
168
+ if (resolved.localeInPath && state.locale) {
169
+ segments.push(resolved.localeCase === "lower"
170
+ ? state.locale.toLowerCase()
171
+ : state.locale);
172
+ }
173
+ const currency = currencyToWrite(state, resolved.defaultCurrency);
174
+ if (resolved.currencyInPath && currency)
175
+ segments.push(currency);
163
176
  const params = (state.params ?? {});
164
177
  if (state.page === "details") {
165
178
  const id = params.id;
@@ -195,8 +208,8 @@ export function buildCorasUrl(state, strategy = {}) {
195
208
  if (value != null && value !== "")
196
209
  query.set(key, String(value));
197
210
  }
198
- if (!resolved.currencyInPath && state.currency) {
199
- query.set(resolved.currencyParam, state.currency);
211
+ if (!resolved.currencyInPath && currency) {
212
+ query.set(resolved.currencyParam, currency);
200
213
  }
201
214
  const path = `/${segments.join("/")}`.replace(/\/+/g, "/");
202
215
  const queryString = query.toString();
@@ -243,3 +256,38 @@ export function createCorasUrlState(strategy = {}) {
243
256
  isSame: isSameCorasUrlState,
244
257
  };
245
258
  }
259
+ function urlStateOf(detail) {
260
+ return {
261
+ page: detail.page,
262
+ params: detail.params ?? {},
263
+ ...(detail.locale ? { locale: detail.locale } : {}),
264
+ ...(detail.currency ? { currency: detail.currency } : {}),
265
+ };
266
+ }
267
+ function openInNewTab(href) {
268
+ window.open(href, "_blank", "noopener,noreferrer");
269
+ }
270
+ /**
271
+ * The three mount options that connect Coras to a host router, built from one
272
+ * URL helper so the link a control renders (`hrefFor`) and the route a click
273
+ * takes (`onNavigate`) are always the same URL. `onNavigate` pushes a history
274
+ * entry through `navigate`, `onStateChange` replaces the current one through
275
+ * `replace`, and an intent carrying `href` is an external link: it gets no
276
+ * `hrefFor` and is opened by `external` instead of routed. Spread the result
277
+ * into `mount()`.
278
+ */
279
+ export function createCorasRouting({ url: urlOrStrategy, navigate, replace, external = openInNewTab, }) {
280
+ const url = "build" in urlOrStrategy && typeof urlOrStrategy.build === "function"
281
+ ? urlOrStrategy
282
+ : createCorasUrlState(urlOrStrategy);
283
+ return {
284
+ hrefFor: (intent) => intent.href ? undefined : url.build(urlStateOf(intent)),
285
+ onNavigate: (intent) => {
286
+ if (intent.href)
287
+ external(intent.href, intent);
288
+ else
289
+ navigate(url.build(urlStateOf(intent)), intent);
290
+ },
291
+ onStateChange: (state) => replace(url.build(urlStateOf(state)), state),
292
+ };
293
+ }
@@ -1,11 +1,6 @@
1
1
  import type { CorasConfig, CorasMountOptions, CorasPageName } from "./types.js";
2
2
  export { assertValidPage, CorasValidationError, normalizeCurrency, normalizeLocale, PAGE_PARAM_KEYS, PUBLIC_PAGES, type CorasValidationErrorCode, } from "./params.js";
3
- /**
4
- * Require an https URL (http allowed only for localhost dev). Returns the
5
- * parsed origin-safe href, or throws.
6
- */
7
- export declare function assertSecureUrl(value: string, field: string): string;
8
- export type ValidatedMount = {
3
+ type ValidatedMount = {
9
4
  page: CorasPageName;
10
5
  config: CorasConfig;
11
6
  params: Record<string, unknown>;
@@ -37,10 +37,9 @@ function isLocalHost(hostname) {
37
37
  hostname.endsWith(".localhost"));
38
38
  }
39
39
  /**
40
- * Require an https URL (http allowed only for localhost dev). Returns the
41
- * parsed origin-safe href, or throws.
40
+ * Require an https URL (http allowed only for localhost dev), or throw.
42
41
  */
43
- export function assertSecureUrl(value, field) {
42
+ function assertSecureUrl(value, field) {
44
43
  let url;
45
44
  try {
46
45
  url = new URL(value);
@@ -49,9 +48,9 @@ export function assertSecureUrl(value, field) {
49
48
  throw new CorasValidationError("invalid_url", `${field} must be an absolute URL.`, field);
50
49
  }
51
50
  if (url.protocol === "https:")
52
- return url.href;
51
+ return;
53
52
  if (url.protocol === "http:" && isLocalHost(url.hostname))
54
- return url.href;
53
+ return;
55
54
  throw new CorasValidationError("invalid_url", `${field} must use https (http is only allowed for localhost).`, field);
56
55
  }
57
56
  /**
@@ -194,8 +193,9 @@ export function validateConfig(config, strict) {
194
193
  if (typeof config.assetsUrl !== "string" || config.assetsUrl.length === 0) {
195
194
  throw new CorasValidationError("invalid_config", "config.assetsUrl is required.", "config.assetsUrl");
196
195
  }
197
- validateAssetsUrl(config.assetsUrl);
198
- const normalized = { ...config };
196
+ const assetsUrl = config.assetsUrl.replace(/\/+$/, "");
197
+ validateAssetsUrl(assetsUrl);
198
+ const normalized = { ...config, assetsUrl };
199
199
  if (config.theme != null) {
200
200
  validateTheme(config.theme, strict);
201
201
  }
@@ -22,8 +22,9 @@ export declare class CorasLocationCategories extends LitElement {
22
22
  locale: SupportedLocales;
23
23
  currency: SupportedCurrencies;
24
24
  dispatchPageUpdate: (params: PageDispatchInput) => void;
25
+ pageUpdateHref?: (params: PageDispatchInput) => string | undefined;
25
26
  private categoriesTask;
26
- private handleCategoryClick;
27
+ private categoryTarget;
27
28
  private renderCategory;
28
29
  render(): typeof nothing | import("lit").TemplateResult<1> | undefined;
29
30
  }
@@ -6,6 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { LitElement, html, nothing } from "lit";
8
8
  import { property } from "lit/decorators.js";
9
+ import { ifDefined } from "lit/directives/if-defined.js";
9
10
  import { consume } from "@lit/context";
10
11
  import { localized, msg, str } from "@lit/localize";
11
12
  import { Task } from "@lit/task";
@@ -17,7 +18,8 @@ import { apiGet } from "../../../../core/api/queries.js";
17
18
  import { APIError } from "../../../../core/api/api-error.js";
18
19
  import { clientContext } from "../../../../contexts/client.context.js";
19
20
  import { assetsURLContext, currencyContext, distributorIdContext, localeContext, } from "../../../../contexts/properties.context.js";
20
- import { pageDispatchContext, } from "../../../../contexts/events.context.js";
21
+ import { pageDispatchContext, pageHrefContext, } from "../../../../contexts/events.context.js";
22
+ import { claimLinkClick } from "../../../../core/utils/link-click.js";
21
23
  import styles from "./location-categories.styles.js";
22
24
  /**
23
25
  * Below this the row is too thin to read as a set of things to explore, and
@@ -67,17 +69,21 @@ let CorasLocationCategories = class CorasLocationCategories extends LitElement {
67
69
  });
68
70
  }
69
71
  static { this.styles = styles; }
70
- handleCategoryClick(category) {
71
- this.dispatchPageUpdate({
72
+ categoryTarget(category) {
73
+ return {
72
74
  page: "landing",
73
75
  country: this.country,
74
76
  city: this.city,
75
77
  categories: category.slug,
76
78
  locale: this.locale,
77
79
  currency: this.currency,
78
- });
80
+ };
79
81
  }
82
+ // A link when the host builds URLs, a button otherwise; a plain click
83
+ // navigates in the app either way.
80
84
  renderCategory(category) {
85
+ const target = this.categoryTarget(category);
86
+ const href = this.pageUpdateHref?.(target);
81
87
  return html `
82
88
  <coras-explore-card
83
89
  image=${category.image}
@@ -87,7 +93,11 @@ let CorasLocationCategories = class CorasLocationCategories extends LitElement {
87
93
  <coras-button
88
94
  slot="button"
89
95
  variant="outlined"
90
- @click=${() => this.handleCategoryClick(category)}
96
+ href=${ifDefined(href)}
97
+ @click=${(event) => {
98
+ if (!href || claimLinkClick(event))
99
+ this.dispatchPageUpdate(target);
100
+ }}
91
101
  >
92
102
  ${msg("Explore")}
93
103
  </coras-button>
@@ -143,6 +153,9 @@ __decorate([
143
153
  __decorate([
144
154
  consume({ context: pageDispatchContext })
145
155
  ], CorasLocationCategories.prototype, "dispatchPageUpdate", void 0);
156
+ __decorate([
157
+ consume({ context: pageHrefContext })
158
+ ], CorasLocationCategories.prototype, "pageUpdateHref", void 0);
146
159
  CorasLocationCategories = __decorate([
147
160
  localized()
148
161
  ], CorasLocationCategories);
@@ -1,6 +1,6 @@
1
1
  import { msg, str } from "@lit/localize";
2
2
  import { OTP_INACTIVITY_TIMEOUT_MS, OTP_MIN_RESEND_INTERVAL_MS, OTP_MAX_ATTEMPTS_PER_SESSION, SMS_OTP_MIN_RESEND_INTERVAL_MS, SMS_OTP_MAX_ATTEMPTS_PER_SESSION, } from "../payment-page.constants.js";
3
- import { sanitizeErrorMessage, toE164 } from "../payment-page.utils.js";
3
+ import { redactedErrorMessage, sanitizeErrorMessage, toE164, } from "../payment-page.utils.js";
4
4
  /**
5
5
  * CryptoAuthController manages the OTP email authentication and MFA enrollment
6
6
  * flows for crypto payments.
@@ -101,7 +101,7 @@ export class CryptoAuthController {
101
101
  this.lastOtpSentTime = Date.now();
102
102
  }
103
103
  catch (error) {
104
- this.deps.logger.error("Error sending verification code:", error);
104
+ this.deps.logger.error("Error sending verification code:", redactedErrorMessage(error));
105
105
  setEmailError(sanitizeErrorMessage(error, msg("Failed to send verification code. Please try again.")));
106
106
  }
107
107
  finally {
@@ -127,7 +127,7 @@ export class CryptoAuthController {
127
127
  this.startOtpInactivityTimer(codeSent, hasSession);
128
128
  }
129
129
  catch (error) {
130
- this.deps.logger.error("Error resending verification code:", error);
130
+ this.deps.logger.error("Error resending verification code:", redactedErrorMessage(error));
131
131
  // The OTP step shows otpError; the email field error is not visible there.
132
132
  this.otpError = sanitizeErrorMessage(error, msg("Failed to resend the verification code. Please try again."));
133
133
  }
@@ -196,7 +196,7 @@ export class CryptoAuthController {
196
196
  this.mfaEnrollmentPhoneNumber = phoneNumber;
197
197
  }
198
198
  catch (error) {
199
- this.deps.logger.error("MFA enrollment initiation failed:", error);
199
+ this.deps.logger.error("MFA enrollment initiation failed:", redactedErrorMessage(error));
200
200
  setEnrollmentError(sanitizeErrorMessage(error, msg("Failed to initiate MFA enrollment")));
201
201
  }
202
202
  finally {
@@ -19,7 +19,7 @@ export type TransferOutcome = "completed" | "failed";
19
19
  */
20
20
  export interface CryptoTransferDeps {
21
21
  logger: Logger;
22
- transferTokens(amount: string): Promise<TransferResult>;
22
+ transferTokens(amountWei: bigint): Promise<TransferResult>;
23
23
  confirmReservation(): Promise<{
24
24
  transaction_id: string;
25
25
  user_id: string;
@@ -32,9 +32,9 @@ export interface CryptoTransferDeps {
32
32
  submitMfaVerification(code: string): Promise<boolean>;
33
33
  initiateMfaVerification(): Promise<void>;
34
34
  resetMfaVerificationState(): void;
35
- /** Returns the current pending transfer amount */
36
- getPendingTransferAmount(): string;
37
- /** Returns the current cart token total for amount matching */
35
+ /** Returns the current pending transfer amount in base units */
36
+ getPendingTransferAmountWei(): bigint;
37
+ /** Returns the current cart token total, formatted from base units, for amount matching */
38
38
  getCurrentCartTotal(): string;
39
39
  /** Setter for transactionId on the host */
40
40
  setTransactionId(id: string): void;
@@ -1,5 +1,7 @@
1
1
  import { msg } from "@lit/localize";
2
- import { isValidPendingTransferPayload, computeTransferChecksum, verifyTransferChecksum, sanitizeErrorMessage, } from "../payment-page.utils.js";
2
+ import { formatUnits } from "viem/utils";
3
+ import { TOKEN_DECIMALS } from "../../../mixins/coinbase.mixin.js";
4
+ import { isValidPendingTransferPayload, computeTransferChecksum, verifyTransferChecksum, sanitizeErrorMessage, redactedErrorMessage, } from "../payment-page.utils.js";
3
5
  const PENDING_TRANSFER_KEY = "coras-pending-crypto-transfer";
4
6
  const ONE_HOUR_MS = 60 * 60 * 1000;
5
7
  /**
@@ -37,9 +39,10 @@ export class CryptoTransferController {
37
39
  // Captured before the transfer: the mixin clears its pending amount once
38
40
  // the user operation settles, and the persisted payload must carry the
39
41
  // amount that actually left the wallet.
40
- const amount = this.deps.getPendingTransferAmount();
42
+ const amountWei = this.deps.getPendingTransferAmountWei();
43
+ const amount = formatUnits(amountWei, TOKEN_DECIMALS);
41
44
  try {
42
- const result = await this.deps.transferTokens(amount);
45
+ const result = await this.deps.transferTokens(amountWei);
43
46
  if (!result.success || !result.transactionHash) {
44
47
  this.showTransferModal = false;
45
48
  this.transferModalState = "mfa-verification";
@@ -50,7 +53,7 @@ export class CryptoTransferController {
50
53
  return await this.handleTransferSuccess(result.transactionHash, amount);
51
54
  }
52
55
  catch (error) {
53
- this.deps.logger.error("Transfer error:", error);
56
+ this.deps.logger.error("Transfer error:", redactedErrorMessage(error));
54
57
  this.showTransferModal = false;
55
58
  this.transferModalState = "mfa-verification";
56
59
  this.host.requestUpdate();
@@ -109,7 +112,7 @@ export class CryptoTransferController {
109
112
  this.transferModalState = "loading";
110
113
  }
111
114
  catch (error) {
112
- this.deps.logger.error("MFA verification error:", error);
115
+ this.deps.logger.error("MFA verification error:", redactedErrorMessage(error));
113
116
  this.mfaVerificationError = sanitizeErrorMessage(error, msg("Verification failed"));
114
117
  }
115
118
  finally {
@@ -124,7 +127,7 @@ export class CryptoTransferController {
124
127
  await this.deps.initiateMfaVerification();
125
128
  }
126
129
  catch (error) {
127
- this.deps.logger.error("Failed to resend MFA code:", error);
130
+ this.deps.logger.error("Failed to resend MFA code:", redactedErrorMessage(error));
128
131
  this.mfaVerificationError = sanitizeErrorMessage(error, msg("Failed to resend code"));
129
132
  this.host.requestUpdate();
130
133
  }
@@ -56,7 +56,10 @@ export declare class StripePaymentController implements ReactiveController {
56
56
  /**
57
57
  * Process a Stripe payment (card or Apple/Google Pay).
58
58
  *
59
- * Returns true if payment was successful, false otherwise.
59
+ * Returns true when the PaymentIntent succeeded or is still settling
60
+ * (`processing`, `requires_capture`), so the page polls the transaction,
61
+ * including when Stripe reports an error for an intent that already
62
+ * succeeded. Returns false otherwise.
60
63
  * Sets error state on the controller for the host to render.
61
64
  *
62
65
  * The charged amount is not checked here, and deliberately so. It is fixed by
@@ -1,5 +1,17 @@
1
1
  import { msg } from "@lit/localize";
2
2
  import { mapStripeErrorToField, extractPaymentIntentId, } from "../payment-page.utils.js";
3
+ const POLLABLE_PAYMENT_INTENT_STATUSES = new Set(["succeeded", "processing", "requires_capture"]);
4
+ function confirmedPaymentIntentStatus(result) {
5
+ return result.error
6
+ ? result.error.payment_intent?.status
7
+ : result.paymentIntent?.status;
8
+ }
9
+ function stripeErrorLogData(error) {
10
+ if (!error || typeof error !== "object")
11
+ return {};
12
+ const { code, decline_code, type } = error;
13
+ return { code, decline_code, type };
14
+ }
3
15
  /**
4
16
  * StripePaymentController manages Stripe-specific payment processing:
5
17
  * - Card payment confirmation
@@ -97,7 +109,10 @@ export class StripePaymentController {
97
109
  /**
98
110
  * Process a Stripe payment (card or Apple/Google Pay).
99
111
  *
100
- * Returns true if payment was successful, false otherwise.
112
+ * Returns true when the PaymentIntent succeeded or is still settling
113
+ * (`processing`, `requires_capture`), so the page polls the transaction,
114
+ * including when Stripe reports an error for an intent that already
115
+ * succeeded. Returns false otherwise.
101
116
  * Sets error state on the controller for the host to render.
102
117
  *
103
118
  * The charged amount is not checked here, and deliberately so. It is fixed by
@@ -162,8 +177,12 @@ export class StripePaymentController {
162
177
  payment_method: this.authorizedPaymentMethod.id,
163
178
  });
164
179
  if (result.error) {
165
- this.logger.error(`${this.authorizedPaymentEvent ? "wallet" : "card"} payment failed`);
166
- this.cardError = result.error.message || msg("Payment failed");
180
+ this.logger.error("Wallet payment confirmation returned an error", stripeErrorLogData(result.error));
181
+ }
182
+ const status = confirmedPaymentIntentStatus(result);
183
+ if (!POLLABLE_PAYMENT_INTENT_STATUSES.has(status)) {
184
+ this.logger.error("Wallet payment not completed", { status });
185
+ this.cardError = result.error?.message || msg("Payment failed");
167
186
  this.authorizedPaymentEvent.complete("fail");
168
187
  this.authorizedPaymentMethod = null;
169
188
  this.authorizedPaymentEvent = null;
@@ -176,8 +195,8 @@ export class StripePaymentController {
176
195
  this.host.requestUpdate();
177
196
  return true;
178
197
  }
179
- catch {
180
- this.logger.error("Error processing wallet payment");
198
+ catch (error) {
199
+ this.logger.error("Error processing wallet payment", stripeErrorLogData(error));
181
200
  this.cardError = msg("An error occurred while processing your payment. Please try again.");
182
201
  if (this.authorizedPaymentEvent) {
183
202
  this.authorizedPaymentEvent.complete("fail");
@@ -209,14 +228,23 @@ export class StripePaymentController {
209
228
  },
210
229
  });
211
230
  if (result.error) {
212
- this.logger.error("Card payment failed");
231
+ this.logger.error("Card payment confirmation returned an error", stripeErrorLogData(result.error));
232
+ }
233
+ const status = confirmedPaymentIntentStatus(result);
234
+ if (POLLABLE_PAYMENT_INTENT_STATUSES.has(status))
235
+ return true;
236
+ this.logger.error("Card payment not completed", { status });
237
+ if (result.error) {
213
238
  this.handleStripeValidationError(result.error);
214
- return false;
215
239
  }
216
- return !!result.paymentIntent;
240
+ else {
241
+ this.cardError = msg("Payment failed");
242
+ this.host.requestUpdate();
243
+ }
244
+ return false;
217
245
  }
218
- catch {
219
- this.logger.error("Error processing payment");
246
+ catch (error) {
247
+ this.logger.error("Error processing payment", stripeErrorLogData(error));
220
248
  this.cardError = msg("An error occurred while processing your payment. Please try again.");
221
249
  this.host.requestUpdate();
222
250
  return false;
@@ -153,7 +153,7 @@ let CorasActivityDetails = class CorasActivityDetails extends LitElement {
153
153
  assets-url=${this.assetsURL}
154
154
  @value-changed=${(e) => {
155
155
  e.stopPropagation();
156
- this.handleValueChanged(fieldName, e.detail.coras_pickup_id);
156
+ this.handleValueChanged(fieldName, e.detail.value);
157
157
  }}
158
158
  ></coras-hotel-pickup-field>
159
159
  `;
@@ -10,7 +10,9 @@ export declare class CorasConfirmation extends LitElement {
10
10
  reservations: ReservationSummary[];
11
11
  loyalty: boolean;
12
12
  private dispatchPageUpdate;
13
+ private pageUpdateHref?;
13
14
  private handleHelpClick;
15
+ private renderHelpLink;
14
16
  private getImgixParams;
15
17
  private renderTicketImage;
16
18
  render(): import("lit").TemplateResult<1>;
@@ -15,7 +15,9 @@ import { getLoyaltyAmount } from "../../../../core/utils/loyalty.js";
15
15
  import { formatDateTimeForDisplay, formatTimeForDisplay, } from "../../../../core/utils/datetime.js";
16
16
  import { getSeatDetails } from "../../../../core/utils/seats.js";
17
17
  import { consume } from "@lit/context";
18
- import { pageDispatchContext, } from "../../../../contexts/events.context.js";
18
+ import { pageDispatchContext, pageHrefContext, } from "../../../../contexts/events.context.js";
19
+ import { claimLinkClick } from "../../../../core/utils/link-click.js";
20
+ const HELP_PAGE = { page: "help" };
19
21
  let CorasConfirmation = class CorasConfirmation extends LitElement {
20
22
  constructor() {
21
23
  super(...arguments);
@@ -27,8 +29,25 @@ let CorasConfirmation = class CorasConfirmation extends LitElement {
27
29
  }
28
30
  static { this.styles = styles; }
29
31
  handleHelpClick(event) {
30
- event.preventDefault();
31
- this.dispatchPageUpdate?.({ page: "help" });
32
+ const linked = Boolean(this.pageUpdateHref?.(HELP_PAGE));
33
+ if (!linked || claimLinkClick(event))
34
+ this.dispatchPageUpdate?.(HELP_PAGE);
35
+ }
36
+ // A link to the help page when the host builds URLs, a button otherwise.
37
+ renderHelpLink() {
38
+ const href = this.pageUpdateHref?.(HELP_PAGE);
39
+ const label = msg("Help Centre");
40
+ return href
41
+ ? html `<a class="help-link" href=${href} @click=${this.handleHelpClick}
42
+ >${label}</a
43
+ >`
44
+ : html `<button
45
+ type="button"
46
+ class="help-link"
47
+ @click=${this.handleHelpClick}
48
+ >
49
+ ${label}
50
+ </button>`;
32
51
  }
33
52
  getImgixParams() {
34
53
  const params = new URLSearchParams({
@@ -183,9 +202,7 @@ let CorasConfirmation = class CorasConfirmation extends LitElement {
183
202
 
184
203
  <div class="help-text">
185
204
  ${msg("If you need help with your order, please visit our")}
186
- <span class="help-link" @click="${this.handleHelpClick}">
187
- ${msg("Help Centre")}
188
- </span>
205
+ ${this.renderHelpLink()}
189
206
  </div>
190
207
  `;
191
208
  }
@@ -208,6 +225,9 @@ __decorate([
208
225
  __decorate([
209
226
  consume({ context: pageDispatchContext })
210
227
  ], CorasConfirmation.prototype, "dispatchPageUpdate", void 0);
228
+ __decorate([
229
+ consume({ context: pageHrefContext })
230
+ ], CorasConfirmation.prototype, "pageUpdateHref", void 0);
211
231
  CorasConfirmation = __decorate([
212
232
  localized()
213
233
  ], CorasConfirmation);
@@ -158,6 +158,10 @@ export default css `
158
158
  }
159
159
 
160
160
  .help-link {
161
+ padding: 0;
162
+ border: 0;
163
+ background: none;
164
+ font: inherit;
161
165
  color: var(--confirmation-help-link-color);
162
166
  text-decoration: none;
163
167
  font-weight: var(--confirmation-help-link-font-weight);
@@ -7,6 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  import { LitElement, html, nothing } from "lit";
8
8
  import { property, state } from "lit/decorators.js";
9
9
  import { localized, msg } from "@lit/localize";
10
+ import { fireInternalEvent } from "../../../../core/events.js";
10
11
  import "../../../../components/dropdown/dropdown.js";
11
12
  import "../../../../components/input-field/input-field.js";
12
13
  import "../../../../components/icon/icon.js";
@@ -70,8 +71,9 @@ let CorasHotelPickupField = class CorasHotelPickupField extends LitElement {
70
71
  <coras-hotel-pickup-list
71
72
  .options=${this.options}
72
73
  .value=${this.value}
73
- @value-changed=${() => {
74
+ @value-changed=${(e) => {
74
75
  this.dropdownOpen = false;
76
+ fireInternalEvent(this, "value-changed", { value: e.detail.value });
75
77
  }}
76
78
  ></coras-hotel-pickup-list>
77
79
  </coras-dropdown>
@@ -22,7 +22,7 @@ export class CorasHotelPickupList extends LitElement {
22
22
  <div
23
23
  class="pickup-item ${selected ? "selected" : ""}"
24
24
  @click=${() => {
25
- fireInternalEvent(this, "value-changed", option);
25
+ fireInternalEvent(this, "value-changed", { value });
26
26
  }}
27
27
  >
28
28
  ${option.pickup_name}
@@ -114,7 +114,8 @@ export declare class CorasPaymentPage extends CorasPaymentPage_base {
114
114
  private reservationsCheckTask;
115
115
  private reservationsTask;
116
116
  private hasReservations;
117
- private getReservationsLoyaltyTotal;
117
+ private getReservationsEarnTotal;
118
+ private getReservationsPayAmountWei;
118
119
  private formatEarnedTokens;
119
120
  private handlePhoneCodeSelection;
120
121
  private handleTermsChange;