@stripe/connect-js 3.3.30-preview-1 → 3.3.30
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/README.md +3 -3
- package/dist/connect.esm.js +46 -91
- package/dist/connect.js +46 -91
- package/dist/pure.esm.js +38 -83
- package/dist/pure.js +38 -83
- package/dist/src/index.d.ts +1 -1
- package/dist/src/pure.d.ts +1 -1
- package/dist/src/shared.d.ts +3 -2
- package/dist/types/config.d.ts +24 -74
- package/package.json +14 -10
- package/src/index.ts +3 -6
- package/src/pure.test.ts +2 -2
- package/src/pure.ts +3 -6
- package/src/shared.ts +57 -61
- package/types/checks.ts +2 -2
- package/types/config.ts +39 -118
- package/types/index.d.ts +1 -1
- package/types/shared.d.ts +11 -20
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ const fetchClientSecret = async () => {
|
|
|
36
36
|
|
|
37
37
|
const instance = loadConnectAndInitialize({
|
|
38
38
|
publishableKey: "{{pk test123}}",
|
|
39
|
-
fetchClientSecret: fetchClientSecret
|
|
39
|
+
fetchClientSecret: fetchClientSecret,
|
|
40
40
|
});
|
|
41
41
|
```
|
|
42
42
|
|
|
@@ -47,7 +47,7 @@ test this code through your Connect account.
|
|
|
47
47
|
If you have deployed a
|
|
48
48
|
[Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/Security/CSP),
|
|
49
49
|
make sure to
|
|
50
|
-
[include Connect.js in your directives](https://stripe.com/docs/
|
|
50
|
+
[include Connect.js in your directives](https://stripe.com/docs/connect/get-started-connect-embedded-components?platform=web#csp-and-http-header-requirements).
|
|
51
51
|
|
|
52
52
|
### Import as a side effect
|
|
53
53
|
|
|
@@ -71,6 +71,6 @@ import { loadConnectAndInitialize } from "@stripe/connect-js/pure";
|
|
|
71
71
|
// Connect.js will not be loaded until `loadConnect` is called
|
|
72
72
|
const instance = loadConnectAndInitialize({
|
|
73
73
|
publishableKey: "{{pk test123}}",
|
|
74
|
-
fetchClientSecret: fetchClientSecret
|
|
74
|
+
fetchClientSecret: fetchClientSecret,
|
|
75
75
|
});
|
|
76
76
|
```
|
package/dist/connect.esm.js
CHANGED
|
@@ -5,17 +5,6 @@ const ConnectElementCommonMethodConfig = {
|
|
|
5
5
|
setOnLoaderStart: _listener => {}
|
|
6
6
|
};
|
|
7
7
|
const ConnectElementCustomMethodConfig = {
|
|
8
|
-
payments: {
|
|
9
|
-
setDefaultFilters: _filters => {}
|
|
10
|
-
},
|
|
11
|
-
"payment-details": {
|
|
12
|
-
setPayment: _payment => {},
|
|
13
|
-
setOnClose: _listener => {}
|
|
14
|
-
},
|
|
15
|
-
"payment-disputes": {
|
|
16
|
-
setPayment: _payment => {},
|
|
17
|
-
setOnDisputesLoaded: _listener => {}
|
|
18
|
-
},
|
|
19
8
|
"account-onboarding": {
|
|
20
9
|
setFullTermsOfServiceUrl: _termOfServiceUrl => {},
|
|
21
10
|
setRecipientTermsOfServiceUrl: _recipientTermsOfServiceUrl => {},
|
|
@@ -32,6 +21,10 @@ const ConnectElementCustomMethodConfig = {
|
|
|
32
21
|
setCollectionOptions: _collectionOptions => {},
|
|
33
22
|
setOnNotificationsChange: _listener => {}
|
|
34
23
|
},
|
|
24
|
+
"instant-payouts-promotion": {
|
|
25
|
+
setOnInstantPayoutsPromotionLoaded: _listener => {},
|
|
26
|
+
setOnInstantPayoutCreated: _listener => {}
|
|
27
|
+
},
|
|
35
28
|
"issuing-card": {
|
|
36
29
|
setDefaultCard: _defaultCard => {},
|
|
37
30
|
setCardSwitching: _cardSwitching => {},
|
|
@@ -49,46 +42,16 @@ const ConnectElementCustomMethodConfig = {
|
|
|
49
42
|
"financial-account-transactions": {
|
|
50
43
|
setFinancialAccount: _financialAccount => {}
|
|
51
44
|
},
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
},
|
|
55
|
-
"app-install": {
|
|
56
|
-
setApp: _app => {},
|
|
57
|
-
setOnAppInstallStateFetched: _listener => {},
|
|
58
|
-
setOnAppInstallStateChanged: _listener => {}
|
|
59
|
-
},
|
|
60
|
-
"app-viewport": {
|
|
61
|
-
setApp: _app => {},
|
|
62
|
-
setAppData: _appData => {}
|
|
63
|
-
},
|
|
64
|
-
"payment-method-settings": {
|
|
65
|
-
setPaymentMethodConfiguration: _paymentMethodConfiguration => {}
|
|
66
|
-
},
|
|
67
|
-
"capital-financing": {
|
|
68
|
-
setDefaultFinancingOffer: _defaultFinancingOffer => {},
|
|
69
|
-
setShowFinancingSelector: _showFinancingSelector => {},
|
|
70
|
-
setHowCapitalWorksUrl: _howCapitalWorksUrl => {},
|
|
71
|
-
setSupportUrl: _supportUrl => {},
|
|
72
|
-
setOnFinancingsLoaded: _listener => {}
|
|
73
|
-
},
|
|
74
|
-
"capital-financing-application": {
|
|
75
|
-
setOnApplicationSubmitted: _listener => {},
|
|
76
|
-
setPrivacyPolicyUrl: _privacyPolicyUrl => {},
|
|
77
|
-
setHowCapitalWorksUrl: _howCapitalWorksUrl => {}
|
|
45
|
+
payments: {
|
|
46
|
+
setDefaultFilters: _filters => {}
|
|
78
47
|
},
|
|
79
|
-
"
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
setOnEligibleFinancingOfferLoaded: _listener => {},
|
|
83
|
-
setPrivacyPolicyUrl: _privacyPolicyUrl => {},
|
|
84
|
-
setHowCapitalWorksUrl: _howCapitalWorksUrl => {},
|
|
85
|
-
setEligibilityCriteriaUrl: _eligibilityCriteriaUrl => {}
|
|
48
|
+
"payment-details": {
|
|
49
|
+
setPayment: _payment => {},
|
|
50
|
+
setOnClose: _listener => {}
|
|
86
51
|
},
|
|
87
|
-
"
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
setIntervalEnd: _intervalEnd => {},
|
|
91
|
-
setIntervalType: _intervalType => {}
|
|
52
|
+
"payment-disputes": {
|
|
53
|
+
setPayment: _payment => {},
|
|
54
|
+
setOnDisputesLoaded: _listener => {}
|
|
92
55
|
},
|
|
93
56
|
"tax-settings": {
|
|
94
57
|
setHideProductTaxCodeSelector: _hidden => {},
|
|
@@ -99,54 +62,38 @@ const ConnectElementCustomMethodConfig = {
|
|
|
99
62
|
setOnAfterTaxRegistrationAdded: _listener => {},
|
|
100
63
|
setDisplayCountries: _countries => {}
|
|
101
64
|
},
|
|
102
|
-
"
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
setOnTaxCodeSelect: _listener => {},
|
|
107
|
-
setHideDescription: _hideDescription => {},
|
|
108
|
-
setDisabled: _disabled => {},
|
|
109
|
-
setInitialTaxCode: _initialTaxCode => {}
|
|
110
|
-
},
|
|
111
|
-
"export-tax-transactions": {}
|
|
65
|
+
"payout-details": {
|
|
66
|
+
setPayout: _payout => {},
|
|
67
|
+
setOnClose: _listener => {}
|
|
68
|
+
}
|
|
112
69
|
};
|
|
113
70
|
|
|
114
71
|
const componentNameMapping = {
|
|
72
|
+
"account-onboarding": "stripe-connect-account-onboarding",
|
|
73
|
+
"disputes-list": "stripe-connect-disputes-list",
|
|
115
74
|
payments: "stripe-connect-payments",
|
|
116
|
-
payouts: "stripe-connect-payouts",
|
|
117
75
|
"payment-details": "stripe-connect-payment-details",
|
|
118
76
|
"payment-disputes": "stripe-connect-payment-disputes",
|
|
119
|
-
|
|
120
|
-
"
|
|
77
|
+
payouts: "stripe-connect-payouts",
|
|
78
|
+
"payouts-list": "stripe-connect-payouts-list",
|
|
79
|
+
"payout-details": "stripe-connect-payout-details",
|
|
80
|
+
balances: "stripe-connect-balances",
|
|
121
81
|
"account-management": "stripe-connect-account-management",
|
|
122
82
|
"notification-banner": "stripe-connect-notification-banner",
|
|
123
|
-
"instant-payouts": "stripe-connect-instant-payouts",
|
|
83
|
+
"instant-payouts-promotion": "stripe-connect-instant-payouts-promotion",
|
|
124
84
|
"issuing-card": "stripe-connect-issuing-card",
|
|
125
85
|
"issuing-cards-list": "stripe-connect-issuing-cards-list",
|
|
126
86
|
"financial-account": "stripe-connect-financial-account",
|
|
127
|
-
recipients: "stripe-connect-recipients",
|
|
128
87
|
"financial-account-transactions": "stripe-connect-financial-account-transactions",
|
|
129
|
-
"capital-financing": "stripe-connect-capital-financing",
|
|
130
|
-
"capital-financing-application": "stripe-connect-capital-financing-application",
|
|
131
|
-
"capital-financing-promotion": "stripe-connect-capital-financing-promotion",
|
|
132
|
-
"capital-overview": "stripe-connect-capital-overview",
|
|
133
88
|
documents: "stripe-connect-documents",
|
|
134
|
-
"product-tax-code-selector": "stripe-connect-product-tax-code-selector",
|
|
135
|
-
"export-tax-transactions": "stripe-connect-export-tax-transactions",
|
|
136
89
|
"tax-registrations": "stripe-connect-tax-registrations",
|
|
137
|
-
"tax-settings": "stripe-connect-tax-settings"
|
|
138
|
-
"tax-threshold-monitoring": "stripe-connect-tax-threshold-monitoring",
|
|
139
|
-
balances: "stripe-connect-balances",
|
|
140
|
-
"payouts-list": "stripe-connect-payouts-list",
|
|
141
|
-
"app-install": "stripe-connect-app-install",
|
|
142
|
-
"app-viewport": "stripe-connect-app-viewport",
|
|
143
|
-
"reporting-chart": "stripe-connect-reporting-chart"
|
|
90
|
+
"tax-settings": "stripe-connect-tax-settings"
|
|
144
91
|
};
|
|
145
92
|
const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
|
|
146
93
|
const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
|
|
147
94
|
const V1_URL = "https://connect-js.stripe.com/v1.0/connect.js";
|
|
148
95
|
const findScript = () => {
|
|
149
|
-
return document.querySelectorAll(`script[src="${
|
|
96
|
+
return document.querySelectorAll(`script[src="${V1_URL}"]`)[0] || document.querySelectorAll(`script[src="${V0_URL}"]`)[0] || null;
|
|
150
97
|
};
|
|
151
98
|
const injectScript = () => {
|
|
152
99
|
const script = document.createElement("script");
|
|
@@ -158,21 +105,26 @@ const injectScript = () => {
|
|
|
158
105
|
document.head.appendChild(script);
|
|
159
106
|
return script;
|
|
160
107
|
};
|
|
161
|
-
let stripePromise = null;
|
|
108
|
+
let stripePromise$1 = null;
|
|
109
|
+
const isWindowStripeConnectDefined = stripeConnect => {
|
|
110
|
+
// We only consider `StripeConnect` defined if `init` is a function
|
|
111
|
+
// Why? HTML markup like:
|
|
112
|
+
// <a id="StripeConnect"><a id="StripeConnect" name="init" href="stripe"></a></a> in the <head> of the page
|
|
113
|
+
// can end up "contaminating" the window.StripeConnect object and cause issues in connect.js initialization
|
|
114
|
+
return !!(stripeConnect && typeof stripeConnect === "object" && "init" in stripeConnect && typeof stripeConnect.init === "function");
|
|
115
|
+
};
|
|
162
116
|
const loadScript = () => {
|
|
163
117
|
// Ensure that we only attempt to load Connect.js at most once
|
|
164
|
-
if (stripePromise !== null) {
|
|
165
|
-
return stripePromise;
|
|
118
|
+
if (stripePromise$1 !== null) {
|
|
119
|
+
return stripePromise$1;
|
|
166
120
|
}
|
|
167
|
-
stripePromise = new Promise((resolve, reject) => {
|
|
121
|
+
stripePromise$1 = new Promise((resolve, reject) => {
|
|
168
122
|
if (typeof window === "undefined") {
|
|
169
123
|
reject("ConnectJS won't load when rendering code in the server - it can only be loaded on a browser. This error is expected when loading ConnectJS in SSR environments, like NextJS. It will have no impact in the UI, however if you wish to avoid it, you can switch to the `pure` version of the connect.js loader: https://github.com/stripe/connect-js#importing-loadconnect-without-side-effects.");
|
|
170
124
|
return;
|
|
171
125
|
}
|
|
172
|
-
if (window.StripeConnect) {
|
|
126
|
+
if (isWindowStripeConnectDefined(window.StripeConnect)) {
|
|
173
127
|
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
174
|
-
}
|
|
175
|
-
if (window.StripeConnect) {
|
|
176
128
|
const wrapper = createWrapper(window.StripeConnect);
|
|
177
129
|
resolve(wrapper);
|
|
178
130
|
return;
|
|
@@ -185,7 +137,7 @@ const loadScript = () => {
|
|
|
185
137
|
script = injectScript();
|
|
186
138
|
}
|
|
187
139
|
script.addEventListener("load", () => {
|
|
188
|
-
if (window.StripeConnect) {
|
|
140
|
+
if (isWindowStripeConnectDefined(window.StripeConnect)) {
|
|
189
141
|
const wrapper = createWrapper(window.StripeConnect);
|
|
190
142
|
resolve(wrapper);
|
|
191
143
|
} else {
|
|
@@ -199,7 +151,7 @@ const loadScript = () => {
|
|
|
199
151
|
reject(error);
|
|
200
152
|
}
|
|
201
153
|
});
|
|
202
|
-
return stripePromise;
|
|
154
|
+
return stripePromise$1;
|
|
203
155
|
};
|
|
204
156
|
const hasCustomMethod = tagName => {
|
|
205
157
|
return tagName in ConnectElementCustomMethodConfig;
|
|
@@ -231,6 +183,9 @@ const initStripeConnect = (stripePromise, initParams) => {
|
|
|
231
183
|
for (const method in methods) {
|
|
232
184
|
element[method] = function (value) {
|
|
233
185
|
stripeConnectInstance.then(() => {
|
|
186
|
+
if (!this[`${method}InternalOnly`]) {
|
|
187
|
+
throw new Error(`Method ${method} is not available in the ${tagName} HTML element. Are you using a supported version of the "@stripe/connect-js" package? Using version: 3.3.30`);
|
|
188
|
+
}
|
|
234
189
|
this[`${method}InternalOnly`](value);
|
|
235
190
|
});
|
|
236
191
|
};
|
|
@@ -283,7 +238,7 @@ const createWrapper = stripeConnect => {
|
|
|
283
238
|
sdk: true,
|
|
284
239
|
sdkOptions: {
|
|
285
240
|
// This will be replaced by the npm package version when bundling
|
|
286
|
-
sdkVersion: "3.3.30
|
|
241
|
+
sdkVersion: "3.3.30"
|
|
287
242
|
}
|
|
288
243
|
})
|
|
289
244
|
}));
|
|
@@ -295,16 +250,16 @@ const createWrapper = stripeConnect => {
|
|
|
295
250
|
|
|
296
251
|
// Execute our own script injection after a tick to give users time to do their
|
|
297
252
|
// own script injection.
|
|
298
|
-
const stripePromise
|
|
253
|
+
const stripePromise = Promise.resolve().then(() => loadScript());
|
|
299
254
|
let loadCalled = false;
|
|
300
|
-
stripePromise
|
|
255
|
+
stripePromise.catch(err => {
|
|
301
256
|
if (!loadCalled) {
|
|
302
257
|
console.warn(err);
|
|
303
258
|
}
|
|
304
259
|
});
|
|
305
260
|
const loadConnectAndInitialize = initParams => {
|
|
306
261
|
loadCalled = true;
|
|
307
|
-
return initStripeConnect(stripePromise
|
|
262
|
+
return initStripeConnect(stripePromise, initParams);
|
|
308
263
|
};
|
|
309
264
|
|
|
310
265
|
export { loadConnectAndInitialize };
|
package/dist/connect.js
CHANGED
|
@@ -9,17 +9,6 @@ const ConnectElementCommonMethodConfig = {
|
|
|
9
9
|
setOnLoaderStart: _listener => {}
|
|
10
10
|
};
|
|
11
11
|
const ConnectElementCustomMethodConfig = {
|
|
12
|
-
payments: {
|
|
13
|
-
setDefaultFilters: _filters => {}
|
|
14
|
-
},
|
|
15
|
-
"payment-details": {
|
|
16
|
-
setPayment: _payment => {},
|
|
17
|
-
setOnClose: _listener => {}
|
|
18
|
-
},
|
|
19
|
-
"payment-disputes": {
|
|
20
|
-
setPayment: _payment => {},
|
|
21
|
-
setOnDisputesLoaded: _listener => {}
|
|
22
|
-
},
|
|
23
12
|
"account-onboarding": {
|
|
24
13
|
setFullTermsOfServiceUrl: _termOfServiceUrl => {},
|
|
25
14
|
setRecipientTermsOfServiceUrl: _recipientTermsOfServiceUrl => {},
|
|
@@ -36,6 +25,10 @@ const ConnectElementCustomMethodConfig = {
|
|
|
36
25
|
setCollectionOptions: _collectionOptions => {},
|
|
37
26
|
setOnNotificationsChange: _listener => {}
|
|
38
27
|
},
|
|
28
|
+
"instant-payouts-promotion": {
|
|
29
|
+
setOnInstantPayoutsPromotionLoaded: _listener => {},
|
|
30
|
+
setOnInstantPayoutCreated: _listener => {}
|
|
31
|
+
},
|
|
39
32
|
"issuing-card": {
|
|
40
33
|
setDefaultCard: _defaultCard => {},
|
|
41
34
|
setCardSwitching: _cardSwitching => {},
|
|
@@ -53,46 +46,16 @@ const ConnectElementCustomMethodConfig = {
|
|
|
53
46
|
"financial-account-transactions": {
|
|
54
47
|
setFinancialAccount: _financialAccount => {}
|
|
55
48
|
},
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
},
|
|
59
|
-
"app-install": {
|
|
60
|
-
setApp: _app => {},
|
|
61
|
-
setOnAppInstallStateFetched: _listener => {},
|
|
62
|
-
setOnAppInstallStateChanged: _listener => {}
|
|
63
|
-
},
|
|
64
|
-
"app-viewport": {
|
|
65
|
-
setApp: _app => {},
|
|
66
|
-
setAppData: _appData => {}
|
|
67
|
-
},
|
|
68
|
-
"payment-method-settings": {
|
|
69
|
-
setPaymentMethodConfiguration: _paymentMethodConfiguration => {}
|
|
70
|
-
},
|
|
71
|
-
"capital-financing": {
|
|
72
|
-
setDefaultFinancingOffer: _defaultFinancingOffer => {},
|
|
73
|
-
setShowFinancingSelector: _showFinancingSelector => {},
|
|
74
|
-
setHowCapitalWorksUrl: _howCapitalWorksUrl => {},
|
|
75
|
-
setSupportUrl: _supportUrl => {},
|
|
76
|
-
setOnFinancingsLoaded: _listener => {}
|
|
77
|
-
},
|
|
78
|
-
"capital-financing-application": {
|
|
79
|
-
setOnApplicationSubmitted: _listener => {},
|
|
80
|
-
setPrivacyPolicyUrl: _privacyPolicyUrl => {},
|
|
81
|
-
setHowCapitalWorksUrl: _howCapitalWorksUrl => {}
|
|
49
|
+
payments: {
|
|
50
|
+
setDefaultFilters: _filters => {}
|
|
82
51
|
},
|
|
83
|
-
"
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
setOnEligibleFinancingOfferLoaded: _listener => {},
|
|
87
|
-
setPrivacyPolicyUrl: _privacyPolicyUrl => {},
|
|
88
|
-
setHowCapitalWorksUrl: _howCapitalWorksUrl => {},
|
|
89
|
-
setEligibilityCriteriaUrl: _eligibilityCriteriaUrl => {}
|
|
52
|
+
"payment-details": {
|
|
53
|
+
setPayment: _payment => {},
|
|
54
|
+
setOnClose: _listener => {}
|
|
90
55
|
},
|
|
91
|
-
"
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
setIntervalEnd: _intervalEnd => {},
|
|
95
|
-
setIntervalType: _intervalType => {}
|
|
56
|
+
"payment-disputes": {
|
|
57
|
+
setPayment: _payment => {},
|
|
58
|
+
setOnDisputesLoaded: _listener => {}
|
|
96
59
|
},
|
|
97
60
|
"tax-settings": {
|
|
98
61
|
setHideProductTaxCodeSelector: _hidden => {},
|
|
@@ -103,54 +66,38 @@ const ConnectElementCustomMethodConfig = {
|
|
|
103
66
|
setOnAfterTaxRegistrationAdded: _listener => {},
|
|
104
67
|
setDisplayCountries: _countries => {}
|
|
105
68
|
},
|
|
106
|
-
"
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
setOnTaxCodeSelect: _listener => {},
|
|
111
|
-
setHideDescription: _hideDescription => {},
|
|
112
|
-
setDisabled: _disabled => {},
|
|
113
|
-
setInitialTaxCode: _initialTaxCode => {}
|
|
114
|
-
},
|
|
115
|
-
"export-tax-transactions": {}
|
|
69
|
+
"payout-details": {
|
|
70
|
+
setPayout: _payout => {},
|
|
71
|
+
setOnClose: _listener => {}
|
|
72
|
+
}
|
|
116
73
|
};
|
|
117
74
|
|
|
118
75
|
const componentNameMapping = {
|
|
76
|
+
"account-onboarding": "stripe-connect-account-onboarding",
|
|
77
|
+
"disputes-list": "stripe-connect-disputes-list",
|
|
119
78
|
payments: "stripe-connect-payments",
|
|
120
|
-
payouts: "stripe-connect-payouts",
|
|
121
79
|
"payment-details": "stripe-connect-payment-details",
|
|
122
80
|
"payment-disputes": "stripe-connect-payment-disputes",
|
|
123
|
-
|
|
124
|
-
"
|
|
81
|
+
payouts: "stripe-connect-payouts",
|
|
82
|
+
"payouts-list": "stripe-connect-payouts-list",
|
|
83
|
+
"payout-details": "stripe-connect-payout-details",
|
|
84
|
+
balances: "stripe-connect-balances",
|
|
125
85
|
"account-management": "stripe-connect-account-management",
|
|
126
86
|
"notification-banner": "stripe-connect-notification-banner",
|
|
127
|
-
"instant-payouts": "stripe-connect-instant-payouts",
|
|
87
|
+
"instant-payouts-promotion": "stripe-connect-instant-payouts-promotion",
|
|
128
88
|
"issuing-card": "stripe-connect-issuing-card",
|
|
129
89
|
"issuing-cards-list": "stripe-connect-issuing-cards-list",
|
|
130
90
|
"financial-account": "stripe-connect-financial-account",
|
|
131
|
-
recipients: "stripe-connect-recipients",
|
|
132
91
|
"financial-account-transactions": "stripe-connect-financial-account-transactions",
|
|
133
|
-
"capital-financing": "stripe-connect-capital-financing",
|
|
134
|
-
"capital-financing-application": "stripe-connect-capital-financing-application",
|
|
135
|
-
"capital-financing-promotion": "stripe-connect-capital-financing-promotion",
|
|
136
|
-
"capital-overview": "stripe-connect-capital-overview",
|
|
137
92
|
documents: "stripe-connect-documents",
|
|
138
|
-
"product-tax-code-selector": "stripe-connect-product-tax-code-selector",
|
|
139
|
-
"export-tax-transactions": "stripe-connect-export-tax-transactions",
|
|
140
93
|
"tax-registrations": "stripe-connect-tax-registrations",
|
|
141
|
-
"tax-settings": "stripe-connect-tax-settings"
|
|
142
|
-
"tax-threshold-monitoring": "stripe-connect-tax-threshold-monitoring",
|
|
143
|
-
balances: "stripe-connect-balances",
|
|
144
|
-
"payouts-list": "stripe-connect-payouts-list",
|
|
145
|
-
"app-install": "stripe-connect-app-install",
|
|
146
|
-
"app-viewport": "stripe-connect-app-viewport",
|
|
147
|
-
"reporting-chart": "stripe-connect-reporting-chart"
|
|
94
|
+
"tax-settings": "stripe-connect-tax-settings"
|
|
148
95
|
};
|
|
149
96
|
const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
|
|
150
97
|
const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
|
|
151
98
|
const V1_URL = "https://connect-js.stripe.com/v1.0/connect.js";
|
|
152
99
|
const findScript = () => {
|
|
153
|
-
return document.querySelectorAll(`script[src="${
|
|
100
|
+
return document.querySelectorAll(`script[src="${V1_URL}"]`)[0] || document.querySelectorAll(`script[src="${V0_URL}"]`)[0] || null;
|
|
154
101
|
};
|
|
155
102
|
const injectScript = () => {
|
|
156
103
|
const script = document.createElement("script");
|
|
@@ -162,21 +109,26 @@ const injectScript = () => {
|
|
|
162
109
|
document.head.appendChild(script);
|
|
163
110
|
return script;
|
|
164
111
|
};
|
|
165
|
-
let stripePromise = null;
|
|
112
|
+
let stripePromise$1 = null;
|
|
113
|
+
const isWindowStripeConnectDefined = stripeConnect => {
|
|
114
|
+
// We only consider `StripeConnect` defined if `init` is a function
|
|
115
|
+
// Why? HTML markup like:
|
|
116
|
+
// <a id="StripeConnect"><a id="StripeConnect" name="init" href="stripe"></a></a> in the <head> of the page
|
|
117
|
+
// can end up "contaminating" the window.StripeConnect object and cause issues in connect.js initialization
|
|
118
|
+
return !!(stripeConnect && typeof stripeConnect === "object" && "init" in stripeConnect && typeof stripeConnect.init === "function");
|
|
119
|
+
};
|
|
166
120
|
const loadScript = () => {
|
|
167
121
|
// Ensure that we only attempt to load Connect.js at most once
|
|
168
|
-
if (stripePromise !== null) {
|
|
169
|
-
return stripePromise;
|
|
122
|
+
if (stripePromise$1 !== null) {
|
|
123
|
+
return stripePromise$1;
|
|
170
124
|
}
|
|
171
|
-
stripePromise = new Promise((resolve, reject) => {
|
|
125
|
+
stripePromise$1 = new Promise((resolve, reject) => {
|
|
172
126
|
if (typeof window === "undefined") {
|
|
173
127
|
reject("ConnectJS won't load when rendering code in the server - it can only be loaded on a browser. This error is expected when loading ConnectJS in SSR environments, like NextJS. It will have no impact in the UI, however if you wish to avoid it, you can switch to the `pure` version of the connect.js loader: https://github.com/stripe/connect-js#importing-loadconnect-without-side-effects.");
|
|
174
128
|
return;
|
|
175
129
|
}
|
|
176
|
-
if (window.StripeConnect) {
|
|
130
|
+
if (isWindowStripeConnectDefined(window.StripeConnect)) {
|
|
177
131
|
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
178
|
-
}
|
|
179
|
-
if (window.StripeConnect) {
|
|
180
132
|
const wrapper = createWrapper(window.StripeConnect);
|
|
181
133
|
resolve(wrapper);
|
|
182
134
|
return;
|
|
@@ -189,7 +141,7 @@ const loadScript = () => {
|
|
|
189
141
|
script = injectScript();
|
|
190
142
|
}
|
|
191
143
|
script.addEventListener("load", () => {
|
|
192
|
-
if (window.StripeConnect) {
|
|
144
|
+
if (isWindowStripeConnectDefined(window.StripeConnect)) {
|
|
193
145
|
const wrapper = createWrapper(window.StripeConnect);
|
|
194
146
|
resolve(wrapper);
|
|
195
147
|
} else {
|
|
@@ -203,7 +155,7 @@ const loadScript = () => {
|
|
|
203
155
|
reject(error);
|
|
204
156
|
}
|
|
205
157
|
});
|
|
206
|
-
return stripePromise;
|
|
158
|
+
return stripePromise$1;
|
|
207
159
|
};
|
|
208
160
|
const hasCustomMethod = tagName => {
|
|
209
161
|
return tagName in ConnectElementCustomMethodConfig;
|
|
@@ -235,6 +187,9 @@ const initStripeConnect = (stripePromise, initParams) => {
|
|
|
235
187
|
for (const method in methods) {
|
|
236
188
|
element[method] = function (value) {
|
|
237
189
|
stripeConnectInstance.then(() => {
|
|
190
|
+
if (!this[`${method}InternalOnly`]) {
|
|
191
|
+
throw new Error(`Method ${method} is not available in the ${tagName} HTML element. Are you using a supported version of the "@stripe/connect-js" package? Using version: 3.3.30`);
|
|
192
|
+
}
|
|
238
193
|
this[`${method}InternalOnly`](value);
|
|
239
194
|
});
|
|
240
195
|
};
|
|
@@ -287,7 +242,7 @@ const createWrapper = stripeConnect => {
|
|
|
287
242
|
sdk: true,
|
|
288
243
|
sdkOptions: {
|
|
289
244
|
// This will be replaced by the npm package version when bundling
|
|
290
|
-
sdkVersion: "3.3.30
|
|
245
|
+
sdkVersion: "3.3.30"
|
|
291
246
|
}
|
|
292
247
|
})
|
|
293
248
|
}));
|
|
@@ -299,16 +254,16 @@ const createWrapper = stripeConnect => {
|
|
|
299
254
|
|
|
300
255
|
// Execute our own script injection after a tick to give users time to do their
|
|
301
256
|
// own script injection.
|
|
302
|
-
const stripePromise
|
|
257
|
+
const stripePromise = Promise.resolve().then(() => loadScript());
|
|
303
258
|
let loadCalled = false;
|
|
304
|
-
stripePromise
|
|
259
|
+
stripePromise.catch(err => {
|
|
305
260
|
if (!loadCalled) {
|
|
306
261
|
console.warn(err);
|
|
307
262
|
}
|
|
308
263
|
});
|
|
309
264
|
const loadConnectAndInitialize = initParams => {
|
|
310
265
|
loadCalled = true;
|
|
311
|
-
return initStripeConnect(stripePromise
|
|
266
|
+
return initStripeConnect(stripePromise, initParams);
|
|
312
267
|
};
|
|
313
268
|
|
|
314
269
|
exports.loadConnectAndInitialize = loadConnectAndInitialize;
|