@benbraide/inlinejs-stripe 1.0.8 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,141 @@
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.StripeFieldElementCompact = exports.StripeFieldElement = void 0;
21
+ const inlinejs_1 = require("@benbraide/inlinejs");
22
+ const inlinejs_element_1 = require("@benbraide/inlinejs-element");
23
+ class StripeFieldElement extends inlinejs_element_1.CustomElement {
24
+ constructor() {
25
+ super();
26
+ this.stripeField_ = null;
27
+ this.isReady_ = false;
28
+ this.readyWaiters_ = new Array();
29
+ this.stripe = null;
30
+ this.options = null;
31
+ this.type = '';
32
+ this.onready = '';
33
+ this.oncomplete = '';
34
+ this.onerrors = '';
35
+ }
36
+ WaitReady() {
37
+ return new Promise(resolve => {
38
+ this.isReady_ ? resolve() : this.readyWaiters_.push(() => resolve());
39
+ });
40
+ }
41
+ ToggleFocus(focused) {
42
+ var _a, _b;
43
+ (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()));
44
+ }
45
+ Reset() {
46
+ var _a;
47
+ this.stripeField_ && ((_a = this.stripeField_) === null || _a === void 0 ? void 0 : _a.clear());
48
+ }
49
+ AddDetails(details) {
50
+ (this.stripeField_ && (this.type === 'card' || this.type === 'number' || this.type === 'cardNumber')) && (details.method = this.stripeField_);
51
+ }
52
+ HandleElementScopeCreated_(_a, postAttributesCallback) {
53
+ var { scope } = _a, rest = __rest(_a, ["scope"]);
54
+ super.HandleElementScopeCreated_(Object.assign({ scope }, rest), () => {
55
+ var _a;
56
+ (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.AddStripeField(this);
57
+ postAttributesCallback && postAttributesCallback();
58
+ });
59
+ scope.AddPostProcessCallback(() => {
60
+ var _a;
61
+ (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.WaitInstance().then((stripe) => {
62
+ var _a;
63
+ if (!stripe) {
64
+ return;
65
+ }
66
+ let type = '';
67
+ if (['number', 'expiry', 'cvc'].includes(this.type)) {
68
+ type = `card${this.type.substring(0, 1).toUpperCase()}${this.type.substring(1)}`;
69
+ }
70
+ else if (['card', 'cardNumber', 'cardExpiry', 'cardCvc', 'postalCode', 'paymentRequestButton', 'iban', 'idealBank'].includes(this.type)) {
71
+ type = this.type;
72
+ }
73
+ if (type) {
74
+ this.stripeField_ = stripe.elements().create(type, (this.options || ((_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.options) || undefined));
75
+ this.stripeField_.on('ready', () => {
76
+ this.isReady_ = true;
77
+ this.onready && (0, inlinejs_1.EvaluateLater)({
78
+ componentId: this.componentId_,
79
+ contextElement: this,
80
+ expression: this.onready,
81
+ disableFunctionCall: false,
82
+ })();
83
+ this.readyWaiters_.splice(0).forEach(waiter => (0, inlinejs_1.JournalTry)(waiter));
84
+ });
85
+ this.stripeField_.on('change', (event) => {
86
+ var _a;
87
+ if (event === null || event === void 0 ? void 0 : event.error) {
88
+ (0, inlinejs_1.EvaluateLater)({
89
+ componentId: this.componentId_,
90
+ contextElement: this,
91
+ expression: this.onerrors,
92
+ disableFunctionCall: false,
93
+ })(undefined, [], { error: event.error });
94
+ }
95
+ else if (event === null || event === void 0 ? void 0 : event.complete) {
96
+ (0, inlinejs_1.EvaluateLater)({
97
+ componentId: this.componentId_,
98
+ contextElement: this,
99
+ expression: this.oncomplete,
100
+ disableFunctionCall: false,
101
+ })();
102
+ (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.FocusNextField(this);
103
+ }
104
+ });
105
+ this.stripeField_.mount(this);
106
+ }
107
+ });
108
+ });
109
+ scope.AddUninitCallback(() => {
110
+ var _a;
111
+ (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.RemoveStripeField(this);
112
+ this.stripeField_ = null;
113
+ });
114
+ }
115
+ GetStripe_() {
116
+ return (this.stripe || (0, inlinejs_1.FindAncestor)(this, ancestor => ('AddStripeField' in ancestor)));
117
+ }
118
+ }
119
+ __decorate([
120
+ (0, inlinejs_element_1.Property)({ type: 'object', checkStoredObject: true })
121
+ ], StripeFieldElement.prototype, "stripe", void 0);
122
+ __decorate([
123
+ (0, inlinejs_element_1.Property)({ type: 'object', checkStoredObject: true })
124
+ ], StripeFieldElement.prototype, "options", void 0);
125
+ __decorate([
126
+ (0, inlinejs_element_1.Property)({ type: 'string' })
127
+ ], StripeFieldElement.prototype, "type", void 0);
128
+ __decorate([
129
+ (0, inlinejs_element_1.Property)({ type: 'string' })
130
+ ], StripeFieldElement.prototype, "onready", void 0);
131
+ __decorate([
132
+ (0, inlinejs_element_1.Property)({ type: 'string' })
133
+ ], StripeFieldElement.prototype, "oncomplete", void 0);
134
+ __decorate([
135
+ (0, inlinejs_element_1.Property)({ type: 'string' })
136
+ ], StripeFieldElement.prototype, "onerrors", void 0);
137
+ exports.StripeFieldElement = StripeFieldElement;
138
+ function StripeFieldElementCompact() {
139
+ (0, inlinejs_element_1.RegisterCustomElement)(StripeFieldElement, 'stripe-field');
140
+ }
141
+ exports.StripeFieldElementCompact = StripeFieldElementCompact;
@@ -0,0 +1,12 @@
1
+ /// <reference types="stripe-v3" />
2
+ import { CustomElement } from "@benbraide/inlinejs-element";
3
+ import { IStripeField, IStripePaymentDetails } from "../types";
4
+ export declare class StripePaymentMenthodElement extends CustomElement implements IStripeField {
5
+ value: stripe.elements.Element | string;
6
+ constructor();
7
+ WaitReady(): Promise<void>;
8
+ ToggleFocus(focused: boolean): void;
9
+ Reset(): void;
10
+ AddDetails(details: IStripePaymentDetails): void;
11
+ }
12
+ export declare function StripePaymentMenthodElementCompact(): void;
@@ -0,0 +1,35 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.StripePaymentMenthodElementCompact = exports.StripePaymentMenthodElement = void 0;
10
+ const inlinejs_element_1 = require("@benbraide/inlinejs-element");
11
+ class StripePaymentMenthodElement extends inlinejs_element_1.CustomElement {
12
+ constructor() {
13
+ super({
14
+ isTemplate: true,
15
+ isHidden: true,
16
+ });
17
+ this.value = '';
18
+ }
19
+ WaitReady() {
20
+ return Promise.resolve();
21
+ }
22
+ ToggleFocus(focused) { }
23
+ Reset() { }
24
+ AddDetails(details) {
25
+ this.value && (details.method = this.value);
26
+ }
27
+ }
28
+ __decorate([
29
+ (0, inlinejs_element_1.Property)({ type: 'object', checkStoredObject: true })
30
+ ], StripePaymentMenthodElement.prototype, "value", void 0);
31
+ exports.StripePaymentMenthodElement = StripePaymentMenthodElement;
32
+ function StripePaymentMenthodElementCompact() {
33
+ (0, inlinejs_element_1.RegisterCustomElement)(StripePaymentMenthodElement, 'stripe-payment-method');
34
+ }
35
+ exports.StripePaymentMenthodElementCompact = StripePaymentMenthodElementCompact;
@@ -0,0 +1,32 @@
1
+ /// <reference types="stripe-v3" />
2
+ import { IElementScopeCreatedCallbackParams } from "@benbraide/inlinejs";
3
+ import { CustomElement } from "@benbraide/inlinejs-element";
4
+ import { IStripeElement, IStripeField } from "../types";
5
+ export declare class StripeElement extends CustomElement implements IStripeElement {
6
+ protected stripe_: stripe.Stripe | null;
7
+ protected mounting_: boolean;
8
+ protected mounted_: boolean;
9
+ protected isReady_: boolean;
10
+ protected readyWaiters_: (() => void)[];
11
+ protected fields_: Array<IStripeField> | null;
12
+ protected readyFields_: Array<IStripeField> | null;
13
+ protected instanceWaiters_: (() => void)[];
14
+ options: stripe.elements.ElementsOptions | null;
15
+ publicKey: string;
16
+ onready: string;
17
+ defer: boolean;
18
+ autofocus: boolean;
19
+ constructor();
20
+ AddStripeField(field: IStripeField): void;
21
+ RemoveStripeField(field: IStripeField): void;
22
+ FocusNextField(field: IStripeField): void;
23
+ GetInstance(): stripe.Stripe | null;
24
+ WaitInstance(): Promise<stripe.Stripe | null>;
25
+ Mount(): void;
26
+ Pay(clientSecret: string, save?: boolean): Promise<false | stripe.PaymentIntentResponse>;
27
+ Setup(clientSecret: string): Promise<false | stripe.PaymentIntentResponse>;
28
+ WaitReady(): Promise<void>;
29
+ protected HandleElementScopeCreated_({ scope, ...rest }: IElementScopeCreatedCallbackParams, postAttributesCallback?: () => void): void;
30
+ protected PayOrSetup_(pay: boolean, clientSecret: string, save?: boolean): Promise<false | stripe.PaymentIntentResponse>;
31
+ }
32
+ export declare function StripeElementCompact(): void;
@@ -0,0 +1,162 @@
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.StripeElementCompact = exports.StripeElement = void 0;
21
+ const inlinejs_1 = require("@benbraide/inlinejs");
22
+ const inlinejs_element_1 = require("@benbraide/inlinejs-element");
23
+ class StripeElement extends inlinejs_element_1.CustomElement {
24
+ constructor() {
25
+ super();
26
+ this.stripe_ = null;
27
+ this.mounting_ = false;
28
+ this.mounted_ = false;
29
+ this.isReady_ = false;
30
+ this.readyWaiters_ = new Array();
31
+ this.fields_ = null;
32
+ this.readyFields_ = null;
33
+ this.instanceWaiters_ = new Array();
34
+ this.options = null;
35
+ this.publicKey = '';
36
+ this.onready = '';
37
+ this.defer = false;
38
+ this.autofocus = false;
39
+ }
40
+ AddStripeField(field) {
41
+ this.fields_ = (this.fields_ || []);
42
+ this.fields_.push(field);
43
+ field.WaitReady().then(() => {
44
+ this.readyFields_ = (this.readyFields_ || []);
45
+ this.readyFields_.push(field);
46
+ (this.fields_ && this.readyFields_ && this.fields_.length <= this.readyFields_.length) && (0, inlinejs_1.JournalTry)(() => {
47
+ this.isReady_ = true;
48
+ this.onready && (0, inlinejs_1.EvaluateLater)({
49
+ componentId: this.componentId_,
50
+ contextElement: this,
51
+ expression: this.onready,
52
+ disableFunctionCall: false,
53
+ })();
54
+ this.readyWaiters_.splice(0).forEach(waiter => (0, inlinejs_1.JournalTry)(waiter));
55
+ });
56
+ });
57
+ }
58
+ RemoveStripeField(field) {
59
+ this.fields_ && (this.fields_ = this.fields_.filter(x => x !== field));
60
+ this.readyFields_ && (this.readyFields_ = this.readyFields_.filter(x => x !== field));
61
+ }
62
+ FocusNextField(field) {
63
+ if (this.autofocus && this.fields_) {
64
+ const index = this.fields_.indexOf(field);
65
+ (index >= 0 && index < this.fields_.length - 1) && this.fields_[index + 1].ToggleFocus(true);
66
+ }
67
+ }
68
+ GetInstance() {
69
+ return this.stripe_;
70
+ }
71
+ WaitInstance() {
72
+ return new Promise(resolve => {
73
+ this.mounted_ ? resolve(this.stripe_) : this.instanceWaiters_.push(() => resolve(this.stripe_));
74
+ });
75
+ }
76
+ Mount() {
77
+ if (this.mounted_ || this.mounting_) {
78
+ return;
79
+ }
80
+ this.mounting_ = true;
81
+ this.LoadResources().then(() => {
82
+ this.mounting_ = false;
83
+ this.mounted_ = true;
84
+ this.stripe_ = Stripe(this.publicKey);
85
+ this.instanceWaiters_.splice(0).forEach(waiter => (0, inlinejs_1.JournalTry)(waiter));
86
+ });
87
+ }
88
+ Pay(clientSecret, save = false) {
89
+ return this.PayOrSetup_(true, clientSecret, save);
90
+ }
91
+ Setup(clientSecret) {
92
+ return this.PayOrSetup_(false, clientSecret);
93
+ }
94
+ WaitReady() {
95
+ return new Promise(resolve => {
96
+ this.isReady_ ? resolve() : this.readyWaiters_.push(() => resolve());
97
+ });
98
+ }
99
+ HandleElementScopeCreated_(_a, postAttributesCallback) {
100
+ var { scope } = _a, rest = __rest(_a, ["scope"]);
101
+ super.HandleElementScopeCreated_(Object.assign({ scope }, rest), postAttributesCallback);
102
+ scope.AddPostProcessCallback(() => (!this.defer && this.Mount()));
103
+ scope.AddUninitCallback(() => (this.stripe_ = null));
104
+ }
105
+ PayOrSetup_(pay, clientSecret, save = false) {
106
+ return new Promise((resolve, reject) => {
107
+ this.WaitInstance().then((stripe) => {
108
+ var _a, _b;
109
+ if (!stripe) {
110
+ return resolve(false);
111
+ }
112
+ const details = {};
113
+ (_a = this.fields_) === null || _a === void 0 ? void 0 : _a.forEach(field => field.AddDetails(details));
114
+ if (!details.method) {
115
+ return resolve(false);
116
+ }
117
+ let cardDetails;
118
+ if (typeof details.method !== 'string') {
119
+ cardDetails = {
120
+ payment_method: {
121
+ card: details.method,
122
+ billing_details: details.billingDetails,
123
+ },
124
+ };
125
+ }
126
+ else {
127
+ cardDetails = {
128
+ payment_method: details.method,
129
+ };
130
+ }
131
+ if (pay) {
132
+ ((_b = details.billingDetails) === null || _b === void 0 ? void 0 : _b.email) && (cardDetails.receipt_email = details.billingDetails.email);
133
+ save && (cardDetails.setup_future_usage = 'off_session');
134
+ stripe.confirmCardPayment(clientSecret, cardDetails).then(resolve).catch(reject);
135
+ }
136
+ else {
137
+ stripe.confirmCardSetup(clientSecret, cardDetails).then(resolve).catch(reject);
138
+ }
139
+ }).catch(reject);
140
+ });
141
+ }
142
+ }
143
+ __decorate([
144
+ (0, inlinejs_element_1.Property)({ type: 'object', checkStoredObject: true })
145
+ ], StripeElement.prototype, "options", void 0);
146
+ __decorate([
147
+ (0, inlinejs_element_1.Property)({ type: 'string' })
148
+ ], StripeElement.prototype, "publicKey", void 0);
149
+ __decorate([
150
+ (0, inlinejs_element_1.Property)({ type: 'string' })
151
+ ], StripeElement.prototype, "onready", void 0);
152
+ __decorate([
153
+ (0, inlinejs_element_1.Property)({ type: 'boolean' })
154
+ ], StripeElement.prototype, "defer", void 0);
155
+ __decorate([
156
+ (0, inlinejs_element_1.Property)({ type: 'boolean' })
157
+ ], StripeElement.prototype, "autofocus", void 0);
158
+ exports.StripeElement = StripeElement;
159
+ function StripeElementCompact() {
160
+ (0, inlinejs_element_1.RegisterCustomElement)(StripeElement, 'stripe');
161
+ }
162
+ exports.StripeElementCompact = StripeElementCompact;
@@ -2,8 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InlineJSStripe = void 0;
4
4
  const inlinejs_1 = require("@benbraide/inlinejs");
5
- const stripe_1 = require("./directive/stripe");
5
+ const stripe_1 = require("./components/stripe");
6
+ const field_1 = require("./components/field");
7
+ const detail_1 = require("./components/detail");
8
+ const payment_method_1 = require("./components/payment-method");
6
9
  function InlineJSStripe() {
7
- (0, inlinejs_1.WaitForGlobal)().then(() => (0, stripe_1.StripeDirectiveHandlerCompact)());
10
+ (0, inlinejs_1.WaitForGlobal)().then(() => {
11
+ (0, stripe_1.StripeElementCompact)();
12
+ (0, field_1.StripeFieldElementCompact)();
13
+ (0, detail_1.StripeDetailElementCompact)();
14
+ (0, payment_method_1.StripePaymentMenthodElementCompact)();
15
+ });
8
16
  }
9
17
  exports.InlineJSStripe = InlineJSStripe;
@@ -1 +1,5 @@
1
- export * from './directive/stripe';
1
+ export * from './components/stripe';
2
+ export * from './components/field';
3
+ export * from './components/detail';
4
+ export * from './components/payment-method';
5
+ export * from './entry';
@@ -14,4 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./directive/stripe"), exports);
17
+ __exportStar(require("./components/stripe"), exports);
18
+ __exportStar(require("./components/field"), exports);
19
+ __exportStar(require("./components/detail"), exports);
20
+ __exportStar(require("./components/payment-method"), exports);
21
+ __exportStar(require("./entry"), exports);
@@ -0,0 +1,20 @@
1
+ /// <reference types="stripe-v3" />
2
+ export interface IStripePaymentDetails {
3
+ method?: stripe.elements.Element | string;
4
+ billingDetails?: stripe.BillingDetails;
5
+ }
6
+ export interface IStripeField {
7
+ WaitReady(): Promise<void>;
8
+ ToggleFocus(focused: boolean): void;
9
+ Reset(): void;
10
+ AddDetails(details: IStripePaymentDetails): void;
11
+ }
12
+ export interface IStripeElement {
13
+ options: stripe.elements.ElementsOptions | null;
14
+ AddStripeField(field: IStripeField): void;
15
+ RemoveStripeField(field: IStripeField): void;
16
+ FocusNextField(field: IStripeField): void;
17
+ GetInstance(): stripe.Stripe | null;
18
+ WaitInstance(): Promise<stripe.Stripe | null>;
19
+ Mount(): void;
20
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ import { CustomElement } from "@benbraide/inlinejs-element";
2
+ import { IStripeField, IStripePaymentDetails } from "../types";
3
+ export declare class StripeDetailElement extends CustomElement implements IStripeField {
4
+ input: HTMLInputElement | null;
5
+ name: string;
6
+ value: string;
7
+ constructor();
8
+ WaitReady(): Promise<void>;
9
+ ToggleFocus(focused: boolean): void;
10
+ Reset(): void;
11
+ AddDetails(details: IStripePaymentDetails): void;
12
+ protected GetInput_(): HTMLInputElement | null;
13
+ }
14
+ export declare function StripeDetailElementCompact(): void;
@@ -0,0 +1,55 @@
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
+ import { CustomElement, Property, RegisterCustomElement } from "@benbraide/inlinejs-element";
8
+ export class StripeDetailElement extends CustomElement {
9
+ constructor() {
10
+ super();
11
+ this.input = null;
12
+ this.name = '';
13
+ this.value = '';
14
+ }
15
+ WaitReady() {
16
+ return Promise.resolve();
17
+ }
18
+ ToggleFocus(focused) {
19
+ const input = this.GetInput_();
20
+ input && (focused ? input.focus() : input.blur());
21
+ }
22
+ Reset() {
23
+ const input = this.GetInput_();
24
+ input && (input.value = '');
25
+ }
26
+ AddDetails(details) {
27
+ const input = this.GetInput_();
28
+ if (!this.name || (!input && !this.value)) {
29
+ return;
30
+ }
31
+ details.billingDetails = (details.billingDetails || {});
32
+ if (this.name === 'address') {
33
+ details.billingDetails.address = (details.billingDetails.address || {});
34
+ details.billingDetails.address.line1 = ((input === null || input === void 0 ? void 0 : input.value) || this.value);
35
+ }
36
+ else {
37
+ details.billingDetails[this.name] = ((input === null || input === void 0 ? void 0 : input.value) || this.value);
38
+ }
39
+ }
40
+ GetInput_() {
41
+ return (this.input || this.querySelector('input'));
42
+ }
43
+ }
44
+ __decorate([
45
+ Property({ type: 'object', checkStoredObject: true })
46
+ ], StripeDetailElement.prototype, "input", void 0);
47
+ __decorate([
48
+ Property({ type: 'string' })
49
+ ], StripeDetailElement.prototype, "name", void 0);
50
+ __decorate([
51
+ Property({ type: 'string' })
52
+ ], StripeDetailElement.prototype, "value", void 0);
53
+ export function StripeDetailElementCompact() {
54
+ RegisterCustomElement(StripeDetailElement, 'stripe-detail');
55
+ }
@@ -0,0 +1,23 @@
1
+ /// <reference types="stripe-v3" />
2
+ import { IElementScopeCreatedCallbackParams } from "@benbraide/inlinejs";
3
+ import { CustomElement } from "@benbraide/inlinejs-element";
4
+ import { IStripeElement, IStripeField, IStripePaymentDetails } from "../types";
5
+ export declare class StripeFieldElement extends CustomElement implements IStripeField {
6
+ protected stripeField_: stripe.elements.Element | null;
7
+ protected isReady_: boolean;
8
+ protected readyWaiters_: (() => void)[];
9
+ stripe: IStripeElement | null;
10
+ options: stripe.elements.ElementsOptions | null;
11
+ type: string;
12
+ onready: string;
13
+ oncomplete: string;
14
+ onerrors: string;
15
+ constructor();
16
+ WaitReady(): Promise<void>;
17
+ ToggleFocus(focused: boolean): void;
18
+ Reset(): void;
19
+ AddDetails(details: IStripePaymentDetails): void;
20
+ protected HandleElementScopeCreated_({ scope, ...rest }: IElementScopeCreatedCallbackParams, postAttributesCallback?: () => void): void;
21
+ protected GetStripe_(): IStripeElement | null;
22
+ }
23
+ export declare function StripeFieldElementCompact(): void;