@benbraide/inlinejs-stripe 1.0.8 → 2.0.0

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