@benbraide/inlinejs-stripe 2.0.3 → 2.0.5
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/inlinejs-stripe.js +94 -45
- 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 +3 -5
- package/lib/common/components/field.js +7 -17
- package/lib/common/components/generic-field.d.ts +14 -0
- package/lib/common/components/generic-field.js +51 -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 +4 -2
- package/lib/common/components/stripe.js +22 -14
- package/lib/common/types.d.ts +6 -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 +3 -5
- package/lib/esm/components/field.js +9 -19
- package/lib/esm/components/generic-field.d.ts +14 -0
- package/lib/esm/components/generic-field.js +47 -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 +4 -2
- package/lib/esm/components/stripe.js +22 -14
- package/lib/esm/types.d.ts +6 -1
- package/package.json +1 -1
@@ -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;
|
@@ -65,7 +66,7 @@ export class StripeElement extends CustomElement {
|
|
65
66
|
}
|
66
67
|
else if (!data && this.completeFields_.includes(field)) {
|
67
68
|
this.completeFields_ = this.completeFields_.filter(x => x !== field);
|
68
|
-
changed = (this.completeFields_.length ==
|
69
|
+
changed = !!(this.readyFields_ && (this.completeFields_.length == (this.readyFields_.length - 1)));
|
69
70
|
}
|
70
71
|
changed && this.oncomplete && EvaluateLater({
|
71
72
|
componentId: this.componentId_,
|
@@ -107,12 +108,18 @@ export class StripeElement extends CustomElement {
|
|
107
108
|
(index >= 0 && index < this.fields_.length - 1) && this.fields_[index + 1].ToggleFocus(true);
|
108
109
|
}
|
109
110
|
}
|
111
|
+
GetDetails() {
|
112
|
+
return {
|
113
|
+
stripe: this.stripe_,
|
114
|
+
elements: this.elements_,
|
115
|
+
};
|
116
|
+
}
|
110
117
|
GetInstance() {
|
111
118
|
return this.stripe_;
|
112
119
|
}
|
113
120
|
WaitInstance() {
|
114
121
|
return new Promise(resolve => {
|
115
|
-
this.mounted_ ? resolve(this.
|
122
|
+
this.mounted_ ? resolve(this.GetDetails()) : this.instanceWaiters_.push(() => resolve(this.GetDetails()));
|
116
123
|
});
|
117
124
|
}
|
118
125
|
Mount() {
|
@@ -124,6 +131,7 @@ export class StripeElement extends CustomElement {
|
|
124
131
|
this.mounting_ = false;
|
125
132
|
this.mounted_ = true;
|
126
133
|
this.stripe_ = Stripe(this.publicKey);
|
134
|
+
this.elements_ = this.stripe_.elements();
|
127
135
|
this.instanceWaiters_.splice(0).forEach(waiter => JournalTry(waiter));
|
128
136
|
});
|
129
137
|
}
|
@@ -146,37 +154,37 @@ export class StripeElement extends CustomElement {
|
|
146
154
|
}
|
147
155
|
PayOrSetup_(pay, clientSecret, save = false) {
|
148
156
|
return new Promise((resolve, reject) => {
|
149
|
-
this.WaitInstance().then((
|
157
|
+
this.WaitInstance().then((details) => {
|
150
158
|
var _a, _b;
|
151
|
-
if (!stripe) {
|
159
|
+
if (!(details === null || details === void 0 ? void 0 : details.stripe)) {
|
152
160
|
return resolve(false);
|
153
161
|
}
|
154
|
-
const
|
155
|
-
(_a = this.fields_) === null || _a === void 0 ? void 0 : _a.forEach(field => field.AddDetails(
|
156
|
-
if (!
|
162
|
+
const paymentDetails = {};
|
163
|
+
(_a = this.fields_) === null || _a === void 0 ? void 0 : _a.forEach(field => field.AddDetails(paymentDetails));
|
164
|
+
if (!paymentDetails.method) {
|
157
165
|
return resolve(false);
|
158
166
|
}
|
159
167
|
let cardDetails;
|
160
|
-
if (typeof
|
168
|
+
if (typeof paymentDetails.method !== 'string') {
|
161
169
|
cardDetails = {
|
162
170
|
payment_method: {
|
163
|
-
card:
|
164
|
-
billing_details:
|
171
|
+
card: paymentDetails.method,
|
172
|
+
billing_details: paymentDetails.billingDetails,
|
165
173
|
},
|
166
174
|
};
|
167
175
|
}
|
168
176
|
else {
|
169
177
|
cardDetails = {
|
170
|
-
payment_method:
|
178
|
+
payment_method: paymentDetails.method,
|
171
179
|
};
|
172
180
|
}
|
173
181
|
if (pay) {
|
174
|
-
((_b =
|
182
|
+
((_b = paymentDetails.billingDetails) === null || _b === void 0 ? void 0 : _b.email) && (cardDetails.receipt_email = paymentDetails.billingDetails.email);
|
175
183
|
save && (cardDetails.setup_future_usage = 'off_session');
|
176
|
-
stripe.confirmCardPayment(clientSecret, cardDetails).then(resolve).catch(reject);
|
184
|
+
details.stripe.confirmCardPayment(clientSecret, cardDetails).then(resolve).catch(reject);
|
177
185
|
}
|
178
186
|
else {
|
179
|
-
stripe.confirmCardSetup(clientSecret, cardDetails).then(resolve).catch(reject);
|
187
|
+
details.stripe.confirmCardSetup(clientSecret, cardDetails).then(resolve).catch(reject);
|
180
188
|
}
|
181
189
|
}).catch(reject);
|
182
190
|
});
|
package/lib/esm/types.d.ts
CHANGED
@@ -13,12 +13,17 @@ export interface IStripeField {
|
|
13
13
|
Reset(): void;
|
14
14
|
AddDetails(details: IStripePaymentDetails): void;
|
15
15
|
}
|
16
|
+
export interface IStripeDetails {
|
17
|
+
stripe: stripe.Stripe | null;
|
18
|
+
elements: stripe.elements.Elements | null;
|
19
|
+
}
|
16
20
|
export interface IStripeElement {
|
17
21
|
options: stripe.elements.ElementsOptions | null;
|
18
22
|
AddStripeField(field: IStripeField): void;
|
19
23
|
RemoveStripeField(field: IStripeField): void;
|
20
24
|
FocusNextField(field: IStripeField): void;
|
25
|
+
GetDetails(): IStripeDetails | null;
|
21
26
|
GetInstance(): stripe.Stripe | null;
|
22
|
-
WaitInstance(): Promise<
|
27
|
+
WaitInstance(): Promise<IStripeDetails | null>;
|
23
28
|
Mount(): void;
|
24
29
|
}
|
package/package.json
CHANGED