@stripe/connect-js 3.3.43-preview-1 → 3.3.44-preview-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/connect.esm.js +336 -0
- package/dist/connect.js +340 -0
- package/dist/pure.esm.js +330 -0
- package/dist/pure.js +334 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/pure.d.ts +2 -0
- package/dist/src/shared.d.ts +15 -0
- package/dist/src/utils/jestHelpers.d.ts +2 -0
- package/dist/src/utils/jestSetup.d.ts +1 -0
- package/dist/types/config.d.ts +242 -0
- package/package.json +1 -1
- package/src/shared.ts +3 -1
- package/types/config.ts +9 -0
- package/types/shared.d.ts +2 -1
package/dist/pure.esm.js
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
|
+
const ConnectElementCommonMethodConfig = {
|
|
4
|
+
setOnLoadError: _listener => {},
|
|
5
|
+
setOnLoaderStart: _listener => {}
|
|
6
|
+
};
|
|
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
|
+
"account-onboarding": {
|
|
20
|
+
setFullTermsOfServiceUrl: _termOfServiceUrl => {},
|
|
21
|
+
setRecipientTermsOfServiceUrl: _recipientTermsOfServiceUrl => {},
|
|
22
|
+
setPrivacyPolicyUrl: _privacyPolicyUrl => {},
|
|
23
|
+
setSkipTermsOfServiceCollection: _skipTermsOfServiceCollection => {},
|
|
24
|
+
setCollectionOptions: _collectionOptions => {},
|
|
25
|
+
setOnExit: _listener => {},
|
|
26
|
+
setOnStepChange: _listener => {}
|
|
27
|
+
},
|
|
28
|
+
"account-management": {
|
|
29
|
+
setCollectionOptions: _collectionOptions => {}
|
|
30
|
+
},
|
|
31
|
+
"notification-banner": {
|
|
32
|
+
setCollectionOptions: _collectionOptions => {},
|
|
33
|
+
setOnNotificationsChange: _listener => {}
|
|
34
|
+
},
|
|
35
|
+
"instant-payouts-promotion": {
|
|
36
|
+
setOnInstantPayoutsPromotionLoaded: _listener => {},
|
|
37
|
+
setOnInstantPayoutCreated: _listener => {}
|
|
38
|
+
},
|
|
39
|
+
"issuing-card": {
|
|
40
|
+
setDefaultCard: _defaultCard => {},
|
|
41
|
+
setCardSwitching: _cardSwitching => {},
|
|
42
|
+
setFetchEphemeralKey: _fetchEphemeralKey => {},
|
|
43
|
+
setShowSpendControls: _showSpendControls => {}
|
|
44
|
+
},
|
|
45
|
+
"issuing-cards-list": {
|
|
46
|
+
setFetchEphemeralKey: _fetchEphemeralKey => {},
|
|
47
|
+
setShowSpendControls: _showSpendControls => {},
|
|
48
|
+
setIssuingProgram: _issuingProgram => {}
|
|
49
|
+
},
|
|
50
|
+
"financial-account": {
|
|
51
|
+
setFinancialAccount: _financialAccount => {}
|
|
52
|
+
},
|
|
53
|
+
"financial-account-transactions": {
|
|
54
|
+
setFinancialAccount: _financialAccount => {}
|
|
55
|
+
},
|
|
56
|
+
recipients: {
|
|
57
|
+
setDataSource: _dataSource => {}
|
|
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 => {},
|
|
82
|
+
setOnApplicationStepChange: _listener => {}
|
|
83
|
+
},
|
|
84
|
+
"capital-financing-promotion": {
|
|
85
|
+
setLayout: _layout => {},
|
|
86
|
+
setOnApplicationSubmitted: _listener => {},
|
|
87
|
+
setOnEligibleFinancingOfferLoaded: _listener => {},
|
|
88
|
+
setPrivacyPolicyUrl: _privacyPolicyUrl => {},
|
|
89
|
+
setHowCapitalWorksUrl: _howCapitalWorksUrl => {},
|
|
90
|
+
setEligibilityCriteriaUrl: _eligibilityCriteriaUrl => {},
|
|
91
|
+
setOnApplicationStepChange: _listener => {}
|
|
92
|
+
},
|
|
93
|
+
"reporting-chart": {
|
|
94
|
+
setReportName: _reportName => {},
|
|
95
|
+
setIntervalStart: _intervalStart => {},
|
|
96
|
+
setIntervalEnd: _intervalEnd => {},
|
|
97
|
+
setIntervalType: _intervalType => {}
|
|
98
|
+
},
|
|
99
|
+
"tax-settings": {
|
|
100
|
+
setHideProductTaxCodeSelector: _hidden => {},
|
|
101
|
+
setDisplayHeadOfficeCountries: _countries => {},
|
|
102
|
+
setOnTaxSettingsUpdated: _listener => {}
|
|
103
|
+
},
|
|
104
|
+
"tax-registrations": {
|
|
105
|
+
setOnAfterTaxRegistrationAdded: _listener => {},
|
|
106
|
+
setDisplayCountries: _countries => {},
|
|
107
|
+
setOnAfterTaxRegistrationExpired: _listener => {}
|
|
108
|
+
},
|
|
109
|
+
"tax-threshold-monitoring": {
|
|
110
|
+
setDisplayCountries: _countries => {}
|
|
111
|
+
},
|
|
112
|
+
"product-tax-code-selector": {
|
|
113
|
+
setOnTaxCodeSelect: _listener => {},
|
|
114
|
+
setHideDescription: _hideDescription => {},
|
|
115
|
+
setDisabled: _disabled => {},
|
|
116
|
+
setInitialTaxCode: _initialTaxCode => {}
|
|
117
|
+
},
|
|
118
|
+
"export-tax-transactions": {},
|
|
119
|
+
"payout-details": {
|
|
120
|
+
setPayout: _payout => {},
|
|
121
|
+
setOnClose: _listener => {}
|
|
122
|
+
},
|
|
123
|
+
"check-scanning": {
|
|
124
|
+
setHandleCheckScanSubmitted: _handleCheckScanSubmitted => {}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const componentNameMapping = {
|
|
129
|
+
payments: "stripe-connect-payments",
|
|
130
|
+
payouts: "stripe-connect-payouts",
|
|
131
|
+
"payment-details": "stripe-connect-payment-details",
|
|
132
|
+
"payment-disputes": "stripe-connect-payment-disputes",
|
|
133
|
+
"disputes-list": "stripe-connect-disputes-list",
|
|
134
|
+
"account-onboarding": "stripe-connect-account-onboarding",
|
|
135
|
+
"payment-method-settings": "stripe-connect-payment-method-settings",
|
|
136
|
+
"account-management": "stripe-connect-account-management",
|
|
137
|
+
"notification-banner": "stripe-connect-notification-banner",
|
|
138
|
+
"instant-payouts": "stripe-connect-instant-payouts",
|
|
139
|
+
"instant-payouts-promotion": "stripe-connect-instant-payouts-promotion",
|
|
140
|
+
"issuing-card": "stripe-connect-issuing-card",
|
|
141
|
+
"issuing-cards-list": "stripe-connect-issuing-cards-list",
|
|
142
|
+
"financial-account": "stripe-connect-financial-account",
|
|
143
|
+
recipients: "stripe-connect-recipients",
|
|
144
|
+
"financial-account-transactions": "stripe-connect-financial-account-transactions",
|
|
145
|
+
"capital-financing": "stripe-connect-capital-financing",
|
|
146
|
+
"capital-financing-application": "stripe-connect-capital-financing-application",
|
|
147
|
+
"capital-financing-promotion": "stripe-connect-capital-financing-promotion",
|
|
148
|
+
"capital-overview": "stripe-connect-capital-overview",
|
|
149
|
+
documents: "stripe-connect-documents",
|
|
150
|
+
"product-tax-code-selector": "stripe-connect-product-tax-code-selector",
|
|
151
|
+
"export-tax-transactions": "stripe-connect-export-tax-transactions",
|
|
152
|
+
"tax-registrations": "stripe-connect-tax-registrations",
|
|
153
|
+
"tax-settings": "stripe-connect-tax-settings",
|
|
154
|
+
"tax-threshold-monitoring": "stripe-connect-tax-threshold-monitoring",
|
|
155
|
+
balances: "stripe-connect-balances",
|
|
156
|
+
"payouts-list": "stripe-connect-payouts-list",
|
|
157
|
+
"payout-details": "stripe-connect-payout-details",
|
|
158
|
+
"app-install": "stripe-connect-app-install",
|
|
159
|
+
"app-viewport": "stripe-connect-app-viewport",
|
|
160
|
+
"reporting-chart": "stripe-connect-reporting-chart",
|
|
161
|
+
"check-scanning": "stripe-connect-check-scanning"
|
|
162
|
+
};
|
|
163
|
+
const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
|
|
164
|
+
const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
|
|
165
|
+
const V1_URL = "https://connect-js.stripe.com/v1.0/connect.js";
|
|
166
|
+
const findScript = () => {
|
|
167
|
+
return document.querySelectorAll(`script[src="${V0_URL}"]`)[0] || document.querySelectorAll(`script[src="${V1_URL}"]`)[0] || null;
|
|
168
|
+
};
|
|
169
|
+
const injectScript = () => {
|
|
170
|
+
const script = document.createElement("script");
|
|
171
|
+
script.src = V1_URL;
|
|
172
|
+
const head = document.head;
|
|
173
|
+
if (!head) {
|
|
174
|
+
throw new Error("Expected document.head not to be null. Connect.js requires a <head> element.");
|
|
175
|
+
}
|
|
176
|
+
document.head.appendChild(script);
|
|
177
|
+
return script;
|
|
178
|
+
};
|
|
179
|
+
let stripePromise = null;
|
|
180
|
+
const isWindowStripeConnectDefined = stripeConnect => {
|
|
181
|
+
// We only consider `StripeConnect` defined if `init` is a function
|
|
182
|
+
// Why? HTML markup like:
|
|
183
|
+
// <a id="StripeConnect"><a id="StripeConnect" name="init" href="stripe"></a></a> in the <head> of the page
|
|
184
|
+
// can end up "contaminating" the window.StripeConnect object and cause issues in connect.js initialization
|
|
185
|
+
return !!(stripeConnect && typeof stripeConnect === "object" && "init" in stripeConnect && typeof stripeConnect.init === "function");
|
|
186
|
+
};
|
|
187
|
+
const loadScript = () => {
|
|
188
|
+
// Ensure that we only attempt to load Connect.js at most once
|
|
189
|
+
if (stripePromise !== null) {
|
|
190
|
+
return stripePromise;
|
|
191
|
+
}
|
|
192
|
+
stripePromise = new Promise((resolve, reject) => {
|
|
193
|
+
if (typeof window === "undefined") {
|
|
194
|
+
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.");
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (isWindowStripeConnectDefined(window.StripeConnect)) {
|
|
198
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
199
|
+
const wrapper = createWrapper(window.StripeConnect);
|
|
200
|
+
resolve(wrapper);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
let script = findScript();
|
|
205
|
+
if (script) {
|
|
206
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
207
|
+
} else if (!script) {
|
|
208
|
+
script = injectScript();
|
|
209
|
+
}
|
|
210
|
+
script.addEventListener("load", () => {
|
|
211
|
+
if (isWindowStripeConnectDefined(window.StripeConnect)) {
|
|
212
|
+
const wrapper = createWrapper(window.StripeConnect);
|
|
213
|
+
resolve(wrapper);
|
|
214
|
+
} else {
|
|
215
|
+
reject(new Error("Connect.js did not load the necessary objects"));
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
script.addEventListener("error", () => {
|
|
219
|
+
reject(new Error("Failed to load Connect.js"));
|
|
220
|
+
});
|
|
221
|
+
} catch (error) {
|
|
222
|
+
reject(error);
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
return stripePromise;
|
|
226
|
+
};
|
|
227
|
+
const hasCustomMethod = tagName => {
|
|
228
|
+
return tagName in ConnectElementCustomMethodConfig;
|
|
229
|
+
};
|
|
230
|
+
const initStripeConnect = (stripePromise, initParams) => {
|
|
231
|
+
var _a;
|
|
232
|
+
const eagerClientSecretPromise = (() => {
|
|
233
|
+
try {
|
|
234
|
+
return initParams.fetchClientSecret();
|
|
235
|
+
} catch (error) {
|
|
236
|
+
return Promise.reject(error);
|
|
237
|
+
}
|
|
238
|
+
})();
|
|
239
|
+
const metaOptions = (_a = initParams.metaOptions) !== null && _a !== void 0 ? _a : {};
|
|
240
|
+
const stripeConnectInstance = stripePromise.then(wrapper => wrapper.initialize(Object.assign(Object.assign({}, initParams), {
|
|
241
|
+
metaOptions: Object.assign(Object.assign({}, metaOptions), {
|
|
242
|
+
eagerClientSecretPromise
|
|
243
|
+
})
|
|
244
|
+
})));
|
|
245
|
+
return {
|
|
246
|
+
create: tagName => {
|
|
247
|
+
let htmlName = componentNameMapping[tagName];
|
|
248
|
+
if (!htmlName) {
|
|
249
|
+
htmlName = tagName;
|
|
250
|
+
}
|
|
251
|
+
const element = document.createElement(htmlName);
|
|
252
|
+
const customMethods = hasCustomMethod(tagName) ? ConnectElementCustomMethodConfig[tagName] : {};
|
|
253
|
+
const methods = Object.assign(Object.assign({}, customMethods), ConnectElementCommonMethodConfig);
|
|
254
|
+
for (const method in methods) {
|
|
255
|
+
element[method] = function (value) {
|
|
256
|
+
stripeConnectInstance.then(() => {
|
|
257
|
+
if (!this[`${method}InternalOnly`]) {
|
|
258
|
+
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.44-preview-1`);
|
|
259
|
+
}
|
|
260
|
+
this[`${method}InternalOnly`](value);
|
|
261
|
+
});
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
stripeConnectInstance.then(instance => {
|
|
265
|
+
if (!element.isConnected && !element.setConnector) {
|
|
266
|
+
// If the element is not connected to the DOM and the `setConnector` method is not
|
|
267
|
+
// defined, this indicates the element was created before connect.js was loaded, and has
|
|
268
|
+
// not been transformed into a custom element yet
|
|
269
|
+
// To load the custom element code on it, we need to connect and disconnect it to the DOM
|
|
270
|
+
// This isn't a problem, as the element will be invisible, and we know the element is already
|
|
271
|
+
// not currently connected to the DOM
|
|
272
|
+
const oldDisplay = element.style.display;
|
|
273
|
+
element.style.display = "none";
|
|
274
|
+
document.body.appendChild(element);
|
|
275
|
+
document.body.removeChild(element);
|
|
276
|
+
element.style.display = oldDisplay;
|
|
277
|
+
}
|
|
278
|
+
if (!element || !element.setConnector) {
|
|
279
|
+
throw new Error(`Element ${tagName} was not transformed into a custom element. Are you using a documented component? See https://docs.stripe.com/connect/supported-embedded-components for a list of supported components`);
|
|
280
|
+
}
|
|
281
|
+
element.setConnector(instance.connect);
|
|
282
|
+
});
|
|
283
|
+
return element;
|
|
284
|
+
},
|
|
285
|
+
update: updateOptions => {
|
|
286
|
+
stripeConnectInstance.then(instance => {
|
|
287
|
+
instance.update(updateOptions);
|
|
288
|
+
});
|
|
289
|
+
},
|
|
290
|
+
debugInstance: () => {
|
|
291
|
+
return stripeConnectInstance;
|
|
292
|
+
},
|
|
293
|
+
logout: () => {
|
|
294
|
+
return stripeConnectInstance.then(instance => {
|
|
295
|
+
return instance.logout();
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
};
|
|
300
|
+
const createWrapper = stripeConnect => {
|
|
301
|
+
window.StripeConnect = window.StripeConnect || {};
|
|
302
|
+
window.StripeConnect.optimizedLoading = true;
|
|
303
|
+
const wrapper = {
|
|
304
|
+
initialize: params => {
|
|
305
|
+
var _a;
|
|
306
|
+
const metaOptions = (_a = params.metaOptions) !== null && _a !== void 0 ? _a : {};
|
|
307
|
+
const stripeConnectInstance = stripeConnect.init(Object.assign(Object.assign({}, params), {
|
|
308
|
+
metaOptions: Object.assign(Object.assign({}, metaOptions), {
|
|
309
|
+
sdk: true,
|
|
310
|
+
sdkOptions: {
|
|
311
|
+
// This will be replaced by the npm package version when bundling
|
|
312
|
+
sdkVersion: "3.3.44-preview-1"
|
|
313
|
+
}
|
|
314
|
+
})
|
|
315
|
+
}));
|
|
316
|
+
return stripeConnectInstance;
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
return wrapper;
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
const loadConnectAndInitialize = initParams => {
|
|
323
|
+
const maybeConnect = loadScript();
|
|
324
|
+
if (initParams == null) {
|
|
325
|
+
throw new Error("You must provide required parameters to initialize Connect");
|
|
326
|
+
}
|
|
327
|
+
return initStripeConnect(maybeConnect, initParams);
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
export { loadConnectAndInitialize };
|
package/dist/pure.js
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
6
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
7
|
+
const ConnectElementCommonMethodConfig = {
|
|
8
|
+
setOnLoadError: _listener => {},
|
|
9
|
+
setOnLoaderStart: _listener => {}
|
|
10
|
+
};
|
|
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
|
+
"account-onboarding": {
|
|
24
|
+
setFullTermsOfServiceUrl: _termOfServiceUrl => {},
|
|
25
|
+
setRecipientTermsOfServiceUrl: _recipientTermsOfServiceUrl => {},
|
|
26
|
+
setPrivacyPolicyUrl: _privacyPolicyUrl => {},
|
|
27
|
+
setSkipTermsOfServiceCollection: _skipTermsOfServiceCollection => {},
|
|
28
|
+
setCollectionOptions: _collectionOptions => {},
|
|
29
|
+
setOnExit: _listener => {},
|
|
30
|
+
setOnStepChange: _listener => {}
|
|
31
|
+
},
|
|
32
|
+
"account-management": {
|
|
33
|
+
setCollectionOptions: _collectionOptions => {}
|
|
34
|
+
},
|
|
35
|
+
"notification-banner": {
|
|
36
|
+
setCollectionOptions: _collectionOptions => {},
|
|
37
|
+
setOnNotificationsChange: _listener => {}
|
|
38
|
+
},
|
|
39
|
+
"instant-payouts-promotion": {
|
|
40
|
+
setOnInstantPayoutsPromotionLoaded: _listener => {},
|
|
41
|
+
setOnInstantPayoutCreated: _listener => {}
|
|
42
|
+
},
|
|
43
|
+
"issuing-card": {
|
|
44
|
+
setDefaultCard: _defaultCard => {},
|
|
45
|
+
setCardSwitching: _cardSwitching => {},
|
|
46
|
+
setFetchEphemeralKey: _fetchEphemeralKey => {},
|
|
47
|
+
setShowSpendControls: _showSpendControls => {}
|
|
48
|
+
},
|
|
49
|
+
"issuing-cards-list": {
|
|
50
|
+
setFetchEphemeralKey: _fetchEphemeralKey => {},
|
|
51
|
+
setShowSpendControls: _showSpendControls => {},
|
|
52
|
+
setIssuingProgram: _issuingProgram => {}
|
|
53
|
+
},
|
|
54
|
+
"financial-account": {
|
|
55
|
+
setFinancialAccount: _financialAccount => {}
|
|
56
|
+
},
|
|
57
|
+
"financial-account-transactions": {
|
|
58
|
+
setFinancialAccount: _financialAccount => {}
|
|
59
|
+
},
|
|
60
|
+
recipients: {
|
|
61
|
+
setDataSource: _dataSource => {}
|
|
62
|
+
},
|
|
63
|
+
"app-install": {
|
|
64
|
+
setApp: _app => {},
|
|
65
|
+
setOnAppInstallStateFetched: _listener => {},
|
|
66
|
+
setOnAppInstallStateChanged: _listener => {}
|
|
67
|
+
},
|
|
68
|
+
"app-viewport": {
|
|
69
|
+
setApp: _app => {},
|
|
70
|
+
setAppData: _appData => {}
|
|
71
|
+
},
|
|
72
|
+
"payment-method-settings": {
|
|
73
|
+
setPaymentMethodConfiguration: _paymentMethodConfiguration => {}
|
|
74
|
+
},
|
|
75
|
+
"capital-financing": {
|
|
76
|
+
setDefaultFinancingOffer: _defaultFinancingOffer => {},
|
|
77
|
+
setShowFinancingSelector: _showFinancingSelector => {},
|
|
78
|
+
setHowCapitalWorksUrl: _howCapitalWorksUrl => {},
|
|
79
|
+
setSupportUrl: _supportUrl => {},
|
|
80
|
+
setOnFinancingsLoaded: _listener => {}
|
|
81
|
+
},
|
|
82
|
+
"capital-financing-application": {
|
|
83
|
+
setOnApplicationSubmitted: _listener => {},
|
|
84
|
+
setPrivacyPolicyUrl: _privacyPolicyUrl => {},
|
|
85
|
+
setHowCapitalWorksUrl: _howCapitalWorksUrl => {},
|
|
86
|
+
setOnApplicationStepChange: _listener => {}
|
|
87
|
+
},
|
|
88
|
+
"capital-financing-promotion": {
|
|
89
|
+
setLayout: _layout => {},
|
|
90
|
+
setOnApplicationSubmitted: _listener => {},
|
|
91
|
+
setOnEligibleFinancingOfferLoaded: _listener => {},
|
|
92
|
+
setPrivacyPolicyUrl: _privacyPolicyUrl => {},
|
|
93
|
+
setHowCapitalWorksUrl: _howCapitalWorksUrl => {},
|
|
94
|
+
setEligibilityCriteriaUrl: _eligibilityCriteriaUrl => {},
|
|
95
|
+
setOnApplicationStepChange: _listener => {}
|
|
96
|
+
},
|
|
97
|
+
"reporting-chart": {
|
|
98
|
+
setReportName: _reportName => {},
|
|
99
|
+
setIntervalStart: _intervalStart => {},
|
|
100
|
+
setIntervalEnd: _intervalEnd => {},
|
|
101
|
+
setIntervalType: _intervalType => {}
|
|
102
|
+
},
|
|
103
|
+
"tax-settings": {
|
|
104
|
+
setHideProductTaxCodeSelector: _hidden => {},
|
|
105
|
+
setDisplayHeadOfficeCountries: _countries => {},
|
|
106
|
+
setOnTaxSettingsUpdated: _listener => {}
|
|
107
|
+
},
|
|
108
|
+
"tax-registrations": {
|
|
109
|
+
setOnAfterTaxRegistrationAdded: _listener => {},
|
|
110
|
+
setDisplayCountries: _countries => {},
|
|
111
|
+
setOnAfterTaxRegistrationExpired: _listener => {}
|
|
112
|
+
},
|
|
113
|
+
"tax-threshold-monitoring": {
|
|
114
|
+
setDisplayCountries: _countries => {}
|
|
115
|
+
},
|
|
116
|
+
"product-tax-code-selector": {
|
|
117
|
+
setOnTaxCodeSelect: _listener => {},
|
|
118
|
+
setHideDescription: _hideDescription => {},
|
|
119
|
+
setDisabled: _disabled => {},
|
|
120
|
+
setInitialTaxCode: _initialTaxCode => {}
|
|
121
|
+
},
|
|
122
|
+
"export-tax-transactions": {},
|
|
123
|
+
"payout-details": {
|
|
124
|
+
setPayout: _payout => {},
|
|
125
|
+
setOnClose: _listener => {}
|
|
126
|
+
},
|
|
127
|
+
"check-scanning": {
|
|
128
|
+
setHandleCheckScanSubmitted: _handleCheckScanSubmitted => {}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const componentNameMapping = {
|
|
133
|
+
payments: "stripe-connect-payments",
|
|
134
|
+
payouts: "stripe-connect-payouts",
|
|
135
|
+
"payment-details": "stripe-connect-payment-details",
|
|
136
|
+
"payment-disputes": "stripe-connect-payment-disputes",
|
|
137
|
+
"disputes-list": "stripe-connect-disputes-list",
|
|
138
|
+
"account-onboarding": "stripe-connect-account-onboarding",
|
|
139
|
+
"payment-method-settings": "stripe-connect-payment-method-settings",
|
|
140
|
+
"account-management": "stripe-connect-account-management",
|
|
141
|
+
"notification-banner": "stripe-connect-notification-banner",
|
|
142
|
+
"instant-payouts": "stripe-connect-instant-payouts",
|
|
143
|
+
"instant-payouts-promotion": "stripe-connect-instant-payouts-promotion",
|
|
144
|
+
"issuing-card": "stripe-connect-issuing-card",
|
|
145
|
+
"issuing-cards-list": "stripe-connect-issuing-cards-list",
|
|
146
|
+
"financial-account": "stripe-connect-financial-account",
|
|
147
|
+
recipients: "stripe-connect-recipients",
|
|
148
|
+
"financial-account-transactions": "stripe-connect-financial-account-transactions",
|
|
149
|
+
"capital-financing": "stripe-connect-capital-financing",
|
|
150
|
+
"capital-financing-application": "stripe-connect-capital-financing-application",
|
|
151
|
+
"capital-financing-promotion": "stripe-connect-capital-financing-promotion",
|
|
152
|
+
"capital-overview": "stripe-connect-capital-overview",
|
|
153
|
+
documents: "stripe-connect-documents",
|
|
154
|
+
"product-tax-code-selector": "stripe-connect-product-tax-code-selector",
|
|
155
|
+
"export-tax-transactions": "stripe-connect-export-tax-transactions",
|
|
156
|
+
"tax-registrations": "stripe-connect-tax-registrations",
|
|
157
|
+
"tax-settings": "stripe-connect-tax-settings",
|
|
158
|
+
"tax-threshold-monitoring": "stripe-connect-tax-threshold-monitoring",
|
|
159
|
+
balances: "stripe-connect-balances",
|
|
160
|
+
"payouts-list": "stripe-connect-payouts-list",
|
|
161
|
+
"payout-details": "stripe-connect-payout-details",
|
|
162
|
+
"app-install": "stripe-connect-app-install",
|
|
163
|
+
"app-viewport": "stripe-connect-app-viewport",
|
|
164
|
+
"reporting-chart": "stripe-connect-reporting-chart",
|
|
165
|
+
"check-scanning": "stripe-connect-check-scanning"
|
|
166
|
+
};
|
|
167
|
+
const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
|
|
168
|
+
const V0_URL = "https://connect-js.stripe.com/v0.1/connect.js";
|
|
169
|
+
const V1_URL = "https://connect-js.stripe.com/v1.0/connect.js";
|
|
170
|
+
const findScript = () => {
|
|
171
|
+
return document.querySelectorAll(`script[src="${V0_URL}"]`)[0] || document.querySelectorAll(`script[src="${V1_URL}"]`)[0] || null;
|
|
172
|
+
};
|
|
173
|
+
const injectScript = () => {
|
|
174
|
+
const script = document.createElement("script");
|
|
175
|
+
script.src = V1_URL;
|
|
176
|
+
const head = document.head;
|
|
177
|
+
if (!head) {
|
|
178
|
+
throw new Error("Expected document.head not to be null. Connect.js requires a <head> element.");
|
|
179
|
+
}
|
|
180
|
+
document.head.appendChild(script);
|
|
181
|
+
return script;
|
|
182
|
+
};
|
|
183
|
+
let stripePromise = null;
|
|
184
|
+
const isWindowStripeConnectDefined = stripeConnect => {
|
|
185
|
+
// We only consider `StripeConnect` defined if `init` is a function
|
|
186
|
+
// Why? HTML markup like:
|
|
187
|
+
// <a id="StripeConnect"><a id="StripeConnect" name="init" href="stripe"></a></a> in the <head> of the page
|
|
188
|
+
// can end up "contaminating" the window.StripeConnect object and cause issues in connect.js initialization
|
|
189
|
+
return !!(stripeConnect && typeof stripeConnect === "object" && "init" in stripeConnect && typeof stripeConnect.init === "function");
|
|
190
|
+
};
|
|
191
|
+
const loadScript = () => {
|
|
192
|
+
// Ensure that we only attempt to load Connect.js at most once
|
|
193
|
+
if (stripePromise !== null) {
|
|
194
|
+
return stripePromise;
|
|
195
|
+
}
|
|
196
|
+
stripePromise = new Promise((resolve, reject) => {
|
|
197
|
+
if (typeof window === "undefined") {
|
|
198
|
+
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.");
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (isWindowStripeConnectDefined(window.StripeConnect)) {
|
|
202
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
203
|
+
const wrapper = createWrapper(window.StripeConnect);
|
|
204
|
+
resolve(wrapper);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
try {
|
|
208
|
+
let script = findScript();
|
|
209
|
+
if (script) {
|
|
210
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
211
|
+
} else if (!script) {
|
|
212
|
+
script = injectScript();
|
|
213
|
+
}
|
|
214
|
+
script.addEventListener("load", () => {
|
|
215
|
+
if (isWindowStripeConnectDefined(window.StripeConnect)) {
|
|
216
|
+
const wrapper = createWrapper(window.StripeConnect);
|
|
217
|
+
resolve(wrapper);
|
|
218
|
+
} else {
|
|
219
|
+
reject(new Error("Connect.js did not load the necessary objects"));
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
script.addEventListener("error", () => {
|
|
223
|
+
reject(new Error("Failed to load Connect.js"));
|
|
224
|
+
});
|
|
225
|
+
} catch (error) {
|
|
226
|
+
reject(error);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
return stripePromise;
|
|
230
|
+
};
|
|
231
|
+
const hasCustomMethod = tagName => {
|
|
232
|
+
return tagName in ConnectElementCustomMethodConfig;
|
|
233
|
+
};
|
|
234
|
+
const initStripeConnect = (stripePromise, initParams) => {
|
|
235
|
+
var _a;
|
|
236
|
+
const eagerClientSecretPromise = (() => {
|
|
237
|
+
try {
|
|
238
|
+
return initParams.fetchClientSecret();
|
|
239
|
+
} catch (error) {
|
|
240
|
+
return Promise.reject(error);
|
|
241
|
+
}
|
|
242
|
+
})();
|
|
243
|
+
const metaOptions = (_a = initParams.metaOptions) !== null && _a !== void 0 ? _a : {};
|
|
244
|
+
const stripeConnectInstance = stripePromise.then(wrapper => wrapper.initialize(Object.assign(Object.assign({}, initParams), {
|
|
245
|
+
metaOptions: Object.assign(Object.assign({}, metaOptions), {
|
|
246
|
+
eagerClientSecretPromise
|
|
247
|
+
})
|
|
248
|
+
})));
|
|
249
|
+
return {
|
|
250
|
+
create: tagName => {
|
|
251
|
+
let htmlName = componentNameMapping[tagName];
|
|
252
|
+
if (!htmlName) {
|
|
253
|
+
htmlName = tagName;
|
|
254
|
+
}
|
|
255
|
+
const element = document.createElement(htmlName);
|
|
256
|
+
const customMethods = hasCustomMethod(tagName) ? ConnectElementCustomMethodConfig[tagName] : {};
|
|
257
|
+
const methods = Object.assign(Object.assign({}, customMethods), ConnectElementCommonMethodConfig);
|
|
258
|
+
for (const method in methods) {
|
|
259
|
+
element[method] = function (value) {
|
|
260
|
+
stripeConnectInstance.then(() => {
|
|
261
|
+
if (!this[`${method}InternalOnly`]) {
|
|
262
|
+
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.44-preview-1`);
|
|
263
|
+
}
|
|
264
|
+
this[`${method}InternalOnly`](value);
|
|
265
|
+
});
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
stripeConnectInstance.then(instance => {
|
|
269
|
+
if (!element.isConnected && !element.setConnector) {
|
|
270
|
+
// If the element is not connected to the DOM and the `setConnector` method is not
|
|
271
|
+
// defined, this indicates the element was created before connect.js was loaded, and has
|
|
272
|
+
// not been transformed into a custom element yet
|
|
273
|
+
// To load the custom element code on it, we need to connect and disconnect it to the DOM
|
|
274
|
+
// This isn't a problem, as the element will be invisible, and we know the element is already
|
|
275
|
+
// not currently connected to the DOM
|
|
276
|
+
const oldDisplay = element.style.display;
|
|
277
|
+
element.style.display = "none";
|
|
278
|
+
document.body.appendChild(element);
|
|
279
|
+
document.body.removeChild(element);
|
|
280
|
+
element.style.display = oldDisplay;
|
|
281
|
+
}
|
|
282
|
+
if (!element || !element.setConnector) {
|
|
283
|
+
throw new Error(`Element ${tagName} was not transformed into a custom element. Are you using a documented component? See https://docs.stripe.com/connect/supported-embedded-components for a list of supported components`);
|
|
284
|
+
}
|
|
285
|
+
element.setConnector(instance.connect);
|
|
286
|
+
});
|
|
287
|
+
return element;
|
|
288
|
+
},
|
|
289
|
+
update: updateOptions => {
|
|
290
|
+
stripeConnectInstance.then(instance => {
|
|
291
|
+
instance.update(updateOptions);
|
|
292
|
+
});
|
|
293
|
+
},
|
|
294
|
+
debugInstance: () => {
|
|
295
|
+
return stripeConnectInstance;
|
|
296
|
+
},
|
|
297
|
+
logout: () => {
|
|
298
|
+
return stripeConnectInstance.then(instance => {
|
|
299
|
+
return instance.logout();
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
};
|
|
304
|
+
const createWrapper = stripeConnect => {
|
|
305
|
+
window.StripeConnect = window.StripeConnect || {};
|
|
306
|
+
window.StripeConnect.optimizedLoading = true;
|
|
307
|
+
const wrapper = {
|
|
308
|
+
initialize: params => {
|
|
309
|
+
var _a;
|
|
310
|
+
const metaOptions = (_a = params.metaOptions) !== null && _a !== void 0 ? _a : {};
|
|
311
|
+
const stripeConnectInstance = stripeConnect.init(Object.assign(Object.assign({}, params), {
|
|
312
|
+
metaOptions: Object.assign(Object.assign({}, metaOptions), {
|
|
313
|
+
sdk: true,
|
|
314
|
+
sdkOptions: {
|
|
315
|
+
// This will be replaced by the npm package version when bundling
|
|
316
|
+
sdkVersion: "3.3.44-preview-1"
|
|
317
|
+
}
|
|
318
|
+
})
|
|
319
|
+
}));
|
|
320
|
+
return stripeConnectInstance;
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
return wrapper;
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
const loadConnectAndInitialize = initParams => {
|
|
327
|
+
const maybeConnect = loadScript();
|
|
328
|
+
if (initParams == null) {
|
|
329
|
+
throw new Error("You must provide required parameters to initialize Connect");
|
|
330
|
+
}
|
|
331
|
+
return initStripeConnect(maybeConnect, initParams);
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
exports.loadConnectAndInitialize = loadConnectAndInitialize;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IStripeConnectInitParams, StripeConnectInstance, ConnectElementTagName } from "../types";
|
|
2
|
+
export type LoadConnectAndInitialize = (initParams: IStripeConnectInitParams) => StripeConnectInstance;
|
|
3
|
+
export type ConnectElementHTMLName = "stripe-connect-payments" | "stripe-connect-payouts" | "stripe-connect-payment-details" | "stripe-connect-payment-disputes" | "stripe-connect-disputes-list" | "stripe-connect-account-onboarding" | "stripe-connect-payment-method-settings" | "stripe-connect-account-management" | "stripe-connect-notification-banner" | "stripe-connect-instant-payouts" | "stripe-connect-instant-payouts-promotion" | "stripe-connect-issuing-card" | "stripe-connect-issuing-cards-list" | "stripe-connect-financial-account" | "stripe-connect-financial-account-transactions" | "stripe-connect-recipients" | "stripe-connect-capital-financing" | "stripe-connect-capital-financing-application" | "stripe-connect-capital-financing-promotion" | "stripe-connect-capital-overview" | "stripe-connect-documents" | "stripe-connect-product-tax-code-selector" | "stripe-connect-export-tax-transactions" | "stripe-connect-tax-registrations" | "stripe-connect-tax-settings" | "stripe-connect-tax-threshold-monitoring" | "stripe-connect-balances" | "stripe-connect-payouts-list" | "stripe-connect-payout-details" | "stripe-connect-app-install" | "stripe-connect-app-viewport" | "stripe-connect-reporting-chart" | "stripe-connect-check-scanning";
|
|
4
|
+
export declare const componentNameMapping: Record<ConnectElementTagName, ConnectElementHTMLName>;
|
|
5
|
+
type StripeConnectInstanceExtended = StripeConnectInstance & {
|
|
6
|
+
debugInstance: () => Promise<StripeConnectInstance>;
|
|
7
|
+
};
|
|
8
|
+
interface StripeConnectWrapper {
|
|
9
|
+
initialize: (params: IStripeConnectInitParams) => StripeConnectInstance;
|
|
10
|
+
}
|
|
11
|
+
export declare const findScript: () => HTMLScriptElement | null;
|
|
12
|
+
export declare const isWindowStripeConnectDefined: (stripeConnect: unknown) => boolean;
|
|
13
|
+
export declare const loadScript: () => Promise<StripeConnectWrapper>;
|
|
14
|
+
export declare const initStripeConnect: (stripePromise: Promise<StripeConnectWrapper>, initParams: IStripeConnectInitParams) => StripeConnectInstanceExtended;
|
|
15
|
+
export {};
|