@stripe/stripe-js 10.0.0-rc.0 → 10.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +107 -45
- package/dist/index.mjs +107 -45
- package/dist/pure.js +107 -45
- package/dist/pure.mjs +107 -45
- package/dist/stripe-js/elements-group.d.mts +4 -32
- package/dist/stripe-js/elements-group.d.ts +4 -32
- package/package.json +1 -1
- package/src/index.test.ts +44 -3
- package/src/shared.ts +52 -47
package/dist/index.js
CHANGED
|
@@ -18,6 +18,42 @@ function _typeof(obj) {
|
|
|
18
18
|
return _typeof(obj);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
22
|
+
try {
|
|
23
|
+
var info = gen[key](arg);
|
|
24
|
+
var value = info.value;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
reject(error);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (info.done) {
|
|
31
|
+
resolve(value);
|
|
32
|
+
} else {
|
|
33
|
+
Promise.resolve(value).then(_next, _throw);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function _asyncToGenerator(fn) {
|
|
38
|
+
return function () {
|
|
39
|
+
var self = this,
|
|
40
|
+
args = arguments;
|
|
41
|
+
return new Promise(function (resolve, reject) {
|
|
42
|
+
var gen = fn.apply(self, args);
|
|
43
|
+
|
|
44
|
+
function _next(value) {
|
|
45
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function _throw(err) {
|
|
49
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
_next(undefined);
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
21
57
|
var RELEASE_TRAIN = 'endive';
|
|
22
58
|
|
|
23
59
|
var runtimeVersionToUrlVersion = function runtimeVersionToUrlVersion(version) {
|
|
@@ -71,7 +107,7 @@ var registerWrapper = function registerWrapper(stripe, startTime) {
|
|
|
71
107
|
|
|
72
108
|
stripe._registerWrapper({
|
|
73
109
|
name: 'stripe-js',
|
|
74
|
-
version: "10.0.0-rc.
|
|
110
|
+
version: "10.0.0-rc.2",
|
|
75
111
|
startTime: startTime
|
|
76
112
|
});
|
|
77
113
|
};
|
|
@@ -104,55 +140,81 @@ var loadScript = function loadScript(params) {
|
|
|
104
140
|
return stripePromise$1;
|
|
105
141
|
}
|
|
106
142
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (window.Stripe && params) {
|
|
116
|
-
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
117
|
-
}
|
|
143
|
+
var load = function load() {
|
|
144
|
+
return new Promise(function (resolve, reject) {
|
|
145
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
146
|
+
// Resolve to null when imported server side. This makes the module
|
|
147
|
+
// safe to import in an isomorphic code base.
|
|
148
|
+
resolve(null);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
118
151
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
152
|
+
if (window.Stripe && params) {
|
|
153
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
154
|
+
}
|
|
123
155
|
|
|
124
|
-
|
|
125
|
-
|
|
156
|
+
if (window.Stripe) {
|
|
157
|
+
resolve(window.Stripe);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
126
160
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
script
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
161
|
+
try {
|
|
162
|
+
var script = findScript();
|
|
163
|
+
|
|
164
|
+
if (script && params) {
|
|
165
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
166
|
+
} else if (!script) {
|
|
167
|
+
script = injectScript(params);
|
|
168
|
+
} else if (script && onLoadListener !== null && onErrorListener !== null) {
|
|
169
|
+
var _script$parentNode;
|
|
170
|
+
|
|
171
|
+
// remove event listeners
|
|
172
|
+
script.removeEventListener('load', onLoadListener);
|
|
173
|
+
script.removeEventListener('error', onErrorListener); // if script exists, but we are reloading due to an error,
|
|
174
|
+
// reload script to trigger 'load' event
|
|
175
|
+
|
|
176
|
+
(_script$parentNode = script.parentNode) === null || _script$parentNode === void 0 ? void 0 : _script$parentNode.removeChild(script);
|
|
177
|
+
script = injectScript(params);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
onLoadListener = onLoad(resolve, reject);
|
|
181
|
+
onErrorListener = onError(reject);
|
|
182
|
+
script.addEventListener('load', onLoadListener);
|
|
183
|
+
script.addEventListener('error', onErrorListener);
|
|
184
|
+
} catch (error) {
|
|
185
|
+
reject(error);
|
|
186
|
+
return;
|
|
141
187
|
}
|
|
188
|
+
});
|
|
189
|
+
};
|
|
142
190
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
191
|
+
var retryableLoad = /*#__PURE__*/function () {
|
|
192
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
193
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
194
|
+
while (1) {
|
|
195
|
+
switch (_context.prev = _context.next) {
|
|
196
|
+
case 0:
|
|
197
|
+
return _context.abrupt("return", load()["catch"](function (error) {
|
|
198
|
+
stripePromise$1 = null;
|
|
199
|
+
return Promise.reject(error);
|
|
200
|
+
}));
|
|
201
|
+
|
|
202
|
+
case 1:
|
|
203
|
+
case "end":
|
|
204
|
+
return _context.stop();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}, _callee);
|
|
208
|
+
}));
|
|
152
209
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
210
|
+
return function retryableLoad() {
|
|
211
|
+
return _ref.apply(this, arguments);
|
|
212
|
+
};
|
|
213
|
+
}(); // Resets stripePromise on error
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
return retryableLoad()["catch"](function () {
|
|
217
|
+
return retryableLoad();
|
|
156
218
|
});
|
|
157
219
|
};
|
|
158
220
|
var initStripe = function initStripe(maybeStripe, args, startTime) {
|
|
@@ -172,7 +234,7 @@ var initStripe = function initStripe(maybeStripe, args, startTime) {
|
|
|
172
234
|
var expectedVersion = RELEASE_TRAIN;
|
|
173
235
|
|
|
174
236
|
if (isTestKey && version !== expectedVersion) {
|
|
175
|
-
console.warn("Stripe.js@".concat(version, " was loaded on the page, but @stripe/stripe-js@").concat("10.0.0-rc.
|
|
237
|
+
console.warn("Stripe.js@".concat(version, " was loaded on the page, but @stripe/stripe-js@").concat("10.0.0-rc.2", " expected Stripe.js@").concat(expectedVersion, ". This may result in unexpected behavior. For more information, see https://docs.stripe.com/sdks/stripejs-versioning"));
|
|
176
238
|
}
|
|
177
239
|
|
|
178
240
|
var stripe = maybeStripe.apply(undefined, args);
|
package/dist/index.mjs
CHANGED
|
@@ -14,6 +14,42 @@ function _typeof(obj) {
|
|
|
14
14
|
return _typeof(obj);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
18
|
+
try {
|
|
19
|
+
var info = gen[key](arg);
|
|
20
|
+
var value = info.value;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
reject(error);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (info.done) {
|
|
27
|
+
resolve(value);
|
|
28
|
+
} else {
|
|
29
|
+
Promise.resolve(value).then(_next, _throw);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function _asyncToGenerator(fn) {
|
|
34
|
+
return function () {
|
|
35
|
+
var self = this,
|
|
36
|
+
args = arguments;
|
|
37
|
+
return new Promise(function (resolve, reject) {
|
|
38
|
+
var gen = fn.apply(self, args);
|
|
39
|
+
|
|
40
|
+
function _next(value) {
|
|
41
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function _throw(err) {
|
|
45
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
_next(undefined);
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
17
53
|
var RELEASE_TRAIN = 'endive';
|
|
18
54
|
|
|
19
55
|
var runtimeVersionToUrlVersion = function runtimeVersionToUrlVersion(version) {
|
|
@@ -67,7 +103,7 @@ var registerWrapper = function registerWrapper(stripe, startTime) {
|
|
|
67
103
|
|
|
68
104
|
stripe._registerWrapper({
|
|
69
105
|
name: 'stripe-js',
|
|
70
|
-
version: "10.0.0-rc.
|
|
106
|
+
version: "10.0.0-rc.2",
|
|
71
107
|
startTime: startTime
|
|
72
108
|
});
|
|
73
109
|
};
|
|
@@ -100,55 +136,81 @@ var loadScript = function loadScript(params) {
|
|
|
100
136
|
return stripePromise$1;
|
|
101
137
|
}
|
|
102
138
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (window.Stripe && params) {
|
|
112
|
-
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
113
|
-
}
|
|
139
|
+
var load = function load() {
|
|
140
|
+
return new Promise(function (resolve, reject) {
|
|
141
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
142
|
+
// Resolve to null when imported server side. This makes the module
|
|
143
|
+
// safe to import in an isomorphic code base.
|
|
144
|
+
resolve(null);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
114
147
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
148
|
+
if (window.Stripe && params) {
|
|
149
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
150
|
+
}
|
|
119
151
|
|
|
120
|
-
|
|
121
|
-
|
|
152
|
+
if (window.Stripe) {
|
|
153
|
+
resolve(window.Stripe);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
122
156
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
script
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
157
|
+
try {
|
|
158
|
+
var script = findScript();
|
|
159
|
+
|
|
160
|
+
if (script && params) {
|
|
161
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
162
|
+
} else if (!script) {
|
|
163
|
+
script = injectScript(params);
|
|
164
|
+
} else if (script && onLoadListener !== null && onErrorListener !== null) {
|
|
165
|
+
var _script$parentNode;
|
|
166
|
+
|
|
167
|
+
// remove event listeners
|
|
168
|
+
script.removeEventListener('load', onLoadListener);
|
|
169
|
+
script.removeEventListener('error', onErrorListener); // if script exists, but we are reloading due to an error,
|
|
170
|
+
// reload script to trigger 'load' event
|
|
171
|
+
|
|
172
|
+
(_script$parentNode = script.parentNode) === null || _script$parentNode === void 0 ? void 0 : _script$parentNode.removeChild(script);
|
|
173
|
+
script = injectScript(params);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
onLoadListener = onLoad(resolve, reject);
|
|
177
|
+
onErrorListener = onError(reject);
|
|
178
|
+
script.addEventListener('load', onLoadListener);
|
|
179
|
+
script.addEventListener('error', onErrorListener);
|
|
180
|
+
} catch (error) {
|
|
181
|
+
reject(error);
|
|
182
|
+
return;
|
|
137
183
|
}
|
|
184
|
+
});
|
|
185
|
+
};
|
|
138
186
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
187
|
+
var retryableLoad = /*#__PURE__*/function () {
|
|
188
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
189
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
190
|
+
while (1) {
|
|
191
|
+
switch (_context.prev = _context.next) {
|
|
192
|
+
case 0:
|
|
193
|
+
return _context.abrupt("return", load()["catch"](function (error) {
|
|
194
|
+
stripePromise$1 = null;
|
|
195
|
+
return Promise.reject(error);
|
|
196
|
+
}));
|
|
197
|
+
|
|
198
|
+
case 1:
|
|
199
|
+
case "end":
|
|
200
|
+
return _context.stop();
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}, _callee);
|
|
204
|
+
}));
|
|
148
205
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
206
|
+
return function retryableLoad() {
|
|
207
|
+
return _ref.apply(this, arguments);
|
|
208
|
+
};
|
|
209
|
+
}(); // Resets stripePromise on error
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
return retryableLoad()["catch"](function () {
|
|
213
|
+
return retryableLoad();
|
|
152
214
|
});
|
|
153
215
|
};
|
|
154
216
|
var initStripe = function initStripe(maybeStripe, args, startTime) {
|
|
@@ -168,7 +230,7 @@ var initStripe = function initStripe(maybeStripe, args, startTime) {
|
|
|
168
230
|
var expectedVersion = RELEASE_TRAIN;
|
|
169
231
|
|
|
170
232
|
if (isTestKey && version !== expectedVersion) {
|
|
171
|
-
console.warn("Stripe.js@".concat(version, " was loaded on the page, but @stripe/stripe-js@").concat("10.0.0-rc.
|
|
233
|
+
console.warn("Stripe.js@".concat(version, " was loaded on the page, but @stripe/stripe-js@").concat("10.0.0-rc.2", " expected Stripe.js@").concat(expectedVersion, ". This may result in unexpected behavior. For more information, see https://docs.stripe.com/sdks/stripejs-versioning"));
|
|
172
234
|
}
|
|
173
235
|
|
|
174
236
|
var stripe = maybeStripe.apply(undefined, args);
|
package/dist/pure.js
CHANGED
|
@@ -18,6 +18,42 @@ function _typeof(obj) {
|
|
|
18
18
|
return _typeof(obj);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
22
|
+
try {
|
|
23
|
+
var info = gen[key](arg);
|
|
24
|
+
var value = info.value;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
reject(error);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (info.done) {
|
|
31
|
+
resolve(value);
|
|
32
|
+
} else {
|
|
33
|
+
Promise.resolve(value).then(_next, _throw);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function _asyncToGenerator(fn) {
|
|
38
|
+
return function () {
|
|
39
|
+
var self = this,
|
|
40
|
+
args = arguments;
|
|
41
|
+
return new Promise(function (resolve, reject) {
|
|
42
|
+
var gen = fn.apply(self, args);
|
|
43
|
+
|
|
44
|
+
function _next(value) {
|
|
45
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function _throw(err) {
|
|
49
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
_next(undefined);
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
21
57
|
var RELEASE_TRAIN = 'endive';
|
|
22
58
|
|
|
23
59
|
var runtimeVersionToUrlVersion = function runtimeVersionToUrlVersion(version) {
|
|
@@ -71,7 +107,7 @@ var registerWrapper = function registerWrapper(stripe, startTime) {
|
|
|
71
107
|
|
|
72
108
|
stripe._registerWrapper({
|
|
73
109
|
name: 'stripe-js',
|
|
74
|
-
version: "10.0.0-rc.
|
|
110
|
+
version: "10.0.0-rc.2",
|
|
75
111
|
startTime: startTime
|
|
76
112
|
});
|
|
77
113
|
};
|
|
@@ -104,55 +140,81 @@ var loadScript = function loadScript(params) {
|
|
|
104
140
|
return stripePromise;
|
|
105
141
|
}
|
|
106
142
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (window.Stripe && params) {
|
|
116
|
-
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
117
|
-
}
|
|
143
|
+
var load = function load() {
|
|
144
|
+
return new Promise(function (resolve, reject) {
|
|
145
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
146
|
+
// Resolve to null when imported server side. This makes the module
|
|
147
|
+
// safe to import in an isomorphic code base.
|
|
148
|
+
resolve(null);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
118
151
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
152
|
+
if (window.Stripe && params) {
|
|
153
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
154
|
+
}
|
|
123
155
|
|
|
124
|
-
|
|
125
|
-
|
|
156
|
+
if (window.Stripe) {
|
|
157
|
+
resolve(window.Stripe);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
126
160
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
script
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
161
|
+
try {
|
|
162
|
+
var script = findScript();
|
|
163
|
+
|
|
164
|
+
if (script && params) {
|
|
165
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
166
|
+
} else if (!script) {
|
|
167
|
+
script = injectScript(params);
|
|
168
|
+
} else if (script && onLoadListener !== null && onErrorListener !== null) {
|
|
169
|
+
var _script$parentNode;
|
|
170
|
+
|
|
171
|
+
// remove event listeners
|
|
172
|
+
script.removeEventListener('load', onLoadListener);
|
|
173
|
+
script.removeEventListener('error', onErrorListener); // if script exists, but we are reloading due to an error,
|
|
174
|
+
// reload script to trigger 'load' event
|
|
175
|
+
|
|
176
|
+
(_script$parentNode = script.parentNode) === null || _script$parentNode === void 0 ? void 0 : _script$parentNode.removeChild(script);
|
|
177
|
+
script = injectScript(params);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
onLoadListener = onLoad(resolve, reject);
|
|
181
|
+
onErrorListener = onError(reject);
|
|
182
|
+
script.addEventListener('load', onLoadListener);
|
|
183
|
+
script.addEventListener('error', onErrorListener);
|
|
184
|
+
} catch (error) {
|
|
185
|
+
reject(error);
|
|
186
|
+
return;
|
|
141
187
|
}
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
var retryableLoad = /*#__PURE__*/function () {
|
|
192
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
193
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
194
|
+
while (1) {
|
|
195
|
+
switch (_context.prev = _context.next) {
|
|
196
|
+
case 0:
|
|
197
|
+
return _context.abrupt("return", load()["catch"](function (error) {
|
|
198
|
+
stripePromise = null;
|
|
199
|
+
return Promise.reject(error);
|
|
200
|
+
}));
|
|
201
|
+
|
|
202
|
+
case 1:
|
|
203
|
+
case "end":
|
|
204
|
+
return _context.stop();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}, _callee);
|
|
208
|
+
}));
|
|
209
|
+
|
|
210
|
+
return function retryableLoad() {
|
|
211
|
+
return _ref.apply(this, arguments);
|
|
212
|
+
};
|
|
213
|
+
}(); // Resets stripePromise on error
|
|
142
214
|
|
|
143
|
-
onLoadListener = onLoad(resolve, reject);
|
|
144
|
-
onErrorListener = onError(reject);
|
|
145
|
-
script.addEventListener('load', onLoadListener);
|
|
146
|
-
script.addEventListener('error', onErrorListener);
|
|
147
|
-
} catch (error) {
|
|
148
|
-
reject(error);
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
}); // Resets stripePromise on error
|
|
152
215
|
|
|
153
|
-
return
|
|
154
|
-
|
|
155
|
-
return Promise.reject(error);
|
|
216
|
+
return retryableLoad()["catch"](function () {
|
|
217
|
+
return retryableLoad();
|
|
156
218
|
});
|
|
157
219
|
};
|
|
158
220
|
var initStripe = function initStripe(maybeStripe, args, startTime) {
|
|
@@ -172,7 +234,7 @@ var initStripe = function initStripe(maybeStripe, args, startTime) {
|
|
|
172
234
|
var expectedVersion = RELEASE_TRAIN;
|
|
173
235
|
|
|
174
236
|
if (isTestKey && version !== expectedVersion) {
|
|
175
|
-
console.warn("Stripe.js@".concat(version, " was loaded on the page, but @stripe/stripe-js@").concat("10.0.0-rc.
|
|
237
|
+
console.warn("Stripe.js@".concat(version, " was loaded on the page, but @stripe/stripe-js@").concat("10.0.0-rc.2", " expected Stripe.js@").concat(expectedVersion, ". This may result in unexpected behavior. For more information, see https://docs.stripe.com/sdks/stripejs-versioning"));
|
|
176
238
|
}
|
|
177
239
|
|
|
178
240
|
var stripe = maybeStripe.apply(undefined, args);
|
package/dist/pure.mjs
CHANGED
|
@@ -14,6 +14,42 @@ function _typeof(obj) {
|
|
|
14
14
|
return _typeof(obj);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
18
|
+
try {
|
|
19
|
+
var info = gen[key](arg);
|
|
20
|
+
var value = info.value;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
reject(error);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (info.done) {
|
|
27
|
+
resolve(value);
|
|
28
|
+
} else {
|
|
29
|
+
Promise.resolve(value).then(_next, _throw);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function _asyncToGenerator(fn) {
|
|
34
|
+
return function () {
|
|
35
|
+
var self = this,
|
|
36
|
+
args = arguments;
|
|
37
|
+
return new Promise(function (resolve, reject) {
|
|
38
|
+
var gen = fn.apply(self, args);
|
|
39
|
+
|
|
40
|
+
function _next(value) {
|
|
41
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function _throw(err) {
|
|
45
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
_next(undefined);
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
17
53
|
var RELEASE_TRAIN = 'endive';
|
|
18
54
|
|
|
19
55
|
var runtimeVersionToUrlVersion = function runtimeVersionToUrlVersion(version) {
|
|
@@ -67,7 +103,7 @@ var registerWrapper = function registerWrapper(stripe, startTime) {
|
|
|
67
103
|
|
|
68
104
|
stripe._registerWrapper({
|
|
69
105
|
name: 'stripe-js',
|
|
70
|
-
version: "10.0.0-rc.
|
|
106
|
+
version: "10.0.0-rc.2",
|
|
71
107
|
startTime: startTime
|
|
72
108
|
});
|
|
73
109
|
};
|
|
@@ -100,55 +136,81 @@ var loadScript = function loadScript(params) {
|
|
|
100
136
|
return stripePromise;
|
|
101
137
|
}
|
|
102
138
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (window.Stripe && params) {
|
|
112
|
-
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
113
|
-
}
|
|
139
|
+
var load = function load() {
|
|
140
|
+
return new Promise(function (resolve, reject) {
|
|
141
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
142
|
+
// Resolve to null when imported server side. This makes the module
|
|
143
|
+
// safe to import in an isomorphic code base.
|
|
144
|
+
resolve(null);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
114
147
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
148
|
+
if (window.Stripe && params) {
|
|
149
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
150
|
+
}
|
|
119
151
|
|
|
120
|
-
|
|
121
|
-
|
|
152
|
+
if (window.Stripe) {
|
|
153
|
+
resolve(window.Stripe);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
122
156
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
script
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
157
|
+
try {
|
|
158
|
+
var script = findScript();
|
|
159
|
+
|
|
160
|
+
if (script && params) {
|
|
161
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
162
|
+
} else if (!script) {
|
|
163
|
+
script = injectScript(params);
|
|
164
|
+
} else if (script && onLoadListener !== null && onErrorListener !== null) {
|
|
165
|
+
var _script$parentNode;
|
|
166
|
+
|
|
167
|
+
// remove event listeners
|
|
168
|
+
script.removeEventListener('load', onLoadListener);
|
|
169
|
+
script.removeEventListener('error', onErrorListener); // if script exists, but we are reloading due to an error,
|
|
170
|
+
// reload script to trigger 'load' event
|
|
171
|
+
|
|
172
|
+
(_script$parentNode = script.parentNode) === null || _script$parentNode === void 0 ? void 0 : _script$parentNode.removeChild(script);
|
|
173
|
+
script = injectScript(params);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
onLoadListener = onLoad(resolve, reject);
|
|
177
|
+
onErrorListener = onError(reject);
|
|
178
|
+
script.addEventListener('load', onLoadListener);
|
|
179
|
+
script.addEventListener('error', onErrorListener);
|
|
180
|
+
} catch (error) {
|
|
181
|
+
reject(error);
|
|
182
|
+
return;
|
|
137
183
|
}
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
var retryableLoad = /*#__PURE__*/function () {
|
|
188
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
189
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
190
|
+
while (1) {
|
|
191
|
+
switch (_context.prev = _context.next) {
|
|
192
|
+
case 0:
|
|
193
|
+
return _context.abrupt("return", load()["catch"](function (error) {
|
|
194
|
+
stripePromise = null;
|
|
195
|
+
return Promise.reject(error);
|
|
196
|
+
}));
|
|
197
|
+
|
|
198
|
+
case 1:
|
|
199
|
+
case "end":
|
|
200
|
+
return _context.stop();
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}, _callee);
|
|
204
|
+
}));
|
|
205
|
+
|
|
206
|
+
return function retryableLoad() {
|
|
207
|
+
return _ref.apply(this, arguments);
|
|
208
|
+
};
|
|
209
|
+
}(); // Resets stripePromise on error
|
|
138
210
|
|
|
139
|
-
onLoadListener = onLoad(resolve, reject);
|
|
140
|
-
onErrorListener = onError(reject);
|
|
141
|
-
script.addEventListener('load', onLoadListener);
|
|
142
|
-
script.addEventListener('error', onErrorListener);
|
|
143
|
-
} catch (error) {
|
|
144
|
-
reject(error);
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
}); // Resets stripePromise on error
|
|
148
211
|
|
|
149
|
-
return
|
|
150
|
-
|
|
151
|
-
return Promise.reject(error);
|
|
212
|
+
return retryableLoad()["catch"](function () {
|
|
213
|
+
return retryableLoad();
|
|
152
214
|
});
|
|
153
215
|
};
|
|
154
216
|
var initStripe = function initStripe(maybeStripe, args, startTime) {
|
|
@@ -168,7 +230,7 @@ var initStripe = function initStripe(maybeStripe, args, startTime) {
|
|
|
168
230
|
var expectedVersion = RELEASE_TRAIN;
|
|
169
231
|
|
|
170
232
|
if (isTestKey && version !== expectedVersion) {
|
|
171
|
-
console.warn("Stripe.js@".concat(version, " was loaded on the page, but @stripe/stripe-js@").concat("10.0.0-rc.
|
|
233
|
+
console.warn("Stripe.js@".concat(version, " was loaded on the page, but @stripe/stripe-js@").concat("10.0.0-rc.2", " expected Stripe.js@").concat(expectedVersion, ". This may result in unexpected behavior. For more information, see https://docs.stripe.com/sdks/stripejs-versioning"));
|
|
172
234
|
}
|
|
173
235
|
|
|
174
236
|
var stripe = maybeStripe.apply(undefined, args);
|
|
@@ -895,20 +895,6 @@ interface StripeElementsOptionsModeBase extends BaseStripeElementsOptions {
|
|
|
895
895
|
*/
|
|
896
896
|
on_behalf_of?: string;
|
|
897
897
|
|
|
898
|
-
/**
|
|
899
|
-
* Instead of using automatic payment methods, declare specific payment methods to enable.
|
|
900
|
-
*
|
|
901
|
-
* @docs https://stripe.com/docs/payments/payment-methods/overview
|
|
902
|
-
*/
|
|
903
|
-
paymentMethodTypes?: string[];
|
|
904
|
-
|
|
905
|
-
/**
|
|
906
|
-
* Instead of using automatic payment methods, declare specific payment methods to enable.
|
|
907
|
-
*
|
|
908
|
-
* @docs https://stripe.com/docs/payments/payment-methods/overview
|
|
909
|
-
*/
|
|
910
|
-
payment_method_types?: string[];
|
|
911
|
-
|
|
912
898
|
/**
|
|
913
899
|
* The list of payment method types to exclude from use with this payment.
|
|
914
900
|
*
|
|
@@ -924,7 +910,7 @@ interface StripeElementsOptionsModeBase extends BaseStripeElementsOptions {
|
|
|
924
910
|
allowedPaymentMethodTypes?: string[];
|
|
925
911
|
|
|
926
912
|
/**
|
|
927
|
-
* When using automatic payment methods
|
|
913
|
+
* When using automatic payment methods, provide a
|
|
928
914
|
* payment method configuration ID for deriving payment methods.
|
|
929
915
|
*
|
|
930
916
|
* @docs https://stripe.com/docs/connect/payment-method-configurations
|
|
@@ -932,7 +918,7 @@ interface StripeElementsOptionsModeBase extends BaseStripeElementsOptions {
|
|
|
932
918
|
paymentMethodConfiguration?: string;
|
|
933
919
|
|
|
934
920
|
/**
|
|
935
|
-
* When using automatic payment methods
|
|
921
|
+
* When using automatic payment methods, provide a
|
|
936
922
|
* payment method configuration ID for deriving payment methods.
|
|
937
923
|
*
|
|
938
924
|
* @docs https://stripe.com/docs/connect/payment-method-configurations
|
|
@@ -1085,20 +1071,6 @@ export interface StripeElementsUpdateOptions {
|
|
|
1085
1071
|
*/
|
|
1086
1072
|
capture_method?: 'manual' | 'automatic' | 'automatic_async';
|
|
1087
1073
|
|
|
1088
|
-
/**
|
|
1089
|
-
* Instead of using automatic payment methods, declare specific payment methods to enable.
|
|
1090
|
-
*
|
|
1091
|
-
* @docs https://stripe.com/docs/payments/payment-methods/overview
|
|
1092
|
-
*/
|
|
1093
|
-
payment_method_types?: string[];
|
|
1094
|
-
|
|
1095
|
-
/**
|
|
1096
|
-
* Instead of using automatic payment methods, declare specific payment methods to enable.
|
|
1097
|
-
*
|
|
1098
|
-
* @docs https://stripe.com/docs/payments/payment-methods/overview
|
|
1099
|
-
*/
|
|
1100
|
-
paymentMethodTypes?: string[];
|
|
1101
|
-
|
|
1102
1074
|
/**
|
|
1103
1075
|
* The list of payment method types to exclude from use with this payment.
|
|
1104
1076
|
*
|
|
@@ -1114,7 +1086,7 @@ export interface StripeElementsUpdateOptions {
|
|
|
1114
1086
|
allowedPaymentMethodTypes?: string[];
|
|
1115
1087
|
|
|
1116
1088
|
/**
|
|
1117
|
-
* When using automatic payment methods
|
|
1089
|
+
* When using automatic payment methods, provide a
|
|
1118
1090
|
* payment method configuration ID for deriving payment methods.
|
|
1119
1091
|
*
|
|
1120
1092
|
* @docs https://stripe.com/docs/connect/payment-method-configurations
|
|
@@ -1122,7 +1094,7 @@ export interface StripeElementsUpdateOptions {
|
|
|
1122
1094
|
paymentMethodConfiguration?: string;
|
|
1123
1095
|
|
|
1124
1096
|
/**
|
|
1125
|
-
* When using automatic payment methods
|
|
1097
|
+
* When using automatic payment methods, provide a
|
|
1126
1098
|
* payment method configuration ID for deriving payment methods.
|
|
1127
1099
|
*
|
|
1128
1100
|
* @docs https://stripe.com/docs/connect/payment-method-configurations
|
|
@@ -895,20 +895,6 @@ interface StripeElementsOptionsModeBase extends BaseStripeElementsOptions {
|
|
|
895
895
|
*/
|
|
896
896
|
on_behalf_of?: string;
|
|
897
897
|
|
|
898
|
-
/**
|
|
899
|
-
* Instead of using automatic payment methods, declare specific payment methods to enable.
|
|
900
|
-
*
|
|
901
|
-
* @docs https://stripe.com/docs/payments/payment-methods/overview
|
|
902
|
-
*/
|
|
903
|
-
paymentMethodTypes?: string[];
|
|
904
|
-
|
|
905
|
-
/**
|
|
906
|
-
* Instead of using automatic payment methods, declare specific payment methods to enable.
|
|
907
|
-
*
|
|
908
|
-
* @docs https://stripe.com/docs/payments/payment-methods/overview
|
|
909
|
-
*/
|
|
910
|
-
payment_method_types?: string[];
|
|
911
|
-
|
|
912
898
|
/**
|
|
913
899
|
* The list of payment method types to exclude from use with this payment.
|
|
914
900
|
*
|
|
@@ -924,7 +910,7 @@ interface StripeElementsOptionsModeBase extends BaseStripeElementsOptions {
|
|
|
924
910
|
allowedPaymentMethodTypes?: string[];
|
|
925
911
|
|
|
926
912
|
/**
|
|
927
|
-
* When using automatic payment methods
|
|
913
|
+
* When using automatic payment methods, provide a
|
|
928
914
|
* payment method configuration ID for deriving payment methods.
|
|
929
915
|
*
|
|
930
916
|
* @docs https://stripe.com/docs/connect/payment-method-configurations
|
|
@@ -932,7 +918,7 @@ interface StripeElementsOptionsModeBase extends BaseStripeElementsOptions {
|
|
|
932
918
|
paymentMethodConfiguration?: string;
|
|
933
919
|
|
|
934
920
|
/**
|
|
935
|
-
* When using automatic payment methods
|
|
921
|
+
* When using automatic payment methods, provide a
|
|
936
922
|
* payment method configuration ID for deriving payment methods.
|
|
937
923
|
*
|
|
938
924
|
* @docs https://stripe.com/docs/connect/payment-method-configurations
|
|
@@ -1085,20 +1071,6 @@ export interface StripeElementsUpdateOptions {
|
|
|
1085
1071
|
*/
|
|
1086
1072
|
capture_method?: 'manual' | 'automatic' | 'automatic_async';
|
|
1087
1073
|
|
|
1088
|
-
/**
|
|
1089
|
-
* Instead of using automatic payment methods, declare specific payment methods to enable.
|
|
1090
|
-
*
|
|
1091
|
-
* @docs https://stripe.com/docs/payments/payment-methods/overview
|
|
1092
|
-
*/
|
|
1093
|
-
payment_method_types?: string[];
|
|
1094
|
-
|
|
1095
|
-
/**
|
|
1096
|
-
* Instead of using automatic payment methods, declare specific payment methods to enable.
|
|
1097
|
-
*
|
|
1098
|
-
* @docs https://stripe.com/docs/payments/payment-methods/overview
|
|
1099
|
-
*/
|
|
1100
|
-
paymentMethodTypes?: string[];
|
|
1101
|
-
|
|
1102
1074
|
/**
|
|
1103
1075
|
* The list of payment method types to exclude from use with this payment.
|
|
1104
1076
|
*
|
|
@@ -1114,7 +1086,7 @@ export interface StripeElementsUpdateOptions {
|
|
|
1114
1086
|
allowedPaymentMethodTypes?: string[];
|
|
1115
1087
|
|
|
1116
1088
|
/**
|
|
1117
|
-
* When using automatic payment methods
|
|
1089
|
+
* When using automatic payment methods, provide a
|
|
1118
1090
|
* payment method configuration ID for deriving payment methods.
|
|
1119
1091
|
*
|
|
1120
1092
|
* @docs https://stripe.com/docs/connect/payment-method-configurations
|
|
@@ -1122,7 +1094,7 @@ export interface StripeElementsUpdateOptions {
|
|
|
1122
1094
|
paymentMethodConfiguration?: string;
|
|
1123
1095
|
|
|
1124
1096
|
/**
|
|
1125
|
-
* When using automatic payment methods
|
|
1097
|
+
* When using automatic payment methods, provide a
|
|
1126
1098
|
* payment method configuration ID for deriving payment methods.
|
|
1127
1099
|
*
|
|
1128
1100
|
* @docs https://stripe.com/docs/connect/payment-method-configurations
|
package/package.json
CHANGED
package/src/index.test.ts
CHANGED
|
@@ -110,6 +110,10 @@ describe('Stripe module loader', () => {
|
|
|
110
110
|
await Promise.resolve();
|
|
111
111
|
dispatchScriptEvent('error');
|
|
112
112
|
|
|
113
|
+
// Wait for the retry attempt to set up a new script element
|
|
114
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
115
|
+
dispatchScriptEvent('error');
|
|
116
|
+
|
|
113
117
|
await expect(stripePromise).rejects.toEqual(
|
|
114
118
|
new Error('Failed to load Stripe.js')
|
|
115
119
|
);
|
|
@@ -124,20 +128,43 @@ describe('Stripe module loader', () => {
|
|
|
124
128
|
await Promise.resolve();
|
|
125
129
|
dispatchScriptEvent('load');
|
|
126
130
|
|
|
131
|
+
// Wait for the retry attempt to set up a new script element
|
|
132
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
133
|
+
dispatchScriptEvent('load');
|
|
134
|
+
|
|
127
135
|
return expect(stripePromise).rejects.toEqual(
|
|
128
136
|
new Error('Stripe.js not available')
|
|
129
137
|
);
|
|
130
138
|
});
|
|
131
139
|
|
|
140
|
+
it('resolves with Stripe object when a single load failure is followed by a load success', async () => {
|
|
141
|
+
const {loadStripe} = require(requirePath);
|
|
142
|
+
const stripePromise = loadStripe('pk_test_foo');
|
|
143
|
+
|
|
144
|
+
await Promise.resolve();
|
|
145
|
+
dispatchScriptEvent('error');
|
|
146
|
+
|
|
147
|
+
// Wait for the retry attempt to set up a new script element
|
|
148
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
149
|
+
window.Stripe = jest.fn((key) => ({key})) as any;
|
|
150
|
+
dispatchScriptEvent('load');
|
|
151
|
+
|
|
152
|
+
await expect(stripePromise).resolves.toEqual({key: 'pk_test_foo'});
|
|
153
|
+
});
|
|
154
|
+
|
|
132
155
|
it('rejects on first load, and succeeds on second load resolving with Stripe object', async () => {
|
|
133
156
|
const {loadStripe} = require(requirePath);
|
|
134
157
|
|
|
135
|
-
// start of first load, expect load failure
|
|
158
|
+
// start of first load, expect load failure (both initial attempt and retry fail)
|
|
136
159
|
let stripePromise = loadStripe('pk_test_foo');
|
|
137
160
|
|
|
138
161
|
await Promise.resolve();
|
|
139
162
|
dispatchScriptEvent('error');
|
|
140
163
|
|
|
164
|
+
// Wait for the retry attempt to set up a new script element
|
|
165
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
166
|
+
dispatchScriptEvent('error');
|
|
167
|
+
|
|
141
168
|
await expect(stripePromise).rejects.toEqual(
|
|
142
169
|
new Error('Failed to load Stripe.js')
|
|
143
170
|
);
|
|
@@ -157,24 +184,30 @@ describe('Stripe module loader', () => {
|
|
|
157
184
|
it('rejects on first load and second load but succeeds on third load resolving with Stripe object', async () => {
|
|
158
185
|
const {loadStripe} = require(requirePath);
|
|
159
186
|
|
|
160
|
-
// start of first load, expect load failure
|
|
187
|
+
// start of first load, expect load failure (both initial attempt and retry fail)
|
|
161
188
|
let stripePromise = loadStripe('pk_test_foo');
|
|
162
189
|
|
|
163
190
|
await Promise.resolve();
|
|
164
191
|
dispatchScriptEvent('error');
|
|
165
192
|
|
|
193
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
194
|
+
dispatchScriptEvent('error');
|
|
195
|
+
|
|
166
196
|
await expect(stripePromise).rejects.toEqual(
|
|
167
197
|
new Error('Failed to load Stripe.js')
|
|
168
198
|
);
|
|
169
199
|
|
|
170
200
|
expect(console.warn).not.toHaveBeenCalled();
|
|
171
201
|
|
|
172
|
-
// start of second load, expect load failure
|
|
202
|
+
// start of second load, expect load failure (both initial attempt and retry fail)
|
|
173
203
|
stripePromise = loadStripe('pk_test_foo');
|
|
174
204
|
|
|
175
205
|
await Promise.resolve();
|
|
176
206
|
dispatchScriptEvent('error');
|
|
177
207
|
|
|
208
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
209
|
+
dispatchScriptEvent('error');
|
|
210
|
+
|
|
178
211
|
await expect(stripePromise).rejects.toEqual(
|
|
179
212
|
new Error('Failed to load Stripe.js')
|
|
180
213
|
);
|
|
@@ -193,12 +226,20 @@ describe('Stripe module loader', () => {
|
|
|
193
226
|
});
|
|
194
227
|
|
|
195
228
|
describe('loadStripe (index.ts)', () => {
|
|
229
|
+
beforeEach(() => {
|
|
230
|
+
jest.spyOn(console, 'warn').mockReturnValue();
|
|
231
|
+
});
|
|
232
|
+
|
|
196
233
|
it('does not cause unhandled rejects when the script fails', async () => {
|
|
197
234
|
require('./index');
|
|
198
235
|
|
|
199
236
|
await Promise.resolve();
|
|
200
237
|
dispatchScriptEvent('error');
|
|
201
238
|
|
|
239
|
+
// Wait for the retry attempt to set up a new script element
|
|
240
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
241
|
+
dispatchScriptEvent('error');
|
|
242
|
+
|
|
202
243
|
// Turn the task loop to make sure the internal promise handler has been invoked
|
|
203
244
|
await new Promise((resolve) => setImmediate(resolve));
|
|
204
245
|
|
package/src/shared.ts
CHANGED
|
@@ -103,60 +103,65 @@ export const loadScript = (
|
|
|
103
103
|
return stripePromise;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (window.Stripe && params) {
|
|
115
|
-
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
116
|
-
}
|
|
106
|
+
const load = () =>
|
|
107
|
+
new Promise<StripeConstructor | null>((resolve, reject) => {
|
|
108
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
109
|
+
// Resolve to null when imported server side. This makes the module
|
|
110
|
+
// safe to import in an isomorphic code base.
|
|
111
|
+
resolve(null);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
117
114
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
115
|
+
if (window.Stripe && params) {
|
|
116
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
117
|
+
}
|
|
122
118
|
|
|
123
|
-
|
|
124
|
-
|
|
119
|
+
if (window.Stripe) {
|
|
120
|
+
resolve(window.Stripe);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
125
123
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
script
|
|
130
|
-
|
|
131
|
-
script
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
124
|
+
try {
|
|
125
|
+
let script = findScript();
|
|
126
|
+
|
|
127
|
+
if (script && params) {
|
|
128
|
+
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
129
|
+
} else if (!script) {
|
|
130
|
+
script = injectScript(params);
|
|
131
|
+
} else if (
|
|
132
|
+
script &&
|
|
133
|
+
onLoadListener !== null &&
|
|
134
|
+
onErrorListener !== null
|
|
135
|
+
) {
|
|
136
|
+
// remove event listeners
|
|
137
|
+
script.removeEventListener('load', onLoadListener);
|
|
138
|
+
script.removeEventListener('error', onErrorListener);
|
|
139
|
+
|
|
140
|
+
// if script exists, but we are reloading due to an error,
|
|
141
|
+
// reload script to trigger 'load' event
|
|
142
|
+
script.parentNode?.removeChild(script);
|
|
143
|
+
script = injectScript(params);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
onLoadListener = onLoad(resolve, reject);
|
|
147
|
+
onErrorListener = onError(reject);
|
|
148
|
+
script.addEventListener('load', onLoadListener);
|
|
149
|
+
|
|
150
|
+
script.addEventListener('error', onErrorListener);
|
|
151
|
+
} catch (error) {
|
|
152
|
+
reject(error);
|
|
153
|
+
return;
|
|
143
154
|
}
|
|
155
|
+
});
|
|
144
156
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
157
|
+
const retryableLoad = async () =>
|
|
158
|
+
load().catch((error) => {
|
|
159
|
+
stripePromise = null;
|
|
160
|
+
return Promise.reject(error);
|
|
161
|
+
});
|
|
148
162
|
|
|
149
|
-
script.addEventListener('error', onErrorListener);
|
|
150
|
-
} catch (error) {
|
|
151
|
-
reject(error);
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
163
|
// Resets stripePromise on error
|
|
156
|
-
return
|
|
157
|
-
stripePromise = null;
|
|
158
|
-
return Promise.reject(error);
|
|
159
|
-
});
|
|
164
|
+
return retryableLoad().catch(() => retryableLoad());
|
|
160
165
|
};
|
|
161
166
|
|
|
162
167
|
export const initStripe = (
|