@stripe/connect-js 3.0.0-beta.1 → 3.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/README.md +24 -19
- package/dist/connect.esm.js +28 -12
- package/dist/connect.js +28 -12
- package/dist/pure.esm.js +28 -12
- package/dist/pure.js +28 -12
- package/dist/{shared.d.ts → src/shared.d.ts} +1 -1
- package/dist/types/config.d.ts +9 -0
- package/package.json +1 -1
- package/src/shared.ts +23 -23
- package/types/config.ts +27 -0
- package/types/shared.d.ts +10 -56
- /package/dist/{pure.d.ts → src/pure.d.ts} +0 -0
- /package/dist/{utils → src/utils}/jestHelpers.d.ts +0 -0
- /package/dist/{utils → src/utils}/jestSetup.d.ts +0 -0
package/README.md
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
The [Connect.js library](https://stripe.com/docs/connect/get-started-connect-embedded-components) and its supporting API allows you to add connected account dashboard functionality to your website.
|
|
4
4
|
This NPM package contains initialization logic for Connect embedded components along with related types.
|
|
5
5
|
|
|
6
|
-
Calling `
|
|
6
|
+
Calling `loadConnectAndInitialize` always loads the latest version of Connect.js, regardless of which version of `@stripe/connect-js` you use. Updates for this package only impact tooling around the `loadConnectAndInitialize` helper itself and the TypeScript type definitions provided for Connect.js. Updates do not affect runtime availability of features of Connect.js.
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
The embedded onboarding component is generally available now. Please refer to our [documentation](https://stripe.com/docs/connect/get-started-connect-embedded-components#account-onboarding) for more information.
|
|
9
|
+
|
|
10
|
+
Note: Majority of Connect embedded components are currently still in beta. Please [contact us](https://stripe.com/docs/connect/get-started-connect-embedded-components#access) to request beta access.
|
|
9
11
|
|
|
10
12
|
## Installation
|
|
11
13
|
|
|
@@ -17,25 +19,25 @@ npm install @stripe/connect-js
|
|
|
17
19
|
|
|
18
20
|
## Documentation
|
|
19
21
|
|
|
20
|
-
- [Connect embedded components](https://stripe.com/docs/connect/get-started-connect-embedded-
|
|
21
|
-
- [Quickstart guide](https://stripe.com/docs/connect/connect-embedded-
|
|
22
|
+
- [Connect embedded components](https://stripe.com/docs/connect/get-started-connect-embedded-components)
|
|
23
|
+
- [Quickstart guide for GA](https://stripe.com/docs/connect/connect-embedded-components/quickstart)
|
|
24
|
+
- [Quickstart guide for beta](https://stripe.com/docs/connect/connect-embedded-components/beta-quickstart)
|
|
22
25
|
|
|
23
26
|
## Usage
|
|
24
27
|
|
|
25
|
-
### `
|
|
26
|
-
|
|
27
|
-
This function returns a `Promise` that resolves with a newly created `StripeConnect`
|
|
28
|
-
object once Connect.js has loaded. If necessary, it will load Connect.js for you by inserting the Connect.js script tag.
|
|
28
|
+
### `loadConnectAndInitialize`
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
This synchronous function takes in a publishable key, a function to retrieve the client secret returned from the [Account Session API](https://stripe.com/docs/api/account_sessions/create), and other [initialization parameters](https://stripe.com/docs/connect/get-started-connect-embedded-components#configuring-connect-js). It returns a `StripeConnectInstance`. If necessary, it will load Connect.js for you by inserting the Connect.js script tag.
|
|
31
31
|
|
|
32
32
|
```js
|
|
33
|
-
import {
|
|
33
|
+
import { loadConnectAndInitialize } from "@stripe/connect-js";
|
|
34
|
+
const fetchClientSecret = async () => {
|
|
35
|
+
// Fetch the AccountSession client secret by making an API call to your service
|
|
36
|
+
};
|
|
34
37
|
|
|
35
|
-
const
|
|
36
|
-
const connectInstance = stripeConnect.initialize({
|
|
38
|
+
const instance = loadConnectAndInitialize({
|
|
37
39
|
publishableKey: "{{pk test123}}",
|
|
38
|
-
|
|
40
|
+
fetchClientSecret: fetchClientSecret
|
|
39
41
|
});
|
|
40
42
|
```
|
|
41
43
|
|
|
@@ -62,22 +64,25 @@ import "@stripe/connect-js";
|
|
|
62
64
|
|
|
63
65
|
Manually add the Connect.js script tag to the `<head>` of each page on your site.
|
|
64
66
|
If an existing script tag is already present, this module will not insert a new
|
|
65
|
-
one. When you call `
|
|
67
|
+
one. When you call `loadConnectAndInitialize`, it will use the existing script tag.
|
|
66
68
|
|
|
67
69
|
```html
|
|
68
70
|
<!-- Somewhere in your site's <head> -->
|
|
69
71
|
<script src="https://connect-js.stripe.com/v0.1/connect.js" async></script>
|
|
70
72
|
```
|
|
71
73
|
|
|
72
|
-
### Importing `
|
|
74
|
+
### Importing `loadConnectAndInitialize` without side effects
|
|
73
75
|
|
|
74
|
-
If you would like to use `
|
|
75
|
-
Connect.js script until `
|
|
76
|
+
If you would like to use `loadConnectAndInitialize` in your application, but defer loading the
|
|
77
|
+
Connect.js script until `loadConnectAndInitialize` is first called, use the alternative
|
|
76
78
|
`@stripe/connect-js/pure` import path:
|
|
77
79
|
|
|
78
80
|
```js
|
|
79
|
-
import {
|
|
81
|
+
import { loadConnectAndInitialize } from "@stripe/connect-js/pure";
|
|
80
82
|
|
|
81
83
|
// Connect.js will not be loaded until `loadConnect` is called
|
|
82
|
-
const
|
|
84
|
+
const instance = loadConnectAndInitialize({
|
|
85
|
+
publishableKey: "{{pk test123}}",
|
|
86
|
+
fetchClientSecret: fetchClientSecret
|
|
87
|
+
});
|
|
83
88
|
```
|
package/dist/connect.esm.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
|
+
const ConnectElementCustomMethodConfig = {
|
|
4
|
+
"account-onboarding": {
|
|
5
|
+
setFullTermsOfServiceUrl: termOfServiceUrl => {},
|
|
6
|
+
setRecipientTermsOfServiceUrl: recipientTermsOfServiceUrl => {},
|
|
7
|
+
setPrivacyPolicyUrl: privacyPolicyUrl => {},
|
|
8
|
+
setSkipTermsOfServiceCollection: skipTermsOfServiceCollection => {},
|
|
9
|
+
setOnExit: listener => {}
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
1
13
|
const componentNameMapping = {
|
|
2
|
-
|
|
3
|
-
payouts: "stripe-connect-payouts",
|
|
4
|
-
"payment-details": "stripe-connect-payment-details",
|
|
5
|
-
"account-onboarding": "stripe-connect-account-onboarding",
|
|
6
|
-
"payment-method-settings": "stripe-connect-payment-method-settings",
|
|
7
|
-
"account-management": "stripe-connect-account-management",
|
|
8
|
-
"notification-banner": "stripe-connect-notification-banner",
|
|
9
|
-
"instant-payouts": "stripe-connect-instant-payouts",
|
|
10
|
-
"issuing-card": "stripe-connect-issuing-card",
|
|
11
|
-
"issuing-cards-list": "stripe-connect-issuing-cards-list"
|
|
14
|
+
"account-onboarding": "stripe-connect-account-onboarding"
|
|
12
15
|
};
|
|
13
16
|
const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
|
|
14
|
-
const V0_URL = "https://connect-js.stripe.com/
|
|
17
|
+
const V0_URL = "https://connect-js.stripe.com/v1.0/connect.js";
|
|
15
18
|
const findScript = () => {
|
|
16
19
|
return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
|
|
17
20
|
};
|
|
@@ -68,6 +71,9 @@ const loadScript = () => {
|
|
|
68
71
|
});
|
|
69
72
|
return stripePromise;
|
|
70
73
|
};
|
|
74
|
+
const hasCustomMethod = tagName => {
|
|
75
|
+
return tagName in ConnectElementCustomMethodConfig;
|
|
76
|
+
};
|
|
71
77
|
const initStripeConnect = (stripePromise, initParams) => {
|
|
72
78
|
const stripeConnectInstance = stripePromise.then(wrapper => wrapper.initialize(initParams));
|
|
73
79
|
return {
|
|
@@ -77,6 +83,16 @@ const initStripeConnect = (stripePromise, initParams) => {
|
|
|
77
83
|
htmlName = tagName;
|
|
78
84
|
}
|
|
79
85
|
const element = document.createElement(htmlName);
|
|
86
|
+
if (hasCustomMethod(tagName)) {
|
|
87
|
+
const methods = ConnectElementCustomMethodConfig[tagName];
|
|
88
|
+
for (const method in methods) {
|
|
89
|
+
element[method] = function (value) {
|
|
90
|
+
stripeConnectInstance.then(() => {
|
|
91
|
+
this[`${method}InternalOnly`](value);
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
80
96
|
stripeConnectInstance.then(instance => {
|
|
81
97
|
element.setConnector(instance.connect);
|
|
82
98
|
});
|
|
@@ -109,7 +125,7 @@ const createWrapper = stripeConnect => {
|
|
|
109
125
|
sdk: true,
|
|
110
126
|
sdkOptions: {
|
|
111
127
|
// This will be replaced by the npm package version when bundling
|
|
112
|
-
sdkVersion: "3.0.
|
|
128
|
+
sdkVersion: "3.0.1"
|
|
113
129
|
}
|
|
114
130
|
})
|
|
115
131
|
}));
|
package/dist/connect.js
CHANGED
|
@@ -2,20 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
6
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
7
|
+
const ConnectElementCustomMethodConfig = {
|
|
8
|
+
"account-onboarding": {
|
|
9
|
+
setFullTermsOfServiceUrl: termOfServiceUrl => {},
|
|
10
|
+
setRecipientTermsOfServiceUrl: recipientTermsOfServiceUrl => {},
|
|
11
|
+
setPrivacyPolicyUrl: privacyPolicyUrl => {},
|
|
12
|
+
setSkipTermsOfServiceCollection: skipTermsOfServiceCollection => {},
|
|
13
|
+
setOnExit: listener => {}
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
5
17
|
const componentNameMapping = {
|
|
6
|
-
|
|
7
|
-
payouts: "stripe-connect-payouts",
|
|
8
|
-
"payment-details": "stripe-connect-payment-details",
|
|
9
|
-
"account-onboarding": "stripe-connect-account-onboarding",
|
|
10
|
-
"payment-method-settings": "stripe-connect-payment-method-settings",
|
|
11
|
-
"account-management": "stripe-connect-account-management",
|
|
12
|
-
"notification-banner": "stripe-connect-notification-banner",
|
|
13
|
-
"instant-payouts": "stripe-connect-instant-payouts",
|
|
14
|
-
"issuing-card": "stripe-connect-issuing-card",
|
|
15
|
-
"issuing-cards-list": "stripe-connect-issuing-cards-list"
|
|
18
|
+
"account-onboarding": "stripe-connect-account-onboarding"
|
|
16
19
|
};
|
|
17
20
|
const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
|
|
18
|
-
const V0_URL = "https://connect-js.stripe.com/
|
|
21
|
+
const V0_URL = "https://connect-js.stripe.com/v1.0/connect.js";
|
|
19
22
|
const findScript = () => {
|
|
20
23
|
return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
|
|
21
24
|
};
|
|
@@ -72,6 +75,9 @@ const loadScript = () => {
|
|
|
72
75
|
});
|
|
73
76
|
return stripePromise;
|
|
74
77
|
};
|
|
78
|
+
const hasCustomMethod = tagName => {
|
|
79
|
+
return tagName in ConnectElementCustomMethodConfig;
|
|
80
|
+
};
|
|
75
81
|
const initStripeConnect = (stripePromise, initParams) => {
|
|
76
82
|
const stripeConnectInstance = stripePromise.then(wrapper => wrapper.initialize(initParams));
|
|
77
83
|
return {
|
|
@@ -81,6 +87,16 @@ const initStripeConnect = (stripePromise, initParams) => {
|
|
|
81
87
|
htmlName = tagName;
|
|
82
88
|
}
|
|
83
89
|
const element = document.createElement(htmlName);
|
|
90
|
+
if (hasCustomMethod(tagName)) {
|
|
91
|
+
const methods = ConnectElementCustomMethodConfig[tagName];
|
|
92
|
+
for (const method in methods) {
|
|
93
|
+
element[method] = function (value) {
|
|
94
|
+
stripeConnectInstance.then(() => {
|
|
95
|
+
this[`${method}InternalOnly`](value);
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
84
100
|
stripeConnectInstance.then(instance => {
|
|
85
101
|
element.setConnector(instance.connect);
|
|
86
102
|
});
|
|
@@ -113,7 +129,7 @@ const createWrapper = stripeConnect => {
|
|
|
113
129
|
sdk: true,
|
|
114
130
|
sdkOptions: {
|
|
115
131
|
// This will be replaced by the npm package version when bundling
|
|
116
|
-
sdkVersion: "3.0.
|
|
132
|
+
sdkVersion: "3.0.1"
|
|
117
133
|
}
|
|
118
134
|
})
|
|
119
135
|
}));
|
package/dist/pure.esm.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
|
+
const ConnectElementCustomMethodConfig = {
|
|
4
|
+
"account-onboarding": {
|
|
5
|
+
setFullTermsOfServiceUrl: termOfServiceUrl => {},
|
|
6
|
+
setRecipientTermsOfServiceUrl: recipientTermsOfServiceUrl => {},
|
|
7
|
+
setPrivacyPolicyUrl: privacyPolicyUrl => {},
|
|
8
|
+
setSkipTermsOfServiceCollection: skipTermsOfServiceCollection => {},
|
|
9
|
+
setOnExit: listener => {}
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
1
13
|
const componentNameMapping = {
|
|
2
|
-
|
|
3
|
-
payouts: "stripe-connect-payouts",
|
|
4
|
-
"payment-details": "stripe-connect-payment-details",
|
|
5
|
-
"account-onboarding": "stripe-connect-account-onboarding",
|
|
6
|
-
"payment-method-settings": "stripe-connect-payment-method-settings",
|
|
7
|
-
"account-management": "stripe-connect-account-management",
|
|
8
|
-
"notification-banner": "stripe-connect-notification-banner",
|
|
9
|
-
"instant-payouts": "stripe-connect-instant-payouts",
|
|
10
|
-
"issuing-card": "stripe-connect-issuing-card",
|
|
11
|
-
"issuing-cards-list": "stripe-connect-issuing-cards-list"
|
|
14
|
+
"account-onboarding": "stripe-connect-account-onboarding"
|
|
12
15
|
};
|
|
13
16
|
const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
|
|
14
|
-
const V0_URL = "https://connect-js.stripe.com/
|
|
17
|
+
const V0_URL = "https://connect-js.stripe.com/v1.0/connect.js";
|
|
15
18
|
const findScript = () => {
|
|
16
19
|
return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
|
|
17
20
|
};
|
|
@@ -68,6 +71,9 @@ const loadScript = () => {
|
|
|
68
71
|
});
|
|
69
72
|
return stripePromise;
|
|
70
73
|
};
|
|
74
|
+
const hasCustomMethod = tagName => {
|
|
75
|
+
return tagName in ConnectElementCustomMethodConfig;
|
|
76
|
+
};
|
|
71
77
|
const initStripeConnect = (stripePromise, initParams) => {
|
|
72
78
|
const stripeConnectInstance = stripePromise.then(wrapper => wrapper.initialize(initParams));
|
|
73
79
|
return {
|
|
@@ -77,6 +83,16 @@ const initStripeConnect = (stripePromise, initParams) => {
|
|
|
77
83
|
htmlName = tagName;
|
|
78
84
|
}
|
|
79
85
|
const element = document.createElement(htmlName);
|
|
86
|
+
if (hasCustomMethod(tagName)) {
|
|
87
|
+
const methods = ConnectElementCustomMethodConfig[tagName];
|
|
88
|
+
for (const method in methods) {
|
|
89
|
+
element[method] = function (value) {
|
|
90
|
+
stripeConnectInstance.then(() => {
|
|
91
|
+
this[`${method}InternalOnly`](value);
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
80
96
|
stripeConnectInstance.then(instance => {
|
|
81
97
|
element.setConnector(instance.connect);
|
|
82
98
|
});
|
|
@@ -109,7 +125,7 @@ const createWrapper = stripeConnect => {
|
|
|
109
125
|
sdk: true,
|
|
110
126
|
sdkOptions: {
|
|
111
127
|
// This will be replaced by the npm package version when bundling
|
|
112
|
-
sdkVersion: "3.0.
|
|
128
|
+
sdkVersion: "3.0.1"
|
|
113
129
|
}
|
|
114
130
|
})
|
|
115
131
|
}));
|
package/dist/pure.js
CHANGED
|
@@ -2,20 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
6
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
7
|
+
const ConnectElementCustomMethodConfig = {
|
|
8
|
+
"account-onboarding": {
|
|
9
|
+
setFullTermsOfServiceUrl: termOfServiceUrl => {},
|
|
10
|
+
setRecipientTermsOfServiceUrl: recipientTermsOfServiceUrl => {},
|
|
11
|
+
setPrivacyPolicyUrl: privacyPolicyUrl => {},
|
|
12
|
+
setSkipTermsOfServiceCollection: skipTermsOfServiceCollection => {},
|
|
13
|
+
setOnExit: listener => {}
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
5
17
|
const componentNameMapping = {
|
|
6
|
-
|
|
7
|
-
payouts: "stripe-connect-payouts",
|
|
8
|
-
"payment-details": "stripe-connect-payment-details",
|
|
9
|
-
"account-onboarding": "stripe-connect-account-onboarding",
|
|
10
|
-
"payment-method-settings": "stripe-connect-payment-method-settings",
|
|
11
|
-
"account-management": "stripe-connect-account-management",
|
|
12
|
-
"notification-banner": "stripe-connect-notification-banner",
|
|
13
|
-
"instant-payouts": "stripe-connect-instant-payouts",
|
|
14
|
-
"issuing-card": "stripe-connect-issuing-card",
|
|
15
|
-
"issuing-cards-list": "stripe-connect-issuing-cards-list"
|
|
18
|
+
"account-onboarding": "stripe-connect-account-onboarding"
|
|
16
19
|
};
|
|
17
20
|
const EXISTING_SCRIPT_MESSAGE = "loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
|
|
18
|
-
const V0_URL = "https://connect-js.stripe.com/
|
|
21
|
+
const V0_URL = "https://connect-js.stripe.com/v1.0/connect.js";
|
|
19
22
|
const findScript = () => {
|
|
20
23
|
return document.querySelectorAll(`script[src="${V0_URL}"]`)[0];
|
|
21
24
|
};
|
|
@@ -72,6 +75,9 @@ const loadScript = () => {
|
|
|
72
75
|
});
|
|
73
76
|
return stripePromise;
|
|
74
77
|
};
|
|
78
|
+
const hasCustomMethod = tagName => {
|
|
79
|
+
return tagName in ConnectElementCustomMethodConfig;
|
|
80
|
+
};
|
|
75
81
|
const initStripeConnect = (stripePromise, initParams) => {
|
|
76
82
|
const stripeConnectInstance = stripePromise.then(wrapper => wrapper.initialize(initParams));
|
|
77
83
|
return {
|
|
@@ -81,6 +87,16 @@ const initStripeConnect = (stripePromise, initParams) => {
|
|
|
81
87
|
htmlName = tagName;
|
|
82
88
|
}
|
|
83
89
|
const element = document.createElement(htmlName);
|
|
90
|
+
if (hasCustomMethod(tagName)) {
|
|
91
|
+
const methods = ConnectElementCustomMethodConfig[tagName];
|
|
92
|
+
for (const method in methods) {
|
|
93
|
+
element[method] = function (value) {
|
|
94
|
+
stripeConnectInstance.then(() => {
|
|
95
|
+
this[`${method}InternalOnly`](value);
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
84
100
|
stripeConnectInstance.then(instance => {
|
|
85
101
|
element.setConnector(instance.connect);
|
|
86
102
|
});
|
|
@@ -113,7 +129,7 @@ const createWrapper = stripeConnect => {
|
|
|
113
129
|
sdk: true,
|
|
114
130
|
sdkOptions: {
|
|
115
131
|
// This will be replaced by the npm package version when bundling
|
|
116
|
-
sdkVersion: "3.0.
|
|
132
|
+
sdkVersion: "3.0.1"
|
|
117
133
|
}
|
|
118
134
|
})
|
|
119
135
|
}));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IStripeConnectInitParams, StripeConnectInstance, ConnectElementTagName } from "../types";
|
|
2
2
|
export type LoadConnectAndInitialize = (initParams: IStripeConnectInitParams) => StripeConnectInstance;
|
|
3
|
-
|
|
3
|
+
type ConnectElementHTMLName = "stripe-connect-account-onboarding";
|
|
4
4
|
export declare const componentNameMapping: Record<ConnectElementTagName, ConnectElementHTMLName>;
|
|
5
5
|
type StripeConnectInstanceExtended = StripeConnectInstance & {
|
|
6
6
|
debugInstance: () => Promise<StripeConnectInstance>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const ConnectElementCustomMethodConfig: {
|
|
2
|
+
"account-onboarding": {
|
|
3
|
+
setFullTermsOfServiceUrl: (termOfServiceUrl: string | undefined) => void;
|
|
4
|
+
setRecipientTermsOfServiceUrl: (recipientTermsOfServiceUrl: string | undefined) => void;
|
|
5
|
+
setPrivacyPolicyUrl: (privacyPolicyUrl: string | undefined) => void;
|
|
6
|
+
setSkipTermsOfServiceCollection: (skipTermsOfServiceCollection: boolean | undefined) => void;
|
|
7
|
+
setOnExit: (listener: (() => void) | undefined) => void;
|
|
8
|
+
};
|
|
9
|
+
};
|
package/package.json
CHANGED
package/src/shared.ts
CHANGED
|
@@ -4,37 +4,19 @@ import {
|
|
|
4
4
|
ConnectElementTagName,
|
|
5
5
|
ConnectHTMLElementRecord
|
|
6
6
|
} from "../types";
|
|
7
|
+
import { ConnectElementCustomMethodConfig } from "../types/config";
|
|
7
8
|
|
|
8
9
|
export type LoadConnectAndInitialize = (
|
|
9
10
|
initParams: IStripeConnectInitParams
|
|
10
11
|
) => StripeConnectInstance;
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
| "stripe-connect-payments"
|
|
14
|
-
| "stripe-connect-payouts"
|
|
15
|
-
| "stripe-connect-payment-details"
|
|
16
|
-
| "stripe-connect-account-onboarding"
|
|
17
|
-
| "stripe-connect-payment-method-settings"
|
|
18
|
-
| "stripe-connect-account-management"
|
|
19
|
-
| "stripe-connect-notification-banner"
|
|
20
|
-
| "stripe-connect-instant-payouts"
|
|
21
|
-
| "stripe-connect-issuing-card"
|
|
22
|
-
| "stripe-connect-issuing-cards-list";
|
|
13
|
+
type ConnectElementHTMLName = "stripe-connect-account-onboarding";
|
|
23
14
|
|
|
24
15
|
export const componentNameMapping: Record<
|
|
25
16
|
ConnectElementTagName,
|
|
26
17
|
ConnectElementHTMLName
|
|
27
18
|
> = {
|
|
28
|
-
|
|
29
|
-
payouts: "stripe-connect-payouts",
|
|
30
|
-
"payment-details": "stripe-connect-payment-details",
|
|
31
|
-
"account-onboarding": "stripe-connect-account-onboarding",
|
|
32
|
-
"payment-method-settings": "stripe-connect-payment-method-settings",
|
|
33
|
-
"account-management": "stripe-connect-account-management",
|
|
34
|
-
"notification-banner": "stripe-connect-notification-banner",
|
|
35
|
-
"instant-payouts": "stripe-connect-instant-payouts",
|
|
36
|
-
"issuing-card": "stripe-connect-issuing-card",
|
|
37
|
-
"issuing-cards-list": "stripe-connect-issuing-cards-list"
|
|
19
|
+
"account-onboarding": "stripe-connect-account-onboarding"
|
|
38
20
|
};
|
|
39
21
|
|
|
40
22
|
type StripeConnectInstanceExtended = StripeConnectInstance & {
|
|
@@ -47,7 +29,7 @@ interface StripeConnectWrapper {
|
|
|
47
29
|
|
|
48
30
|
const EXISTING_SCRIPT_MESSAGE =
|
|
49
31
|
"loadConnect was called but an existing Connect.js script already exists in the document; existing script parameters will be used";
|
|
50
|
-
const V0_URL = "https://connect-js.stripe.com/
|
|
32
|
+
const V0_URL = "https://connect-js.stripe.com/v1.0/connect.js";
|
|
51
33
|
|
|
52
34
|
export const findScript = (): HTMLScriptElement | null => {
|
|
53
35
|
return document.querySelectorAll<HTMLScriptElement>(
|
|
@@ -127,6 +109,12 @@ export const loadScript = (): Promise<StripeConnectWrapper> => {
|
|
|
127
109
|
return stripePromise;
|
|
128
110
|
};
|
|
129
111
|
|
|
112
|
+
const hasCustomMethod = (
|
|
113
|
+
tagName: ConnectElementTagName
|
|
114
|
+
): tagName is keyof typeof ConnectElementCustomMethodConfig => {
|
|
115
|
+
return tagName in ConnectElementCustomMethodConfig;
|
|
116
|
+
};
|
|
117
|
+
|
|
130
118
|
export const initStripeConnect = (
|
|
131
119
|
stripePromise: Promise<StripeConnectWrapper>,
|
|
132
120
|
initParams: IStripeConnectInitParams
|
|
@@ -139,9 +127,21 @@ export const initStripeConnect = (
|
|
|
139
127
|
create: tagName => {
|
|
140
128
|
let htmlName = componentNameMapping[tagName];
|
|
141
129
|
if (!htmlName) {
|
|
142
|
-
htmlName = tagName as ConnectElementHTMLName;
|
|
130
|
+
htmlName = (tagName as unknown) as ConnectElementHTMLName;
|
|
143
131
|
}
|
|
144
132
|
const element = document.createElement(htmlName);
|
|
133
|
+
|
|
134
|
+
if (hasCustomMethod(tagName)) {
|
|
135
|
+
const methods = ConnectElementCustomMethodConfig[tagName];
|
|
136
|
+
for (const method in methods) {
|
|
137
|
+
(element as any)[method] = function(value: any) {
|
|
138
|
+
stripeConnectInstance.then(() => {
|
|
139
|
+
this[`${method}InternalOnly`](value);
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
145
|
stripeConnectInstance.then(instance => {
|
|
146
146
|
(element as any).setConnector((instance as any).connect);
|
|
147
147
|
});
|
package/types/config.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ConnectElementTagName } from "./shared.d";
|
|
2
|
+
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
5
|
+
|
|
6
|
+
export const ConnectElementCustomMethodConfig = {
|
|
7
|
+
"account-onboarding": {
|
|
8
|
+
setFullTermsOfServiceUrl: (
|
|
9
|
+
termOfServiceUrl: string | undefined
|
|
10
|
+
): void => {},
|
|
11
|
+
setRecipientTermsOfServiceUrl: (
|
|
12
|
+
recipientTermsOfServiceUrl: string | undefined
|
|
13
|
+
): void => {},
|
|
14
|
+
setPrivacyPolicyUrl: (privacyPolicyUrl: string | undefined): void => {},
|
|
15
|
+
setSkipTermsOfServiceCollection: (
|
|
16
|
+
skipTermsOfServiceCollection: boolean | undefined
|
|
17
|
+
): void => {},
|
|
18
|
+
setOnExit: (listener: (() => void) | undefined): void => {}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// ensure that keys of ConnectElementCustomMethodConfig are from ConnectElementTagName
|
|
23
|
+
type HasType<T, Q extends T> = Q;
|
|
24
|
+
type CustomMethodConfigValidation = HasType<
|
|
25
|
+
ConnectElementTagName,
|
|
26
|
+
keyof typeof ConnectElementCustomMethodConfig
|
|
27
|
+
>;
|
package/types/shared.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ConnectElementCustomMethodConfig } from "./config";
|
|
2
|
+
|
|
1
3
|
export declare type LoadConnectAndInitialize = (
|
|
2
4
|
initParams: IStripeConnectInitParams
|
|
3
5
|
) => StripeConnectInstance;
|
|
@@ -209,14 +211,6 @@ export declare type AppearanceVariables = {
|
|
|
209
211
|
overlayZIndex?: number;
|
|
210
212
|
|
|
211
213
|
// Body Typography
|
|
212
|
-
/**
|
|
213
|
-
* The font size for the large body typography. Body typography variables accept a valid font size value.
|
|
214
|
-
*/
|
|
215
|
-
bodyLgFontSize?: string;
|
|
216
|
-
/**
|
|
217
|
-
* The font weight for the large body typography. Body typography variables accept a valid font weight value.
|
|
218
|
-
*/
|
|
219
|
-
bodyLgFontWeight?: string;
|
|
220
214
|
/**
|
|
221
215
|
* The font size for the medium body typography. Body typography variables accept a valid font size value.
|
|
222
216
|
*/
|
|
@@ -297,18 +291,6 @@ export declare type AppearanceVariables = {
|
|
|
297
291
|
headingXsTextTransform?: string;
|
|
298
292
|
|
|
299
293
|
// Label Typography
|
|
300
|
-
/**
|
|
301
|
-
* The font size for the large label typography. Label typography variables accept a valid font size value.
|
|
302
|
-
*/
|
|
303
|
-
labelLgFontSize?: string;
|
|
304
|
-
/**
|
|
305
|
-
* The font weight for the large label typography. Label typography variables accept a valid font weight value.
|
|
306
|
-
*/
|
|
307
|
-
labelLgFontWeight?: string;
|
|
308
|
-
/**
|
|
309
|
-
* The text transform for the large label typography. Label typography variables accept a valid text transform value.
|
|
310
|
-
*/
|
|
311
|
-
labelLgTextTransform?: string;
|
|
312
294
|
/**
|
|
313
295
|
* The font size for the medium label typography. Label typography variables accept a valid font size value.
|
|
314
296
|
*/
|
|
@@ -374,32 +356,14 @@ export interface IStripeConnectInitParams {
|
|
|
374
356
|
locale?: string;
|
|
375
357
|
}
|
|
376
358
|
|
|
377
|
-
type
|
|
378
|
-
[key in string]: HTMLElement | null;
|
|
379
|
-
};
|
|
380
|
-
type ConnectHTMLElementRecordBase = {
|
|
381
|
-
[tagName in ConnectElementTagName]: HTMLElement;
|
|
382
|
-
};
|
|
359
|
+
type ConnectElementCustomMethods = typeof ConnectElementCustomMethodConfig;
|
|
383
360
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
};
|
|
391
|
-
"account-onboarding": HTMLElement & {
|
|
392
|
-
setFullTermsOfServiceUrl: (termOfServiceUrl: string | undefined) => void;
|
|
393
|
-
setRecipientTermsOfServiceUrl: (
|
|
394
|
-
recipientTermsOfServiceUrl: string | undefined
|
|
395
|
-
) => void;
|
|
396
|
-
setPrivacyPolicyUrl: (privacyPolicyUrl: string | undefined) => void;
|
|
397
|
-
setSkipTermsOfServiceCollection: (
|
|
398
|
-
skipTermsOfServiceCollection: boolean | undefined
|
|
399
|
-
) => void;
|
|
400
|
-
setOnExit: (listener: (() => void) | undefined) => void;
|
|
401
|
-
};
|
|
402
|
-
}
|
|
361
|
+
type ConnectHTMLElementRecord = {
|
|
362
|
+
[K in keyof ConnectElementCustomMethods]: HTMLElement &
|
|
363
|
+
ConnectElementCustomMethods[K];
|
|
364
|
+
} & {
|
|
365
|
+
[key: string]: HTMLElement;
|
|
366
|
+
};
|
|
403
367
|
|
|
404
368
|
export interface StripeConnectInstance {
|
|
405
369
|
/**
|
|
@@ -427,14 +391,4 @@ export interface StripeConnectInstance {
|
|
|
427
391
|
/**
|
|
428
392
|
* Tagnames to be used with the `create` method of the Connect instance.
|
|
429
393
|
*/
|
|
430
|
-
export type ConnectElementTagName =
|
|
431
|
-
| "payments"
|
|
432
|
-
| "payouts"
|
|
433
|
-
| "payment-details"
|
|
434
|
-
| "account-onboarding"
|
|
435
|
-
| "payment-method-settings"
|
|
436
|
-
| "account-management"
|
|
437
|
-
| "notification-banner"
|
|
438
|
-
| "instant-payouts"
|
|
439
|
-
| "issuing-card"
|
|
440
|
-
| "issuing-cards-list";
|
|
394
|
+
export type ConnectElementTagName = "account-onboarding";
|
|
File without changes
|
|
File without changes
|
|
File without changes
|