stripe-pwa-elements 4.0.2 → 4.0.4

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 (72) hide show
  1. package/dist/cjs/{factory-tenFFIul.js → factory-Cm6zUD7R.js} +7 -1
  2. package/dist/cjs/{i18n-FhEOc8vz.js → i18n-lBbOeQt4.js} +6 -0
  3. package/dist/cjs/ion-icon_2.cjs.entry.js +5 -3
  4. package/dist/cjs/loader.cjs.js +1 -1
  5. package/dist/cjs/stripe-address-element.cjs.entry.js +2 -2
  6. package/dist/cjs/stripe-card-element.cjs.entry.js +13 -3
  7. package/dist/cjs/stripe-currency-selector.cjs.entry.js +2 -2
  8. package/dist/cjs/stripe-elements.cjs.js +1 -1
  9. package/dist/cjs/stripe-express-checkout-element.cjs.entry.js +2 -2
  10. package/dist/cjs/stripe-link-authentication-element.cjs.entry.js +2 -2
  11. package/dist/cjs/stripe-payment-element.cjs.entry.js +11 -3
  12. package/dist/cjs/{stripe-payment-element.helpers-DukP33RI.js → stripe-payment-element.helpers-lafmSRmb.js} +7 -8
  13. package/dist/cjs/stripe-payment-sheet.cjs.entry.js +516 -35
  14. package/dist/collection/components/stripe-address-element/stripe-address-element.js +2 -2
  15. package/dist/collection/components/stripe-card-element/stripe-card-element.js +11 -1
  16. package/dist/collection/components/stripe-modal/stripe-modal.css +4 -0
  17. package/dist/collection/components/stripe-modal/stripe-modal.js +3 -1
  18. package/dist/collection/components/stripe-payment-element/stripe-payment-element.helpers.js +7 -8
  19. package/dist/collection/components/stripe-payment-element/stripe-payment-element.js +12 -4
  20. package/dist/collection/components/stripe-payment-sheet/payment-sheet-state.js +21 -7
  21. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.checkout.js +94 -0
  22. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.helpers.js +193 -9
  23. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.js +240 -21
  24. package/dist/collection/services/link-authentication-element-manager.js +5 -0
  25. package/dist/collection/utils/i18n.js +6 -0
  26. package/dist/components/factory.js +1 -1
  27. package/dist/components/i18n.js +1 -1
  28. package/dist/components/stripe-card-element2.js +1 -1
  29. package/dist/components/stripe-modal2.js +1 -1
  30. package/dist/components/stripe-payment-element.helpers.js +1 -1
  31. package/dist/components/stripe-payment-element.js +1 -1
  32. package/dist/components/stripe-payment-sheet.js +1 -1
  33. package/dist/esm/{factory-Cd6OGTWN.js → factory-BaGv8K_i.js} +7 -2
  34. package/dist/esm/{i18n-B6JoQetF.js → i18n-CL5n3bOb.js} +6 -0
  35. package/dist/esm/ion-icon_2.entry.js +5 -3
  36. package/dist/esm/loader.js +1 -1
  37. package/dist/esm/stripe-address-element.entry.js +2 -2
  38. package/dist/esm/stripe-card-element.entry.js +13 -3
  39. package/dist/esm/stripe-currency-selector.entry.js +2 -2
  40. package/dist/esm/stripe-elements.js +1 -1
  41. package/dist/esm/stripe-express-checkout-element.entry.js +2 -2
  42. package/dist/esm/stripe-link-authentication-element.entry.js +2 -2
  43. package/dist/esm/stripe-payment-element.entry.js +11 -3
  44. package/dist/esm/{stripe-payment-element.helpers-CipV87b8.js → stripe-payment-element.helpers-CklK5RlF.js} +7 -8
  45. package/dist/esm/stripe-payment-sheet.entry.js +516 -35
  46. package/dist/stripe-elements/{p-f892e375.entry.js → p-2e41699e.entry.js} +1 -1
  47. package/dist/stripe-elements/{p-6a9c8b7a.entry.js → p-3fc4583a.entry.js} +1 -1
  48. package/dist/stripe-elements/p-5d3d93ec.entry.js +1 -0
  49. package/dist/stripe-elements/p-7a8f783c.entry.js +1 -0
  50. package/dist/stripe-elements/{p-915b86ed.entry.js → p-7e826964.entry.js} +1 -1
  51. package/dist/stripe-elements/p-BoZLkOAy.js +1 -0
  52. package/dist/stripe-elements/p-CL5n3bOb.js +1 -0
  53. package/dist/stripe-elements/{p-C7MQk9FK.js → p-DlMEZwSe.js} +1 -1
  54. package/dist/stripe-elements/{p-5338bc5e.entry.js → p-b62c9dae.entry.js} +1 -1
  55. package/dist/stripe-elements/p-b69f6103.entry.js +1 -0
  56. package/dist/stripe-elements/{p-7fe4a287.entry.js → p-f5552c81.entry.js} +1 -1
  57. package/dist/stripe-elements/stripe-elements.esm.js +1 -1
  58. package/dist/types/components/stripe-card-element/stripe-card-element.d.ts +1 -0
  59. package/dist/types/components/stripe-payment-element/stripe-payment-element.helpers.d.ts +9 -2
  60. package/dist/types/components/stripe-payment-sheet/payment-sheet-state.d.ts +21 -4
  61. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.checkout.d.ts +39 -0
  62. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.d.ts +50 -5
  63. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.helpers.d.ts +66 -8
  64. package/dist/types/components.d.ts +22 -9
  65. package/dist/types/services/interfaces.d.ts +2 -0
  66. package/package.json +4 -2
  67. package/readme.md +78 -27
  68. package/dist/stripe-elements/p-B6JoQetF.js +0 -1
  69. package/dist/stripe-elements/p-DFAhQS0n.js +0 -1
  70. package/dist/stripe-elements/p-b06a254f.entry.js +0 -1
  71. package/dist/stripe-elements/p-b91c4fa7.entry.js +0 -1
  72. package/dist/stripe-elements/p-e7372ca7.entry.js +0 -1
@@ -146,6 +146,7 @@ export declare class StripeCardElement {
146
146
  * ```
147
147
  */
148
148
  intentClientSecret?: string;
149
+ updateIntentClientSecret(): void;
149
150
  /**
150
151
  * The component will confirm the intent for you: `stripe.confirmCardPayment` when `intentType` is `'payment'`,
151
152
  * `stripe.confirmCardSetup` when it is `'setup'`.
@@ -1,10 +1,12 @@
1
- import type { Stripe, StripeElements, StripeCheckoutElementsSdk, StripeCheckoutConfirmResult } from '@stripe/stripe-js';
1
+ import type { Stripe, StripeElements, StripeCheckoutElementsSdk, StripeCheckoutConfirmResult, ConfirmPaymentData, ConfirmSetupData } from '@stripe/stripe-js';
2
2
  import type { IntentType, ProgressStatus } from '../../interfaces';
3
3
  import type { PaymentElementSubmitEvent } from './stripe-payment-element';
4
4
  /**
5
5
  * Determine whether the submit button should be disabled.
6
6
  * For Checkout Session mode: the checkout is ready once Stripe finished loading.
7
7
  * For Payment Intent / Setup Intent mode: an intent client secret must be present.
8
+ * The button stays disabled after a successful payment as well: the intent or
9
+ * checkout is already confirmed and cannot be submitted again.
8
10
  * @param params progress / loading state and the current mode information
9
11
  * @returns true when the submit button should be disabled
10
12
  */
@@ -14,6 +16,10 @@ export declare const isSubmitButtonDisabled: (params: {
14
16
  loadStripeStatus: ProgressStatus;
15
17
  intentClientSecret?: string;
16
18
  }) => boolean;
19
+ /**
20
+ * Params accepted by both `confirmPayment` and `confirmSetup` on top of `return_url`
21
+ */
22
+ export type ExtraConfirmParams = Pick<ConfirmPaymentData & ConfirmSetupData, 'payment_method_data'>;
17
23
  /**
18
24
  * Run the default Stripe confirmation flow for Payment Intent / Setup Intent mode.
19
25
  * Calls `confirmPayment` or `confirmSetup` depending on the intent type.
@@ -21,10 +27,11 @@ export declare const isSubmitButtonDisabled: (params: {
21
27
  * @param elements the Stripe Elements instance bound to the payment element
22
28
  * @param intentType the configured intent type
23
29
  * @param returnUrl the URL Stripe should redirect back to when required
30
+ * @param extraConfirmParams optional params merged into `confirmParams` (for example `payment_method_data.billing_details`)
24
31
  * @returns the confirmation result
25
32
  * @throws StripeAPIError when Stripe returns an error
26
33
  */
27
- export declare const confirmPaymentOrSetup: (stripe: Stripe, elements: StripeElements, intentType: IntentType, returnUrl: string) => Promise<import("@stripe/stripe-js").PaymentIntentResult | import("@stripe/stripe-js").SetupIntentResult>;
34
+ export declare const confirmPaymentOrSetup: (stripe: Stripe, elements: StripeElements, intentType: IntentType, returnUrl: string, extraConfirmParams?: ExtraConfirmParams) => Promise<import("@stripe/stripe-js").PaymentIntentResult | import("@stripe/stripe-js").SetupIntentResult>;
28
35
  /**
29
36
  * Confirm a Checkout Session payment using the checkout actions.
30
37
  * @param checkout the Stripe Checkout instance
@@ -6,9 +6,13 @@
6
6
  * The same rules are model-checked in Quint; see the exhaustive test next to this file.
7
7
  */
8
8
  /**
9
- * Kind of intent a client secret belongs to
9
+ * What a client secret belongs to: a PaymentIntent, a SetupIntent or a Checkout Session
10
10
  */
11
- export type IntentKind = 'payment' | 'setup';
11
+ export type IntentKind = 'payment' | 'setup' | 'checkoutSession';
12
+ /**
13
+ * Attribute a client secret was set through: `intent-client-secret` or `checkout-session-client-secret`
14
+ */
15
+ export type SecretSource = 'intent' | 'checkoutSession';
12
16
  /**
13
17
  * Lifecycle phase of the sheet
14
18
  */
@@ -31,11 +35,15 @@ export type SheetState = Readonly<{
31
35
  /** Whether the sheet should open as soon as loading finishes */
32
36
  openRequested: boolean;
33
37
  /** Secret received while confirming; applied once the confirmation finishes */
34
- deferredClientSecret?: string;
38
+ deferredSecret?: {
39
+ clientSecret: string;
40
+ source: SecretSource;
41
+ };
35
42
  }>;
36
43
  export type SheetEvent = {
37
44
  type: 'secretChanged';
38
45
  clientSecret: string;
46
+ source: SecretSource;
39
47
  } | {
40
48
  type: 'loadSucceeded';
41
49
  generation: number;
@@ -95,7 +103,16 @@ export declare const initialSheetState: SheetState;
95
103
  * @param clientSecret - The `client_secret` of a PaymentIntent (`pi_..._secret_...`) or SetupIntent (`seti_..._secret_...`)
96
104
  * @returns The intent kind, or undefined when the format is not recognized
97
105
  */
98
- export declare const intentKindFromClientSecret: (clientSecret: string) => IntentKind | undefined;
106
+ export declare const intentKindFromClientSecret: (clientSecret: string) => "payment" | "setup" | undefined;
107
+ /**
108
+ * Tell what a client secret belongs to.
109
+ * A secret from `checkout-session-client-secret` is always a Checkout Session: Stripe does not document the format
110
+ * of a Checkout Session client secret, so it is never inspected. Intent secrets are told apart by their prefix.
111
+ * @param clientSecret - The client secret
112
+ * @param source - The attribute the secret was set through
113
+ * @returns The kind, or undefined when an intent secret has an unknown format
114
+ */
115
+ export declare const intentKindOf: (clientSecret: string, source: SecretSource) => IntentKind | undefined;
99
116
  /**
100
117
  * Compute the next state and the effects to perform for an event.
101
118
  * @param state - Current state
@@ -0,0 +1,39 @@
1
+ import type { StripeCheckoutConfirmResult, StripeCheckoutElementsOptions, StripeCheckoutElementsSdk, StripeCheckoutPaymentElementOptions } from '@stripe/stripe-js';
2
+ import type { PaymentSheetOptions } from './stripe-payment-sheet.helpers';
3
+ /**
4
+ * Build the Checkout Payment Element options from the payment sheet options.
5
+ * The Checkout Payment Element takes fewer options than the regular one: `business` and `defaultValues` are not
6
+ * available, so only the layout is passed.
7
+ * @param options - Payment sheet options
8
+ */
9
+ export declare const toCheckoutPaymentElementOptions: (options: PaymentSheetOptions | undefined) => StripeCheckoutPaymentElementOptions;
10
+ /**
11
+ * List the given options that a Checkout Session does not use, sorted by name.
12
+ * Name, phone and address come from the session or from other Checkout elements; the email is passed to `confirm`.
13
+ * @param options - Payment sheet options
14
+ */
15
+ export declare const checkoutIgnoredOptionKeys: (options: PaymentSheetOptions | undefined) => string[];
16
+ /**
17
+ * Build the `elementsOptions` passed to `initCheckoutElementsSdk` from the payment sheet options.
18
+ * @param options - Payment sheet options
19
+ */
20
+ export declare const toCheckoutElementsOptions: (options: PaymentSheetOptions | undefined) => StripeCheckoutElementsOptions | undefined;
21
+ /**
22
+ * Confirm a Checkout Session from the payment sheet.
23
+ *
24
+ * Unlike the default of `confirm`, which always redirects to `returnUrl`, this passes `redirect: 'if_required'`
25
+ * so that payment methods without a redirect finish in the page and can be reported as `paymentSheetCompleted`.
26
+ *
27
+ * Errors are thrown as `StripeAPIError` with a `type` that `isRecoverableConfirmError` understands.
28
+ * A confirm error only carries `code: 'paymentFailed'` or `code: null` (`StripeCheckoutConfirmResult` in @stripe/stripe-js),
29
+ * so whether the session can still be paid is read from `session.status`:
30
+ * - session `expired` or `complete` (before confirming or after a failed confirm): `invalid_request_error`, which ends the sheet
31
+ * - `paymentFailed` on an open session (a decline): `card_error`, which keeps the sheet open
32
+ * - any other confirm error on an open session, or a failure to load the actions: `api_error`, which keeps the sheet open
33
+ * @param checkout - The Checkout instance from `initCheckoutElementsSdk`
34
+ * @param returnUrl - Where Stripe redirects after a redirect-based payment method
35
+ * @param email - Customer email; needed when the session was created without `customer_email` or `customer`
36
+ * @returns The confirmation result
37
+ * @throws StripeAPIError when the actions cannot be loaded, the session can no longer be paid, or the confirmation fails
38
+ */
39
+ export declare const confirmCheckoutSessionSheet: (checkout: StripeCheckoutElementsSdk, returnUrl: string, email?: string) => Promise<StripeCheckoutConfirmResult>;
@@ -1,23 +1,31 @@
1
1
  import { EventEmitter } from '../../stencil-public-runtime';
2
- import type { PaymentIntentResult, SetupIntentResult } from '@stripe/stripe-js';
2
+ import type { PaymentIntentResult, SetupIntentResult, StripeCheckoutConfirmResult } from '@stripe/stripe-js';
3
3
  import type { StripeLoadedEvent } from '../../interfaces';
4
4
  import type { SheetState } from './payment-sheet-state';
5
- import type { PaymentSheetOptions, PaymentSheetPresentResult } from './stripe-payment-sheet.helpers';
5
+ import type { BillingDetailsCollectionPlan, PaymentSheetOptions, PaymentSheetPresentResult } from './stripe-payment-sheet.helpers';
6
6
  /**
7
7
  * A payment sheet: the Payment Element in a modal, with the same events and results as the native PaymentSheet
8
- * of `@capacitor-community/stripe`. PaymentIntent and SetupIntent are told apart by the client secret prefix.
8
+ * of `@capacitor-community/stripe`. PaymentIntent and SetupIntent are told apart by the client secret prefix;
9
+ * a Checkout Session is used when `checkout-session-client-secret` is set.
9
10
  */
10
11
  export declare class StripePaymentSheet {
11
12
  el: HTMLStripePaymentSheetElement;
12
13
  private stripeService;
13
14
  private paymentElementManager;
15
+ /** Extra elements, created from the same Elements instance as the Payment Element so that their values combine */
16
+ private billingAddressElementManager;
17
+ private shippingAddressElementManager;
18
+ private emailElementManager;
14
19
  /** Pending `present()` promise; at most one */
15
20
  private presentPromise?;
16
21
  private resolvePresent?;
17
22
  /** Details for the next emitted event */
18
23
  private lastError?;
19
24
  private lastResult?;
25
+ /** Key of the last requested load (see `loadTarget`), so that unchanged values do not reload */
26
+ private lastLoadKey?;
20
27
  private warnedUnsupportedOptions;
28
+ private warnedCheckoutIgnoredOptions;
21
29
  /**
22
30
  * Your Stripe publishable API key.
23
31
  */
@@ -27,6 +35,12 @@ export declare class StripePaymentSheet {
27
35
  * The prefix decides whether `confirmPayment` or `confirmSetup` is used.
28
36
  */
29
37
  readonly intentClientSecret?: string;
38
+ /**
39
+ * The client secret of a Checkout Session created with `ui_mode: 'elements'` (named `custom` in older Stripe API versions). Its format is not inspected.
40
+ * When it is set, it is used instead of `intent-client-secret` (the same rule as `stripe-payment-element`).
41
+ * Create the session with `customer_email` or `customer`, or pass `options.defaultBillingDetails.email`, because the sheet has no email field.
42
+ */
43
+ readonly checkoutSessionClientSecret?: string;
30
44
  /**
31
45
  * Optional. Making API calls for connected accounts
32
46
  * @info https://stripe.com/docs/connect/authentication
@@ -55,6 +69,8 @@ export declare class StripePaymentSheet {
55
69
  sheet: SheetState;
56
70
  visible: boolean;
57
71
  errorMessage: string;
72
+ /** Extra elements of the current load and the billing details passed at confirmation */
73
+ collection?: BillingDetailsCollectionPlan;
58
74
  /**
59
75
  * Stripe.js and the Payment Element are ready
60
76
  */
@@ -64,9 +80,9 @@ export declare class StripePaymentSheet {
64
80
  */
65
81
  paymentSheetFailedToLoad: EventEmitter<unknown>;
66
82
  /**
67
- * The payment or setup succeeded
83
+ * The payment or setup succeeded. In Checkout Session mode the detail is the result of `confirm` (`{ type: 'success', session }`)
68
84
  */
69
- paymentSheetCompleted: EventEmitter<PaymentIntentResult | SetupIntentResult>;
85
+ paymentSheetCompleted: EventEmitter<PaymentIntentResult | SetupIntentResult | StripeCheckoutConfirmResult>;
70
86
  /**
71
87
  * The customer closed the sheet
72
88
  */
@@ -96,13 +112,42 @@ export declare class StripePaymentSheet {
96
112
  componentWillLoad(): void;
97
113
  componentDidLoad(): void;
98
114
  disconnectedCallback(): void;
115
+ private unmountExtraElements;
116
+ /**
117
+ * Decide what to load from the attributes and load it only when it differs from the last load.
118
+ * A change that does not alter the result (the attribute that is not used, or an empty value that means unset)
119
+ * must neither reload Stripe.js nor cancel an open sheet.
120
+ */
99
121
  private startLoading;
122
+ /**
123
+ * The secret to load and a key of everything the load depends on, or undefined when nothing can be loaded.
124
+ * The Checkout Session wins when both secrets are set (the same rule as `stripe-payment-element`).
125
+ */
126
+ private loadTarget;
100
127
  private dispatch;
101
128
  private perform;
102
129
  private load;
130
+ /**
131
+ * Render the mount points of the plan's extra elements and mount them. Elements a previous load needed but this one does not are unmounted
132
+ * (the managers unmount their previous element themselves when initialized again).
133
+ */
134
+ private mountExtraElements;
135
+ /**
136
+ * Billing details read from the extra elements and the `never` fields, as extra confirm params
137
+ */
138
+ private confirmParams;
103
139
  private confirm;
140
+ /**
141
+ * Run a confirmation and report its result to the state machine.
142
+ * `confirm` is called synchronously, so that its first step still runs inside the customer's submit event.
143
+ * Errors the customer can fix or retry keep the sheet open; others end it with `paymentSheetFailed`.
144
+ */
145
+ private runConfirm;
146
+ private loadCheckoutSession;
147
+ private confirmCheckoutSession;
104
148
  private emit;
105
149
  private warnUnsupportedOptions;
150
+ private warnCheckoutIgnoredOptions;
106
151
  private handleSubmit;
107
152
  /**
108
153
  * The modal closes itself on a backdrop or close button click. Keep it open when the sheet refuses to close (while confirming).
@@ -1,5 +1,6 @@
1
- import type { Appearance, StripePaymentElementOptions } from '@stripe/stripe-js';
2
- import type { PaymentSheetResult } from './payment-sheet-state';
1
+ import type { Appearance, StripeAddressElementChangeEvent, StripeAddressElementOptions, StripeLinkAuthenticationElementOptions, StripePaymentElementOptions } from '@stripe/stripe-js';
2
+ import type { ExtraConfirmParams } from '../stripe-payment-element/stripe-payment-element.helpers';
3
+ import type { IntentKind, PaymentSheetResult } from './payment-sheet-state';
3
4
  /**
4
5
  * Value returned by `present()` (same shape as `presentPaymentSheet()` of `@capacitor-community/stripe`)
5
6
  */
@@ -38,22 +39,28 @@ export type PaymentSheetOptions = {
38
39
  returnURL?: string;
39
40
  /** `alwaysLight` = Stripe theme, `alwaysDark` = Night theme */
40
41
  style?: 'alwaysLight' | 'alwaysDark';
41
- /** Not supported yet on the web */
42
+ /**
43
+ * Which billing details are collected (PaymentIntent / SetupIntent).
44
+ * `never` hides the field and sends the `defaultBillingDetails` value instead (loading fails when it is missing).
45
+ * `email: 'always'` shows an email (Link Authentication) element, `address: 'full'` shows a billing Address Element,
46
+ * `phone: 'always'` asks for the phone in that Address Element (no effect without `address: 'full'`),
47
+ * `name: 'always'` has no effect on the web (it needs Stripe beta access).
48
+ */
42
49
  billingDetailsCollectionConfiguration?: {
43
50
  email?: 'automatic' | 'always' | 'never';
44
51
  name?: 'automatic' | 'always' | 'never';
45
52
  phone?: 'automatic' | 'always' | 'never';
46
53
  address?: 'automatic' | 'full' | 'never';
47
54
  };
48
- /** Not supported yet on the web */
55
+ /** Shows a shipping Address Element prefilled with these values (PaymentIntent only; no effect for a SetupIntent) */
49
56
  shippingDetails?: {
50
57
  name?: string;
51
58
  phone?: string;
52
59
  address?: PaymentSheetAddress;
53
60
  };
54
- /** Not supported yet on the web */
61
+ /** `true` shows Apple Pay when available, `false` hides it */
55
62
  enableApplePay?: boolean;
56
- /** Not supported yet on the web */
63
+ /** `true` shows Google Pay when available, `false` hides it */
57
64
  enableGooglePay?: boolean;
58
65
  /** No effect on the web (the web uses CustomerSession instead) */
59
66
  customerId?: string;
@@ -83,10 +90,61 @@ export declare const toPaymentElementOptions: (options: PaymentSheetOptions | un
83
90
  */
84
91
  export declare const toAppearance: (style: PaymentSheetOptions["style"]) => Appearance | undefined;
85
92
  /**
86
- * List the given options that have no effect on the web (yet), sorted by name.
93
+ * List the given options (or option values, as `option.key`) that have no effect on the web (yet), sorted by name.
87
94
  * @param options - Payment sheet options
95
+ * @param intentKind - Kind of the intent, when known
88
96
  */
89
- export declare const unsupportedOptionKeys: (options: PaymentSheetOptions | undefined) => string[];
97
+ export declare const unsupportedOptionKeys: (options: PaymentSheetOptions | undefined, intentKind?: IntentKind) => string[];
98
+ /**
99
+ * `payment_method_data.billing_details` passed to `confirmPayment` / `confirmSetup`
100
+ */
101
+ export type ConfirmBillingDetails = NonNullable<NonNullable<ExtraConfirmParams['payment_method_data']>['billing_details']>;
102
+ /**
103
+ * Extra elements to show next to the Payment Element, and the billing details to pass at confirmation
104
+ */
105
+ export type BillingDetailsCollectionPlan = {
106
+ /** Billing details whose Payment Element field is `never`, taken from `defaultBillingDetails` */
107
+ fixedBillingDetails: ConfirmBillingDetails;
108
+ /** Whether the phone typed into the billing Address Element is passed at confirmation */
109
+ collectPhoneFromAddress: boolean;
110
+ /** Options of the billing Address Element (`address: 'full'`) */
111
+ billingAddressElement?: StripeAddressElementOptions;
112
+ /** Options of the shipping Address Element (`shippingDetails`, PaymentIntent only) */
113
+ shippingAddressElement?: StripeAddressElementOptions;
114
+ /** Options of the email (Link Authentication) element (`email: 'always'`) */
115
+ emailElement?: StripeLinkAuthenticationElementOptions;
116
+ };
117
+ /**
118
+ * Values read from the extra elements right before confirmation
119
+ */
120
+ export type CollectedDetails = {
121
+ billingAddress?: Pick<StripeAddressElementChangeEvent, 'complete' | 'value'>;
122
+ /** Email of the latest change event of the email element; undefined until it reports one */
123
+ email?: string;
124
+ /** `complete` of the latest change event of the email element; undefined until it reports one */
125
+ emailComplete?: boolean;
126
+ };
127
+ /**
128
+ * Tell whether an error was raised by this sheet's own validation (its message is an i18n key), rather than by Stripe (already localized).
129
+ * @param error - Error thrown while confirming
130
+ */
131
+ export declare const isSheetValidationError: (error: unknown) => boolean;
132
+ /**
133
+ * Decide which extra elements to show and which billing details to pass at confirmation (PaymentIntent / SetupIntent mode).
134
+ * @param options - Payment sheet options
135
+ * @param intentKind - Kind of the intent being confirmed
136
+ * @throws Error when a `never` field has no value in `defaultBillingDetails`
137
+ */
138
+ export declare const planBillingDetailsCollection: (options: PaymentSheetOptions | undefined, intentKind: IntentKind) => BillingDetailsCollectionPlan;
139
+ /**
140
+ * Build `payment_method_data.billing_details` for the confirmation.
141
+ * Values fixed by a `never` field win over the values typed into the extra elements.
142
+ * @param plan - Result of `planBillingDetailsCollection`
143
+ * @param collected - Values read from the extra elements
144
+ * @returns The billing details, or undefined when nothing has to be passed
145
+ * @throws Error with `type: 'validation_error'` when an extra element is not complete
146
+ */
147
+ export declare const collectedBillingDetails: (plan: BillingDetailsCollectionPlan, collected: CollectedDetails) => ConfirmBillingDetails | undefined;
90
148
  /**
91
149
  * Tell whether a confirmation error lets the customer try again in the open sheet.
92
150
  * Other errors (for example `invalid_request_error` for an intent that already succeeded) end the sheet with `paymentSheetFailed`.
@@ -7,13 +7,13 @@
7
7
  import { HTMLStencilElement, JSXBase } from "./stencil-public-runtime";
8
8
  import { AddressSubmitEvent, AddressSubmitHandler } from "./components/stripe-address-element/stripe-address-element";
9
9
  import { CurrencySelectorChangeEvent, CurrencySelectorChangeHandler, DefaultFormSubmitResult, FormSubmitEvent, FormSubmitHandler, InitStripeOptions, IntentType, LinkAuthenticationElementChangeEvent, LinkAuthenticationElementChangeHandler, PaymentRequestButtonOption, PaymentRequestPaymentMethodEventHandler, PaymentRequestShippingAddressEventHandler, PaymentRequestShippingOptionEventHandler, ProgressStatus, StripeDidLoadedHandler, StripeLoadedEvent } from "./interfaces";
10
- import { PaymentIntentResult, PaymentRequestOptions, PaymentRequestWallet, SetupIntentResult, StripeExpressCheckoutElementClickEvent, StripeExpressCheckoutElementConfirmEvent } from "@stripe/stripe-js";
10
+ import { PaymentIntentResult, PaymentRequestOptions, PaymentRequestWallet, SetupIntentResult, StripeCheckoutConfirmResult, StripeExpressCheckoutElementClickEvent, StripeExpressCheckoutElementConfirmEvent } from "@stripe/stripe-js";
11
11
  import { ExpressCheckoutElementOptions } from "./services/interfaces";
12
12
  import { CheckoutSessionFormSubmitResult, InitCheckoutSessionOptions, PaymentElementSubmitEvent, PaymentElementSubmitHandler } from "./components/stripe-payment-element/stripe-payment-element";
13
13
  import { PaymentSheetOptions, PaymentSheetPresentResult } from "./components/stripe-payment-sheet/stripe-payment-sheet.helpers";
14
14
  export { AddressSubmitEvent, AddressSubmitHandler } from "./components/stripe-address-element/stripe-address-element";
15
15
  export { CurrencySelectorChangeEvent, CurrencySelectorChangeHandler, DefaultFormSubmitResult, FormSubmitEvent, FormSubmitHandler, InitStripeOptions, IntentType, LinkAuthenticationElementChangeEvent, LinkAuthenticationElementChangeHandler, PaymentRequestButtonOption, PaymentRequestPaymentMethodEventHandler, PaymentRequestShippingAddressEventHandler, PaymentRequestShippingOptionEventHandler, ProgressStatus, StripeDidLoadedHandler, StripeLoadedEvent } from "./interfaces";
16
- export { PaymentIntentResult, PaymentRequestOptions, PaymentRequestWallet, SetupIntentResult, StripeExpressCheckoutElementClickEvent, StripeExpressCheckoutElementConfirmEvent } from "@stripe/stripe-js";
16
+ export { PaymentIntentResult, PaymentRequestOptions, PaymentRequestWallet, SetupIntentResult, StripeCheckoutConfirmResult, StripeExpressCheckoutElementClickEvent, StripeExpressCheckoutElementConfirmEvent } from "@stripe/stripe-js";
17
17
  export { ExpressCheckoutElementOptions } from "./services/interfaces";
18
18
  export { CheckoutSessionFormSubmitResult, InitCheckoutSessionOptions, PaymentElementSubmitEvent, PaymentElementSubmitHandler } from "./components/stripe-payment-element/stripe-payment-element";
19
19
  export { PaymentSheetOptions, PaymentSheetPresentResult } from "./components/stripe-payment-sheet/stripe-payment-sheet.helpers";
@@ -649,7 +649,8 @@ export namespace Components {
649
649
  }
650
650
  /**
651
651
  * A payment sheet: the Payment Element in a modal, with the same events and results as the native PaymentSheet
652
- * of `@capacitor-community/stripe`. PaymentIntent and SetupIntent are told apart by the client secret prefix.
652
+ * of `@capacitor-community/stripe`. PaymentIntent and SetupIntent are told apart by the client secret prefix;
653
+ * a Checkout Session is used when `checkout-session-client-secret` is set.
653
654
  */
654
655
  interface StripePaymentSheet {
655
656
  /**
@@ -662,6 +663,10 @@ export namespace Components {
662
663
  * @default 'Pay'
663
664
  */
664
665
  "buttonLabel": string;
666
+ /**
667
+ * The client secret of a Checkout Session created with `ui_mode: 'elements'` (named `custom` in older Stripe API versions). Its format is not inspected. When it is set, it is used instead of `intent-client-secret` (the same rule as `stripe-payment-element`). Create the session with `customer_email` or `customer`, or pass `options.defaultBillingDetails.email`, because the sheet has no email field.
668
+ */
669
+ "checkoutSessionClientSecret"?: string;
665
670
  /**
666
671
  * The client secret of a PaymentIntent (`pi_..._secret_...`) or a SetupIntent (`seti_..._secret_...`). The prefix decides whether `confirmPayment` or `confirmSetup` is used.
667
672
  */
@@ -930,13 +935,14 @@ declare global {
930
935
  interface HTMLStripePaymentSheetElementEventMap {
931
936
  "paymentSheetLoaded": StripeLoadedEvent;
932
937
  "paymentSheetFailedToLoad": unknown;
933
- "paymentSheetCompleted": PaymentIntentResult | SetupIntentResult;
938
+ "paymentSheetCompleted": PaymentIntentResult | SetupIntentResult | StripeCheckoutConfirmResult;
934
939
  "paymentSheetCanceled": void;
935
940
  "paymentSheetFailed": unknown;
936
941
  }
937
942
  /**
938
943
  * A payment sheet: the Payment Element in a modal, with the same events and results as the native PaymentSheet
939
- * of `@capacitor-community/stripe`. PaymentIntent and SetupIntent are told apart by the client secret prefix.
944
+ * of `@capacitor-community/stripe`. PaymentIntent and SetupIntent are told apart by the client secret prefix;
945
+ * a Checkout Session is used when `checkout-session-client-secret` is set.
940
946
  */
941
947
  interface HTMLStripePaymentSheetElement extends Components.StripePaymentSheet, HTMLStencilElement {
942
948
  addEventListener<K extends keyof HTMLStripePaymentSheetElementEventMap>(type: K, listener: (this: HTMLStripePaymentSheetElement, ev: StripePaymentSheetCustomEvent<HTMLStripePaymentSheetElementEventMap[K]>) => any, options?: boolean | AddEventListenerOptions): void;
@@ -1478,7 +1484,8 @@ declare namespace LocalJSX {
1478
1484
  }
1479
1485
  /**
1480
1486
  * A payment sheet: the Payment Element in a modal, with the same events and results as the native PaymentSheet
1481
- * of `@capacitor-community/stripe`. PaymentIntent and SetupIntent are told apart by the client secret prefix.
1487
+ * of `@capacitor-community/stripe`. PaymentIntent and SetupIntent are told apart by the client secret prefix;
1488
+ * a Checkout Session is used when `checkout-session-client-secret` is set.
1482
1489
  */
1483
1490
  interface StripePaymentSheet {
1484
1491
  /**
@@ -1491,6 +1498,10 @@ declare namespace LocalJSX {
1491
1498
  * @default 'Pay'
1492
1499
  */
1493
1500
  "buttonLabel"?: string;
1501
+ /**
1502
+ * The client secret of a Checkout Session created with `ui_mode: 'elements'` (named `custom` in older Stripe API versions). Its format is not inspected. When it is set, it is used instead of `intent-client-secret` (the same rule as `stripe-payment-element`). Create the session with `customer_email` or `customer`, or pass `options.defaultBillingDetails.email`, because the sheet has no email field.
1503
+ */
1504
+ "checkoutSessionClientSecret"?: string;
1494
1505
  /**
1495
1506
  * The client secret of a PaymentIntent (`pi_..._secret_...`) or a SetupIntent (`seti_..._secret_...`). The prefix decides whether `confirmPayment` or `confirmSetup` is used.
1496
1507
  */
@@ -1500,9 +1511,9 @@ declare namespace LocalJSX {
1500
1511
  */
1501
1512
  "onPaymentSheetCanceled"?: (event: StripePaymentSheetCustomEvent<void>) => void;
1502
1513
  /**
1503
- * The payment or setup succeeded
1514
+ * The payment or setup succeeded. In Checkout Session mode the detail is the result of `confirm` (`{ type: 'success', session }`)
1504
1515
  */
1505
- "onPaymentSheetCompleted"?: (event: StripePaymentSheetCustomEvent<PaymentIntentResult | SetupIntentResult>) => void;
1516
+ "onPaymentSheetCompleted"?: (event: StripePaymentSheetCustomEvent<PaymentIntentResult | SetupIntentResult | StripeCheckoutConfirmResult>) => void;
1506
1517
  /**
1507
1518
  * The confirmation failed with an error the customer cannot fix in the sheet
1508
1519
  */
@@ -1623,6 +1634,7 @@ declare namespace LocalJSX {
1623
1634
  interface StripePaymentSheetAttributes {
1624
1635
  "publishableKey": string;
1625
1636
  "intentClientSecret": string;
1637
+ "checkoutSessionClientSecret": string;
1626
1638
  "stripeAccount": string;
1627
1639
  "open": boolean;
1628
1640
  "sheetTitle": string;
@@ -1682,7 +1694,8 @@ declare module "@stencil/core" {
1682
1694
  "stripe-payment-request-button": LocalJSX.IntrinsicElements["stripe-payment-request-button"] & JSXBase.HTMLAttributes<HTMLStripePaymentRequestButtonElement>;
1683
1695
  /**
1684
1696
  * A payment sheet: the Payment Element in a modal, with the same events and results as the native PaymentSheet
1685
- * of `@capacitor-community/stripe`. PaymentIntent and SetupIntent are told apart by the client secret prefix.
1697
+ * of `@capacitor-community/stripe`. PaymentIntent and SetupIntent are told apart by the client secret prefix;
1698
+ * a Checkout Session is used when `checkout-session-client-secret` is set.
1686
1699
  */
1687
1700
  "stripe-payment-sheet": LocalJSX.IntrinsicElements["stripe-payment-sheet"] & JSXBase.HTMLAttributes<HTMLStripePaymentSheetElement>;
1688
1701
  }
@@ -59,6 +59,8 @@ export type AddressElementState = {
59
59
  export type LinkAuthenticationElementState = {
60
60
  errorMessage: string;
61
61
  email?: string;
62
+ /** `complete` of the latest change event: whether the email is valid. Undefined until the element reports a change */
63
+ complete?: boolean;
62
64
  };
63
65
  /**
64
66
  * Core Stripe service interface
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stripe-pwa-elements",
3
- "version": "4.0.2",
3
+ "version": "4.0.4",
4
4
  "description": "Framework-agnostic Stripe Payment Elements as Web Components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.js",
@@ -64,6 +64,7 @@
64
64
  "@eslint/eslintrc": "^3.3.3",
65
65
  "@eslint/js": "^9.39.2",
66
66
  "@jsr/circleci__jest-circleci-coverage": "^0.4.0",
67
+ "@playwright/test": "1.56.1",
67
68
  "@stencil-community/eslint-plugin": "^0.10.0",
68
69
  "@stencil/sass": "^3.2.3",
69
70
  "@stencil/store": "^2.2.1",
@@ -106,6 +107,7 @@
106
107
  "example:serve": "pnpm dlx serve example",
107
108
  "changeset": "changeset",
108
109
  "changeset:version": "changeset version",
109
- "changeset:publish": "pnpm run build && pnpm -F hono-stripe-elements run build && changeset publish"
110
+ "changeset:publish": "pnpm run build && pnpm -F hono-stripe-elements run build && changeset publish",
111
+ "test:e2e:stripe": "playwright test -c e2e/stripe/playwright.config.ts"
110
112
  }
111
113
  }