stripe-pwa-elements 4.0.1 → 4.0.2

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 (100) hide show
  1. package/dist/cjs/factory-tenFFIul.js +1200 -0
  2. package/dist/cjs/{factory-Cd2VI_N2.js → i18n-FhEOc8vz.js} +6 -1149
  3. package/dist/cjs/ion-icon_2.cjs.entry.js +723 -0
  4. package/dist/cjs/loader.cjs.js +1 -1
  5. package/dist/cjs/stripe-address-element.cjs.entry.js +5 -4
  6. package/dist/cjs/stripe-card-element-modal.cjs.entry.js +3 -2
  7. package/dist/cjs/{stripe-card-element_2.cjs.entry.js → stripe-card-element.cjs.entry.js} +8 -93
  8. package/dist/cjs/stripe-currency-selector.cjs.entry.js +4 -3
  9. package/dist/cjs/stripe-elements.cjs.js +1 -1
  10. package/dist/cjs/stripe-express-checkout-element.cjs.entry.js +24 -5
  11. package/dist/cjs/stripe-link-authentication-element.cjs.entry.js +4 -3
  12. package/dist/cjs/stripe-payment-element.cjs.entry.js +12 -124
  13. package/dist/cjs/stripe-payment-element.helpers-DukP33RI.js +122 -0
  14. package/dist/cjs/stripe-payment-request-button.cjs.entry.js +2 -2
  15. package/dist/cjs/stripe-payment-sheet.cjs.entry.js +506 -0
  16. package/dist/collection/collection-manifest.json +2 -1
  17. package/dist/collection/components/stripe-card-element/stripe-card-element.js +3 -2
  18. package/dist/collection/components/stripe-card-element-modal/stripe-card-element-modal.js +4 -3
  19. package/dist/collection/components/stripe-express-checkout-element/stripe-express-checkout-element.js +18 -0
  20. package/dist/collection/components/stripe-modal/stripe-modal.css +23 -1
  21. package/dist/collection/components/stripe-modal/stripe-modal.js +130 -1
  22. package/dist/collection/components/stripe-payment-request-button/stripe-payment-request-button.js +3 -3
  23. package/dist/collection/components/stripe-payment-sheet/payment-sheet-state.js +179 -0
  24. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.css +68 -0
  25. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.helpers.js +90 -0
  26. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.js +544 -0
  27. package/dist/collection/services/express-checkout-element-manager.js +36 -2
  28. package/dist/collection/services/stripe-service.js +20 -6
  29. package/dist/collection/utils/focus.js +76 -0
  30. package/dist/collection/utils/i18n.js +6 -0
  31. package/dist/components/factory.js +1 -1
  32. package/dist/components/i18n.js +1 -0
  33. package/dist/components/stripe-address-element.js +1 -1
  34. package/dist/components/stripe-card-element-modal.js +1 -1
  35. package/dist/components/stripe-card-element2.js +1 -1
  36. package/dist/components/stripe-currency-selector.js +1 -1
  37. package/dist/components/stripe-express-checkout-element.js +1 -1
  38. package/dist/components/stripe-link-authentication-element.js +1 -1
  39. package/dist/components/stripe-modal2.js +1 -1
  40. package/dist/components/stripe-payment-element.helpers.js +1 -0
  41. package/dist/components/stripe-payment-element.js +1 -1
  42. package/dist/components/stripe-payment-request-button2.js +1 -1
  43. package/dist/components/stripe-payment-sheet.d.ts +11 -0
  44. package/dist/components/stripe-payment-sheet.js +1 -0
  45. package/dist/esm/factory-Cd6OGTWN.js +1198 -0
  46. package/dist/esm/{factory-VTa1Gc94.js → i18n-B6JoQetF.js} +7 -1149
  47. package/dist/esm/ion-icon_2.entry.js +720 -0
  48. package/dist/esm/loader.js +1 -1
  49. package/dist/esm/stripe-address-element.entry.js +2 -1
  50. package/dist/esm/stripe-card-element-modal.entry.js +3 -2
  51. package/dist/esm/{stripe-card-element_2.entry.js → stripe-card-element.entry.js} +6 -90
  52. package/dist/esm/stripe-currency-selector.entry.js +2 -1
  53. package/dist/esm/stripe-elements.js +1 -1
  54. package/dist/esm/stripe-express-checkout-element.entry.js +20 -1
  55. package/dist/esm/stripe-link-authentication-element.entry.js +2 -1
  56. package/dist/esm/stripe-payment-element.entry.js +4 -116
  57. package/dist/esm/stripe-payment-element.helpers-CipV87b8.js +117 -0
  58. package/dist/esm/stripe-payment-request-button.entry.js +2 -2
  59. package/dist/esm/stripe-payment-sheet.entry.js +504 -0
  60. package/dist/stripe-elements/{p-ae0c336e.entry.js → p-4891edf0.entry.js} +1 -1
  61. package/dist/stripe-elements/p-5338bc5e.entry.js +1 -0
  62. package/dist/stripe-elements/p-6a9c8b7a.entry.js +1 -0
  63. package/dist/stripe-elements/p-7fe4a287.entry.js +1 -0
  64. package/dist/stripe-elements/p-915b86ed.entry.js +1 -0
  65. package/dist/stripe-elements/p-B6JoQetF.js +1 -0
  66. package/dist/stripe-elements/p-C7MQk9FK.js +1 -0
  67. package/dist/stripe-elements/p-DFAhQS0n.js +1 -0
  68. package/dist/stripe-elements/p-b06a254f.entry.js +1 -0
  69. package/dist/stripe-elements/p-b91c4fa7.entry.js +1 -0
  70. package/dist/stripe-elements/p-ba791c8f.entry.js +1 -0
  71. package/dist/stripe-elements/p-e7372ca7.entry.js +1 -0
  72. package/dist/stripe-elements/p-f892e375.entry.js +1 -0
  73. package/dist/stripe-elements/stripe-elements.esm.js +1 -1
  74. package/dist/types/components/stripe-card-element/stripe-card-element.d.ts +2 -1
  75. package/dist/types/components/stripe-card-element-modal/stripe-card-element-modal.d.ts +2 -1
  76. package/dist/types/components/stripe-express-checkout-element/stripe-express-checkout-element.d.ts +5 -0
  77. package/dist/types/components/stripe-modal/stripe-modal.d.ts +43 -0
  78. package/dist/types/components/stripe-payment-request-button/stripe-payment-request-button.d.ts +1 -1
  79. package/dist/types/components/stripe-payment-sheet/payment-sheet-state.d.ts +104 -0
  80. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.d.ts +112 -0
  81. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.helpers.d.ts +95 -0
  82. package/dist/types/components.d.ts +169 -10
  83. package/dist/types/index.d.ts +2 -0
  84. package/dist/types/services/interfaces.d.ts +1 -0
  85. package/dist/types/services/stripe-service.d.ts +7 -2
  86. package/dist/types/utils/focus.d.ts +15 -0
  87. package/package.json +5 -3
  88. package/readme.md +42 -6
  89. package/dist/cjs/ion-icon.cjs.entry.js +0 -431
  90. package/dist/components/utils.js +0 -1
  91. package/dist/esm/ion-icon.entry.js +0 -429
  92. package/dist/stripe-elements/p-1bd46766.entry.js +0 -1
  93. package/dist/stripe-elements/p-1c6e0a45.entry.js +0 -1
  94. package/dist/stripe-elements/p-3f42ca0c.entry.js +0 -1
  95. package/dist/stripe-elements/p-5cf62945.entry.js +0 -1
  96. package/dist/stripe-elements/p-74de1556.entry.js +0 -1
  97. package/dist/stripe-elements/p-76e57d78.entry.js +0 -1
  98. package/dist/stripe-elements/p-840d499f.entry.js +0 -1
  99. package/dist/stripe-elements/p-CrjrbGJ3.js +0 -1
  100. package/dist/stripe-elements/p-cfd8e081.entry.js +0 -1
@@ -0,0 +1,122 @@
1
+ 'use strict';
2
+
3
+ var error = require('./error-FFC4kSs5.js');
4
+
5
+ /**
6
+ * Determine whether the submit button should be disabled.
7
+ * For Checkout Session mode: the checkout is ready once Stripe finished loading.
8
+ * For Payment Intent / Setup Intent mode: an intent client secret must be present.
9
+ * @param params progress / loading state and the current mode information
10
+ * @returns true when the submit button should be disabled
11
+ */
12
+ const isSubmitButtonDisabled = (params) => {
13
+ const { progress, isCheckoutSession, loadStripeStatus, intentClientSecret } = params;
14
+ const hasValidSecret = isCheckoutSession ? loadStripeStatus === 'success' : intentClientSecret != null && intentClientSecret !== '';
15
+ return progress === 'loading' || !hasValidSecret;
16
+ };
17
+ /**
18
+ * Run the default Stripe confirmation flow for Payment Intent / Setup Intent mode.
19
+ * Calls `confirmPayment` or `confirmSetup` depending on the intent type.
20
+ * @param stripe the loaded Stripe.js instance
21
+ * @param elements the Stripe Elements instance bound to the payment element
22
+ * @param intentType the configured intent type
23
+ * @param returnUrl the URL Stripe should redirect back to when required
24
+ * @returns the confirmation result
25
+ * @throws StripeAPIError when Stripe returns an error
26
+ */
27
+ const confirmPaymentOrSetup = async (stripe, elements, intentType, returnUrl) => {
28
+ const result = await (() => {
29
+ if (intentType === 'payment') {
30
+ return stripe.confirmPayment({
31
+ elements,
32
+ confirmParams: {
33
+ return_url: returnUrl,
34
+ },
35
+ redirect: 'if_required',
36
+ });
37
+ }
38
+ return stripe.confirmSetup({
39
+ elements,
40
+ confirmParams: {
41
+ return_url: returnUrl,
42
+ },
43
+ redirect: 'if_required',
44
+ });
45
+ })();
46
+ if (result.error) {
47
+ throw new error.StripeAPIError(result.error);
48
+ }
49
+ return result;
50
+ };
51
+ /**
52
+ * Confirm a Checkout Session payment using the checkout actions.
53
+ * @param checkout the Stripe Checkout instance
54
+ * @param returnUrl the URL Stripe should redirect back to when required
55
+ * @returns the confirmation result
56
+ * @throws StripeAPIError when loading actions or confirming fails
57
+ */
58
+ const confirmCheckoutSession = async (checkout, returnUrl) => {
59
+ var _a;
60
+ // Load actions from the checkout session
61
+ const loadActionsResult = await checkout.loadActions();
62
+ if (loadActionsResult.type === 'error') {
63
+ // Create a StripeError-compatible object from the Checkout Session error
64
+ const stripeError = {
65
+ type: 'api_error',
66
+ code: loadActionsResult.error.code || 'checkout_session_error',
67
+ message: loadActionsResult.error.message,
68
+ };
69
+ throw new error.StripeAPIError(stripeError);
70
+ }
71
+ const { actions } = loadActionsResult;
72
+ // Confirm the payment using checkout session actions
73
+ const result = await actions.confirm({
74
+ returnUrl,
75
+ redirect: 'if_required',
76
+ });
77
+ if (result.type === 'error') {
78
+ // Create a StripeError-compatible object from the confirm error
79
+ const stripeError = {
80
+ type: 'card_error',
81
+ code: result.error.code || 'payment_failed',
82
+ message: result.error.message,
83
+ decline_code: result.error.code === 'paymentFailed' ? (_a = result.error.paymentFailed) === null || _a === void 0 ? void 0 : _a.declineCode : undefined,
84
+ };
85
+ throw new error.StripeAPIError(stripeError);
86
+ }
87
+ return result;
88
+ };
89
+ /**
90
+ * Resolve the mode-specific properties for a submit event.
91
+ * Picks the Checkout or Elements payload depending on the active mode and
92
+ * reports a descriptive error string when the required instance is missing.
93
+ * @param params the resolved Stripe instances and client secrets for the current mode
94
+ * @returns the submit event props, or an error message when an instance is missing
95
+ */
96
+ const buildSubmitEventProps = (params) => {
97
+ const { stripe, isCheckoutSession, checkout, checkoutSessionClientSecret, elements, intentClientSecret } = params;
98
+ const props = {
99
+ stripe,
100
+ };
101
+ if (isCheckoutSession) {
102
+ // Checkout Session mode
103
+ if (checkout == null) {
104
+ return { error: 'Checkout not properly initialized' };
105
+ }
106
+ props.checkout = checkout;
107
+ props.checkoutSessionClientSecret = checkoutSessionClientSecret;
108
+ return { props };
109
+ }
110
+ // Payment Intent / Setup Intent mode
111
+ if (elements == null) {
112
+ return { error: 'Elements not properly initialized' };
113
+ }
114
+ props.elements = elements;
115
+ props.intentClientSecret = intentClientSecret;
116
+ return { props };
117
+ };
118
+
119
+ exports.buildSubmitEventProps = buildSubmitEventProps;
120
+ exports.confirmCheckoutSession = confirmCheckoutSession;
121
+ exports.confirmPaymentOrSetup = confirmPaymentOrSetup;
122
+ exports.isSubmitButtonDisabled = isSubmitButtonDisabled;
@@ -87,7 +87,7 @@ const StripePaymentRequestButton = class {
87
87
  console.warn('[stripe-pwa-elements] <stripe-payment-request-button> is deprecated. ' +
88
88
  'stripe.paymentRequest() is being removed in Stripe.js 9.x (deprecated 2025-09-30 / removed 2026-03-25). ' +
89
89
  'Please migrate to <stripe-express-checkout-element>, which supports Apple Pay, Google Pay, Link, PayPal, and more. ' +
90
- 'Migration guide: https://hideokamoto.github.io/stripe-pwa-elements/guides/migrate-payment-request-button-to-express-checkout/');
90
+ 'Migration guide: https://stripe-pwa-elements-docs.wp-kyoto.workers.dev/guides/migrate-payment-request-button-to-express-checkout/');
91
91
  }
92
92
  /**
93
93
  * @param option
@@ -194,7 +194,7 @@ const StripePaymentRequestButton = class {
194
194
  this.stripe = undefined;
195
195
  }
196
196
  render() {
197
- return (index.h(index.Host, { key: 'dd3ae348f9e9c798acdeca095ad9c157afd4734f' }, index.h("div", { key: 'f2e13b6980318ede1812d4f54223b7aeb9cfc51b', id: "payment-request" }, index.h("div", { key: 'ff6c1218924044d1ffc11354909f25c1745ef254', id: "payment-request-button" })), index.h("slot", { key: 'ec2131a0503baa15cdcf3571040e9ce6040da708' })));
197
+ return (index.h(index.Host, { key: '644a4b729c72e87b42df5e1b43262d3195e7ebc6' }, index.h("div", { key: 'aff26789868bbec0f1f6abc463fb14d7f3e73c1b', id: "payment-request" }, index.h("div", { key: '074a25f3c5b2575696ddaeacf2715935212964a5', id: "payment-request-button" })), index.h("slot", { key: '5173400bd63ab201f02934cea4edcab4bb7eed9c' })));
198
198
  }
199
199
  get el() { return index.getElement(this); }
200
200
  };
@@ -0,0 +1,506 @@
1
+ 'use strict';
2
+
3
+ var index = require('./index-Dkb0SxZc.js');
4
+ var i18n = require('./i18n-FhEOc8vz.js');
5
+ var factory = require('./factory-tenFFIul.js');
6
+ var stripePaymentElement_helpers = require('./stripe-payment-element.helpers-DukP33RI.js');
7
+ require('./index-CYbA1N_k.js');
8
+ require('./error-FFC4kSs5.js');
9
+
10
+ /**
11
+ * State machine behind `<stripe-payment-sheet>`.
12
+ *
13
+ * Pure functions only: the component feeds events in and performs the returned effects
14
+ * (loading Stripe.js, showing the modal, confirming, emitting events, resolving `present()`).
15
+ * The same rules are model-checked in Quint; see the exhaustive test next to this file.
16
+ */
17
+ const initialSheetState = {
18
+ phase: 'idle',
19
+ generation: 0,
20
+ pendingPresent: false,
21
+ openRequested: false,
22
+ };
23
+ const CLIENT_SECRET_PATTERNS = [
24
+ [/^pi_[A-Za-z0-9]+_secret_[A-Za-z0-9]+$/, 'payment'],
25
+ [/^seti_[A-Za-z0-9]+_secret_[A-Za-z0-9]+$/, 'setup'],
26
+ ];
27
+ /**
28
+ * Tell whether a client secret belongs to a PaymentIntent or a SetupIntent from its prefix.
29
+ * @param clientSecret - The `client_secret` of a PaymentIntent (`pi_..._secret_...`) or SetupIntent (`seti_..._secret_...`)
30
+ * @returns The intent kind, or undefined when the format is not recognized
31
+ */
32
+ const intentKindFromClientSecret = (clientSecret) => {
33
+ const match = CLIENT_SECRET_PATTERNS.find(([pattern]) => pattern.test(clientSecret));
34
+ return match === null || match === void 0 ? void 0 : match[1];
35
+ };
36
+ const unchanged = (state) => ({ state, effects: [] });
37
+ /**
38
+ * Resolve the pending `present()` promise, if any.
39
+ */
40
+ const resolvePending = (state, result) => {
41
+ if (!state.pendingPresent) {
42
+ return unchanged(state);
43
+ }
44
+ return { state: Object.assign(Object.assign({}, state), { pendingPresent: false }), effects: [{ type: 'resolvePresent', result }] };
45
+ };
46
+ /**
47
+ * Close the sheet as canceled: hide it, emit the event and resolve `present()`.
48
+ */
49
+ const cancel = (state) => {
50
+ const resolved = resolvePending(Object.assign(Object.assign({}, state), { openRequested: false }), 'paymentSheetCanceled');
51
+ const visible = state.phase === 'presented' || state.phase === 'confirming';
52
+ return {
53
+ state: resolved.state,
54
+ effects: [...(visible ? [{ type: 'hide' }] : []), { type: 'emit', event: 'paymentSheetCanceled' }, ...resolved.effects],
55
+ };
56
+ };
57
+ const changeSecret = (state, clientSecret) => {
58
+ if (clientSecret === '') {
59
+ return unchanged(state);
60
+ }
61
+ // Never drop the result of a running confirmation; apply the new secret once it finishes
62
+ if (state.phase === 'confirming') {
63
+ return unchanged(Object.assign(Object.assign({}, state), { deferredClientSecret: clientSecret }));
64
+ }
65
+ const canceled = state.phase === 'presented' ? cancel(state) : unchanged(state);
66
+ const generation = state.generation + 1;
67
+ const intentKind = intentKindFromClientSecret(clientSecret);
68
+ if (intentKind == null) {
69
+ const resolved = resolvePending(Object.assign(Object.assign({}, canceled.state), { phase: 'loadFailed', generation, intentKind: undefined, openRequested: false }), 'paymentSheetFailed');
70
+ return {
71
+ state: resolved.state,
72
+ effects: [...canceled.effects, { type: 'emit', event: 'paymentSheetFailedToLoad' }, ...resolved.effects],
73
+ };
74
+ }
75
+ return {
76
+ state: Object.assign(Object.assign({}, canceled.state), { phase: 'loading', generation, intentKind }),
77
+ effects: [...canceled.effects, { type: 'load', generation, clientSecret, intentKind }],
78
+ };
79
+ };
80
+ /**
81
+ * Apply a secret that arrived while confirming.
82
+ */
83
+ const applyDeferredSecret = (result) => {
84
+ const { deferredClientSecret } = result.state;
85
+ if (deferredClientSecret == null) {
86
+ return result;
87
+ }
88
+ const next = changeSecret(Object.assign(Object.assign({}, result.state), { deferredClientSecret: undefined }), deferredClientSecret);
89
+ return { state: next.state, effects: [...result.effects, ...next.effects] };
90
+ };
91
+ const isCurrentConfirmation = (state, generation) => state.phase === 'confirming' && state.generation === generation;
92
+ /**
93
+ * Compute the next state and the effects to perform for an event.
94
+ * @param state - Current state
95
+ * @param event - Event to handle
96
+ */
97
+ const transition = (state, event) => {
98
+ switch (event.type) {
99
+ case 'secretChanged':
100
+ return changeSecret(state, event.clientSecret);
101
+ case 'loadSucceeded': {
102
+ if (event.generation !== state.generation || state.phase !== 'loading') {
103
+ return unchanged(state);
104
+ }
105
+ const open = state.openRequested;
106
+ return {
107
+ state: Object.assign(Object.assign({}, state), { phase: open ? 'presented' : 'ready', openRequested: false }),
108
+ effects: [{ type: 'emit', event: 'paymentSheetLoaded' }, ...(open ? [{ type: 'show' }] : [])],
109
+ };
110
+ }
111
+ case 'loadFailed': {
112
+ if (event.generation !== state.generation || state.phase !== 'loading') {
113
+ return unchanged(state);
114
+ }
115
+ const resolved = resolvePending(Object.assign(Object.assign({}, state), { phase: 'loadFailed', openRequested: false }), 'paymentSheetFailed');
116
+ return { state: resolved.state, effects: [{ type: 'emit', event: 'paymentSheetFailedToLoad' }, ...resolved.effects] };
117
+ }
118
+ case 'presentRequested':
119
+ if (state.pendingPresent) {
120
+ return unchanged(state);
121
+ }
122
+ switch (state.phase) {
123
+ case 'ready':
124
+ return { state: Object.assign(Object.assign({}, state), { phase: 'presented', pendingPresent: true }), effects: [{ type: 'show' }] };
125
+ case 'idle':
126
+ case 'loading':
127
+ return unchanged(Object.assign(Object.assign({}, state), { pendingPresent: true, openRequested: true }));
128
+ case 'presented':
129
+ case 'confirming':
130
+ // Already shown through the `open` attribute: wait for its result
131
+ return unchanged(Object.assign(Object.assign({}, state), { pendingPresent: true }));
132
+ default:
133
+ // loadFailed / completed / errored: nothing can be shown
134
+ return { state, effects: [{ type: 'resolvePresent', result: 'paymentSheetFailed' }] };
135
+ }
136
+ case 'openRequested':
137
+ if (state.phase === 'ready') {
138
+ return { state: Object.assign(Object.assign({}, state), { phase: 'presented' }), effects: [{ type: 'show' }] };
139
+ }
140
+ if (state.phase === 'idle' || state.phase === 'loading') {
141
+ return unchanged(Object.assign(Object.assign({}, state), { openRequested: true }));
142
+ }
143
+ return unchanged(state);
144
+ case 'closeRequested':
145
+ if (state.phase === 'presented') {
146
+ const canceled = cancel(state);
147
+ return { state: Object.assign(Object.assign({}, canceled.state), { phase: 'ready' }), effects: canceled.effects };
148
+ }
149
+ // Closing before the sheet was shown withdraws the request to open it
150
+ if ((state.phase === 'idle' || state.phase === 'loading') && state.openRequested) {
151
+ return cancel(state);
152
+ }
153
+ return unchanged(state);
154
+ case 'submitted':
155
+ if (state.phase !== 'presented' || state.intentKind == null) {
156
+ return unchanged(state);
157
+ }
158
+ return {
159
+ state: Object.assign(Object.assign({}, state), { phase: 'confirming' }),
160
+ effects: [{ type: 'confirm', generation: state.generation, intentKind: state.intentKind }],
161
+ };
162
+ case 'confirmSucceeded': {
163
+ if (!isCurrentConfirmation(state, event.generation)) {
164
+ return unchanged(state);
165
+ }
166
+ const resolved = resolvePending(Object.assign(Object.assign({}, state), { phase: 'completed' }), 'paymentSheetCompleted');
167
+ return applyDeferredSecret({
168
+ state: resolved.state,
169
+ effects: [{ type: 'hide' }, { type: 'emit', event: 'paymentSheetCompleted' }, ...resolved.effects],
170
+ });
171
+ }
172
+ case 'confirmDeclined':
173
+ if (!isCurrentConfirmation(state, event.generation)) {
174
+ return unchanged(state);
175
+ }
176
+ return applyDeferredSecret({ state: Object.assign(Object.assign({}, state), { phase: 'presented' }), effects: [{ type: 'showError', message: event.message }] });
177
+ case 'confirmFailed': {
178
+ if (!isCurrentConfirmation(state, event.generation)) {
179
+ return unchanged(state);
180
+ }
181
+ const resolved = resolvePending(Object.assign(Object.assign({}, state), { phase: 'errored' }), 'paymentSheetFailed');
182
+ return applyDeferredSecret({
183
+ state: resolved.state,
184
+ effects: [{ type: 'hide' }, { type: 'emit', event: 'paymentSheetFailed' }, ...resolved.effects],
185
+ });
186
+ }
187
+ }
188
+ };
189
+
190
+ var __rest = (undefined && undefined.__rest) || function (s, e) {
191
+ var t = {};
192
+ for (var p in s)
193
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
194
+ t[p] = s[p];
195
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
196
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
197
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
198
+ t[p[i]] = s[p[i]];
199
+ }
200
+ return t;
201
+ };
202
+ const SUPPORTED_OPTION_KEYS = ['merchantDisplayName', 'paymentMethodLayout', 'defaultBillingDetails', 'returnURL', 'style'];
203
+ const LAYOUTS = {
204
+ horizontal: 'tabs',
205
+ vertical: 'accordion',
206
+ automatic: 'auto',
207
+ };
208
+ const THEMES = {
209
+ alwaysLight: 'stripe',
210
+ alwaysDark: 'night',
211
+ };
212
+ /**
213
+ * Drop keys whose value is undefined.
214
+ */
215
+ const compact = (value) => Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined));
216
+ /**
217
+ * Build the Payment Element options from the payment sheet options.
218
+ * @param options - Payment sheet options
219
+ */
220
+ const toPaymentElementOptions = (options) => {
221
+ if (options == null) {
222
+ return {};
223
+ }
224
+ const { merchantDisplayName, paymentMethodLayout, defaultBillingDetails } = options;
225
+ const elementOptions = {};
226
+ if (merchantDisplayName != null) {
227
+ elementOptions.business = { name: merchantDisplayName };
228
+ }
229
+ if (paymentMethodLayout != null) {
230
+ elementOptions.layout = LAYOUTS[paymentMethodLayout];
231
+ }
232
+ if (defaultBillingDetails != null) {
233
+ const { address } = defaultBillingDetails, contact = __rest(defaultBillingDetails, ["address"]);
234
+ const billingDetails = compact(contact);
235
+ if (address != null) {
236
+ const { postalCode } = address, rest = __rest(address, ["postalCode"]);
237
+ billingDetails.address = compact(Object.assign(Object.assign({}, rest), { postal_code: postalCode }));
238
+ }
239
+ elementOptions.defaultValues = { billingDetails };
240
+ }
241
+ return elementOptions;
242
+ };
243
+ /**
244
+ * Build the Elements appearance from the payment sheet style.
245
+ * @param style - `alwaysLight` or `alwaysDark`
246
+ */
247
+ const toAppearance = (style) => {
248
+ if (style == null) {
249
+ return undefined;
250
+ }
251
+ return { theme: THEMES[style] };
252
+ };
253
+ /**
254
+ * List the given options that have no effect on the web (yet), sorted by name.
255
+ * @param options - Payment sheet options
256
+ */
257
+ const unsupportedOptionKeys = (options) => {
258
+ if (options == null) {
259
+ return [];
260
+ }
261
+ return Object.entries(options)
262
+ .filter(([key, value]) => value !== undefined && !SUPPORTED_OPTION_KEYS.includes(key))
263
+ .map(([key]) => key)
264
+ .sort();
265
+ };
266
+ /**
267
+ * Stripe error types after which the customer can fix the input or simply try again.
268
+ * Types are listed at https://docs.stripe.com/api/errors and in `StripeErrorType` of @stripe/stripe-js.
269
+ */
270
+ const RECOVERABLE_ERROR_TYPES = ['card_error', 'validation_error', 'api_connection_error', 'rate_limit_error', 'api_error'];
271
+ /**
272
+ * Tell whether a confirmation error lets the customer try again in the open sheet.
273
+ * Other errors (for example `invalid_request_error` for an intent that already succeeded) end the sheet with `paymentSheetFailed`.
274
+ * @param error - Error thrown while confirming
275
+ */
276
+ const isRecoverableConfirmError = (error) => {
277
+ const type = error === null || error === void 0 ? void 0 : error.type;
278
+ return typeof type === 'string' && RECOVERABLE_ERROR_TYPES.includes(type);
279
+ };
280
+
281
+ const stripePaymentSheetCss = () => `:root{--color-label:#565656;--color-placeholder:#acacac;--color-heading-text:#333;--color-text-error:#ef4444;--color-input-border:#e4e4e6;--color-input-border-shadow:rgba(228, 228, 230, 0.6);--color-button-text:rgba(255, 255, 255, 0.95);--color-button-text-disabled:rgba(255, 255, 255, 0.4);--color-primary:#0074d4}stripe-payment-sheet{display:contents}.stripe-payment-sheet-wrap{box-sizing:border-box}.stripe-payment-sheet-wrap *:where(:not(iframe,canvas,img,svg,video):not(svg *)){all:unset;display:revert;background:none;border:none;font-family:"Roboto", sans-serif;box-sizing:border-box}.stripe-payment-sheet-wrap button{cursor:pointer}.stripe-payment-sheet-wrap{display:block;width:100%;background:#fff;padding:32px 16px}.stripe-payment-sheet-wrap .stripe-heading{font-size:24px;font-weight:bold;color:var(--color-heading-text);margin-bottom:24px}.stripe-payment-sheet-wrap .payment-info{margin-top:8px}.stripe-payment-sheet-wrap .stripe-element-errors{margin-top:8px;font-size:14px;color:var(--color-text-error)}.stripe-payment-sheet-wrap .stripe-submit{margin-top:32px}.stripe-payment-sheet-wrap button{display:block;color:var(--color-button-text);background-color:var(--color-primary);width:100%;text-align:center;padding:16px 16px;font-size:18px;border-radius:6px;min-height:42px}.stripe-payment-sheet-wrap button:disabled{color:var(--color-button-text-disabled)}`;
282
+
283
+ const StripePaymentSheet = class {
284
+ /**
285
+ * Show the sheet and wait for its result.
286
+ * Calling it again while a result is pending returns the same promise.
287
+ * @returns `{ paymentResult }`, where `paymentResult` is `paymentSheetCompleted`, `paymentSheetCanceled` or `paymentSheetFailed`
288
+ * @example
289
+ * ```
290
+ * const sheet = document.querySelector('stripe-payment-sheet');
291
+ * const { paymentResult } = await sheet.present();
292
+ * ```
293
+ */
294
+ async present() {
295
+ if (this.presentPromise == null) {
296
+ this.presentPromise = new Promise(resolve => {
297
+ this.resolvePresent = resolve;
298
+ });
299
+ }
300
+ const promise = this.presentPromise;
301
+ this.dispatch({ type: 'presentRequested' });
302
+ return promise;
303
+ }
304
+ handleSecretChange() {
305
+ this.startLoading();
306
+ }
307
+ handleOpenChange(open) {
308
+ this.dispatch({ type: open ? 'openRequested' : 'closeRequested' });
309
+ }
310
+ constructor(hostRef) {
311
+ index.registerInstance(this, hostRef);
312
+ this.paymentSheetLoaded = index.createEvent(this, "paymentSheetLoaded", 7);
313
+ this.paymentSheetFailedToLoad = index.createEvent(this, "paymentSheetFailedToLoad", 7);
314
+ this.paymentSheetCompleted = index.createEvent(this, "paymentSheetCompleted", 7);
315
+ this.paymentSheetCanceled = index.createEvent(this, "paymentSheetCanceled", 7);
316
+ this.paymentSheetFailed = index.createEvent(this, "paymentSheetFailed", 7);
317
+ this.warnedUnsupportedOptions = false;
318
+ /**
319
+ * Whether the sheet is shown. Setting it to false closes the sheet as canceled.
320
+ */
321
+ this.open = false;
322
+ /**
323
+ * Sheet title. Translated automatically by this library.
324
+ */
325
+ this.sheetTitle = 'Add your payment information';
326
+ /**
327
+ * Submit button label. Translated automatically by this library.
328
+ */
329
+ this.buttonLabel = 'Pay';
330
+ /**
331
+ * Application name registered to Stripe.js, for wrapper libraries such as `@capacitor-community/stripe`.
332
+ */
333
+ this.applicationName = 'stripe-pwa-elements';
334
+ this.sheet = initialSheetState;
335
+ this.visible = false;
336
+ this.errorMessage = '';
337
+ this.handleSubmit = (e) => {
338
+ e.preventDefault();
339
+ this.errorMessage = '';
340
+ this.dispatch({ type: 'submitted' });
341
+ };
342
+ /**
343
+ * The modal closes itself on a backdrop or close button click. Keep it open when the sheet refuses to close (while confirming).
344
+ */
345
+ this.handleModalClose = () => {
346
+ var _a;
347
+ this.dispatch({ type: 'closeRequested' });
348
+ if (this.visible) {
349
+ (_a = this.el.querySelector('stripe-modal')) === null || _a === void 0 ? void 0 : _a.openModal();
350
+ }
351
+ };
352
+ this.stripeService = factory.serviceFactory.createStripeService();
353
+ this.paymentElementManager = factory.serviceFactory.createPaymentElementManager(this.stripeService);
354
+ }
355
+ /**
356
+ * Props are not yet populated inside the constructor with the custom-elements build,
357
+ * so loading starts here.
358
+ */
359
+ componentWillLoad() {
360
+ if (this.open) {
361
+ this.dispatch({ type: 'openRequested' });
362
+ }
363
+ this.startLoading();
364
+ }
365
+ componentDidLoad() {
366
+ this.el.classList.add(i18n.checkPlatform());
367
+ }
368
+ disconnectedCallback() {
369
+ this.paymentElementManager.unmount();
370
+ }
371
+ startLoading() {
372
+ if (this.publishableKey == null || this.publishableKey === '' || this.intentClientSecret == null) {
373
+ return;
374
+ }
375
+ this.dispatch({ type: 'secretChanged', clientSecret: this.intentClientSecret });
376
+ }
377
+ dispatch(event) {
378
+ const { state, effects } = transition(this.sheet, event);
379
+ this.sheet = state;
380
+ effects.forEach(effect => this.perform(effect));
381
+ }
382
+ perform(effect) {
383
+ var _a;
384
+ switch (effect.type) {
385
+ case 'load':
386
+ this.load(effect.generation, effect.clientSecret);
387
+ break;
388
+ case 'show':
389
+ this.visible = true;
390
+ this.open = true;
391
+ break;
392
+ case 'hide':
393
+ this.visible = false;
394
+ this.open = false;
395
+ break;
396
+ case 'confirm':
397
+ this.confirm(effect.generation, effect.intentKind);
398
+ break;
399
+ case 'showError':
400
+ this.errorMessage = effect.message;
401
+ break;
402
+ case 'emit':
403
+ this.emit(effect.event);
404
+ break;
405
+ case 'resolvePresent':
406
+ (_a = this.resolvePresent) === null || _a === void 0 ? void 0 : _a.call(this, { paymentResult: effect.result });
407
+ this.presentPromise = undefined;
408
+ this.resolvePresent = undefined;
409
+ break;
410
+ }
411
+ }
412
+ async load(generation, clientSecret) {
413
+ var _a;
414
+ this.warnUnsupportedOptions();
415
+ try {
416
+ await this.stripeService.initialize(this.publishableKey, {
417
+ stripeAccount: this.stripeAccount,
418
+ applicationName: this.applicationName,
419
+ clientSecret,
420
+ });
421
+ if (generation !== this.sheet.generation) {
422
+ return;
423
+ }
424
+ if (this.stripeService.state.loadStripeStatus !== 'success') {
425
+ throw new Error('Failed to load Stripe.js');
426
+ }
427
+ const appearance = toAppearance((_a = this.options) === null || _a === void 0 ? void 0 : _a.style);
428
+ if (appearance != null) {
429
+ await this.stripeService.getElements().update({ appearance });
430
+ }
431
+ await this.paymentElementManager.initialize(this.el, toPaymentElementOptions(this.options));
432
+ this.dispatch({ type: 'loadSucceeded', generation });
433
+ }
434
+ catch (e) {
435
+ this.lastError = e;
436
+ this.dispatch({ type: 'loadFailed', generation });
437
+ }
438
+ }
439
+ async confirm(generation, intentKind) {
440
+ var _a, _b, _c;
441
+ try {
442
+ const returnUrl = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.returnURL) !== null && _b !== void 0 ? _b : window.location.href;
443
+ this.lastResult = await stripePaymentElement_helpers.confirmPaymentOrSetup(this.stripeService.getStripe(), this.stripeService.getElements(), intentKind, returnUrl);
444
+ this.dispatch({ type: 'confirmSucceeded', generation });
445
+ }
446
+ catch (e) {
447
+ const message = (_c = e.message) !== null && _c !== void 0 ? _c : String(e);
448
+ if (isRecoverableConfirmError(e)) {
449
+ this.dispatch({ type: 'confirmDeclined', generation, message });
450
+ return;
451
+ }
452
+ this.lastError = e;
453
+ this.dispatch({ type: 'confirmFailed', generation, message });
454
+ }
455
+ }
456
+ emit(event) {
457
+ switch (event) {
458
+ case 'paymentSheetLoaded':
459
+ this.paymentSheetLoaded.emit({ stripe: this.stripeService.getStripe() });
460
+ break;
461
+ case 'paymentSheetFailedToLoad':
462
+ this.paymentSheetFailedToLoad.emit(this.lastError);
463
+ break;
464
+ case 'paymentSheetCompleted':
465
+ this.paymentSheetCompleted.emit(this.lastResult);
466
+ break;
467
+ case 'paymentSheetCanceled':
468
+ this.paymentSheetCanceled.emit();
469
+ break;
470
+ case 'paymentSheetFailed':
471
+ this.paymentSheetFailed.emit(this.lastError);
472
+ break;
473
+ }
474
+ }
475
+ warnUnsupportedOptions() {
476
+ const keys = unsupportedOptionKeys(this.options);
477
+ if (this.warnedUnsupportedOptions || keys.length === 0) {
478
+ return;
479
+ }
480
+ this.warnedUnsupportedOptions = true;
481
+ console.warn(`<stripe-payment-sheet>: these options have no effect on the web yet: ${keys.join(', ')}`);
482
+ }
483
+ render() {
484
+ const { phase } = this.sheet;
485
+ const confirming = phase === 'confirming';
486
+ return (index.h(index.Host, { key: 'ecb6de4b0674af9f5ecf86acce93e092c3bee881' }, index.h("stripe-modal", { key: '137473608d8cc3c0833c34529f1dafb9fc0cba34', open: this.visible, showCloseButton: !confirming, onClose: this.handleModalClose }, index.h("div", { key: '0da153ef48ddc5464f050ea1921a69f975a7d8e1', class: "stripe-payment-sheet-wrap" }, index.h("form", { key: '6f6653aee9d0ad54c8bf935ace2f6d4fdc648e1f', id: "stripe-payment-sheet", onSubmit: this.handleSubmit }, index.h("div", { key: '85d3e28a20679051decdb02d590c2144e652f0bd', class: "stripe-heading" }, i18n.i18n.t(this.sheetTitle)), index.h("div", { key: 'f6b8d90a3731732c0b36af0512a5ace87a12f98d', class: "payment-info visible" }, index.h("div", { key: '813a1ad3a0db2efa650aceff828412999f34ff2b', id: "payment-element" })), index.h("div", { key: '63bd6a8c20dd7b8b92aa2171553c13570ab17808', class: "stripe-element-errors", role: "alert" }, this.errorMessage), index.h("div", { key: 'f70e9b353ae9eecd1300bbbd40ebb731ef44c344', class: "stripe-submit" }, index.h("button", { key: '6f32a7b94132091348680476b0e7292072800dbf', type: "submit", disabled: phase !== 'presented' }, confirming ? i18n.i18n.t('Loading') : i18n.i18n.t(this.buttonLabel))))))));
487
+ }
488
+ get el() { return index.getElement(this); }
489
+ static get watchers() { return {
490
+ "publishableKey": [{
491
+ "handleSecretChange": 0
492
+ }],
493
+ "intentClientSecret": [{
494
+ "handleSecretChange": 0
495
+ }],
496
+ "stripeAccount": [{
497
+ "handleSecretChange": 0
498
+ }],
499
+ "open": [{
500
+ "handleOpenChange": 0
501
+ }]
502
+ }; }
503
+ };
504
+ StripePaymentSheet.style = stripePaymentSheetCss();
505
+
506
+ exports.stripe_payment_sheet = StripePaymentSheet;
@@ -8,7 +8,8 @@
8
8
  "components/stripe-link-authentication-element/stripe-link-authentication-element.js",
9
9
  "components/stripe-payment-request-button/stripe-payment-request-button.js",
10
10
  "components/stripe-card-element-modal/stripe-card-element-modal.js",
11
- "components/stripe-modal/stripe-modal.js"
11
+ "components/stripe-modal/stripe-modal.js",
12
+ "components/stripe-payment-sheet/stripe-payment-sheet.js"
12
13
  ],
13
14
  "mixins": [],
14
15
  "compiler": {
@@ -228,7 +228,8 @@ export class StripeCardElement {
228
228
  */
229
229
  this.showLabel = false;
230
230
  /**
231
- * The component will provide a function to call the `stripe.confirmCardPayment`API.
231
+ * The component will confirm the intent for you: `stripe.confirmCardPayment` when `intentType` is `'payment'`,
232
+ * `stripe.confirmCardSetup` when it is `'setup'`.
232
233
  * If you want to customize the behavior, should set false.
233
234
  * And listen the 'formSubmit' event on the element
234
235
  */
@@ -578,7 +579,7 @@ export class StripeCardElement {
578
579
  "optional": false,
579
580
  "docs": {
580
581
  "tags": [],
581
- "text": "The component will provide a function to call the `stripe.confirmCardPayment`API.\nIf you want to customize the behavior, should set false.\nAnd listen the 'formSubmit' event on the element"
582
+ "text": "The component will confirm the intent for you: `stripe.confirmCardPayment` when `intentType` is `'payment'`,\n`stripe.confirmCardSetup` when it is `'setup'`.\nIf you want to customize the behavior, should set false.\nAnd listen the 'formSubmit' event on the element"
582
583
  },
583
584
  "getter": false,
584
585
  "setter": false,