@benbraide/inlinejs-stripe 2.0.0 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,6 +26,7 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
26
26
  this.stripeField_ = null;
27
27
  this.isReady_ = false;
28
28
  this.readyWaiters_ = new Array();
29
+ this.changeListeners = new Array();
29
30
  this.stripe = null;
30
31
  this.options = null;
31
32
  this.type = '';
@@ -38,6 +39,13 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
38
39
  this.isReady_ ? resolve() : this.readyWaiters_.push(() => resolve());
39
40
  });
40
41
  }
42
+ AddChangeListener(listener) {
43
+ this.changeListeners.push(listener);
44
+ }
45
+ RemoveChangeListener(listener) {
46
+ const index = this.changeListeners.indexOf(listener);
47
+ (index >= 0) && this.changeListeners.splice(index, 1);
48
+ }
41
49
  ToggleFocus(focused) {
42
50
  var _a, _b;
43
51
  (this.stripeField_ && (focused ? (_a = this.stripeField_) === null || _a === void 0 ? void 0 : _a.focus() : (_b = this.stripeField_) === null || _b === void 0 ? void 0 : _b.blur()));
@@ -74,6 +82,12 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
74
82
  this.stripeField_ = stripe.elements().create(type, (this.options || ((_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.options) || undefined));
75
83
  this.stripeField_.on('ready', () => {
76
84
  this.isReady_ = true;
85
+ this.onready && (0, inlinejs_1.EvaluateLater)({
86
+ componentId: this.componentId_,
87
+ contextElement: this,
88
+ expression: this.onready,
89
+ disableFunctionCall: false,
90
+ })();
77
91
  this.readyWaiters_.splice(0).forEach(waiter => (0, inlinejs_1.JournalTry)(waiter));
78
92
  });
79
93
  this.stripeField_.on('change', (event) => {
@@ -85,6 +99,7 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
85
99
  expression: this.onerrors,
86
100
  disableFunctionCall: false,
87
101
  })(undefined, [], { error: event.error });
102
+ this.changeListeners.forEach(listener => (0, inlinejs_1.JournalTry)(() => listener('error', event.error)));
88
103
  }
89
104
  else if (event === null || event === void 0 ? void 0 : event.complete) {
90
105
  (0, inlinejs_1.EvaluateLater)({
@@ -93,8 +108,15 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
93
108
  expression: this.oncomplete,
94
109
  disableFunctionCall: false,
95
110
  })();
111
+ this.changeListeners.forEach(listener => (0, inlinejs_1.JournalTry)(() => listener('complete', true)));
96
112
  (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.FocusNextField(this);
97
113
  }
114
+ else {
115
+ this.changeListeners.forEach((listener) => {
116
+ (0, inlinejs_1.JournalTry)(() => listener('complete', false));
117
+ (0, inlinejs_1.JournalTry)(() => listener('error', null));
118
+ });
119
+ }
98
120
  });
99
121
  this.stripeField_.mount(this);
100
122
  }
@@ -1,10 +1,12 @@
1
1
  /// <reference types="stripe-v3" />
2
2
  import { CustomElement } from "@benbraide/inlinejs-element";
3
- import { IStripeField, IStripePaymentDetails } from "../types";
3
+ import { IStripeField, IStripePaymentDetails, StripeFieldChangeHandlerType } from "../types";
4
4
  export declare class StripePaymentMenthodElement extends CustomElement implements IStripeField {
5
5
  value: stripe.elements.Element | string;
6
6
  constructor();
7
7
  WaitReady(): Promise<void>;
8
+ AddChangeListener(listener: StripeFieldChangeHandlerType): void;
9
+ RemoveChangeListener(listener: StripeFieldChangeHandlerType): void;
8
10
  ToggleFocus(focused: boolean): void;
9
11
  Reset(): void;
10
12
  AddDetails(details: IStripePaymentDetails): void;
@@ -19,6 +19,8 @@ class StripePaymentMenthodElement extends inlinejs_element_1.CustomElement {
19
19
  WaitReady() {
20
20
  return Promise.resolve();
21
21
  }
22
+ AddChangeListener(listener) { }
23
+ RemoveChangeListener(listener) { }
22
24
  ToggleFocus(focused) { }
23
25
  Reset() { }
24
26
  AddDetails(details) {
@@ -6,11 +6,18 @@ export declare class StripeElement extends CustomElement implements IStripeEleme
6
6
  protected stripe_: stripe.Stripe | null;
7
7
  protected mounting_: boolean;
8
8
  protected mounted_: boolean;
9
+ protected isReady_: boolean;
10
+ protected readyWaiters_: (() => void)[];
9
11
  protected fields_: Array<IStripeField> | null;
12
+ protected readyFields_: Array<IStripeField> | null;
10
13
  protected instanceWaiters_: (() => void)[];
14
+ protected completeFields_: Array<IStripeField> | null;
15
+ protected errorFields_: Array<IStripeField> | null;
11
16
  options: stripe.elements.ElementsOptions | null;
12
17
  publicKey: string;
13
18
  onready: string;
19
+ oncomplete: string;
20
+ onerrors: string;
14
21
  defer: boolean;
15
22
  autofocus: boolean;
16
23
  constructor();
@@ -22,6 +29,7 @@ export declare class StripeElement extends CustomElement implements IStripeEleme
22
29
  Mount(): void;
23
30
  Pay(clientSecret: string, save?: boolean): Promise<false | stripe.PaymentIntentResponse>;
24
31
  Setup(clientSecret: string): Promise<false | stripe.PaymentIntentResponse>;
32
+ WaitReady(): Promise<void>;
25
33
  protected HandleElementScopeCreated_({ scope, ...rest }: IElementScopeCreatedCallbackParams, postAttributesCallback?: () => void): void;
26
34
  protected PayOrSetup_(pay: boolean, clientSecret: string, save?: boolean): Promise<false | stripe.PaymentIntentResponse>;
27
35
  }
@@ -26,20 +26,82 @@ class StripeElement extends inlinejs_element_1.CustomElement {
26
26
  this.stripe_ = null;
27
27
  this.mounting_ = false;
28
28
  this.mounted_ = false;
29
+ this.isReady_ = false;
30
+ this.readyWaiters_ = new Array();
29
31
  this.fields_ = null;
32
+ this.readyFields_ = null;
30
33
  this.instanceWaiters_ = new Array();
34
+ this.completeFields_ = null;
35
+ this.errorFields_ = null;
31
36
  this.options = null;
32
37
  this.publicKey = '';
33
38
  this.onready = '';
39
+ this.oncomplete = '';
40
+ this.onerrors = '';
34
41
  this.defer = false;
35
42
  this.autofocus = false;
36
43
  }
37
44
  AddStripeField(field) {
38
45
  this.fields_ = (this.fields_ || []);
39
46
  this.fields_.push(field);
47
+ field.WaitReady().then(() => {
48
+ this.readyFields_ = (this.readyFields_ || []);
49
+ this.readyFields_.push(field);
50
+ (this.fields_ && this.readyFields_ && this.fields_.length <= this.readyFields_.length) && (0, inlinejs_1.JournalTry)(() => {
51
+ this.isReady_ = true;
52
+ this.onready && (0, inlinejs_1.EvaluateLater)({
53
+ componentId: this.componentId_,
54
+ contextElement: this,
55
+ expression: this.onready,
56
+ disableFunctionCall: false,
57
+ })();
58
+ this.readyWaiters_.splice(0).forEach(waiter => (0, inlinejs_1.JournalTry)(waiter));
59
+ });
60
+ });
61
+ field.AddChangeListener((type, data) => {
62
+ if (type === 'complete') {
63
+ let changed = false;
64
+ this.completeFields_ = (this.completeFields_ || []);
65
+ if (data && !this.completeFields_.includes(field)) {
66
+ this.completeFields_.push(field);
67
+ changed = !!(this.readyFields_ && this.completeFields_.length == this.readyFields_.length);
68
+ }
69
+ else if (!data && this.completeFields_.includes(field)) {
70
+ this.completeFields_ = this.completeFields_.filter(x => x !== field);
71
+ changed = (this.completeFields_.length == 0);
72
+ }
73
+ changed && this.oncomplete && (0, inlinejs_1.EvaluateLater)({
74
+ componentId: this.componentId_,
75
+ contextElement: this,
76
+ expression: this.oncomplete,
77
+ disableFunctionCall: false,
78
+ })(undefined, [!!data], { complete: !!data });
79
+ }
80
+ else if (type === 'error') {
81
+ let changed = false;
82
+ this.errorFields_ = (this.errorFields_ || []);
83
+ this.errorFields_.push(field);
84
+ this.errorFields_ = (this.errorFields_ || []);
85
+ if (data && !this.errorFields_.includes(field)) {
86
+ this.errorFields_.push(field);
87
+ changed = (this.errorFields_.length == 1);
88
+ }
89
+ else if (!data && this.errorFields_.includes(field)) {
90
+ this.errorFields_ = this.errorFields_.filter(x => x !== field);
91
+ changed = (this.errorFields_.length == 0);
92
+ }
93
+ this.onerrors && (0, inlinejs_1.EvaluateLater)({
94
+ componentId: this.componentId_,
95
+ contextElement: this,
96
+ expression: this.onerrors,
97
+ disableFunctionCall: false,
98
+ })(undefined, [data], { error: data });
99
+ }
100
+ });
40
101
  }
41
102
  RemoveStripeField(field) {
42
103
  this.fields_ && (this.fields_ = this.fields_.filter(x => x !== field));
104
+ this.readyFields_ && (this.readyFields_ = this.readyFields_.filter(x => x !== field));
43
105
  }
44
106
  FocusNextField(field) {
45
107
  if (this.autofocus && this.fields_) {
@@ -73,6 +135,11 @@ class StripeElement extends inlinejs_element_1.CustomElement {
73
135
  Setup(clientSecret) {
74
136
  return this.PayOrSetup_(false, clientSecret);
75
137
  }
138
+ WaitReady() {
139
+ return new Promise(resolve => {
140
+ this.isReady_ ? resolve() : this.readyWaiters_.push(() => resolve());
141
+ });
142
+ }
76
143
  HandleElementScopeCreated_(_a, postAttributesCallback) {
77
144
  var { scope } = _a, rest = __rest(_a, ["scope"]);
78
145
  super.HandleElementScopeCreated_(Object.assign({ scope }, rest), postAttributesCallback);
@@ -126,6 +193,12 @@ __decorate([
126
193
  __decorate([
127
194
  (0, inlinejs_element_1.Property)({ type: 'string' })
128
195
  ], StripeElement.prototype, "onready", void 0);
196
+ __decorate([
197
+ (0, inlinejs_element_1.Property)({ type: 'string' })
198
+ ], StripeElement.prototype, "oncomplete", void 0);
199
+ __decorate([
200
+ (0, inlinejs_element_1.Property)({ type: 'string' })
201
+ ], StripeElement.prototype, "onerrors", void 0);
129
202
  __decorate([
130
203
  (0, inlinejs_element_1.Property)({ type: 'boolean' })
131
204
  ], StripeElement.prototype, "defer", void 0);
@@ -3,8 +3,12 @@ export interface IStripePaymentDetails {
3
3
  method?: stripe.elements.Element | string;
4
4
  billingDetails?: stripe.BillingDetails;
5
5
  }
6
+ export declare type StripeFieldChangeType = 'error' | 'complete';
7
+ export declare type StripeFieldChangeHandlerType = (type: StripeFieldChangeType, data: any) => void;
6
8
  export interface IStripeField {
7
9
  WaitReady(): Promise<void>;
10
+ AddChangeListener(listener: StripeFieldChangeHandlerType): void;
11
+ RemoveChangeListener(listener: StripeFieldChangeHandlerType): void;
8
12
  ToggleFocus(focused: boolean): void;
9
13
  Reset(): void;
10
14
  AddDetails(details: IStripePaymentDetails): void;
@@ -1,11 +1,13 @@
1
1
  import { CustomElement } from "@benbraide/inlinejs-element";
2
- import { IStripeField, IStripePaymentDetails } from "../types";
2
+ import { IStripeField, IStripePaymentDetails, StripeFieldChangeHandlerType } from "../types";
3
3
  export declare class StripeDetailElement extends CustomElement implements IStripeField {
4
4
  input: HTMLInputElement | null;
5
5
  name: string;
6
6
  value: string;
7
7
  constructor();
8
8
  WaitReady(): Promise<void>;
9
+ AddChangeListener(listener: StripeFieldChangeHandlerType): void;
10
+ RemoveChangeListener(listener: StripeFieldChangeHandlerType): void;
9
11
  ToggleFocus(focused: boolean): void;
10
12
  Reset(): void;
11
13
  AddDetails(details: IStripePaymentDetails): void;
@@ -15,6 +15,8 @@ export class StripeDetailElement extends CustomElement {
15
15
  WaitReady() {
16
16
  return Promise.resolve();
17
17
  }
18
+ AddChangeListener(listener) { }
19
+ RemoveChangeListener(listener) { }
18
20
  ToggleFocus(focused) {
19
21
  const input = this.GetInput_();
20
22
  input && (focused ? input.focus() : input.blur());
@@ -25,7 +27,7 @@ export class StripeDetailElement extends CustomElement {
25
27
  }
26
28
  AddDetails(details) {
27
29
  const input = this.GetInput_();
28
- if (!this.name || (!input && !this.value)) {
30
+ if (!this.name || (!(input === null || input === void 0 ? void 0 : input.value) && !this.value)) {
29
31
  return;
30
32
  }
31
33
  details.billingDetails = (details.billingDetails || {});
@@ -1,11 +1,12 @@
1
1
  /// <reference types="stripe-v3" />
2
2
  import { IElementScopeCreatedCallbackParams } from "@benbraide/inlinejs";
3
3
  import { CustomElement } from "@benbraide/inlinejs-element";
4
- import { IStripeElement, IStripeField, IStripePaymentDetails } from "../types";
4
+ import { IStripeElement, IStripeField, IStripePaymentDetails, StripeFieldChangeHandlerType } from "../types";
5
5
  export declare class StripeFieldElement extends CustomElement implements IStripeField {
6
6
  protected stripeField_: stripe.elements.Element | null;
7
7
  protected isReady_: boolean;
8
8
  protected readyWaiters_: (() => void)[];
9
+ protected changeListeners: StripeFieldChangeHandlerType[];
9
10
  stripe: IStripeElement | null;
10
11
  options: stripe.elements.ElementsOptions | null;
11
12
  type: string;
@@ -14,6 +15,8 @@ export declare class StripeFieldElement extends CustomElement implements IStripe
14
15
  onerrors: string;
15
16
  constructor();
16
17
  WaitReady(): Promise<void>;
18
+ AddChangeListener(listener: StripeFieldChangeHandlerType): void;
19
+ RemoveChangeListener(listener: StripeFieldChangeHandlerType): void;
17
20
  ToggleFocus(focused: boolean): void;
18
21
  Reset(): void;
19
22
  AddDetails(details: IStripePaymentDetails): void;
@@ -23,6 +23,7 @@ export class StripeFieldElement extends CustomElement {
23
23
  this.stripeField_ = null;
24
24
  this.isReady_ = false;
25
25
  this.readyWaiters_ = new Array();
26
+ this.changeListeners = new Array();
26
27
  this.stripe = null;
27
28
  this.options = null;
28
29
  this.type = '';
@@ -35,6 +36,13 @@ export class StripeFieldElement extends CustomElement {
35
36
  this.isReady_ ? resolve() : this.readyWaiters_.push(() => resolve());
36
37
  });
37
38
  }
39
+ AddChangeListener(listener) {
40
+ this.changeListeners.push(listener);
41
+ }
42
+ RemoveChangeListener(listener) {
43
+ const index = this.changeListeners.indexOf(listener);
44
+ (index >= 0) && this.changeListeners.splice(index, 1);
45
+ }
38
46
  ToggleFocus(focused) {
39
47
  var _a, _b;
40
48
  (this.stripeField_ && (focused ? (_a = this.stripeField_) === null || _a === void 0 ? void 0 : _a.focus() : (_b = this.stripeField_) === null || _b === void 0 ? void 0 : _b.blur()));
@@ -71,6 +79,12 @@ export class StripeFieldElement extends CustomElement {
71
79
  this.stripeField_ = stripe.elements().create(type, (this.options || ((_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.options) || undefined));
72
80
  this.stripeField_.on('ready', () => {
73
81
  this.isReady_ = true;
82
+ this.onready && EvaluateLater({
83
+ componentId: this.componentId_,
84
+ contextElement: this,
85
+ expression: this.onready,
86
+ disableFunctionCall: false,
87
+ })();
74
88
  this.readyWaiters_.splice(0).forEach(waiter => JournalTry(waiter));
75
89
  });
76
90
  this.stripeField_.on('change', (event) => {
@@ -82,6 +96,7 @@ export class StripeFieldElement extends CustomElement {
82
96
  expression: this.onerrors,
83
97
  disableFunctionCall: false,
84
98
  })(undefined, [], { error: event.error });
99
+ this.changeListeners.forEach(listener => JournalTry(() => listener('error', event.error)));
85
100
  }
86
101
  else if (event === null || event === void 0 ? void 0 : event.complete) {
87
102
  EvaluateLater({
@@ -90,8 +105,15 @@ export class StripeFieldElement extends CustomElement {
90
105
  expression: this.oncomplete,
91
106
  disableFunctionCall: false,
92
107
  })();
108
+ this.changeListeners.forEach(listener => JournalTry(() => listener('complete', true)));
93
109
  (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.FocusNextField(this);
94
110
  }
111
+ else {
112
+ this.changeListeners.forEach((listener) => {
113
+ JournalTry(() => listener('complete', false));
114
+ JournalTry(() => listener('error', null));
115
+ });
116
+ }
95
117
  });
96
118
  this.stripeField_.mount(this);
97
119
  }
@@ -1,10 +1,12 @@
1
1
  /// <reference types="stripe-v3" />
2
2
  import { CustomElement } from "@benbraide/inlinejs-element";
3
- import { IStripeField, IStripePaymentDetails } from "../types";
3
+ import { IStripeField, IStripePaymentDetails, StripeFieldChangeHandlerType } from "../types";
4
4
  export declare class StripePaymentMenthodElement extends CustomElement implements IStripeField {
5
5
  value: stripe.elements.Element | string;
6
6
  constructor();
7
7
  WaitReady(): Promise<void>;
8
+ AddChangeListener(listener: StripeFieldChangeHandlerType): void;
9
+ RemoveChangeListener(listener: StripeFieldChangeHandlerType): void;
8
10
  ToggleFocus(focused: boolean): void;
9
11
  Reset(): void;
10
12
  AddDetails(details: IStripePaymentDetails): void;
@@ -16,6 +16,8 @@ export class StripePaymentMenthodElement extends CustomElement {
16
16
  WaitReady() {
17
17
  return Promise.resolve();
18
18
  }
19
+ AddChangeListener(listener) { }
20
+ RemoveChangeListener(listener) { }
19
21
  ToggleFocus(focused) { }
20
22
  Reset() { }
21
23
  AddDetails(details) {
@@ -6,11 +6,18 @@ export declare class StripeElement extends CustomElement implements IStripeEleme
6
6
  protected stripe_: stripe.Stripe | null;
7
7
  protected mounting_: boolean;
8
8
  protected mounted_: boolean;
9
+ protected isReady_: boolean;
10
+ protected readyWaiters_: (() => void)[];
9
11
  protected fields_: Array<IStripeField> | null;
12
+ protected readyFields_: Array<IStripeField> | null;
10
13
  protected instanceWaiters_: (() => void)[];
14
+ protected completeFields_: Array<IStripeField> | null;
15
+ protected errorFields_: Array<IStripeField> | null;
11
16
  options: stripe.elements.ElementsOptions | null;
12
17
  publicKey: string;
13
18
  onready: string;
19
+ oncomplete: string;
20
+ onerrors: string;
14
21
  defer: boolean;
15
22
  autofocus: boolean;
16
23
  constructor();
@@ -22,6 +29,7 @@ export declare class StripeElement extends CustomElement implements IStripeEleme
22
29
  Mount(): void;
23
30
  Pay(clientSecret: string, save?: boolean): Promise<false | stripe.PaymentIntentResponse>;
24
31
  Setup(clientSecret: string): Promise<false | stripe.PaymentIntentResponse>;
32
+ WaitReady(): Promise<void>;
25
33
  protected HandleElementScopeCreated_({ scope, ...rest }: IElementScopeCreatedCallbackParams, postAttributesCallback?: () => void): void;
26
34
  protected PayOrSetup_(pay: boolean, clientSecret: string, save?: boolean): Promise<false | stripe.PaymentIntentResponse>;
27
35
  }
@@ -15,7 +15,7 @@ var __rest = (this && this.__rest) || function (s, e) {
15
15
  }
16
16
  return t;
17
17
  };
18
- import { JournalTry } from "@benbraide/inlinejs";
18
+ import { EvaluateLater, JournalTry } from "@benbraide/inlinejs";
19
19
  import { CustomElement, Property, RegisterCustomElement } from "@benbraide/inlinejs-element";
20
20
  export class StripeElement extends CustomElement {
21
21
  constructor() {
@@ -23,20 +23,82 @@ export class StripeElement extends CustomElement {
23
23
  this.stripe_ = null;
24
24
  this.mounting_ = false;
25
25
  this.mounted_ = false;
26
+ this.isReady_ = false;
27
+ this.readyWaiters_ = new Array();
26
28
  this.fields_ = null;
29
+ this.readyFields_ = null;
27
30
  this.instanceWaiters_ = new Array();
31
+ this.completeFields_ = null;
32
+ this.errorFields_ = null;
28
33
  this.options = null;
29
34
  this.publicKey = '';
30
35
  this.onready = '';
36
+ this.oncomplete = '';
37
+ this.onerrors = '';
31
38
  this.defer = false;
32
39
  this.autofocus = false;
33
40
  }
34
41
  AddStripeField(field) {
35
42
  this.fields_ = (this.fields_ || []);
36
43
  this.fields_.push(field);
44
+ field.WaitReady().then(() => {
45
+ this.readyFields_ = (this.readyFields_ || []);
46
+ this.readyFields_.push(field);
47
+ (this.fields_ && this.readyFields_ && this.fields_.length <= this.readyFields_.length) && JournalTry(() => {
48
+ this.isReady_ = true;
49
+ this.onready && EvaluateLater({
50
+ componentId: this.componentId_,
51
+ contextElement: this,
52
+ expression: this.onready,
53
+ disableFunctionCall: false,
54
+ })();
55
+ this.readyWaiters_.splice(0).forEach(waiter => JournalTry(waiter));
56
+ });
57
+ });
58
+ field.AddChangeListener((type, data) => {
59
+ if (type === 'complete') {
60
+ let changed = false;
61
+ this.completeFields_ = (this.completeFields_ || []);
62
+ if (data && !this.completeFields_.includes(field)) {
63
+ this.completeFields_.push(field);
64
+ changed = !!(this.readyFields_ && this.completeFields_.length == this.readyFields_.length);
65
+ }
66
+ else if (!data && this.completeFields_.includes(field)) {
67
+ this.completeFields_ = this.completeFields_.filter(x => x !== field);
68
+ changed = (this.completeFields_.length == 0);
69
+ }
70
+ changed && this.oncomplete && EvaluateLater({
71
+ componentId: this.componentId_,
72
+ contextElement: this,
73
+ expression: this.oncomplete,
74
+ disableFunctionCall: false,
75
+ })(undefined, [!!data], { complete: !!data });
76
+ }
77
+ else if (type === 'error') {
78
+ let changed = false;
79
+ this.errorFields_ = (this.errorFields_ || []);
80
+ this.errorFields_.push(field);
81
+ this.errorFields_ = (this.errorFields_ || []);
82
+ if (data && !this.errorFields_.includes(field)) {
83
+ this.errorFields_.push(field);
84
+ changed = (this.errorFields_.length == 1);
85
+ }
86
+ else if (!data && this.errorFields_.includes(field)) {
87
+ this.errorFields_ = this.errorFields_.filter(x => x !== field);
88
+ changed = (this.errorFields_.length == 0);
89
+ }
90
+ this.onerrors && EvaluateLater({
91
+ componentId: this.componentId_,
92
+ contextElement: this,
93
+ expression: this.onerrors,
94
+ disableFunctionCall: false,
95
+ })(undefined, [data], { error: data });
96
+ }
97
+ });
37
98
  }
38
99
  RemoveStripeField(field) {
39
100
  this.fields_ && (this.fields_ = this.fields_.filter(x => x !== field));
101
+ this.readyFields_ && (this.readyFields_ = this.readyFields_.filter(x => x !== field));
40
102
  }
41
103
  FocusNextField(field) {
42
104
  if (this.autofocus && this.fields_) {
@@ -70,6 +132,11 @@ export class StripeElement extends CustomElement {
70
132
  Setup(clientSecret) {
71
133
  return this.PayOrSetup_(false, clientSecret);
72
134
  }
135
+ WaitReady() {
136
+ return new Promise(resolve => {
137
+ this.isReady_ ? resolve() : this.readyWaiters_.push(() => resolve());
138
+ });
139
+ }
73
140
  HandleElementScopeCreated_(_a, postAttributesCallback) {
74
141
  var { scope } = _a, rest = __rest(_a, ["scope"]);
75
142
  super.HandleElementScopeCreated_(Object.assign({ scope }, rest), postAttributesCallback);
@@ -123,6 +190,12 @@ __decorate([
123
190
  __decorate([
124
191
  Property({ type: 'string' })
125
192
  ], StripeElement.prototype, "onready", void 0);
193
+ __decorate([
194
+ Property({ type: 'string' })
195
+ ], StripeElement.prototype, "oncomplete", void 0);
196
+ __decorate([
197
+ Property({ type: 'string' })
198
+ ], StripeElement.prototype, "onerrors", void 0);
126
199
  __decorate([
127
200
  Property({ type: 'boolean' })
128
201
  ], StripeElement.prototype, "defer", void 0);
@@ -3,8 +3,12 @@ export interface IStripePaymentDetails {
3
3
  method?: stripe.elements.Element | string;
4
4
  billingDetails?: stripe.BillingDetails;
5
5
  }
6
+ export declare type StripeFieldChangeType = 'error' | 'complete';
7
+ export declare type StripeFieldChangeHandlerType = (type: StripeFieldChangeType, data: any) => void;
6
8
  export interface IStripeField {
7
9
  WaitReady(): Promise<void>;
10
+ AddChangeListener(listener: StripeFieldChangeHandlerType): void;
11
+ RemoveChangeListener(listener: StripeFieldChangeHandlerType): void;
8
12
  ToggleFocus(focused: boolean): void;
9
13
  Reset(): void;
10
14
  AddDetails(details: IStripePaymentDetails): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@benbraide/inlinejs-stripe",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Run javascript code by embedding them in your HTML using the element as context.",
5
5
  "main": "./lib/common/index.js",
6
6
  "module": "./lib/esm/index.js",