@stripe/stripe-js 2.2.0 → 2.2.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/pure.esm.js CHANGED
@@ -54,12 +54,31 @@ var registerWrapper = function registerWrapper(stripe, startTime) {
54
54
 
55
55
  stripe._registerWrapper({
56
56
  name: 'stripe-js',
57
- version: "2.2.0",
57
+ version: "2.2.2",
58
58
  startTime: startTime
59
59
  });
60
60
  };
61
61
 
62
62
  var stripePromise = null;
63
+ var onErrorListener = null;
64
+ var onLoadListener = null;
65
+
66
+ var onError = function onError(reject) {
67
+ return function () {
68
+ reject(new Error('Failed to load Stripe.js'));
69
+ };
70
+ };
71
+
72
+ var onLoad = function onLoad(resolve, reject) {
73
+ return function () {
74
+ if (window.Stripe) {
75
+ resolve(window.Stripe);
76
+ } else {
77
+ reject(new Error('Stripe.js not available'));
78
+ }
79
+ };
80
+ };
81
+
63
82
  var loadScript = function loadScript(params) {
64
83
  // Ensure that we only attempt to load Stripe.js at most once
65
84
  if (stripePromise !== null) {
@@ -90,24 +109,32 @@ var loadScript = function loadScript(params) {
90
109
  console.warn(EXISTING_SCRIPT_MESSAGE);
91
110
  } else if (!script) {
92
111
  script = injectScript(params);
112
+ } else if (script && onLoadListener !== null && onErrorListener !== null) {
113
+ var _script$parentNode;
114
+
115
+ // remove event listeners
116
+ script.removeEventListener('load', onLoadListener);
117
+ script.removeEventListener('error', onErrorListener); // if script exists, but we are reloading due to an error,
118
+ // reload script to trigger 'load' event
119
+
120
+ (_script$parentNode = script.parentNode) === null || _script$parentNode === void 0 ? void 0 : _script$parentNode.removeChild(script);
121
+ script = injectScript(params);
93
122
  }
94
123
 
95
- script.addEventListener('load', function () {
96
- if (window.Stripe) {
97
- resolve(window.Stripe);
98
- } else {
99
- reject(new Error('Stripe.js not available'));
100
- }
101
- });
102
- script.addEventListener('error', function () {
103
- reject(new Error('Failed to load Stripe.js'));
104
- });
124
+ onLoadListener = onLoad(resolve, reject);
125
+ onErrorListener = onError(reject);
126
+ script.addEventListener('load', onLoadListener);
127
+ script.addEventListener('error', onErrorListener);
105
128
  } catch (error) {
106
129
  reject(error);
107
130
  return;
108
131
  }
132
+ }); // Resets stripePromise on error
133
+
134
+ return stripePromise["catch"](function (error) {
135
+ stripePromise = null;
136
+ return Promise.reject(error);
109
137
  });
110
- return stripePromise;
111
138
  };
112
139
  var initStripe = function initStripe(maybeStripe, args, startTime) {
113
140
  if (maybeStripe === null) {
package/dist/pure.js CHANGED
@@ -58,12 +58,31 @@ var registerWrapper = function registerWrapper(stripe, startTime) {
58
58
 
59
59
  stripe._registerWrapper({
60
60
  name: 'stripe-js',
61
- version: "2.2.0",
61
+ version: "2.2.2",
62
62
  startTime: startTime
63
63
  });
64
64
  };
65
65
 
66
66
  var stripePromise = null;
67
+ var onErrorListener = null;
68
+ var onLoadListener = null;
69
+
70
+ var onError = function onError(reject) {
71
+ return function () {
72
+ reject(new Error('Failed to load Stripe.js'));
73
+ };
74
+ };
75
+
76
+ var onLoad = function onLoad(resolve, reject) {
77
+ return function () {
78
+ if (window.Stripe) {
79
+ resolve(window.Stripe);
80
+ } else {
81
+ reject(new Error('Stripe.js not available'));
82
+ }
83
+ };
84
+ };
85
+
67
86
  var loadScript = function loadScript(params) {
68
87
  // Ensure that we only attempt to load Stripe.js at most once
69
88
  if (stripePromise !== null) {
@@ -94,24 +113,32 @@ var loadScript = function loadScript(params) {
94
113
  console.warn(EXISTING_SCRIPT_MESSAGE);
95
114
  } else if (!script) {
96
115
  script = injectScript(params);
116
+ } else if (script && onLoadListener !== null && onErrorListener !== null) {
117
+ var _script$parentNode;
118
+
119
+ // remove event listeners
120
+ script.removeEventListener('load', onLoadListener);
121
+ script.removeEventListener('error', onErrorListener); // if script exists, but we are reloading due to an error,
122
+ // reload script to trigger 'load' event
123
+
124
+ (_script$parentNode = script.parentNode) === null || _script$parentNode === void 0 ? void 0 : _script$parentNode.removeChild(script);
125
+ script = injectScript(params);
97
126
  }
98
127
 
99
- script.addEventListener('load', function () {
100
- if (window.Stripe) {
101
- resolve(window.Stripe);
102
- } else {
103
- reject(new Error('Stripe.js not available'));
104
- }
105
- });
106
- script.addEventListener('error', function () {
107
- reject(new Error('Failed to load Stripe.js'));
108
- });
128
+ onLoadListener = onLoad(resolve, reject);
129
+ onErrorListener = onError(reject);
130
+ script.addEventListener('load', onLoadListener);
131
+ script.addEventListener('error', onErrorListener);
109
132
  } catch (error) {
110
133
  reject(error);
111
134
  return;
112
135
  }
136
+ }); // Resets stripePromise on error
137
+
138
+ return stripePromise["catch"](function (error) {
139
+ stripePromise = null;
140
+ return Promise.reject(error);
113
141
  });
114
- return stripePromise;
115
142
  };
116
143
  var initStripe = function initStripe(maybeStripe, args, startTime) {
117
144
  if (maybeStripe === null) {
@@ -38,12 +38,31 @@ var registerWrapper = function registerWrapper(stripe, startTime) {
38
38
 
39
39
  stripe._registerWrapper({
40
40
  name: 'stripe-js',
41
- version: "2.2.0",
41
+ version: "2.2.2",
42
42
  startTime: startTime
43
43
  });
44
44
  };
45
45
 
46
46
  var stripePromise = null;
47
+ var onErrorListener = null;
48
+ var onLoadListener = null;
49
+
50
+ var onError = function onError(reject) {
51
+ return function () {
52
+ reject(new Error('Failed to load Stripe.js'));
53
+ };
54
+ };
55
+
56
+ var onLoad = function onLoad(resolve, reject) {
57
+ return function () {
58
+ if (window.Stripe) {
59
+ resolve(window.Stripe);
60
+ } else {
61
+ reject(new Error('Stripe.js not available'));
62
+ }
63
+ };
64
+ };
65
+
47
66
  var loadScript = function loadScript(params) {
48
67
  // Ensure that we only attempt to load Stripe.js at most once
49
68
  if (stripePromise !== null) {
@@ -74,24 +93,32 @@ var loadScript = function loadScript(params) {
74
93
  console.warn(EXISTING_SCRIPT_MESSAGE);
75
94
  } else if (!script) {
76
95
  script = injectScript(params);
96
+ } else if (script && onLoadListener !== null && onErrorListener !== null) {
97
+ var _script$parentNode;
98
+
99
+ // remove event listeners
100
+ script.removeEventListener('load', onLoadListener);
101
+ script.removeEventListener('error', onErrorListener); // if script exists, but we are reloading due to an error,
102
+ // reload script to trigger 'load' event
103
+
104
+ (_script$parentNode = script.parentNode) === null || _script$parentNode === void 0 ? void 0 : _script$parentNode.removeChild(script);
105
+ script = injectScript(params);
77
106
  }
78
107
 
79
- script.addEventListener('load', function () {
80
- if (window.Stripe) {
81
- resolve(window.Stripe);
82
- } else {
83
- reject(new Error('Stripe.js not available'));
84
- }
85
- });
86
- script.addEventListener('error', function () {
87
- reject(new Error('Failed to load Stripe.js'));
88
- });
108
+ onLoadListener = onLoad(resolve, reject);
109
+ onErrorListener = onError(reject);
110
+ script.addEventListener('load', onLoadListener);
111
+ script.addEventListener('error', onErrorListener);
89
112
  } catch (error) {
90
113
  reject(error);
91
114
  return;
92
115
  }
116
+ }); // Resets stripePromise on error
117
+
118
+ return stripePromise["catch"](function (error) {
119
+ stripePromise = null;
120
+ return Promise.reject(error);
93
121
  });
94
- return stripePromise;
95
122
  };
96
123
  var initStripe = function initStripe(maybeStripe, args, startTime) {
97
124
  if (maybeStripe === null) {
package/dist/stripe.js CHANGED
@@ -42,12 +42,31 @@ var registerWrapper = function registerWrapper(stripe, startTime) {
42
42
 
43
43
  stripe._registerWrapper({
44
44
  name: 'stripe-js',
45
- version: "2.2.0",
45
+ version: "2.2.2",
46
46
  startTime: startTime
47
47
  });
48
48
  };
49
49
 
50
50
  var stripePromise = null;
51
+ var onErrorListener = null;
52
+ var onLoadListener = null;
53
+
54
+ var onError = function onError(reject) {
55
+ return function () {
56
+ reject(new Error('Failed to load Stripe.js'));
57
+ };
58
+ };
59
+
60
+ var onLoad = function onLoad(resolve, reject) {
61
+ return function () {
62
+ if (window.Stripe) {
63
+ resolve(window.Stripe);
64
+ } else {
65
+ reject(new Error('Stripe.js not available'));
66
+ }
67
+ };
68
+ };
69
+
51
70
  var loadScript = function loadScript(params) {
52
71
  // Ensure that we only attempt to load Stripe.js at most once
53
72
  if (stripePromise !== null) {
@@ -78,24 +97,32 @@ var loadScript = function loadScript(params) {
78
97
  console.warn(EXISTING_SCRIPT_MESSAGE);
79
98
  } else if (!script) {
80
99
  script = injectScript(params);
100
+ } else if (script && onLoadListener !== null && onErrorListener !== null) {
101
+ var _script$parentNode;
102
+
103
+ // remove event listeners
104
+ script.removeEventListener('load', onLoadListener);
105
+ script.removeEventListener('error', onErrorListener); // if script exists, but we are reloading due to an error,
106
+ // reload script to trigger 'load' event
107
+
108
+ (_script$parentNode = script.parentNode) === null || _script$parentNode === void 0 ? void 0 : _script$parentNode.removeChild(script);
109
+ script = injectScript(params);
81
110
  }
82
111
 
83
- script.addEventListener('load', function () {
84
- if (window.Stripe) {
85
- resolve(window.Stripe);
86
- } else {
87
- reject(new Error('Stripe.js not available'));
88
- }
89
- });
90
- script.addEventListener('error', function () {
91
- reject(new Error('Failed to load Stripe.js'));
92
- });
112
+ onLoadListener = onLoad(resolve, reject);
113
+ onErrorListener = onError(reject);
114
+ script.addEventListener('load', onLoadListener);
115
+ script.addEventListener('error', onErrorListener);
93
116
  } catch (error) {
94
117
  reject(error);
95
118
  return;
96
119
  }
120
+ }); // Resets stripePromise on error
121
+
122
+ return stripePromise["catch"](function (error) {
123
+ stripePromise = null;
124
+ return Promise.reject(error);
97
125
  });
98
- return stripePromise;
99
126
  };
100
127
  var initStripe = function initStripe(maybeStripe, args, startTime) {
101
128
  if (maybeStripe === null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stripe/stripe-js",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "Stripe.js loading utility",
5
5
  "repository": "github:stripe/stripe-js",
6
6
  "main": "dist/stripe.js",
package/src/shared.ts CHANGED
@@ -64,6 +64,26 @@ const registerWrapper = (stripe: any, startTime: number): void => {
64
64
 
65
65
  let stripePromise: Promise<StripeConstructor | null> | null = null;
66
66
 
67
+ let onErrorListener: (() => void) | null = null;
68
+ let onLoadListener: (() => void) | null = null;
69
+
70
+ const onError = (reject: (reason?: any) => void) => () => {
71
+ reject(new Error('Failed to load Stripe.js'));
72
+ };
73
+
74
+ const onLoad = (
75
+ resolve: (
76
+ value: StripeConstructor | PromiseLike<StripeConstructor | null> | null
77
+ ) => void,
78
+ reject: (reason?: any) => void
79
+ ) => () => {
80
+ if (window.Stripe) {
81
+ resolve(window.Stripe);
82
+ } else {
83
+ reject(new Error('Stripe.js not available'));
84
+ }
85
+ };
86
+
67
87
  export const loadScript = (
68
88
  params: null | LoadParams
69
89
  ): Promise<StripeConstructor | null> => {
@@ -96,26 +116,36 @@ export const loadScript = (
96
116
  console.warn(EXISTING_SCRIPT_MESSAGE);
97
117
  } else if (!script) {
98
118
  script = injectScript(params);
119
+ } else if (
120
+ script &&
121
+ onLoadListener !== null &&
122
+ onErrorListener !== null
123
+ ) {
124
+ // remove event listeners
125
+ script.removeEventListener('load', onLoadListener);
126
+ script.removeEventListener('error', onErrorListener);
127
+
128
+ // if script exists, but we are reloading due to an error,
129
+ // reload script to trigger 'load' event
130
+ script.parentNode?.removeChild(script);
131
+ script = injectScript(params);
99
132
  }
100
133
 
101
- script.addEventListener('load', () => {
102
- if (window.Stripe) {
103
- resolve(window.Stripe);
104
- } else {
105
- reject(new Error('Stripe.js not available'));
106
- }
107
- });
108
-
109
- script.addEventListener('error', () => {
110
- reject(new Error('Failed to load Stripe.js'));
111
- });
134
+ onLoadListener = onLoad(resolve, reject);
135
+ onErrorListener = onError(reject);
136
+ script.addEventListener('load', onLoadListener);
137
+
138
+ script.addEventListener('error', onErrorListener);
112
139
  } catch (error) {
113
140
  reject(error);
114
141
  return;
115
142
  }
116
143
  });
117
-
118
- return stripePromise;
144
+ // Resets stripePromise on error
145
+ return stripePromise.catch((error) => {
146
+ stripePromise = null;
147
+ return Promise.reject(error);
148
+ });
119
149
  };
120
150
 
121
151
  export const initStripe = (
@@ -0,0 +1,156 @@
1
+ export type ApplePayRecurringPaymentRequestIntervalUnit =
2
+ | 'year'
3
+ | 'month'
4
+ | 'day'
5
+ | 'hour'
6
+ | 'minute';
7
+
8
+ export interface ApplePayLineItem {
9
+ /**
10
+ * A short, localized description of the line item.
11
+ */
12
+ label: string;
13
+
14
+ /**
15
+ * The amount in the currency's subunit (e.g. cents, yen, etc.)
16
+ */
17
+ amount: number;
18
+ }
19
+
20
+ export type ApplePayRegularBilling = ApplePayLineItem & {
21
+ /**
22
+ * The date of the first payment.
23
+ */
24
+ recurringPaymentStartDate?: Date;
25
+
26
+ /**
27
+ * The date of the final payment.
28
+ */
29
+ recurringPaymentEndDate?: Date;
30
+
31
+ /**
32
+ * The amount of time — in calendar units, such as day, month, or year — that represents a fraction of the total payment interval.
33
+ */
34
+ recurringPaymentIntervalUnit?: ApplePayRecurringPaymentRequestIntervalUnit;
35
+
36
+ /**
37
+ * The number of interval units that make up the total payment interval.
38
+ */
39
+ recurringPaymentIntervalCount?: number;
40
+ };
41
+
42
+ export interface ApplePayRecurringPaymentRequest {
43
+ /**
44
+ * The description of the payment that the customer will see in their Apple Pay wallet.
45
+ */
46
+ paymentDescription: string;
47
+
48
+ /**
49
+ * The URL to manage items related to the recurring payment on your website.
50
+ */
51
+ managementURL: string;
52
+ regularBilling: ApplePayRegularBilling;
53
+
54
+ /**
55
+ * The billing agreement label that is displayed to the customer in the Apple Pay payment interface.
56
+ */
57
+ billingAgreement?: string;
58
+ }
59
+
60
+ export type ApplePayAutomaticReloadBilling = ApplePayLineItem & {
61
+ /**
62
+ * The balance an account reaches before the merchant applies the automatic reload amount.
63
+ */
64
+ automaticReloadPaymentThresholdAmount: number;
65
+ };
66
+
67
+ export interface ApplePayAutomaticReloadPaymentRequest {
68
+ /**
69
+ * The description of the payment that the customer will see in their Apple Pay wallet.
70
+ */
71
+ paymentDescription: string;
72
+
73
+ /**
74
+ * The URL to manage items related to the automatic reload payment on your website.
75
+ */
76
+ managementURL: string;
77
+ automaticReloadBilling: ApplePayAutomaticReloadBilling;
78
+
79
+ /**
80
+ * The billing agreement label that is displayed to the customer in the Apple Pay payment interface.
81
+ */
82
+ billingAgreement?: string;
83
+ }
84
+
85
+ export type ApplePayDeferredBilling = ApplePayLineItem & {
86
+ /**
87
+ * The date, in the future, of the payment.
88
+ */
89
+ deferredPaymentDate: Date;
90
+ };
91
+
92
+ export interface ApplePayDeferredPaymentRequest {
93
+ /**
94
+ * The description of the payment that the customer will see in their Apple Pay wallet.
95
+ */
96
+ paymentDescription: string;
97
+
98
+ /**
99
+ * The URL to manage items related to the deferred payment on your website.
100
+ */
101
+ managementURL: string;
102
+ deferredBilling: ApplePayDeferredBilling;
103
+
104
+ /**
105
+ * The billing agreement label that is displayed to the customer in the Apple Pay payment interface.
106
+ */
107
+ billingAgreement?: string;
108
+
109
+ /**
110
+ * The future date before which the customer can cancel the deferred payment for free.
111
+ */
112
+ freeCancellationDate?: Date;
113
+
114
+ /**
115
+ * The time zone of the free cancellation date.
116
+ *
117
+ * These are [tz](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) timezones such as `America/Los_Angeles`, `Europe/Dublin`, and `Asia/Singapore`.
118
+ */
119
+ freeCancellationDateTimeZone?: string;
120
+ }
121
+
122
+ export type ApplePayOption =
123
+ | {
124
+ recurringPaymentRequest: ApplePayRecurringPaymentRequest;
125
+ deferredPaymentRequest?: null;
126
+ automaticReloadPaymentRequest?: null;
127
+ }
128
+ | {
129
+ recurringPaymentRequest?: null;
130
+ deferredPaymentRequest: ApplePayDeferredPaymentRequest;
131
+ automaticReloadPaymentRequest?: null;
132
+ }
133
+ | {
134
+ recurringPaymentRequest?: null;
135
+ deferredPaymentRequest?: null;
136
+ automaticReloadPaymentRequest: ApplePayAutomaticReloadPaymentRequest;
137
+ }
138
+ | {
139
+ recurringPaymentRequest?: null;
140
+ deferredPaymentRequest?: null;
141
+ automaticReloadPaymentRequest?: null;
142
+ };
143
+
144
+ export type ApplePayUpdateOption =
145
+ | {
146
+ recurringPaymentRequest: ApplePayRecurringPaymentRequest;
147
+ automaticReloadPaymentRequest?: null;
148
+ }
149
+ | {
150
+ recurringPaymentRequest?: null;
151
+ automaticReloadPaymentRequest: ApplePayAutomaticReloadPaymentRequest;
152
+ }
153
+ | {
154
+ recurringPaymentRequest?: null;
155
+ automaticReloadPaymentRequest?: null;
156
+ };
@@ -1,5 +1,6 @@
1
1
  import {StripeElementBase} from './base';
2
2
  import {StripeError} from '../stripe';
3
+ import {ApplePayOption, ApplePayUpdateOption} from './apple-pay';
3
4
 
4
5
  export type StripeExpressCheckoutElement = StripeElementBase & {
5
6
  /**
@@ -362,29 +363,6 @@ export interface StripeExpressCheckoutElementReadyEvent {
362
363
  availablePaymentMethods: undefined | AvailablePaymentMethods;
363
364
  }
364
365
 
365
- export type RecurringPaymentIntervalUnit =
366
- | 'year'
367
- | 'month'
368
- | 'day'
369
- | 'hour'
370
- | 'minute';
371
-
372
- export type ApplePayOption = {
373
- recurringPaymentRequest?: {
374
- paymentDescription: string;
375
- managementURL: string;
376
- regularBilling: {
377
- amount: number;
378
- label: string;
379
- recurringPaymentStartDate?: Date;
380
- recurringPaymentEndDate?: Date;
381
- recurringPaymentIntervalUnit?: RecurringPaymentIntervalUnit;
382
- recurringPaymentIntervalCount?: number;
383
- };
384
- billingAgreement?: string;
385
- };
386
- };
387
-
388
366
  export type ClickResolveDetails = {
389
367
  /**
390
368
  * An array of two-letter ISO country codes representing which countries
@@ -451,6 +429,7 @@ export interface StripeExpressCheckoutElementConfirmEvent {
451
429
  export type ChangeResolveDetails = {
452
430
  lineItems?: Array<LineItem>;
453
431
  shippingRates?: Array<ShippingRate>;
432
+ applePay?: ApplePayUpdateOption;
454
433
  };
455
434
 
456
435
  export interface StripeExpressCheckoutElementShippingAddressChangeEvent {
@@ -1,5 +1,6 @@
1
1
  import {StripeElementBase} from './base';
2
2
  import {StripeError} from '../stripe';
3
+ import {ApplePayOption} from './apple-pay';
3
4
 
4
5
  export type StripePaymentElement = StripeElementBase & {
5
6
  /**
@@ -239,6 +240,11 @@ export interface StripePaymentElementOptions {
239
240
  * Specify a layout to use when rendering a Payment Element.
240
241
  */
241
242
  layout?: Layout | LayoutObject;
243
+
244
+ /**
245
+ * Specify the options to be used when the Apple Pay payment interface opens.
246
+ */
247
+ applePay?: ApplePayOption;
242
248
  }
243
249
 
244
250
  export interface StripePaymentElementChangeEvent {
@@ -778,11 +778,6 @@ export interface StripeElementsOptionsMode extends BaseStripeElementsOptions {
778
778
  */
779
779
  paymentMethodCreation?: 'manual';
780
780
 
781
- /**
782
- * Allows PaymentMethods to be created from the Elements instance.
783
- */
784
- payment_method_creation?: 'manual';
785
-
786
781
  /**
787
782
  * Additional payment-method-specific options for configuring Payment Element behavior.
788
783
  *
@@ -1,4 +1,5 @@
1
1
  import {Token, PaymentMethod, Source} from '../api';
2
+ import {ApplePayOption, ApplePayUpdateOption} from './elements/apple-pay';
2
3
 
3
4
  export interface PaymentRequest {
4
5
  /**
@@ -154,6 +155,11 @@ export interface PaymentRequestUpdateOptions {
154
155
  */
155
156
 
156
157
  shippingOptions?: PaymentRequestShippingOption[];
158
+
159
+ /**
160
+ * Specify the options to be used when the Apple Pay payment interface opens.
161
+ */
162
+ applePay?: ApplePayOption;
157
163
  }
158
164
 
159
165
  /**
@@ -226,6 +232,11 @@ export interface PaymentRequestOptions {
226
232
  */
227
233
  disableWallets?: PaymentRequestWallet[];
228
234
 
235
+ /**
236
+ * Specify the options to be used when the Apple Pay payment interface opens.
237
+ */
238
+ applePay?: ApplePayOption;
239
+
229
240
  /**
230
241
  * @deprecated
231
242
  * Use disableWallets instead.
@@ -497,6 +508,11 @@ export interface PaymentRequestUpdateDetails {
497
508
  * The first shipping option listed appears in the browser payment interface as the default option.
498
509
  */
499
510
  shippingOptions?: PaymentRequestShippingOption[];
511
+
512
+ /**
513
+ * Specify new options to refresh the Apple Pay payment interface.
514
+ */
515
+ applePay?: ApplePayUpdateOption;
500
516
  }
501
517
 
502
518
  export interface PaymentRequestShippingOptionEvent {