@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
@@ -20,7 +20,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.StripeFieldElementCompact = exports.StripeFieldElement = void 0;
|
21
21
|
const inlinejs_1 = require("@benbraide/inlinejs");
|
22
22
|
const inlinejs_element_1 = require("@benbraide/inlinejs-element");
|
23
|
-
|
23
|
+
const generic_field_1 = require("./generic-field");
|
24
|
+
class StripeFieldElement extends generic_field_1.StripeGenericField {
|
24
25
|
constructor() {
|
25
26
|
super();
|
26
27
|
this.stripeField_ = null;
|
@@ -29,13 +30,15 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
|
|
29
30
|
this.lastError_ = null;
|
30
31
|
this.readyWaiters_ = new Array();
|
31
32
|
this.changeListeners = new Array();
|
32
|
-
this.stripe = null;
|
33
33
|
this.options = null;
|
34
34
|
this.type = '';
|
35
35
|
this.onready = '';
|
36
36
|
this.oncomplete = '';
|
37
37
|
this.onerrors = '';
|
38
38
|
}
|
39
|
+
IsInteractive() {
|
40
|
+
return true;
|
41
|
+
}
|
39
42
|
WaitReady() {
|
40
43
|
return new Promise(resolve => {
|
41
44
|
this.isReady_ ? resolve() : this.readyWaiters_.push(() => resolve());
|
@@ -61,16 +64,12 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
|
|
61
64
|
}
|
62
65
|
HandleElementScopeCreated_(_a, postAttributesCallback) {
|
63
66
|
var { scope } = _a, rest = __rest(_a, ["scope"]);
|
64
|
-
super.HandleElementScopeCreated_(Object.assign({ scope }, rest),
|
65
|
-
var _a;
|
66
|
-
(_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.AddStripeField(this);
|
67
|
-
postAttributesCallback && postAttributesCallback();
|
68
|
-
});
|
67
|
+
super.HandleElementScopeCreated_(Object.assign({ scope }, rest), postAttributesCallback);
|
69
68
|
scope.AddPostProcessCallback(() => {
|
70
69
|
var _a;
|
71
|
-
(_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.WaitInstance().then((
|
70
|
+
(_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.WaitInstance().then((details) => {
|
72
71
|
var _a;
|
73
|
-
if (!stripe) {
|
72
|
+
if (!(details === null || details === void 0 ? void 0 : details.stripe)) {
|
74
73
|
return;
|
75
74
|
}
|
76
75
|
let type = '';
|
@@ -80,8 +79,8 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
|
|
80
79
|
else if (['card', 'cardNumber', 'cardExpiry', 'cardCvc', 'postalCode', 'paymentRequestButton', 'iban', 'idealBank'].includes(this.type)) {
|
81
80
|
type = this.type;
|
82
81
|
}
|
83
|
-
if (type) {
|
84
|
-
this.stripeField_ =
|
82
|
+
if (type && details.elements) {
|
83
|
+
this.stripeField_ = details.elements.create(type, (this.options || ((_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.options) || undefined));
|
85
84
|
this.stripeField_.on('ready', () => {
|
86
85
|
this.isReady_ = true;
|
87
86
|
this.onready && (0, inlinejs_1.EvaluateLater)({
|
@@ -124,13 +123,7 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
|
|
124
123
|
this.stripeField_ = null;
|
125
124
|
});
|
126
125
|
}
|
127
|
-
GetStripe_() {
|
128
|
-
return (this.stripe || (0, inlinejs_1.FindAncestor)(this, ancestor => ('AddStripeField' in ancestor)));
|
129
|
-
}
|
130
126
|
}
|
131
|
-
__decorate([
|
132
|
-
(0, inlinejs_element_1.Property)({ type: 'object', checkStoredObject: true })
|
133
|
-
], StripeFieldElement.prototype, "stripe", void 0);
|
134
127
|
__decorate([
|
135
128
|
(0, inlinejs_element_1.Property)({ type: 'object', checkStoredObject: true })
|
136
129
|
], StripeFieldElement.prototype, "options", void 0);
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { IElementScopeCreatedCallbackParams } from "@benbraide/inlinejs";
|
2
|
+
import { CustomElement } from "@benbraide/inlinejs-element";
|
3
|
+
import { IStripeElement, IStripeField, IStripePaymentDetails, StripeFieldChangeHandlerType } from "../types";
|
4
|
+
export declare class StripeGenericField extends CustomElement implements IStripeField {
|
5
|
+
stripe: IStripeElement | null;
|
6
|
+
IsInteractive(): boolean;
|
7
|
+
WaitReady(): Promise<void>;
|
8
|
+
AddChangeListener(listener: StripeFieldChangeHandlerType): void;
|
9
|
+
RemoveChangeListener(listener: StripeFieldChangeHandlerType): void;
|
10
|
+
ToggleFocus(focused: boolean): void;
|
11
|
+
Reset(): void;
|
12
|
+
AddDetails(details: IStripePaymentDetails): void;
|
13
|
+
protected HandleElementScopeCreated_({ scope, ...rest }: IElementScopeCreatedCallbackParams, postAttributesCallback?: () => void): void;
|
14
|
+
protected GetStripe_(): IStripeElement | null;
|
15
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7
|
+
};
|
8
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
9
|
+
var t = {};
|
10
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
11
|
+
t[p] = s[p];
|
12
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
13
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
14
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
15
|
+
t[p[i]] = s[p[i]];
|
16
|
+
}
|
17
|
+
return t;
|
18
|
+
};
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
20
|
+
exports.StripeGenericField = void 0;
|
21
|
+
const inlinejs_1 = require("@benbraide/inlinejs");
|
22
|
+
const inlinejs_element_1 = require("@benbraide/inlinejs-element");
|
23
|
+
class StripeGenericField extends inlinejs_element_1.CustomElement {
|
24
|
+
constructor() {
|
25
|
+
super(...arguments);
|
26
|
+
this.stripe = null;
|
27
|
+
}
|
28
|
+
IsInteractive() {
|
29
|
+
return false;
|
30
|
+
}
|
31
|
+
WaitReady() {
|
32
|
+
return Promise.resolve();
|
33
|
+
}
|
34
|
+
AddChangeListener(listener) { }
|
35
|
+
RemoveChangeListener(listener) { }
|
36
|
+
ToggleFocus(focused) { }
|
37
|
+
Reset() { }
|
38
|
+
AddDetails(details) { }
|
39
|
+
HandleElementScopeCreated_(_a, postAttributesCallback) {
|
40
|
+
var { scope } = _a, rest = __rest(_a, ["scope"]);
|
41
|
+
super.HandleElementScopeCreated_(Object.assign({ scope }, rest), () => {
|
42
|
+
var _a;
|
43
|
+
(_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.AddStripeField(this);
|
44
|
+
postAttributesCallback && postAttributesCallback();
|
45
|
+
});
|
46
|
+
}
|
47
|
+
GetStripe_() {
|
48
|
+
return (this.stripe || (0, inlinejs_1.FindAncestor)(this, ancestor => ('AddStripeField' in ancestor)));
|
49
|
+
}
|
50
|
+
}
|
51
|
+
__decorate([
|
52
|
+
(0, inlinejs_element_1.Property)({ type: 'object', checkStoredObject: true })
|
53
|
+
], StripeGenericField.prototype, "stripe", void 0);
|
54
|
+
exports.StripeGenericField = StripeGenericField;
|
@@ -1,14 +1,9 @@
|
|
1
1
|
/// <reference types="stripe-v3" />
|
2
|
-
import {
|
3
|
-
import {
|
4
|
-
export declare class StripePaymentMenthodElement extends
|
2
|
+
import { IStripePaymentDetails } from "../types";
|
3
|
+
import { StripeGenericField } from "./generic-field";
|
4
|
+
export declare class StripePaymentMenthodElement extends StripeGenericField {
|
5
5
|
value: stripe.elements.Element | string;
|
6
6
|
constructor();
|
7
|
-
WaitReady(): Promise<void>;
|
8
|
-
AddChangeListener(listener: StripeFieldChangeHandlerType): void;
|
9
|
-
RemoveChangeListener(listener: StripeFieldChangeHandlerType): void;
|
10
|
-
ToggleFocus(focused: boolean): void;
|
11
|
-
Reset(): void;
|
12
7
|
AddDetails(details: IStripePaymentDetails): void;
|
13
8
|
}
|
14
9
|
export declare function StripePaymentMenthodElementCompact(): void;
|
@@ -8,7 +8,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
9
9
|
exports.StripePaymentMenthodElementCompact = exports.StripePaymentMenthodElement = void 0;
|
10
10
|
const inlinejs_element_1 = require("@benbraide/inlinejs-element");
|
11
|
-
|
11
|
+
const generic_field_1 = require("./generic-field");
|
12
|
+
class StripePaymentMenthodElement extends generic_field_1.StripeGenericField {
|
12
13
|
constructor() {
|
13
14
|
super({
|
14
15
|
isTemplate: true,
|
@@ -16,13 +17,6 @@ class StripePaymentMenthodElement extends inlinejs_element_1.CustomElement {
|
|
16
17
|
});
|
17
18
|
this.value = '';
|
18
19
|
}
|
19
|
-
WaitReady() {
|
20
|
-
return Promise.resolve();
|
21
|
-
}
|
22
|
-
AddChangeListener(listener) { }
|
23
|
-
RemoveChangeListener(listener) { }
|
24
|
-
ToggleFocus(focused) { }
|
25
|
-
Reset() { }
|
26
20
|
AddDetails(details) {
|
27
21
|
this.value && (details.method = this.value);
|
28
22
|
}
|
@@ -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>;
|
@@ -24,6 +24,7 @@ class StripeElement extends inlinejs_element_1.CustomElement {
|
|
24
24
|
constructor() {
|
25
25
|
super();
|
26
26
|
this.stripe_ = null;
|
27
|
+
this.elements_ = null;
|
27
28
|
this.mounting_ = false;
|
28
29
|
this.mounted_ = false;
|
29
30
|
this.isReady_ = false;
|
@@ -31,6 +32,7 @@ class StripeElement extends inlinejs_element_1.CustomElement {
|
|
31
32
|
this.fields_ = null;
|
32
33
|
this.readyFields_ = null;
|
33
34
|
this.instanceWaiters_ = new Array();
|
35
|
+
this.interactiveFields_ = null;
|
34
36
|
this.completeFields_ = null;
|
35
37
|
this.errorFields_ = null;
|
36
38
|
this.options = null;
|
@@ -47,6 +49,10 @@ class StripeElement extends inlinejs_element_1.CustomElement {
|
|
47
49
|
field.WaitReady().then(() => {
|
48
50
|
this.readyFields_ = (this.readyFields_ || []);
|
49
51
|
this.readyFields_.push(field);
|
52
|
+
if (field.IsInteractive()) {
|
53
|
+
this.interactiveFields_ = (this.interactiveFields_ || []);
|
54
|
+
this.interactiveFields_.push(field);
|
55
|
+
}
|
50
56
|
(this.fields_ && this.readyFields_ && this.fields_.length <= this.readyFields_.length) && (0, inlinejs_1.JournalTry)(() => {
|
51
57
|
this.isReady_ = true;
|
52
58
|
this.onready && (0, inlinejs_1.EvaluateLater)({
|
@@ -64,11 +70,11 @@ class StripeElement extends inlinejs_element_1.CustomElement {
|
|
64
70
|
this.completeFields_ = (this.completeFields_ || []);
|
65
71
|
if (data && !this.completeFields_.includes(field)) {
|
66
72
|
this.completeFields_.push(field);
|
67
|
-
changed = !!(this.
|
73
|
+
changed = !!(this.interactiveFields_ && this.completeFields_.length == this.interactiveFields_.length);
|
68
74
|
}
|
69
75
|
else if (!data && this.completeFields_.includes(field)) {
|
70
76
|
this.completeFields_ = this.completeFields_.filter(x => x !== field);
|
71
|
-
changed = !!(this.
|
77
|
+
changed = !!(this.interactiveFields_ && (this.completeFields_.length == (this.interactiveFields_.length - 1)));
|
72
78
|
}
|
73
79
|
changed && this.oncomplete && (0, inlinejs_1.EvaluateLater)({
|
74
80
|
componentId: this.componentId_,
|
@@ -103,6 +109,9 @@ class StripeElement extends inlinejs_element_1.CustomElement {
|
|
103
109
|
RemoveStripeField(field) {
|
104
110
|
this.fields_ && (this.fields_ = this.fields_.filter(x => x !== field));
|
105
111
|
this.readyFields_ && (this.readyFields_ = this.readyFields_.filter(x => x !== field));
|
112
|
+
this.interactiveFields_ && (this.interactiveFields_ = this.interactiveFields_.filter(x => x !== field));
|
113
|
+
this.completeFields_ && (this.completeFields_ = this.completeFields_.filter(x => x !== field));
|
114
|
+
this.errorFields_ && (this.errorFields_ = this.errorFields_.filter(x => x !== field));
|
106
115
|
}
|
107
116
|
FocusNextField(field) {
|
108
117
|
if (this.fields_) {
|
@@ -110,12 +119,18 @@ class StripeElement extends inlinejs_element_1.CustomElement {
|
|
110
119
|
(index >= 0 && index < this.fields_.length - 1) && this.fields_[index + 1].ToggleFocus(true);
|
111
120
|
}
|
112
121
|
}
|
122
|
+
GetDetails() {
|
123
|
+
return {
|
124
|
+
stripe: this.stripe_,
|
125
|
+
elements: this.elements_,
|
126
|
+
};
|
127
|
+
}
|
113
128
|
GetInstance() {
|
114
129
|
return this.stripe_;
|
115
130
|
}
|
116
131
|
WaitInstance() {
|
117
132
|
return new Promise(resolve => {
|
118
|
-
this.mounted_ ? resolve(this.
|
133
|
+
this.mounted_ ? resolve(this.GetDetails()) : this.instanceWaiters_.push(() => resolve(this.GetDetails()));
|
119
134
|
});
|
120
135
|
}
|
121
136
|
Mount() {
|
@@ -127,6 +142,7 @@ class StripeElement extends inlinejs_element_1.CustomElement {
|
|
127
142
|
this.mounting_ = false;
|
128
143
|
this.mounted_ = true;
|
129
144
|
this.stripe_ = Stripe(this.publicKey);
|
145
|
+
this.elements_ = this.stripe_.elements();
|
130
146
|
this.instanceWaiters_.splice(0).forEach(waiter => (0, inlinejs_1.JournalTry)(waiter));
|
131
147
|
});
|
132
148
|
}
|
@@ -149,37 +165,37 @@ class StripeElement extends inlinejs_element_1.CustomElement {
|
|
149
165
|
}
|
150
166
|
PayOrSetup_(pay, clientSecret, save = false) {
|
151
167
|
return new Promise((resolve, reject) => {
|
152
|
-
this.WaitInstance().then((
|
168
|
+
this.WaitInstance().then((details) => {
|
153
169
|
var _a, _b;
|
154
|
-
if (!stripe) {
|
170
|
+
if (!(details === null || details === void 0 ? void 0 : details.stripe)) {
|
155
171
|
return resolve(false);
|
156
172
|
}
|
157
|
-
const
|
158
|
-
(_a = this.fields_) === null || _a === void 0 ? void 0 : _a.forEach(field => field.AddDetails(
|
159
|
-
if (!
|
173
|
+
const paymentDetails = {};
|
174
|
+
(_a = this.fields_) === null || _a === void 0 ? void 0 : _a.forEach(field => field.AddDetails(paymentDetails));
|
175
|
+
if (!paymentDetails.method) {
|
160
176
|
return resolve(false);
|
161
177
|
}
|
162
178
|
let cardDetails;
|
163
|
-
if (typeof
|
179
|
+
if (typeof paymentDetails.method !== 'string') {
|
164
180
|
cardDetails = {
|
165
181
|
payment_method: {
|
166
|
-
card:
|
167
|
-
billing_details:
|
182
|
+
card: paymentDetails.method,
|
183
|
+
billing_details: paymentDetails.billingDetails,
|
168
184
|
},
|
169
185
|
};
|
170
186
|
}
|
171
187
|
else {
|
172
188
|
cardDetails = {
|
173
|
-
payment_method:
|
189
|
+
payment_method: paymentDetails.method,
|
174
190
|
};
|
175
191
|
}
|
176
192
|
if (pay) {
|
177
|
-
((_b =
|
193
|
+
((_b = paymentDetails.billingDetails) === null || _b === void 0 ? void 0 : _b.email) && (cardDetails.receipt_email = paymentDetails.billingDetails.email);
|
178
194
|
save && (cardDetails.setup_future_usage = 'off_session');
|
179
|
-
stripe.confirmCardPayment(clientSecret, cardDetails).then(resolve).catch(reject);
|
195
|
+
details.stripe.confirmCardPayment(clientSecret, cardDetails).then(resolve).catch(reject);
|
180
196
|
}
|
181
197
|
else {
|
182
|
-
stripe.confirmCardSetup(clientSecret, cardDetails).then(resolve).catch(reject);
|
198
|
+
details.stripe.confirmCardSetup(clientSecret, cardDetails).then(resolve).catch(reject);
|
183
199
|
}
|
184
200
|
}).catch(reject);
|
185
201
|
});
|
package/lib/common/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
|
}
|
@@ -1,13 +1,10 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
export declare class StripeDetailElement extends
|
1
|
+
import { IStripePaymentDetails } from "../types";
|
2
|
+
import { StripeGenericField } from "./generic-field";
|
3
|
+
export declare class StripeDetailElement extends StripeGenericField {
|
4
4
|
input: HTMLInputElement | null;
|
5
5
|
name: string;
|
6
6
|
value: string;
|
7
7
|
constructor();
|
8
|
-
WaitReady(): Promise<void>;
|
9
|
-
AddChangeListener(listener: StripeFieldChangeHandlerType): void;
|
10
|
-
RemoveChangeListener(listener: StripeFieldChangeHandlerType): void;
|
11
8
|
ToggleFocus(focused: boolean): void;
|
12
9
|
Reset(): void;
|
13
10
|
AddDetails(details: IStripePaymentDetails): void;
|
@@ -4,19 +4,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
6
|
};
|
7
|
-
import {
|
8
|
-
|
7
|
+
import { Property, RegisterCustomElement } from "@benbraide/inlinejs-element";
|
8
|
+
import { StripeGenericField } from "./generic-field";
|
9
|
+
export class StripeDetailElement extends StripeGenericField {
|
9
10
|
constructor() {
|
10
11
|
super();
|
11
12
|
this.input = null;
|
12
13
|
this.name = '';
|
13
14
|
this.value = '';
|
14
15
|
}
|
15
|
-
WaitReady() {
|
16
|
-
return Promise.resolve();
|
17
|
-
}
|
18
|
-
AddChangeListener(listener) { }
|
19
|
-
RemoveChangeListener(listener) { }
|
20
16
|
ToggleFocus(focused) {
|
21
17
|
const input = this.GetInput_();
|
22
18
|
input && (focused ? input.focus() : input.blur());
|
@@ -1,21 +1,21 @@
|
|
1
1
|
/// <reference types="stripe-v3" />
|
2
2
|
import { IElementScopeCreatedCallbackParams } from "@benbraide/inlinejs";
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
export declare class StripeFieldElement extends
|
3
|
+
import { IStripePaymentDetails, StripeFieldChangeHandlerType } from "../types";
|
4
|
+
import { StripeGenericField } from "./generic-field";
|
5
|
+
export declare class StripeFieldElement extends StripeGenericField {
|
6
6
|
protected stripeField_: stripe.elements.Element | null;
|
7
7
|
protected isReady_: boolean;
|
8
8
|
protected isComplete_: boolean;
|
9
9
|
protected lastError_: stripe.Error | null;
|
10
10
|
protected readyWaiters_: (() => void)[];
|
11
11
|
protected changeListeners: StripeFieldChangeHandlerType[];
|
12
|
-
stripe: IStripeElement | null;
|
13
12
|
options: stripe.elements.ElementsOptions | null;
|
14
13
|
type: string;
|
15
14
|
onready: string;
|
16
15
|
oncomplete: string;
|
17
16
|
onerrors: string;
|
18
17
|
constructor();
|
18
|
+
IsInteractive(): boolean;
|
19
19
|
WaitReady(): Promise<void>;
|
20
20
|
AddChangeListener(listener: StripeFieldChangeHandlerType): void;
|
21
21
|
RemoveChangeListener(listener: StripeFieldChangeHandlerType): void;
|
@@ -23,6 +23,5 @@ export declare class StripeFieldElement extends CustomElement implements IStripe
|
|
23
23
|
Reset(): void;
|
24
24
|
AddDetails(details: IStripePaymentDetails): void;
|
25
25
|
protected HandleElementScopeCreated_({ scope, ...rest }: IElementScopeCreatedCallbackParams, postAttributesCallback?: () => void): void;
|
26
|
-
protected GetStripe_(): IStripeElement | null;
|
27
26
|
}
|
28
27
|
export declare function StripeFieldElementCompact(): void;
|
@@ -15,9 +15,10 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
15
15
|
}
|
16
16
|
return t;
|
17
17
|
};
|
18
|
-
import { EvaluateLater,
|
19
|
-
import {
|
20
|
-
|
18
|
+
import { EvaluateLater, JournalTry } from "@benbraide/inlinejs";
|
19
|
+
import { Property, RegisterCustomElement } from "@benbraide/inlinejs-element";
|
20
|
+
import { StripeGenericField } from "./generic-field";
|
21
|
+
export class StripeFieldElement extends StripeGenericField {
|
21
22
|
constructor() {
|
22
23
|
super();
|
23
24
|
this.stripeField_ = null;
|
@@ -26,13 +27,15 @@ export class StripeFieldElement extends CustomElement {
|
|
26
27
|
this.lastError_ = null;
|
27
28
|
this.readyWaiters_ = new Array();
|
28
29
|
this.changeListeners = new Array();
|
29
|
-
this.stripe = null;
|
30
30
|
this.options = null;
|
31
31
|
this.type = '';
|
32
32
|
this.onready = '';
|
33
33
|
this.oncomplete = '';
|
34
34
|
this.onerrors = '';
|
35
35
|
}
|
36
|
+
IsInteractive() {
|
37
|
+
return true;
|
38
|
+
}
|
36
39
|
WaitReady() {
|
37
40
|
return new Promise(resolve => {
|
38
41
|
this.isReady_ ? resolve() : this.readyWaiters_.push(() => resolve());
|
@@ -58,16 +61,12 @@ export class StripeFieldElement extends CustomElement {
|
|
58
61
|
}
|
59
62
|
HandleElementScopeCreated_(_a, postAttributesCallback) {
|
60
63
|
var { scope } = _a, rest = __rest(_a, ["scope"]);
|
61
|
-
super.HandleElementScopeCreated_(Object.assign({ scope }, rest),
|
62
|
-
var _a;
|
63
|
-
(_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.AddStripeField(this);
|
64
|
-
postAttributesCallback && postAttributesCallback();
|
65
|
-
});
|
64
|
+
super.HandleElementScopeCreated_(Object.assign({ scope }, rest), postAttributesCallback);
|
66
65
|
scope.AddPostProcessCallback(() => {
|
67
66
|
var _a;
|
68
|
-
(_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.WaitInstance().then((
|
67
|
+
(_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.WaitInstance().then((details) => {
|
69
68
|
var _a;
|
70
|
-
if (!stripe) {
|
69
|
+
if (!(details === null || details === void 0 ? void 0 : details.stripe)) {
|
71
70
|
return;
|
72
71
|
}
|
73
72
|
let type = '';
|
@@ -77,8 +76,8 @@ export class StripeFieldElement extends CustomElement {
|
|
77
76
|
else if (['card', 'cardNumber', 'cardExpiry', 'cardCvc', 'postalCode', 'paymentRequestButton', 'iban', 'idealBank'].includes(this.type)) {
|
78
77
|
type = this.type;
|
79
78
|
}
|
80
|
-
if (type) {
|
81
|
-
this.stripeField_ =
|
79
|
+
if (type && details.elements) {
|
80
|
+
this.stripeField_ = details.elements.create(type, (this.options || ((_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.options) || undefined));
|
82
81
|
this.stripeField_.on('ready', () => {
|
83
82
|
this.isReady_ = true;
|
84
83
|
this.onready && EvaluateLater({
|
@@ -121,13 +120,7 @@ export class StripeFieldElement extends CustomElement {
|
|
121
120
|
this.stripeField_ = null;
|
122
121
|
});
|
123
122
|
}
|
124
|
-
GetStripe_() {
|
125
|
-
return (this.stripe || FindAncestor(this, ancestor => ('AddStripeField' in ancestor)));
|
126
|
-
}
|
127
123
|
}
|
128
|
-
__decorate([
|
129
|
-
Property({ type: 'object', checkStoredObject: true })
|
130
|
-
], StripeFieldElement.prototype, "stripe", void 0);
|
131
124
|
__decorate([
|
132
125
|
Property({ type: 'object', checkStoredObject: true })
|
133
126
|
], StripeFieldElement.prototype, "options", void 0);
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { IElementScopeCreatedCallbackParams } from "@benbraide/inlinejs";
|
2
|
+
import { CustomElement } from "@benbraide/inlinejs-element";
|
3
|
+
import { IStripeElement, IStripeField, IStripePaymentDetails, StripeFieldChangeHandlerType } from "../types";
|
4
|
+
export declare class StripeGenericField extends CustomElement implements IStripeField {
|
5
|
+
stripe: IStripeElement | null;
|
6
|
+
IsInteractive(): boolean;
|
7
|
+
WaitReady(): Promise<void>;
|
8
|
+
AddChangeListener(listener: StripeFieldChangeHandlerType): void;
|
9
|
+
RemoveChangeListener(listener: StripeFieldChangeHandlerType): void;
|
10
|
+
ToggleFocus(focused: boolean): void;
|
11
|
+
Reset(): void;
|
12
|
+
AddDetails(details: IStripePaymentDetails): void;
|
13
|
+
protected HandleElementScopeCreated_({ scope, ...rest }: IElementScopeCreatedCallbackParams, postAttributesCallback?: () => void): void;
|
14
|
+
protected GetStripe_(): IStripeElement | null;
|
15
|
+
}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
|
+
};
|
7
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
8
|
+
var t = {};
|
9
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
10
|
+
t[p] = s[p];
|
11
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
12
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
13
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
14
|
+
t[p[i]] = s[p[i]];
|
15
|
+
}
|
16
|
+
return t;
|
17
|
+
};
|
18
|
+
import { FindAncestor } from "@benbraide/inlinejs";
|
19
|
+
import { CustomElement, Property } from "@benbraide/inlinejs-element";
|
20
|
+
export class StripeGenericField extends CustomElement {
|
21
|
+
constructor() {
|
22
|
+
super(...arguments);
|
23
|
+
this.stripe = null;
|
24
|
+
}
|
25
|
+
IsInteractive() {
|
26
|
+
return false;
|
27
|
+
}
|
28
|
+
WaitReady() {
|
29
|
+
return Promise.resolve();
|
30
|
+
}
|
31
|
+
AddChangeListener(listener) { }
|
32
|
+
RemoveChangeListener(listener) { }
|
33
|
+
ToggleFocus(focused) { }
|
34
|
+
Reset() { }
|
35
|
+
AddDetails(details) { }
|
36
|
+
HandleElementScopeCreated_(_a, postAttributesCallback) {
|
37
|
+
var { scope } = _a, rest = __rest(_a, ["scope"]);
|
38
|
+
super.HandleElementScopeCreated_(Object.assign({ scope }, rest), () => {
|
39
|
+
var _a;
|
40
|
+
(_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.AddStripeField(this);
|
41
|
+
postAttributesCallback && postAttributesCallback();
|
42
|
+
});
|
43
|
+
}
|
44
|
+
GetStripe_() {
|
45
|
+
return (this.stripe || FindAncestor(this, ancestor => ('AddStripeField' in ancestor)));
|
46
|
+
}
|
47
|
+
}
|
48
|
+
__decorate([
|
49
|
+
Property({ type: 'object', checkStoredObject: true })
|
50
|
+
], StripeGenericField.prototype, "stripe", void 0);
|
@@ -1,14 +1,9 @@
|
|
1
1
|
/// <reference types="stripe-v3" />
|
2
|
-
import {
|
3
|
-
import {
|
4
|
-
export declare class StripePaymentMenthodElement extends
|
2
|
+
import { IStripePaymentDetails } from "../types";
|
3
|
+
import { StripeGenericField } from "./generic-field";
|
4
|
+
export declare class StripePaymentMenthodElement extends StripeGenericField {
|
5
5
|
value: stripe.elements.Element | string;
|
6
6
|
constructor();
|
7
|
-
WaitReady(): Promise<void>;
|
8
|
-
AddChangeListener(listener: StripeFieldChangeHandlerType): void;
|
9
|
-
RemoveChangeListener(listener: StripeFieldChangeHandlerType): void;
|
10
|
-
ToggleFocus(focused: boolean): void;
|
11
|
-
Reset(): void;
|
12
7
|
AddDetails(details: IStripePaymentDetails): void;
|
13
8
|
}
|
14
9
|
export declare function StripePaymentMenthodElementCompact(): void;
|
@@ -4,8 +4,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
6
|
};
|
7
|
-
import {
|
8
|
-
|
7
|
+
import { Property, RegisterCustomElement } from "@benbraide/inlinejs-element";
|
8
|
+
import { StripeGenericField } from "./generic-field";
|
9
|
+
export class StripePaymentMenthodElement extends StripeGenericField {
|
9
10
|
constructor() {
|
10
11
|
super({
|
11
12
|
isTemplate: true,
|
@@ -13,13 +14,6 @@ export class StripePaymentMenthodElement extends CustomElement {
|
|
13
14
|
});
|
14
15
|
this.value = '';
|
15
16
|
}
|
16
|
-
WaitReady() {
|
17
|
-
return Promise.resolve();
|
18
|
-
}
|
19
|
-
AddChangeListener(listener) { }
|
20
|
-
RemoveChangeListener(listener) { }
|
21
|
-
ToggleFocus(focused) { }
|
22
|
-
Reset() { }
|
23
17
|
AddDetails(details) {
|
24
18
|
this.value && (details.method = this.value);
|
25
19
|
}
|