stripe-pwa-elements 4.0.0 → 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.
- package/dist/cjs/factory-tenFFIul.js +1200 -0
- package/dist/cjs/{factory-da3xAKkz.js → i18n-FhEOc8vz.js} +6 -1131
- package/dist/cjs/ion-icon_2.cjs.entry.js +723 -0
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/stripe-address-element.cjs.entry.js +12 -4
- package/dist/cjs/stripe-card-element-modal.cjs.entry.js +3 -2
- package/dist/cjs/{stripe-card-element_2.cjs.entry.js → stripe-card-element.cjs.entry.js} +15 -82
- package/dist/cjs/stripe-currency-selector.cjs.entry.js +11 -3
- package/dist/cjs/stripe-elements.cjs.js +1 -1
- package/dist/cjs/stripe-express-checkout-element.cjs.entry.js +31 -5
- package/dist/cjs/stripe-link-authentication-element.cjs.entry.js +11 -3
- package/dist/cjs/stripe-payment-element.cjs.entry.js +106 -161
- package/dist/cjs/stripe-payment-element.helpers-DukP33RI.js +122 -0
- package/dist/cjs/stripe-payment-request-button.cjs.entry.js +23 -16
- package/dist/cjs/stripe-payment-sheet.cjs.entry.js +506 -0
- package/dist/collection/collection-manifest.json +3 -2
- package/dist/collection/components/stripe-address-element/stripe-address-element.js +7 -0
- package/dist/collection/components/stripe-card-element/stripe-card-element.js +10 -2
- package/dist/collection/components/stripe-card-element-modal/stripe-card-element-modal.js +4 -3
- package/dist/collection/components/stripe-currency-selector/stripe-currency-selector.js +7 -0
- package/dist/collection/components/stripe-express-checkout-element/stripe-express-checkout-element.js +25 -0
- package/dist/collection/components/stripe-link-authentication-element/stripe-link-authentication-element.js +7 -0
- package/dist/collection/components/stripe-modal/stripe-modal.css +23 -1
- package/dist/collection/components/stripe-modal/stripe-modal.js +147 -6
- package/dist/collection/components/stripe-payment-element/stripe-payment-element.js +94 -37
- package/dist/collection/components/stripe-payment-request-button/stripe-payment-request-button.js +17 -10
- package/dist/collection/components/stripe-payment-sheet/payment-sheet-state.js +179 -0
- package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.css +68 -0
- package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.helpers.js +90 -0
- package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.js +544 -0
- package/dist/collection/services/express-checkout-element-manager.js +36 -2
- package/dist/collection/services/stripe-service.js +37 -5
- package/dist/collection/utils/focus.js +76 -0
- package/dist/collection/utils/i18n.js +6 -0
- package/dist/components/factory.js +1 -1
- package/dist/components/i18n.js +1 -0
- package/dist/components/stripe-address-element.js +1 -1
- package/dist/components/stripe-card-element-modal.js +1 -1
- package/dist/components/stripe-card-element2.js +1 -1
- package/dist/components/stripe-currency-selector.js +1 -1
- package/dist/components/stripe-express-checkout-element.js +1 -1
- package/dist/components/stripe-link-authentication-element.js +1 -1
- package/dist/components/stripe-modal2.js +1 -1
- package/dist/components/stripe-payment-element.helpers.js +1 -0
- package/dist/components/stripe-payment-element.js +1 -1
- package/dist/components/stripe-payment-request-button2.js +1 -1
- package/dist/components/stripe-payment-sheet.d.ts +11 -0
- package/dist/components/stripe-payment-sheet.js +1 -0
- package/dist/esm/factory-Cd6OGTWN.js +1198 -0
- package/dist/esm/{factory-DeqoYLf_.js → i18n-B6JoQetF.js} +7 -1131
- package/dist/esm/ion-icon_2.entry.js +720 -0
- package/dist/esm/loader.js +1 -1
- package/dist/esm/stripe-address-element.entry.js +9 -1
- package/dist/esm/stripe-card-element-modal.entry.js +3 -2
- package/dist/esm/{stripe-card-element_2.entry.js → stripe-card-element.entry.js} +13 -79
- package/dist/esm/stripe-currency-selector.entry.js +9 -1
- package/dist/esm/stripe-elements.js +1 -1
- package/dist/esm/stripe-express-checkout-element.entry.js +27 -1
- package/dist/esm/stripe-link-authentication-element.entry.js +9 -1
- package/dist/esm/stripe-payment-element.entry.js +98 -153
- package/dist/esm/stripe-payment-element.helpers-CipV87b8.js +117 -0
- package/dist/esm/stripe-payment-request-button.entry.js +18 -11
- package/dist/esm/stripe-payment-sheet.entry.js +504 -0
- package/dist/stripe-elements/{p-38e7b187.entry.js → p-4891edf0.entry.js} +1 -1
- package/dist/stripe-elements/p-5338bc5e.entry.js +1 -0
- package/dist/stripe-elements/p-6a9c8b7a.entry.js +1 -0
- package/dist/stripe-elements/p-7fe4a287.entry.js +1 -0
- package/dist/stripe-elements/p-915b86ed.entry.js +1 -0
- package/dist/stripe-elements/p-B6JoQetF.js +1 -0
- package/dist/stripe-elements/p-C7MQk9FK.js +1 -0
- package/dist/stripe-elements/p-DFAhQS0n.js +1 -0
- package/dist/stripe-elements/p-b06a254f.entry.js +1 -0
- package/dist/stripe-elements/p-b91c4fa7.entry.js +1 -0
- package/dist/stripe-elements/p-ba791c8f.entry.js +1 -0
- package/dist/stripe-elements/p-e7372ca7.entry.js +1 -0
- package/dist/stripe-elements/p-f892e375.entry.js +1 -0
- package/dist/stripe-elements/stripe-elements.esm.js +1 -1
- package/dist/types/components/stripe-address-element/stripe-address-element.d.ts +6 -0
- package/dist/types/components/stripe-card-element/stripe-card-element.d.ts +8 -1
- package/dist/types/components/stripe-card-element-modal/stripe-card-element-modal.d.ts +2 -1
- package/dist/types/components/stripe-currency-selector/stripe-currency-selector.d.ts +6 -0
- package/dist/types/components/stripe-express-checkout-element/stripe-express-checkout-element.d.ts +11 -0
- package/dist/types/components/stripe-link-authentication-element/stripe-link-authentication-element.d.ts +6 -0
- package/dist/types/components/stripe-modal/stripe-modal.d.ts +44 -0
- package/dist/types/components/stripe-payment-element/stripe-payment-element.d.ts +18 -0
- package/dist/types/components/stripe-payment-request-button/stripe-payment-request-button.d.ts +7 -2
- package/dist/types/components/stripe-payment-sheet/payment-sheet-state.d.ts +104 -0
- package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.d.ts +112 -0
- package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.helpers.d.ts +95 -0
- package/dist/types/components.d.ts +169 -10
- package/dist/types/index.d.ts +2 -0
- package/dist/types/services/interfaces.d.ts +2 -0
- package/dist/types/services/stripe-service.d.ts +12 -3
- package/dist/types/utils/focus.d.ts +15 -0
- package/package.json +5 -3
- package/readme.md +46 -10
- package/dist/cjs/ion-icon.cjs.entry.js +0 -431
- package/dist/components/utils.js +0 -1
- package/dist/esm/ion-icon.entry.js +0 -429
- package/dist/stripe-elements/p--sA2m1ad.js +0 -1
- package/dist/stripe-elements/p-44495284.entry.js +0 -1
- package/dist/stripe-elements/p-4ba675fa.entry.js +0 -1
- package/dist/stripe-elements/p-5cf62945.entry.js +0 -1
- package/dist/stripe-elements/p-c24ae181.entry.js +0 -1
- package/dist/stripe-elements/p-d9e86451.entry.js +0 -1
- package/dist/stripe-elements/p-f09c86a0.entry.js +0 -1
- package/dist/stripe-elements/p-f64f394d.entry.js +0 -1
- package/dist/stripe-elements/p-f6d2425e.entry.js +0 -1
|
@@ -163,6 +163,13 @@ export class StripeLinkAuthenticationElement {
|
|
|
163
163
|
// Dependency Injection via factory
|
|
164
164
|
this.stripeService = serviceFactory.createStripeService();
|
|
165
165
|
this.linkAuthenticationElementManager = serviceFactory.createLinkAuthenticationElementManager(this.stripeService);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Props are not yet populated inside the constructor when the component is registered via
|
|
169
|
+
* the custom-elements build (`dist/components/*`), so initialization that depends on them
|
|
170
|
+
* must run in `componentWillLoad`, where both the lazy and custom-elements builds have them set.
|
|
171
|
+
*/
|
|
172
|
+
componentWillLoad() {
|
|
166
173
|
if (this.publishableKey) {
|
|
167
174
|
this.initStripe(this.publishableKey, {
|
|
168
175
|
stripeAccount: this.stripeAccount,
|
|
@@ -33,11 +33,13 @@
|
|
|
33
33
|
opacity: 0;
|
|
34
34
|
pointer-events: none;
|
|
35
35
|
will-change: transform;
|
|
36
|
+
visibility: hidden;
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
.modal-row.open {
|
|
39
40
|
opacity: 1;
|
|
40
41
|
pointer-events: auto;
|
|
42
|
+
visibility: visible;
|
|
41
43
|
position: fixed;
|
|
42
44
|
top: 0;
|
|
43
45
|
left: 0;
|
|
@@ -91,8 +93,28 @@
|
|
|
91
93
|
padding-left: 8px;
|
|
92
94
|
}
|
|
93
95
|
.modal-close-button-wrap .modal-close-button {
|
|
96
|
+
display: block;
|
|
97
|
+
width: 32px;
|
|
98
|
+
cursor: pointer;
|
|
99
|
+
border-radius: 4px;
|
|
100
|
+
}
|
|
101
|
+
.modal-close-button-wrap .modal-close-button:focus-visible {
|
|
102
|
+
outline: 2px solid var(--color-label, #000);
|
|
103
|
+
outline-offset: 2px;
|
|
104
|
+
}
|
|
105
|
+
.modal-close-button-wrap .modal-close-button ion-icon {
|
|
94
106
|
width: 32px;
|
|
95
107
|
display: block;
|
|
96
108
|
fill: var(--color-label);
|
|
97
|
-
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.modal-child:focus {
|
|
112
|
+
outline: none;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.focus-guard {
|
|
116
|
+
position: absolute;
|
|
117
|
+
width: 1px;
|
|
118
|
+
height: 1px;
|
|
119
|
+
overflow: hidden;
|
|
98
120
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Host, h } from "@stencil/core";
|
|
2
2
|
import { checkPlatform } from "../../utils/utils";
|
|
3
|
+
import { getDeepActiveElement, getTabbableElements } from "../../utils/focus";
|
|
4
|
+
import { i18n } from "../../utils/i18n";
|
|
3
5
|
export class StripeModal {
|
|
4
6
|
constructor() {
|
|
5
7
|
/**
|
|
@@ -16,6 +18,65 @@ export class StripeModal {
|
|
|
16
18
|
* Ionic Ref: https://github.com/ionic-team/ionic-framework/blob/main/core/src/components/accordion/accordion.tsx#L83
|
|
17
19
|
*/
|
|
18
20
|
this.renderedOpen = false;
|
|
21
|
+
/**
|
|
22
|
+
* The element that had focus before the modal opened. Focus returns to it when the modal closes.
|
|
23
|
+
*/
|
|
24
|
+
this.returnFocusElement = null;
|
|
25
|
+
/**
|
|
26
|
+
* Set when the modal opens; the initial focus is moved after the open state has been rendered.
|
|
27
|
+
*/
|
|
28
|
+
this.shouldFocusOnRender = false;
|
|
29
|
+
/**
|
|
30
|
+
* The last element inside the modal that received focus.
|
|
31
|
+
* `FocusEvent.relatedTarget` is `null` when focus crosses an iframe boundary (e.g. leaving a Stripe Elements field),
|
|
32
|
+
* so the guards fall back to this value to tell which way focus is moving.
|
|
33
|
+
*/
|
|
34
|
+
this.lastFocusedInside = null;
|
|
35
|
+
this.handleKeyDown = (event) => {
|
|
36
|
+
if (!this.open || event.key !== 'Escape') {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
// Escape that cancels an IME composition (keyCode 229) or that a slotted widget (e.g. an autocomplete popup) already handled must not close the modal
|
|
40
|
+
if (event.isComposing || event.keyCode === 229 || event.defaultPrevented) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
// Prevent an outer modal (or the page) from also reacting to the same key press
|
|
44
|
+
event.preventDefault();
|
|
45
|
+
event.stopPropagation();
|
|
46
|
+
this.closeModal();
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Whether focus came from a focusable element inside the modal (not from the container itself or from outside).
|
|
50
|
+
* The guards use it to tell Tab from Shift+Tab: a guard cannot see the key, but it can see where focus came from.
|
|
51
|
+
*/
|
|
52
|
+
this.handleFocusIn = (event) => {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
const target = ((_b = (_a = event.composedPath) === null || _a === void 0 ? void 0 : _a.call(event)[0]) !== null && _b !== void 0 ? _b : event.target);
|
|
55
|
+
if ((target === null || target === void 0 ? void 0 : target.classList) !== undefined && !target.classList.contains('focus-guard')) {
|
|
56
|
+
this.lastFocusedInside = target;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
this.handleStartGuardFocus = (event) => {
|
|
60
|
+
// Shift+Tab from the first element wraps to the last; Tab from the container (or from outside) enters at the first
|
|
61
|
+
this.cameFromFocusableInside(event) ? this.focusLastElement() : this.focusFirstElement();
|
|
62
|
+
};
|
|
63
|
+
this.handleEndGuardFocus = (event) => {
|
|
64
|
+
// Tab from the last element wraps to the first; Shift+Tab from outside enters at the last
|
|
65
|
+
this.isInsideModal(this.getFocusOrigin(event)) ? this.focusFirstElement() : this.focusLastElement();
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
onOpenChange(open) {
|
|
69
|
+
if (open) {
|
|
70
|
+
this.rememberFocus();
|
|
71
|
+
this.openModalAnimation();
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
this.renderedOpen = false;
|
|
75
|
+
this.shouldFocusOnRender = false;
|
|
76
|
+
this.lastFocusedInside = null;
|
|
77
|
+
this.close.emit();
|
|
78
|
+
this.restoreFocus();
|
|
79
|
+
}
|
|
19
80
|
}
|
|
20
81
|
/**
|
|
21
82
|
* Toggle modal state
|
|
@@ -28,15 +89,12 @@ export class StripeModal {
|
|
|
28
89
|
*/
|
|
29
90
|
async openModal() {
|
|
30
91
|
this.open = true;
|
|
31
|
-
this.openModalAnimation();
|
|
32
92
|
}
|
|
33
93
|
/**
|
|
34
94
|
* Close the modal
|
|
35
95
|
*/
|
|
36
96
|
async closeModal() {
|
|
37
97
|
this.open = false;
|
|
38
|
-
this.renderedOpen = false;
|
|
39
|
-
this.close.emit();
|
|
40
98
|
}
|
|
41
99
|
componentDidLoad() {
|
|
42
100
|
const platformName = checkPlatform();
|
|
@@ -44,10 +102,85 @@ export class StripeModal {
|
|
|
44
102
|
this.el.classList.add(platformName);
|
|
45
103
|
}
|
|
46
104
|
if (this.open) {
|
|
105
|
+
this.rememberFocus();
|
|
47
106
|
this.openModalAnimation();
|
|
48
107
|
}
|
|
49
108
|
}
|
|
109
|
+
componentDidRender() {
|
|
110
|
+
if (this.shouldFocusOnRender && this.renderedOpen) {
|
|
111
|
+
this.shouldFocusOnRender = false;
|
|
112
|
+
this.focusFirstElement();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
rememberFocus() {
|
|
116
|
+
var _a;
|
|
117
|
+
if (typeof document === 'undefined') {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const active = getDeepActiveElement(document);
|
|
121
|
+
// Ignore focus that is already inside the modal and the default document focus
|
|
122
|
+
if (active === null || active === document.body || this.el.contains(active) || ((_a = this.el.shadowRoot) === null || _a === void 0 ? void 0 : _a.contains(active)) === true) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
this.returnFocusElement = active;
|
|
126
|
+
}
|
|
127
|
+
restoreFocus() {
|
|
128
|
+
const target = this.returnFocusElement;
|
|
129
|
+
this.returnFocusElement = null;
|
|
130
|
+
if (target != null && target.isConnected && typeof target.focus === 'function') {
|
|
131
|
+
target.focus();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
getTabbableElements() {
|
|
135
|
+
if (this.dialogElement === undefined) {
|
|
136
|
+
return [];
|
|
137
|
+
}
|
|
138
|
+
return getTabbableElements(this.dialogElement).filter(element => !element.classList.contains('focus-guard'));
|
|
139
|
+
}
|
|
140
|
+
isInsideModal(node) {
|
|
141
|
+
var _a;
|
|
142
|
+
return node !== null && (this.el.contains(node) || ((_a = this.dialogElement) === null || _a === void 0 ? void 0 : _a.contains(node)) === true);
|
|
143
|
+
}
|
|
144
|
+
getFocusOrigin(event) {
|
|
145
|
+
var _a;
|
|
146
|
+
return (_a = event.relatedTarget) !== null && _a !== void 0 ? _a : this.lastFocusedInside;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Whether focus came from a focusable element inside the modal (not from the container itself or from outside).
|
|
150
|
+
* The guards use it to tell Tab from Shift+Tab: a guard cannot see the key, but it can see where focus came from.
|
|
151
|
+
*/
|
|
152
|
+
cameFromFocusableInside(event) {
|
|
153
|
+
const from = this.getFocusOrigin(event);
|
|
154
|
+
return from !== this.dialogElement && this.isInsideModal(from);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Slotted content is hidden (and therefore not focusable) while the open transition runs.
|
|
158
|
+
* When it ends, move focus from the placeholder (container / close button) into the content, unless the user already moved it.
|
|
159
|
+
*/
|
|
160
|
+
focusContentAfterLoading() {
|
|
161
|
+
var _a;
|
|
162
|
+
if (!this.open || this.contentElement === undefined) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const active = getDeepActiveElement(document);
|
|
166
|
+
const focusIsIdle = active === null || active === document.body || active === this.dialogElement || active === this.closeButtonElement;
|
|
167
|
+
if (!focusIsIdle) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
(_a = getTabbableElements(this.contentElement)[0]) === null || _a === void 0 ? void 0 : _a.focus();
|
|
171
|
+
}
|
|
172
|
+
focusFirstElement() {
|
|
173
|
+
var _a;
|
|
174
|
+
const [first] = this.getTabbableElements();
|
|
175
|
+
(_a = (first !== null && first !== void 0 ? first : this.dialogElement)) === null || _a === void 0 ? void 0 : _a.focus();
|
|
176
|
+
}
|
|
177
|
+
focusLastElement() {
|
|
178
|
+
var _a, _b;
|
|
179
|
+
const elements = this.getTabbableElements();
|
|
180
|
+
(_b = ((_a = elements[elements.length - 1]) !== null && _a !== void 0 ? _a : this.dialogElement)) === null || _b === void 0 ? void 0 : _b.focus();
|
|
181
|
+
}
|
|
50
182
|
openModalAnimation() {
|
|
183
|
+
this.shouldFocusOnRender = true;
|
|
51
184
|
if (!this.el.shadowRoot) {
|
|
52
185
|
this.renderedOpen = true;
|
|
53
186
|
return;
|
|
@@ -58,14 +191,16 @@ export class StripeModal {
|
|
|
58
191
|
modalChild.addEventListener('transitionend', () => {
|
|
59
192
|
modalChild.style.willChange = 'auto';
|
|
60
193
|
modalChild.classList.remove('loading');
|
|
194
|
+
this.focusContentAfterLoading();
|
|
61
195
|
}, { once: true });
|
|
62
196
|
requestAnimationFrame(() => {
|
|
63
|
-
this.renderedOpen =
|
|
197
|
+
this.renderedOpen = this.open;
|
|
64
198
|
});
|
|
65
199
|
}
|
|
66
200
|
render() {
|
|
67
201
|
const { renderedOpen, showCloseButton } = this;
|
|
68
|
-
|
|
202
|
+
const guardTabIndex = renderedOpen ? 0 : -1;
|
|
203
|
+
return (h(Host, { key: '684539aa83388bec518e73bbd8aa19e73cfde07d', role: renderedOpen ? 'dialog' : undefined, "aria-modal": renderedOpen ? 'true' : undefined, onKeyDown: this.handleKeyDown, onFocusin: this.handleFocusIn }, h("div", { key: 'db6f1088c1ef7e35aefba06faaf3e9c2dcaa3419', class: `modal-row${renderedOpen ? ' open' : ''}`, onClick: () => this.closeModal() }, h("div", { key: '89c783c793261566b77ba962da730a973e8cbd8d', class: "modal-child", tabindex: "-1", ref: el => (this.dialogElement = el), onClick: e => e.stopPropagation() }, h("div", { key: '0e329b32c25509134f5a25adb266b03dd0bd71d8', class: "focus-guard", tabindex: guardTabIndex, onFocus: this.handleStartGuardFocus }), showCloseButton ? (h("div", { class: "modal-close-button-wrap" }, h("button", { type: "button", class: "modal-close-button", "aria-label": i18n.t('Close'), ref: el => (this.closeButtonElement = el), onClick: () => this.closeModal() }, h("ion-icon", { name: "close", size: "large", "aria-hidden": "true" })))) : null, h("div", { key: 'f2b5dcbc72ba3178dd920ceecd4fd339f69598d7', class: "modal-loading" }, h("svg", { key: '1f7afb6cc48be8fc84f9b69678f2c8ca1e2b145e', version: "1.1", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 2400 2400" }, h("g", { key: 'ed40edfeabe02bf198b194eb04777e1f4a6b203e', "stroke-width": "200", "stroke-linecap": "round", stroke: "currentColor", fill: "none", id: "spinner" }, h("line", { key: '03c9170ee9e566227fddcc9037a92c48ed954b89', x1: "1200", y1: "600", x2: "1200", y2: "100" }), h("line", { key: '302aec0abf20ee8afe66245ecbc9d5e2adbade82', opacity: "0.5", x1: "1200", y1: "2300", x2: "1200", y2: "1800" }), h("line", { key: 'd3bea8de4d689a5c5c423a72dd23a0fbc64c29dd', opacity: "0.917", x1: "900", y1: "680.4", x2: "650", y2: "247.4" }), h("line", { key: '543e33091e87bf85c3a0e4d4881babdffbe4b825', opacity: "0.417", x1: "1750", y1: "2152.6", x2: "1500", y2: "1719.6" }), h("line", { key: '5c2e0a3722955a8ee17b57f3061097f18681ba7e', opacity: "0.833", x1: "680.4", y1: "900", x2: "247.4", y2: "650" }), h("line", { key: '1100d48a500bfca6075243cf69be9e6f575bdae6', opacity: "0.333", x1: "2152.6", y1: "1750", x2: "1719.6", y2: "1500" }), h("line", { key: '6c3f7c309a5ed15c6ffce11925efe09dbc8e6f3b', opacity: "0.75", x1: "600", y1: "1200", x2: "100", y2: "1200" }), h("line", { key: '7708c31b141f3a151e8dc78c89b20442f34ce1e2', opacity: "0.25", x1: "2300", y1: "1200", x2: "1800", y2: "1200" }), h("line", { key: 'd419fc4006e8063f9bbc35b4cb2a9a88010c623a', opacity: "0.667", x1: "680.4", y1: "1500", x2: "247.4", y2: "1750" }), h("line", { key: '78ccaf11a6e7c3183d210b787ce9374bd7c4aff4', opacity: "0.167", x1: "2152.6", y1: "650", x2: "1719.6", y2: "900" }), h("line", { key: 'acb1444de9fcd9aa1a3182d759d3b8aeb0906284', opacity: "0.583", x1: "900", y1: "1719.6", x2: "650", y2: "2152.6" }), h("line", { key: '6adef9d6a54f302c8da7c84cae32851723ce25cc', opacity: "0.083", x1: "1750", y1: "247.4", x2: "1500", y2: "680.4" }), h("animateTransform", { key: '7acf982514091f6c3ec9bd4ddfc660f3286ddd4e', attributeName: "transform", attributeType: "XML", type: "rotate", keyTimes: "0;0.08333;0.16667;0.25;0.33333;0.41667;0.5;0.58333;0.66667;0.75;0.83333;0.91667", values: "0 1199 1199;30 1199 1199;60 1199 1199;90 1199 1199;120 1199 1199;150 1199 1199;180 1199 1199;210 1199 1199;240 1199 1199;270 1199 1199;300 1199 1199;330 1199 1199", dur: "0.83333s", begin: "0s", repeatCount: "indefinite", calcMode: "discrete" })))), h("div", { key: '120bebc59c0fc013cb2bfbaf8957ad3731e1ddf4', class: "modal-content", ref: el => (this.contentElement = el) }, h("slot", { key: '0f371823f8fddd61e2b0ce24a59477103d979875' })), h("div", { key: 'fa8436f70871d59055dab2cf0fcfe5d4577328c1', class: "focus-guard", tabindex: guardTabIndex, onFocus: this.handleEndGuardFocus })))));
|
|
69
204
|
}
|
|
70
205
|
static get is() { return "stripe-modal"; }
|
|
71
206
|
static get encapsulation() { return "shadow"; }
|
|
@@ -103,7 +238,7 @@ export class StripeModal {
|
|
|
103
238
|
},
|
|
104
239
|
"open": {
|
|
105
240
|
"type": "boolean",
|
|
106
|
-
"mutable":
|
|
241
|
+
"mutable": true,
|
|
107
242
|
"complexType": {
|
|
108
243
|
"original": "boolean",
|
|
109
244
|
"resolved": "boolean",
|
|
@@ -202,4 +337,10 @@ export class StripeModal {
|
|
|
202
337
|
};
|
|
203
338
|
}
|
|
204
339
|
static get elementRef() { return "el"; }
|
|
340
|
+
static get watchers() {
|
|
341
|
+
return [{
|
|
342
|
+
"propName": "open",
|
|
343
|
+
"methodName": "onOpenChange"
|
|
344
|
+
}];
|
|
345
|
+
}
|
|
205
346
|
}
|
|
@@ -19,26 +19,14 @@ export class StripePaymentElement {
|
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
21
|
async initStripe(publishableKey, options) {
|
|
22
|
+
const generation = ++this.initGeneration;
|
|
22
23
|
await this.stripeService.initialize(publishableKey, {
|
|
23
24
|
stripeAccount: options === null || options === void 0 ? void 0 : options.stripeAccount,
|
|
24
25
|
applicationName: this.applicationName,
|
|
26
|
+
// Payment Element needs the client secret when the Elements group is created
|
|
27
|
+
clientSecret: this.intentClientSecret,
|
|
25
28
|
});
|
|
26
|
-
|
|
27
|
-
if (this.stripeService.state.loadStripeStatus === 'success') {
|
|
28
|
-
await this.initElement();
|
|
29
|
-
this.stripeLoadedEventHandler();
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
// Otherwise, wait for successful load
|
|
33
|
-
const unsubscribe = this.stripeService.onChange('loadStripeStatus', async (newState) => {
|
|
34
|
-
if (newState !== 'success') {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
await this.initElement();
|
|
38
|
-
this.stripeLoadedEventHandler();
|
|
39
|
-
unsubscribe(); // Clean up listener after first success
|
|
40
|
-
});
|
|
41
|
-
}
|
|
29
|
+
await this.mountWhenLoaded(generation);
|
|
42
30
|
}
|
|
43
31
|
/**
|
|
44
32
|
* Get Stripe.js and initialize with Checkout Session mode
|
|
@@ -60,27 +48,13 @@ export class StripePaymentElement {
|
|
|
60
48
|
* ```
|
|
61
49
|
*/
|
|
62
50
|
async initStripeWithCheckoutSession(publishableKey, checkoutSessionClientSecret, options) {
|
|
51
|
+
const generation = ++this.initGeneration;
|
|
63
52
|
await this.stripeService.initializeWithCheckoutSession(publishableKey, checkoutSessionClientSecret, {
|
|
64
53
|
stripeAccount: options === null || options === void 0 ? void 0 : options.stripeAccount,
|
|
65
54
|
applicationName: this.applicationName,
|
|
66
55
|
elementsOptions: options === null || options === void 0 ? void 0 : options.elementsOptions,
|
|
67
56
|
});
|
|
68
|
-
|
|
69
|
-
if (this.stripeService.state.loadStripeStatus === 'success') {
|
|
70
|
-
await this.initElement();
|
|
71
|
-
this.stripeLoadedEventHandler();
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
// Otherwise, wait for successful load
|
|
75
|
-
const unsubscribe = this.stripeService.onChange('loadStripeStatus', async (newState) => {
|
|
76
|
-
if (newState !== 'success') {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
await this.initElement();
|
|
80
|
-
this.stripeLoadedEventHandler();
|
|
81
|
-
unsubscribe(); // Clean up listener after first success
|
|
82
|
-
});
|
|
83
|
-
}
|
|
57
|
+
await this.mountWhenLoaded(generation);
|
|
84
58
|
}
|
|
85
59
|
/**
|
|
86
60
|
* Update the form submit progress
|
|
@@ -122,18 +96,32 @@ export class StripePaymentElement {
|
|
|
122
96
|
const options = {};
|
|
123
97
|
options.stripeAccount = this.stripeService.state.stripeAccount;
|
|
124
98
|
const hasOptionValue = Object.values(options).filter(value => value != null && value !== '').length > 0;
|
|
99
|
+
if (this.hasCheckoutSessionClientSecret()) {
|
|
100
|
+
this.initStripeWithCheckoutSession(publishableKey, this.checkoutSessionClientSecret, { stripeAccount: options.stripeAccount });
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
125
103
|
this.initStripe(publishableKey, hasOptionValue ? options : undefined);
|
|
126
104
|
}
|
|
127
105
|
updateStripeAccountId(stripeAccount) {
|
|
106
|
+
if (this.hasCheckoutSessionClientSecret()) {
|
|
107
|
+
this.initStripeWithCheckoutSession(this.stripeService.state.publishableKey, this.checkoutSessionClientSecret, { stripeAccount });
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
128
110
|
this.initStripe(this.stripeService.state.publishableKey, {
|
|
129
111
|
stripeAccount: stripeAccount,
|
|
130
112
|
});
|
|
131
113
|
}
|
|
132
114
|
async updateIntentClientSecret() {
|
|
133
|
-
//
|
|
134
|
-
if (this.
|
|
135
|
-
|
|
115
|
+
// Checkout Session mode takes precedence (same rule as startStripe); an intent secret must not switch the mode
|
|
116
|
+
if (this.checkoutSessionClientSecret != null && this.checkoutSessionClientSecret !== '') {
|
|
117
|
+
return;
|
|
136
118
|
}
|
|
119
|
+
// The Elements group is bound to its client secret, so it has to be recreated when the secret changes
|
|
120
|
+
const { publishableKey, stripeAccount } = this.stripeService.state;
|
|
121
|
+
if (publishableKey == null || publishableKey === '') {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
await this.initStripe(publishableKey, { stripeAccount });
|
|
137
125
|
}
|
|
138
126
|
async updateCheckoutSessionClientSecret(newValue) {
|
|
139
127
|
// Re-initialize with checkout session when client secret changes
|
|
@@ -187,6 +175,13 @@ export class StripePaymentElement {
|
|
|
187
175
|
if (['success', 'loading'].includes(this.stripeService.state.loadStripeStatus)) {
|
|
188
176
|
return;
|
|
189
177
|
}
|
|
178
|
+
// Retry in the same mode as the initial start
|
|
179
|
+
if (this.checkoutSessionClientSecret != null && this.checkoutSessionClientSecret !== '') {
|
|
180
|
+
this.initStripeWithCheckoutSession(this.stripeService.state.publishableKey, this.checkoutSessionClientSecret, {
|
|
181
|
+
stripeAccount: this.stripeService.state.stripeAccount,
|
|
182
|
+
});
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
190
185
|
this.initStripe(this.stripeService.state.publishableKey, {
|
|
191
186
|
stripeAccount: this.stripeService.state.stripeAccount,
|
|
192
187
|
});
|
|
@@ -233,6 +228,8 @@ export class StripePaymentElement {
|
|
|
233
228
|
}
|
|
234
229
|
}
|
|
235
230
|
constructor() {
|
|
231
|
+
// Incremented on every initStripe call so that a superseded call stops after its awaits
|
|
232
|
+
this.initGeneration = 0;
|
|
236
233
|
/**
|
|
237
234
|
* Default submit handle type.
|
|
238
235
|
* If you want to use `setupIntent`, should update this attribute.
|
|
@@ -274,11 +271,71 @@ export class StripePaymentElement {
|
|
|
274
271
|
// Dependency Injection via factory
|
|
275
272
|
this.stripeService = serviceFactory.createStripeService();
|
|
276
273
|
this.paymentElementManager = serviceFactory.createPaymentElementManager(this.stripeService);
|
|
277
|
-
|
|
278
|
-
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Props are not yet populated inside the constructor when the component is registered via
|
|
277
|
+
* the custom-elements build (`dist/components/*`), so initialization that depends on them
|
|
278
|
+
* must run in `componentWillLoad`, where both the lazy and custom-elements builds have them set.
|
|
279
|
+
*/
|
|
280
|
+
componentWillLoad() {
|
|
281
|
+
this.startStripe();
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Mount the element once Stripe.js has loaded, unless a newer init call (of either mode) has superseded this one.
|
|
285
|
+
* @param generation - The value of `initGeneration` taken when the init call started
|
|
286
|
+
*/
|
|
287
|
+
async mountWhenLoaded(generation) {
|
|
288
|
+
// A newer init call supersedes this one
|
|
289
|
+
if (generation !== this.initGeneration) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
// If already successfully loaded, initialize elements immediately
|
|
293
|
+
if (this.stripeService.state.loadStripeStatus === 'success') {
|
|
294
|
+
await this.initElement();
|
|
295
|
+
if (generation !== this.initGeneration) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
this.stripeLoadedEventHandler();
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
// Otherwise, wait for successful load
|
|
302
|
+
const unsubscribe = this.stripeService.onChange('loadStripeStatus', async (newState) => {
|
|
303
|
+
if (generation !== this.initGeneration) {
|
|
304
|
+
unsubscribe();
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
if (newState !== 'success') {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
await this.initElement();
|
|
311
|
+
if (generation !== this.initGeneration) {
|
|
312
|
+
unsubscribe();
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
this.stripeLoadedEventHandler();
|
|
316
|
+
unsubscribe(); // Clean up listener after first success
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
hasCheckoutSessionClientSecret() {
|
|
320
|
+
return this.checkoutSessionClientSecret != null && this.checkoutSessionClientSecret !== '';
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Start Stripe.js in the mode that matches the given props.
|
|
324
|
+
* Checkout Session mode when `checkoutSessionClientSecret` is set, PaymentIntent / SetupIntent mode otherwise.
|
|
325
|
+
*/
|
|
326
|
+
startStripe() {
|
|
327
|
+
if (this.publishableKey == null || this.publishableKey === '') {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
if (this.checkoutSessionClientSecret != null && this.checkoutSessionClientSecret !== '') {
|
|
331
|
+
this.initStripeWithCheckoutSession(this.publishableKey, this.checkoutSessionClientSecret, {
|
|
279
332
|
stripeAccount: this.stripeAccount,
|
|
280
333
|
});
|
|
334
|
+
return;
|
|
281
335
|
}
|
|
336
|
+
this.initStripe(this.publishableKey, {
|
|
337
|
+
stripeAccount: this.stripeAccount,
|
|
338
|
+
});
|
|
282
339
|
}
|
|
283
340
|
/**
|
|
284
341
|
* Initialize Component using Stripe Element
|
package/dist/collection/components/stripe-payment-request-button/stripe-payment-request-button.js
CHANGED
|
@@ -5,9 +5,17 @@ import { loadStripe } from "@stripe/stripe-js";
|
|
|
5
5
|
* `stripe.paymentRequest()` is being removed in Stripe.js 9.x (deprecated as of 2025-09-30 / 2026-03-25).
|
|
6
6
|
* Please migrate to `<stripe-express-checkout-element>` which supports Apple Pay, Google Pay, Link, PayPal,
|
|
7
7
|
* and more via the modern Express Checkout Element API.
|
|
8
|
-
* Migration guide: https://
|
|
8
|
+
* Migration guide: https://stripe-pwa-elements-docs.wp-kyoto.workers.dev/guides/migrate-payment-request-button-to-express-checkout/
|
|
9
9
|
*/
|
|
10
10
|
export class StripePaymentRequestButton {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.loadStripeStatus = '';
|
|
13
|
+
/**
|
|
14
|
+
* Overwrite the application name that registered
|
|
15
|
+
* For wrapper library (like Capacitor)
|
|
16
|
+
*/
|
|
17
|
+
this.applicationName = 'stripe-pwa-elements';
|
|
18
|
+
}
|
|
11
19
|
/**
|
|
12
20
|
* Check isAvailable ApplePay or GooglePay.
|
|
13
21
|
* If you run this method, you should run before initStripe.
|
|
@@ -60,13 +68,12 @@ export class StripePaymentRequestButton {
|
|
|
60
68
|
}
|
|
61
69
|
this.stripeLoaded.emit(event);
|
|
62
70
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
this.applicationName = 'stripe-pwa-elements';
|
|
71
|
+
/**
|
|
72
|
+
* Props are not yet populated inside the constructor when the component is registered via
|
|
73
|
+
* the custom-elements build (`dist/components/*`), so initialization that depends on them
|
|
74
|
+
* must run in `componentWillLoad`, where both the lazy and custom-elements builds have them set.
|
|
75
|
+
*/
|
|
76
|
+
componentWillLoad() {
|
|
70
77
|
if (this.publishableKey !== undefined && this.paymentRequestOption !== undefined) {
|
|
71
78
|
this.initStripe(this.publishableKey, {
|
|
72
79
|
stripeAccount: this.stripeAccount,
|
|
@@ -80,7 +87,7 @@ export class StripePaymentRequestButton {
|
|
|
80
87
|
console.warn('[stripe-pwa-elements] <stripe-payment-request-button> is deprecated. ' +
|
|
81
88
|
'stripe.paymentRequest() is being removed in Stripe.js 9.x (deprecated 2025-09-30 / removed 2026-03-25). ' +
|
|
82
89
|
'Please migrate to <stripe-express-checkout-element>, which supports Apple Pay, Google Pay, Link, PayPal, and more. ' +
|
|
83
|
-
'Migration guide: https://
|
|
90
|
+
'Migration guide: https://stripe-pwa-elements-docs.wp-kyoto.workers.dev/guides/migrate-payment-request-button-to-express-checkout/');
|
|
84
91
|
}
|
|
85
92
|
/**
|
|
86
93
|
* @param option
|
|
@@ -187,7 +194,7 @@ export class StripePaymentRequestButton {
|
|
|
187
194
|
this.stripe = undefined;
|
|
188
195
|
}
|
|
189
196
|
render() {
|
|
190
|
-
return (h(Host, { key: '
|
|
197
|
+
return (h(Host, { key: '644a4b729c72e87b42df5e1b43262d3195e7ebc6' }, h("div", { key: 'aff26789868bbec0f1f6abc463fb14d7f3e73c1b', id: "payment-request" }, h("div", { key: '074a25f3c5b2575696ddaeacf2715935212964a5', id: "payment-request-button" })), h("slot", { key: '5173400bd63ab201f02934cea4edcab4bb7eed9c' })));
|
|
191
198
|
}
|
|
192
199
|
static get is() { return "stripe-payment-request-button"; }
|
|
193
200
|
static get originalStyleUrls() {
|