stripe-pwa-elements 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{factory-da3xAKkz.js → factory-Cd2VI_N2.js} +22 -4
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/stripe-address-element.cjs.entry.js +8 -1
- package/dist/cjs/stripe-card-element-modal.cjs.entry.js +1 -1
- package/dist/cjs/stripe-card-element_2.cjs.entry.js +24 -6
- package/dist/cjs/stripe-currency-selector.cjs.entry.js +8 -1
- package/dist/cjs/stripe-elements.cjs.js +1 -1
- package/dist/cjs/stripe-express-checkout-element.cjs.entry.js +8 -1
- package/dist/cjs/stripe-link-authentication-element.cjs.entry.js +8 -1
- package/dist/cjs/stripe-payment-element.cjs.entry.js +95 -38
- package/dist/cjs/stripe-payment-request-button.cjs.entry.js +22 -15
- package/dist/collection/collection-manifest.json +3 -3
- package/dist/collection/components/stripe-address-element/stripe-address-element.js +7 -0
- package/dist/collection/components/stripe-card-element/stripe-card-element.js +7 -0
- package/dist/collection/components/stripe-card-element-modal/stripe-card-element-modal.js +1 -1
- 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 +7 -0
- package/dist/collection/components/stripe-link-authentication-element/stripe-link-authentication-element.js +7 -0
- package/dist/collection/components/stripe-modal/stripe-modal.js +18 -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 +15 -8
- package/dist/collection/services/stripe-service.js +22 -4
- package/dist/components/factory.js +1 -1
- 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.js +1 -1
- package/dist/components/stripe-payment-request-button2.js +1 -1
- package/dist/esm/{factory-DeqoYLf_.js → factory-VTa1Gc94.js} +22 -4
- package/dist/esm/loader.js +1 -1
- package/dist/esm/stripe-address-element.entry.js +8 -1
- package/dist/esm/stripe-card-element-modal.entry.js +1 -1
- package/dist/esm/stripe-card-element_2.entry.js +24 -6
- package/dist/esm/stripe-currency-selector.entry.js +8 -1
- package/dist/esm/stripe-elements.js +1 -1
- package/dist/esm/stripe-express-checkout-element.entry.js +8 -1
- package/dist/esm/stripe-link-authentication-element.entry.js +8 -1
- package/dist/esm/stripe-payment-element.entry.js +95 -38
- package/dist/esm/stripe-payment-request-button.entry.js +17 -10
- package/dist/stripe-elements/p-1bd46766.entry.js +1 -0
- package/dist/stripe-elements/p-1c6e0a45.entry.js +1 -0
- package/dist/stripe-elements/p-3f42ca0c.entry.js +1 -0
- package/dist/stripe-elements/p-74de1556.entry.js +1 -0
- package/dist/stripe-elements/p-76e57d78.entry.js +1 -0
- package/dist/stripe-elements/p-840d499f.entry.js +1 -0
- package/dist/stripe-elements/{p--sA2m1ad.js → p-CrjrbGJ3.js} +1 -1
- package/dist/stripe-elements/{p-38e7b187.entry.js → p-ae0c336e.entry.js} +1 -1
- package/dist/stripe-elements/p-cfd8e081.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 +6 -0
- 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 +6 -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 +1 -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 +6 -1
- package/dist/types/services/interfaces.d.ts +1 -0
- package/dist/types/services/stripe-service.d.ts +6 -2
- package/package.json +1 -1
- package/readme.md +4 -4
- 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-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
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index
|
|
4
|
-
var index = require('./index-CYbA1N_k.js');
|
|
3
|
+
var index = require('./index-Dkb0SxZc.js');
|
|
4
|
+
var index$1 = require('./index-CYbA1N_k.js');
|
|
5
5
|
|
|
6
6
|
const stripePaymentRequestButtonCss = () => `:host{display:block}`;
|
|
7
7
|
|
|
8
8
|
const StripePaymentRequestButton = class {
|
|
9
|
+
constructor(hostRef) {
|
|
10
|
+
index.registerInstance(this, hostRef);
|
|
11
|
+
this.stripeLoaded = index.createEvent(this, "stripeLoaded", 7);
|
|
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
|
+
}
|
|
9
19
|
/**
|
|
10
20
|
* Check isAvailable ApplePay or GooglePay.
|
|
11
21
|
* If you run this method, you should run before initStripe.
|
|
@@ -14,7 +24,7 @@ const StripePaymentRequestButton = class {
|
|
|
14
24
|
if (this.publishableKey === undefined) {
|
|
15
25
|
throw new Error('You should set publishableKey before calling this method.');
|
|
16
26
|
}
|
|
17
|
-
const stripe = await index.loadStripe(this.publishableKey, {
|
|
27
|
+
const stripe = await index$1.loadStripe(this.publishableKey, {
|
|
18
28
|
stripeAccount: this.stripeAccount,
|
|
19
29
|
});
|
|
20
30
|
const paymentRequest = stripe.paymentRequest({
|
|
@@ -58,15 +68,12 @@ const StripePaymentRequestButton = class {
|
|
|
58
68
|
}
|
|
59
69
|
this.stripeLoaded.emit(event);
|
|
60
70
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
* For wrapper library (like Capacitor)
|
|
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,
|
|
@@ -97,7 +104,7 @@ const StripePaymentRequestButton = class {
|
|
|
97
104
|
*/
|
|
98
105
|
async initStripe(publishableKey, options = undefined) {
|
|
99
106
|
this.loadStripeStatus = 'loading';
|
|
100
|
-
index.loadStripe(publishableKey, {
|
|
107
|
+
index$1.loadStripe(publishableKey, {
|
|
101
108
|
stripeAccount: options === null || options === void 0 ? void 0 : options.stripeAccount,
|
|
102
109
|
})
|
|
103
110
|
.then(stripe => {
|
|
@@ -187,9 +194,9 @@ const StripePaymentRequestButton = class {
|
|
|
187
194
|
this.stripe = undefined;
|
|
188
195
|
}
|
|
189
196
|
render() {
|
|
190
|
-
return (index
|
|
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' })));
|
|
191
198
|
}
|
|
192
|
-
get el() { return index
|
|
199
|
+
get el() { return index.getElement(this); }
|
|
193
200
|
};
|
|
194
201
|
StripePaymentRequestButton.style = stripePaymentRequestButtonCss();
|
|
195
202
|
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
"components/stripe-address-element/stripe-address-element.js",
|
|
4
4
|
"components/stripe-payment-element/stripe-payment-element.js",
|
|
5
5
|
"components/stripe-card-element/stripe-card-element.js",
|
|
6
|
-
"components/stripe-card-element-modal/stripe-card-element-modal.js",
|
|
7
6
|
"components/stripe-currency-selector/stripe-currency-selector.js",
|
|
8
7
|
"components/stripe-express-checkout-element/stripe-express-checkout-element.js",
|
|
9
8
|
"components/stripe-link-authentication-element/stripe-link-authentication-element.js",
|
|
10
|
-
"components/stripe-
|
|
11
|
-
"components/stripe-
|
|
9
|
+
"components/stripe-payment-request-button/stripe-payment-request-button.js",
|
|
10
|
+
"components/stripe-card-element-modal/stripe-card-element-modal.js",
|
|
11
|
+
"components/stripe-modal/stripe-modal.js"
|
|
12
12
|
],
|
|
13
13
|
"mixins": [],
|
|
14
14
|
"compiler": {
|
|
@@ -184,6 +184,13 @@ export class StripeAddressElement {
|
|
|
184
184
|
// Dependency Injection via factory
|
|
185
185
|
this.stripeService = serviceFactory.createStripeService();
|
|
186
186
|
this.addressElementManager = serviceFactory.createAddressElementManager(this.stripeService);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Props are not yet populated inside the constructor when the component is registered via
|
|
190
|
+
* the custom-elements build (`dist/components/*`), so initialization that depends on them
|
|
191
|
+
* must run in `componentWillLoad`, where both the lazy and custom-elements builds have them set.
|
|
192
|
+
*/
|
|
193
|
+
componentWillLoad() {
|
|
187
194
|
if (this.publishableKey != null && this.publishableKey !== '') {
|
|
188
195
|
this.initStripe(this.publishableKey, {
|
|
189
196
|
stripeAccount: this.stripeAccount,
|
|
@@ -236,6 +236,13 @@ export class StripeCardElement {
|
|
|
236
236
|
// Dependency Injection via factory
|
|
237
237
|
this.stripeService = serviceFactory.createStripeService();
|
|
238
238
|
this.cardElementManager = serviceFactory.createCardElementManager(this.stripeService);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Props are not yet populated inside the constructor when the component is registered via
|
|
242
|
+
* the custom-elements build (`dist/components/*`), so initialization that depends on them
|
|
243
|
+
* must run in `componentWillLoad`, where both the lazy and custom-elements builds have them set.
|
|
244
|
+
*/
|
|
245
|
+
componentWillLoad() {
|
|
239
246
|
if (this.publishableKey != null && this.publishableKey !== '') {
|
|
240
247
|
this.initStripe(this.publishableKey, buildInitStripeOptionsFromAccount(this.stripeAccount));
|
|
241
248
|
}
|
|
@@ -94,7 +94,7 @@ export class StripeCardElementModal {
|
|
|
94
94
|
cardElement.setPaymentRequestOption(options);
|
|
95
95
|
}
|
|
96
96
|
render() {
|
|
97
|
-
return (h("stripe-modal", { key: '
|
|
97
|
+
return (h("stripe-modal", { key: 'a0229c55472e3c6f417086fa08d79e1ec8a8c485', open: this.open, showCloseButton: this.showCloseButton }, h("stripe-card-element", { key: '799f08c781bad089cec8b1338e9a714d080abd51', showLabel: this.showLabel, publishableKey: this.publishableKey, intentClientSecret: this.intentClientSecret, shouldUseDefaultFormSubmitAction: this.shouldUseDefaultFormSubmitAction, handleSubmit: this.handleSubmit, stripeDidLoaded: this.stripeDidLoaded, intentType: this.intentType, zip: this.zip, buttonLabel: this.buttonLabel, sheetTitle: this.sheetTitle, applicationName: this.applicationName })));
|
|
98
98
|
}
|
|
99
99
|
static get is() { return "stripe-card-element-modal"; }
|
|
100
100
|
static get originalStyleUrls() {
|
|
@@ -127,6 +127,13 @@ export class StripeCurrencySelector {
|
|
|
127
127
|
// Dependency Injection via factory
|
|
128
128
|
this.stripeService = serviceFactory.createStripeService();
|
|
129
129
|
this.currencySelectorElementManager = serviceFactory.createCurrencySelectorElementManager(this.stripeService);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Props are not yet populated inside the constructor when the component is registered via
|
|
133
|
+
* the custom-elements build (`dist/components/*`), so initialization that depends on them
|
|
134
|
+
* must run in `componentWillLoad`, where both the lazy and custom-elements builds have them set.
|
|
135
|
+
*/
|
|
136
|
+
componentWillLoad() {
|
|
130
137
|
if (this.publishableKey) {
|
|
131
138
|
this.initStripe(this.publishableKey, {
|
|
132
139
|
stripeAccount: this.stripeAccount,
|
|
@@ -155,6 +155,13 @@ export class StripeExpressCheckoutElement {
|
|
|
155
155
|
// Dependency Injection via factory
|
|
156
156
|
this.stripeService = serviceFactory.createStripeService();
|
|
157
157
|
this.expressCheckoutManager = serviceFactory.createExpressCheckoutElementManager(this.stripeService);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Props are not yet populated inside the constructor when the component is registered via
|
|
161
|
+
* the custom-elements build (`dist/components/*`), so initialization that depends on them
|
|
162
|
+
* must run in `componentWillLoad`, where both the lazy and custom-elements builds have them set.
|
|
163
|
+
*/
|
|
164
|
+
componentWillLoad() {
|
|
158
165
|
if (this.publishableKey != null && this.publishableKey !== '') {
|
|
159
166
|
this.initStripe(this.publishableKey, {
|
|
160
167
|
stripeAccount: this.stripeAccount,
|
|
@@ -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,
|
|
@@ -17,6 +17,15 @@ export class StripeModal {
|
|
|
17
17
|
*/
|
|
18
18
|
this.renderedOpen = false;
|
|
19
19
|
}
|
|
20
|
+
onOpenChange(open) {
|
|
21
|
+
if (open) {
|
|
22
|
+
this.openModalAnimation();
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.renderedOpen = false;
|
|
26
|
+
this.close.emit();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
20
29
|
/**
|
|
21
30
|
* Toggle modal state
|
|
22
31
|
*/
|
|
@@ -28,15 +37,12 @@ export class StripeModal {
|
|
|
28
37
|
*/
|
|
29
38
|
async openModal() {
|
|
30
39
|
this.open = true;
|
|
31
|
-
this.openModalAnimation();
|
|
32
40
|
}
|
|
33
41
|
/**
|
|
34
42
|
* Close the modal
|
|
35
43
|
*/
|
|
36
44
|
async closeModal() {
|
|
37
45
|
this.open = false;
|
|
38
|
-
this.renderedOpen = false;
|
|
39
|
-
this.close.emit();
|
|
40
46
|
}
|
|
41
47
|
componentDidLoad() {
|
|
42
48
|
const platformName = checkPlatform();
|
|
@@ -60,12 +66,12 @@ export class StripeModal {
|
|
|
60
66
|
modalChild.classList.remove('loading');
|
|
61
67
|
}, { once: true });
|
|
62
68
|
requestAnimationFrame(() => {
|
|
63
|
-
this.renderedOpen =
|
|
69
|
+
this.renderedOpen = this.open;
|
|
64
70
|
});
|
|
65
71
|
}
|
|
66
72
|
render() {
|
|
67
73
|
const { renderedOpen, showCloseButton } = this;
|
|
68
|
-
return (h(Host, { key: '
|
|
74
|
+
return (h(Host, { key: '38fb86acf7cf5887a426c67b1a1271f7fae7048c' }, h("div", { key: 'f751d92c327ee2e564edfcd4d18f4dca43c20c37', class: `modal-row${renderedOpen ? ' open' : ''}`, onClick: () => this.closeModal() }, h("div", { key: '11519ccd44a5069df3247c530a2c1e114eab7aef', class: "modal-child", onClick: e => e.stopPropagation() }, showCloseButton ? (h("div", { class: "modal-close-button-wrap" }, h("ion-icon", { name: "close", size: "large", class: "modal-close-button", onClick: () => this.closeModal() }))) : null, h("div", { key: 'a41f7f263b488b5bbc2a999cbabf6b9e407bca85', class: "modal-loading" }, h("svg", { key: '0b3b25cb2812bc4d837fb4b7e6af4a5f42f0247e', version: "1.1", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 2400 2400" }, h("g", { key: '10a9f9ec59699e6d2988b9c65cd02da1754fd760', "stroke-width": "200", "stroke-linecap": "round", stroke: "currentColor", fill: "none", id: "spinner" }, h("line", { key: 'ed271fa584b930ceed5397c271b31e0d48c72f72', x1: "1200", y1: "600", x2: "1200", y2: "100" }), h("line", { key: '3cf855a84f3ab58b914b7aeb784fbc5b95d8ae94', opacity: "0.5", x1: "1200", y1: "2300", x2: "1200", y2: "1800" }), h("line", { key: '2cce4b62a276399235509e94f47a63acf9c69a0f', opacity: "0.917", x1: "900", y1: "680.4", x2: "650", y2: "247.4" }), h("line", { key: '64c175ef068591417b043f7630a44d34eae7cb59', opacity: "0.417", x1: "1750", y1: "2152.6", x2: "1500", y2: "1719.6" }), h("line", { key: '0856a654e3aa756dfb1e9fc316b8b379fa9d5a4e', opacity: "0.833", x1: "680.4", y1: "900", x2: "247.4", y2: "650" }), h("line", { key: 'c60f1f8495df9b8cdcc8941255d08c01a0e1c02f', opacity: "0.333", x1: "2152.6", y1: "1750", x2: "1719.6", y2: "1500" }), h("line", { key: '204bc2a7765e43b86f91c3fb9b1e72a3a39bb323', opacity: "0.75", x1: "600", y1: "1200", x2: "100", y2: "1200" }), h("line", { key: '7584b272f9efd7f746c1bcc5c8a5576098b02381', opacity: "0.25", x1: "2300", y1: "1200", x2: "1800", y2: "1200" }), h("line", { key: '7a053e9eb5f0da3fbf6fb7c9680bf73073bb126d', opacity: "0.667", x1: "680.4", y1: "1500", x2: "247.4", y2: "1750" }), h("line", { key: 'f8b817095143d739589e45c99b03c7afbdfc8293', opacity: "0.167", x1: "2152.6", y1: "650", x2: "1719.6", y2: "900" }), h("line", { key: 'aae0e36dbdfff44196f9758c8a5ed2337139ebe0', opacity: "0.583", x1: "900", y1: "1719.6", x2: "650", y2: "2152.6" }), h("line", { key: '3a257b30cb289f29ba386ccca7519bcdc22c3786', opacity: "0.083", x1: "1750", y1: "247.4", x2: "1500", y2: "680.4" }), h("animateTransform", { key: 'c6b8e73025589403dd3d08f84b02eb824763d056', 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: 'da5ef8031e5b826d854a065d8172389cdd84fbf0', class: "modal-content" }, h("slot", { key: 'fbe97a3a4d5489de5ae6f49342c58d537b317842' }))))));
|
|
69
75
|
}
|
|
70
76
|
static get is() { return "stripe-modal"; }
|
|
71
77
|
static get encapsulation() { return "shadow"; }
|
|
@@ -103,7 +109,7 @@ export class StripeModal {
|
|
|
103
109
|
},
|
|
104
110
|
"open": {
|
|
105
111
|
"type": "boolean",
|
|
106
|
-
"mutable":
|
|
112
|
+
"mutable": true,
|
|
107
113
|
"complexType": {
|
|
108
114
|
"original": "boolean",
|
|
109
115
|
"resolved": "boolean",
|
|
@@ -202,4 +208,10 @@ export class StripeModal {
|
|
|
202
208
|
};
|
|
203
209
|
}
|
|
204
210
|
static get elementRef() { return "el"; }
|
|
211
|
+
static get watchers() {
|
|
212
|
+
return [{
|
|
213
|
+
"propName": "open",
|
|
214
|
+
"methodName": "onOpenChange"
|
|
215
|
+
}];
|
|
216
|
+
}
|
|
205
217
|
}
|
|
@@ -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
|
@@ -8,6 +8,14 @@ import { loadStripe } from "@stripe/stripe-js";
|
|
|
8
8
|
* Migration guide: https://hideokamoto.github.io/stripe-pwa-elements/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,
|
|
@@ -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: 'dd3ae348f9e9c798acdeca095ad9c157afd4734f' }, h("div", { key: 'f2e13b6980318ede1812d4f54223b7aeb9cfc51b', id: "payment-request" }, h("div", { key: 'ff6c1218924044d1ffc11354909f25c1745ef254', id: "payment-request-button" })), h("slot", { key: 'ec2131a0503baa15cdcf3571040e9ce6040da708' })));
|
|
191
198
|
}
|
|
192
199
|
static get is() { return "stripe-payment-request-button"; }
|
|
193
200
|
static get originalStyleUrls() {
|
|
@@ -12,6 +12,8 @@ class StripeServiceClass {
|
|
|
12
12
|
applicationName: 'stripe-pwa-elements',
|
|
13
13
|
isCheckoutSession: false,
|
|
14
14
|
});
|
|
15
|
+
/** Incremented on every init so that a slower, older call cannot overwrite newer state */
|
|
16
|
+
this.initGeneration = 0;
|
|
15
17
|
this.changeListeners = new Map();
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
@@ -39,12 +41,20 @@ class StripeServiceClass {
|
|
|
39
41
|
/**
|
|
40
42
|
* Initialize Stripe.js client with Payment Intent mode
|
|
41
43
|
* @param publishableKey - Your Stripe publishable API key
|
|
42
|
-
* @param options - Optional configuration
|
|
44
|
+
* @param options - Optional configuration (`clientSecret` is the PaymentIntent / SetupIntent client secret)
|
|
43
45
|
*/
|
|
44
46
|
async initialize(publishableKey, options) {
|
|
47
|
+
const generation = ++this.initGeneration;
|
|
48
|
+
// Capture the previous config before overwriting it, so we can detect real changes
|
|
49
|
+
const isUpToDate = this.store.state.stripe != null &&
|
|
50
|
+
!this.store.state.isCheckoutSession &&
|
|
51
|
+
this.store.state.publishableKey === publishableKey &&
|
|
52
|
+
this.store.state.stripeAccount === (options === null || options === void 0 ? void 0 : options.stripeAccount) &&
|
|
53
|
+
this.intentClientSecret === (options === null || options === void 0 ? void 0 : options.clientSecret);
|
|
45
54
|
// Update configuration
|
|
46
55
|
this.store.state.publishableKey = publishableKey;
|
|
47
56
|
this.store.state.isCheckoutSession = false;
|
|
57
|
+
this.intentClientSecret = options === null || options === void 0 ? void 0 : options.clientSecret;
|
|
48
58
|
if ((options === null || options === void 0 ? void 0 : options.stripeAccount) != null && (options === null || options === void 0 ? void 0 : options.stripeAccount) !== '') {
|
|
49
59
|
this.store.state.stripeAccount = options.stripeAccount;
|
|
50
60
|
}
|
|
@@ -52,7 +62,7 @@ class StripeServiceClass {
|
|
|
52
62
|
this.store.state.applicationName = options.applicationName;
|
|
53
63
|
}
|
|
54
64
|
// If Stripe.js already loaded with same config, do nothing
|
|
55
|
-
if (
|
|
65
|
+
if (isUpToDate) {
|
|
56
66
|
return;
|
|
57
67
|
}
|
|
58
68
|
this.store.state.loadStripeStatus = 'loading';
|
|
@@ -60,12 +70,16 @@ class StripeServiceClass {
|
|
|
60
70
|
const stripe = await loadStripe(publishableKey, {
|
|
61
71
|
stripeAccount: options === null || options === void 0 ? void 0 : options.stripeAccount,
|
|
62
72
|
});
|
|
73
|
+
if (generation !== this.initGeneration) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
63
76
|
// Register app info
|
|
64
77
|
stripe.registerAppInfo({
|
|
65
78
|
name: this.store.state.applicationName,
|
|
66
79
|
});
|
|
67
80
|
this.store.state.stripe = stripe;
|
|
68
|
-
|
|
81
|
+
// Payment Element requires the client secret at Elements creation time
|
|
82
|
+
this.store.state.elements = (options === null || options === void 0 ? void 0 : options.clientSecret) != null && options.clientSecret !== '' ? stripe.elements({ clientSecret: options.clientSecret }) : stripe.elements();
|
|
69
83
|
this.store.state.checkout = undefined;
|
|
70
84
|
this.store.state.loadStripeStatus = 'success';
|
|
71
85
|
}
|
|
@@ -78,9 +92,10 @@ class StripeServiceClass {
|
|
|
78
92
|
* Initialize Stripe.js client with Checkout Session mode
|
|
79
93
|
* @param publishableKey - Your Stripe publishable API key
|
|
80
94
|
* @param checkoutSessionClientSecret - The client secret from Checkout Session
|
|
81
|
-
* @param options - Optional configuration
|
|
95
|
+
* @param options - Optional configuration (`clientSecret` is the PaymentIntent / SetupIntent client secret)
|
|
82
96
|
*/
|
|
83
97
|
async initializeWithCheckoutSession(publishableKey, checkoutSessionClientSecret, options) {
|
|
98
|
+
const generation = ++this.initGeneration;
|
|
84
99
|
// Update configuration
|
|
85
100
|
this.store.state.publishableKey = publishableKey;
|
|
86
101
|
this.store.state.isCheckoutSession = true;
|
|
@@ -95,6 +110,9 @@ class StripeServiceClass {
|
|
|
95
110
|
const stripe = await loadStripe(publishableKey, {
|
|
96
111
|
stripeAccount: options === null || options === void 0 ? void 0 : options.stripeAccount,
|
|
97
112
|
});
|
|
113
|
+
if (generation !== this.initGeneration) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
98
116
|
// Register app info
|
|
99
117
|
stripe.registerAppInfo({
|
|
100
118
|
name: this.store.state.applicationName,
|