@benbraide/inlinejs-stripe 2.0.4 → 2.0.6
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/inlinejs-stripe.js +109 -46
- package/dist/inlinejs-stripe.min.js +1 -1
- package/lib/common/components/detail.d.ts +3 -6
- package/lib/common/components/detail.js +2 -6
- package/lib/common/components/field.d.ts +4 -5
- package/lib/common/components/field.js +10 -17
- package/lib/common/components/generic-field.d.ts +15 -0
- package/lib/common/components/generic-field.js +54 -0
- package/lib/common/components/payment-method.d.ts +3 -8
- package/lib/common/components/payment-method.js +2 -8
- package/lib/common/components/stripe.d.ts +5 -2
- package/lib/common/components/stripe.js +31 -15
- package/lib/common/types.d.ts +7 -1
- package/lib/esm/components/detail.d.ts +3 -6
- package/lib/esm/components/detail.js +3 -7
- package/lib/esm/components/field.d.ts +4 -5
- package/lib/esm/components/field.js +12 -19
- package/lib/esm/components/generic-field.d.ts +15 -0
- package/lib/esm/components/generic-field.js +50 -0
- package/lib/esm/components/payment-method.d.ts +3 -8
- package/lib/esm/components/payment-method.js +3 -9
- package/lib/esm/components/stripe.d.ts +5 -2
- package/lib/esm/components/stripe.js +31 -15
- package/lib/esm/types.d.ts +7 -1
- package/package.json +1 -1
@@ -1,9 +1,10 @@
|
|
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 } from "../types";
|
4
|
+
import { IStripeDetails, IStripeElement, IStripeField } from "../types";
|
5
5
|
export declare class StripeElement extends CustomElement implements IStripeElement {
|
6
6
|
protected stripe_: stripe.Stripe | null;
|
7
|
+
protected elements_: stripe.elements.Elements | null;
|
7
8
|
protected mounting_: boolean;
|
8
9
|
protected mounted_: boolean;
|
9
10
|
protected isReady_: boolean;
|
@@ -11,6 +12,7 @@ export declare class StripeElement extends CustomElement implements IStripeEleme
|
|
11
12
|
protected fields_: Array<IStripeField> | null;
|
12
13
|
protected readyFields_: Array<IStripeField> | null;
|
13
14
|
protected instanceWaiters_: (() => void)[];
|
15
|
+
protected interactiveFields_: Array<IStripeField> | null;
|
14
16
|
protected completeFields_: Array<IStripeField> | null;
|
15
17
|
protected errorFields_: Array<IStripeField> | null;
|
16
18
|
options: stripe.elements.ElementsOptions | null;
|
@@ -24,8 +26,9 @@ export declare class StripeElement extends CustomElement implements IStripeEleme
|
|
24
26
|
AddStripeField(field: IStripeField): void;
|
25
27
|
RemoveStripeField(field: IStripeField): void;
|
26
28
|
FocusNextField(field: IStripeField): void;
|
29
|
+
GetDetails(): IStripeDetails;
|
27
30
|
GetInstance(): stripe.Stripe | null;
|
28
|
-
WaitInstance(): Promise<
|
31
|
+
WaitInstance(): Promise<IStripeDetails | null>;
|
29
32
|
Mount(): void;
|
30
33
|
Pay(clientSecret: string, save?: boolean): Promise<false | stripe.PaymentIntentResponse>;
|
31
34
|
Setup(clientSecret: string): Promise<false | stripe.PaymentIntentResponse>;
|
@@ -21,6 +21,7 @@ export class StripeElement extends CustomElement {
|
|
21
21
|
constructor() {
|
22
22
|
super();
|
23
23
|
this.stripe_ = null;
|
24
|
+
this.elements_ = null;
|
24
25
|
this.mounting_ = false;
|
25
26
|
this.mounted_ = false;
|
26
27
|
this.isReady_ = false;
|
@@ -28,6 +29,7 @@ export class StripeElement extends CustomElement {
|
|
28
29
|
this.fields_ = null;
|
29
30
|
this.readyFields_ = null;
|
30
31
|
this.instanceWaiters_ = new Array();
|
32
|
+
this.interactiveFields_ = null;
|
31
33
|
this.completeFields_ = null;
|
32
34
|
this.errorFields_ = null;
|
33
35
|
this.options = null;
|
@@ -44,6 +46,10 @@ export class StripeElement extends CustomElement {
|
|
44
46
|
field.WaitReady().then(() => {
|
45
47
|
this.readyFields_ = (this.readyFields_ || []);
|
46
48
|
this.readyFields_.push(field);
|
49
|
+
if (field.IsInteractive()) {
|
50
|
+
this.interactiveFields_ = (this.interactiveFields_ || []);
|
51
|
+
this.interactiveFields_.push(field);
|
52
|
+
}
|
47
53
|
(this.fields_ && this.readyFields_ && this.fields_.length <= this.readyFields_.length) && JournalTry(() => {
|
48
54
|
this.isReady_ = true;
|
49
55
|
this.onready && EvaluateLater({
|
@@ -61,11 +67,11 @@ export class StripeElement extends CustomElement {
|
|
61
67
|
this.completeFields_ = (this.completeFields_ || []);
|
62
68
|
if (data && !this.completeFields_.includes(field)) {
|
63
69
|
this.completeFields_.push(field);
|
64
|
-
changed = !!(this.
|
70
|
+
changed = !!(this.interactiveFields_ && this.completeFields_.length == this.interactiveFields_.length);
|
65
71
|
}
|
66
72
|
else if (!data && this.completeFields_.includes(field)) {
|
67
73
|
this.completeFields_ = this.completeFields_.filter(x => x !== field);
|
68
|
-
changed = !!(this.
|
74
|
+
changed = !!(this.interactiveFields_ && (this.completeFields_.length == (this.interactiveFields_.length - 1)));
|
69
75
|
}
|
70
76
|
changed && this.oncomplete && EvaluateLater({
|
71
77
|
componentId: this.componentId_,
|
@@ -100,6 +106,9 @@ export class StripeElement extends CustomElement {
|
|
100
106
|
RemoveStripeField(field) {
|
101
107
|
this.fields_ && (this.fields_ = this.fields_.filter(x => x !== field));
|
102
108
|
this.readyFields_ && (this.readyFields_ = this.readyFields_.filter(x => x !== field));
|
109
|
+
this.interactiveFields_ && (this.interactiveFields_ = this.interactiveFields_.filter(x => x !== field));
|
110
|
+
this.completeFields_ && (this.completeFields_ = this.completeFields_.filter(x => x !== field));
|
111
|
+
this.errorFields_ && (this.errorFields_ = this.errorFields_.filter(x => x !== field));
|
103
112
|
}
|
104
113
|
FocusNextField(field) {
|
105
114
|
if (this.fields_) {
|
@@ -107,12 +116,18 @@ export class StripeElement extends CustomElement {
|
|
107
116
|
(index >= 0 && index < this.fields_.length - 1) && this.fields_[index + 1].ToggleFocus(true);
|
108
117
|
}
|
109
118
|
}
|
119
|
+
GetDetails() {
|
120
|
+
return {
|
121
|
+
stripe: this.stripe_,
|
122
|
+
elements: this.elements_,
|
123
|
+
};
|
124
|
+
}
|
110
125
|
GetInstance() {
|
111
126
|
return this.stripe_;
|
112
127
|
}
|
113
128
|
WaitInstance() {
|
114
129
|
return new Promise(resolve => {
|
115
|
-
this.mounted_ ? resolve(this.
|
130
|
+
this.mounted_ ? resolve(this.GetDetails()) : this.instanceWaiters_.push(() => resolve(this.GetDetails()));
|
116
131
|
});
|
117
132
|
}
|
118
133
|
Mount() {
|
@@ -124,6 +139,7 @@ export class StripeElement extends CustomElement {
|
|
124
139
|
this.mounting_ = false;
|
125
140
|
this.mounted_ = true;
|
126
141
|
this.stripe_ = Stripe(this.publicKey);
|
142
|
+
this.elements_ = this.stripe_.elements();
|
127
143
|
this.instanceWaiters_.splice(0).forEach(waiter => JournalTry(waiter));
|
128
144
|
});
|
129
145
|
}
|
@@ -146,37 +162,37 @@ export class StripeElement extends CustomElement {
|
|
146
162
|
}
|
147
163
|
PayOrSetup_(pay, clientSecret, save = false) {
|
148
164
|
return new Promise((resolve, reject) => {
|
149
|
-
this.WaitInstance().then((
|
165
|
+
this.WaitInstance().then((details) => {
|
150
166
|
var _a, _b;
|
151
|
-
if (!stripe) {
|
167
|
+
if (!(details === null || details === void 0 ? void 0 : details.stripe)) {
|
152
168
|
return resolve(false);
|
153
169
|
}
|
154
|
-
const
|
155
|
-
(_a = this.fields_) === null || _a === void 0 ? void 0 : _a.forEach(field => field.AddDetails(
|
156
|
-
if (!
|
170
|
+
const paymentDetails = {};
|
171
|
+
(_a = this.fields_) === null || _a === void 0 ? void 0 : _a.forEach(field => field.AddDetails(paymentDetails));
|
172
|
+
if (!paymentDetails.method) {
|
157
173
|
return resolve(false);
|
158
174
|
}
|
159
175
|
let cardDetails;
|
160
|
-
if (typeof
|
176
|
+
if (typeof paymentDetails.method !== 'string') {
|
161
177
|
cardDetails = {
|
162
178
|
payment_method: {
|
163
|
-
card:
|
164
|
-
billing_details:
|
179
|
+
card: paymentDetails.method,
|
180
|
+
billing_details: paymentDetails.billingDetails,
|
165
181
|
},
|
166
182
|
};
|
167
183
|
}
|
168
184
|
else {
|
169
185
|
cardDetails = {
|
170
|
-
payment_method:
|
186
|
+
payment_method: paymentDetails.method,
|
171
187
|
};
|
172
188
|
}
|
173
189
|
if (pay) {
|
174
|
-
((_b =
|
190
|
+
((_b = paymentDetails.billingDetails) === null || _b === void 0 ? void 0 : _b.email) && (cardDetails.receipt_email = paymentDetails.billingDetails.email);
|
175
191
|
save && (cardDetails.setup_future_usage = 'off_session');
|
176
|
-
stripe.confirmCardPayment(clientSecret, cardDetails).then(resolve).catch(reject);
|
192
|
+
details.stripe.confirmCardPayment(clientSecret, cardDetails).then(resolve).catch(reject);
|
177
193
|
}
|
178
194
|
else {
|
179
|
-
stripe.confirmCardSetup(clientSecret, cardDetails).then(resolve).catch(reject);
|
195
|
+
details.stripe.confirmCardSetup(clientSecret, cardDetails).then(resolve).catch(reject);
|
180
196
|
}
|
181
197
|
}).catch(reject);
|
182
198
|
});
|
package/lib/esm/types.d.ts
CHANGED
@@ -6,6 +6,7 @@ export interface IStripePaymentDetails {
|
|
6
6
|
export declare type StripeFieldChangeType = 'error' | 'complete';
|
7
7
|
export declare type StripeFieldChangeHandlerType = (type: StripeFieldChangeType, data: any) => void;
|
8
8
|
export interface IStripeField {
|
9
|
+
IsInteractive(): boolean;
|
9
10
|
WaitReady(): Promise<void>;
|
10
11
|
AddChangeListener(listener: StripeFieldChangeHandlerType): void;
|
11
12
|
RemoveChangeListener(listener: StripeFieldChangeHandlerType): void;
|
@@ -13,12 +14,17 @@ export interface IStripeField {
|
|
13
14
|
Reset(): void;
|
14
15
|
AddDetails(details: IStripePaymentDetails): void;
|
15
16
|
}
|
17
|
+
export interface IStripeDetails {
|
18
|
+
stripe: stripe.Stripe | null;
|
19
|
+
elements: stripe.elements.Elements | null;
|
20
|
+
}
|
16
21
|
export interface IStripeElement {
|
17
22
|
options: stripe.elements.ElementsOptions | null;
|
18
23
|
AddStripeField(field: IStripeField): void;
|
19
24
|
RemoveStripeField(field: IStripeField): void;
|
20
25
|
FocusNextField(field: IStripeField): void;
|
26
|
+
GetDetails(): IStripeDetails | null;
|
21
27
|
GetInstance(): stripe.Stripe | null;
|
22
|
-
WaitInstance(): Promise<
|
28
|
+
WaitInstance(): Promise<IStripeDetails | null>;
|
23
29
|
Mount(): void;
|
24
30
|
}
|
package/package.json
CHANGED