@benbraide/inlinejs-stripe 2.0.4 → 2.0.5

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.
@@ -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
- class StripeFieldElement extends inlinejs_element_1.CustomElement {
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,7 +30,6 @@ 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 = '';
@@ -61,16 +61,12 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
61
61
  }
62
62
  HandleElementScopeCreated_(_a, postAttributesCallback) {
63
63
  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
- });
64
+ super.HandleElementScopeCreated_(Object.assign({ scope }, rest), postAttributesCallback);
69
65
  scope.AddPostProcessCallback(() => {
70
66
  var _a;
71
- (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.WaitInstance().then((stripe) => {
67
+ (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.WaitInstance().then((details) => {
72
68
  var _a;
73
- if (!stripe) {
69
+ if (!(details === null || details === void 0 ? void 0 : details.stripe)) {
74
70
  return;
75
71
  }
76
72
  let type = '';
@@ -80,8 +76,8 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
80
76
  else if (['card', 'cardNumber', 'cardExpiry', 'cardCvc', 'postalCode', 'paymentRequestButton', 'iban', 'idealBank'].includes(this.type)) {
81
77
  type = this.type;
82
78
  }
83
- if (type) {
84
- this.stripeField_ = stripe.elements().create(type, (this.options || ((_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.options) || undefined));
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));
85
81
  this.stripeField_.on('ready', () => {
86
82
  this.isReady_ = true;
87
83
  this.onready && (0, inlinejs_1.EvaluateLater)({
@@ -124,13 +120,7 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
124
120
  this.stripeField_ = null;
125
121
  });
126
122
  }
127
- GetStripe_() {
128
- return (this.stripe || (0, inlinejs_1.FindAncestor)(this, ancestor => ('AddStripeField' in ancestor)));
129
- }
130
123
  }
131
- __decorate([
132
- (0, inlinejs_element_1.Property)({ type: 'object', checkStoredObject: true })
133
- ], StripeFieldElement.prototype, "stripe", void 0);
134
124
  __decorate([
135
125
  (0, inlinejs_element_1.Property)({ type: 'object', checkStoredObject: true })
136
126
  ], StripeFieldElement.prototype, "options", void 0);
@@ -0,0 +1,14 @@
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
+ WaitReady(): Promise<void>;
7
+ AddChangeListener(listener: StripeFieldChangeHandlerType): void;
8
+ RemoveChangeListener(listener: StripeFieldChangeHandlerType): void;
9
+ ToggleFocus(focused: boolean): void;
10
+ Reset(): void;
11
+ AddDetails(details: IStripePaymentDetails): void;
12
+ protected HandleElementScopeCreated_({ scope, ...rest }: IElementScopeCreatedCallbackParams, postAttributesCallback?: () => void): void;
13
+ protected GetStripe_(): IStripeElement | null;
14
+ }
@@ -0,0 +1,51 @@
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
+ 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 || (0, inlinejs_1.FindAncestor)(this, ancestor => ('AddStripeField' in ancestor)));
46
+ }
47
+ }
48
+ __decorate([
49
+ (0, inlinejs_element_1.Property)({ type: 'object', checkStoredObject: true })
50
+ ], StripeGenericField.prototype, "stripe", void 0);
51
+ exports.StripeGenericField = StripeGenericField;
@@ -1,14 +1,9 @@
1
1
  /// <reference types="stripe-v3" />
2
- import { CustomElement } from "@benbraide/inlinejs-element";
3
- import { IStripeField, IStripePaymentDetails, StripeFieldChangeHandlerType } from "../types";
4
- export declare class StripePaymentMenthodElement extends CustomElement implements IStripeField {
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
- class StripePaymentMenthodElement extends inlinejs_element_1.CustomElement {
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;
@@ -24,8 +25,9 @@ export declare class StripeElement extends CustomElement implements IStripeEleme
24
25
  AddStripeField(field: IStripeField): void;
25
26
  RemoveStripeField(field: IStripeField): void;
26
27
  FocusNextField(field: IStripeField): void;
28
+ GetDetails(): IStripeDetails;
27
29
  GetInstance(): stripe.Stripe | null;
28
- WaitInstance(): Promise<stripe.Stripe | null>;
30
+ WaitInstance(): Promise<IStripeDetails | null>;
29
31
  Mount(): void;
30
32
  Pay(clientSecret: string, save?: boolean): Promise<false | stripe.PaymentIntentResponse>;
31
33
  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;
@@ -110,12 +111,18 @@ class StripeElement extends inlinejs_element_1.CustomElement {
110
111
  (index >= 0 && index < this.fields_.length - 1) && this.fields_[index + 1].ToggleFocus(true);
111
112
  }
112
113
  }
114
+ GetDetails() {
115
+ return {
116
+ stripe: this.stripe_,
117
+ elements: this.elements_,
118
+ };
119
+ }
113
120
  GetInstance() {
114
121
  return this.stripe_;
115
122
  }
116
123
  WaitInstance() {
117
124
  return new Promise(resolve => {
118
- this.mounted_ ? resolve(this.stripe_) : this.instanceWaiters_.push(() => resolve(this.stripe_));
125
+ this.mounted_ ? resolve(this.GetDetails()) : this.instanceWaiters_.push(() => resolve(this.GetDetails()));
119
126
  });
120
127
  }
121
128
  Mount() {
@@ -127,6 +134,7 @@ class StripeElement extends inlinejs_element_1.CustomElement {
127
134
  this.mounting_ = false;
128
135
  this.mounted_ = true;
129
136
  this.stripe_ = Stripe(this.publicKey);
137
+ this.elements_ = this.stripe_.elements();
130
138
  this.instanceWaiters_.splice(0).forEach(waiter => (0, inlinejs_1.JournalTry)(waiter));
131
139
  });
132
140
  }
@@ -149,37 +157,37 @@ class StripeElement extends inlinejs_element_1.CustomElement {
149
157
  }
150
158
  PayOrSetup_(pay, clientSecret, save = false) {
151
159
  return new Promise((resolve, reject) => {
152
- this.WaitInstance().then((stripe) => {
160
+ this.WaitInstance().then((details) => {
153
161
  var _a, _b;
154
- if (!stripe) {
162
+ if (!(details === null || details === void 0 ? void 0 : details.stripe)) {
155
163
  return resolve(false);
156
164
  }
157
- const details = {};
158
- (_a = this.fields_) === null || _a === void 0 ? void 0 : _a.forEach(field => field.AddDetails(details));
159
- if (!details.method) {
165
+ const paymentDetails = {};
166
+ (_a = this.fields_) === null || _a === void 0 ? void 0 : _a.forEach(field => field.AddDetails(paymentDetails));
167
+ if (!paymentDetails.method) {
160
168
  return resolve(false);
161
169
  }
162
170
  let cardDetails;
163
- if (typeof details.method !== 'string') {
171
+ if (typeof paymentDetails.method !== 'string') {
164
172
  cardDetails = {
165
173
  payment_method: {
166
- card: details.method,
167
- billing_details: details.billingDetails,
174
+ card: paymentDetails.method,
175
+ billing_details: paymentDetails.billingDetails,
168
176
  },
169
177
  };
170
178
  }
171
179
  else {
172
180
  cardDetails = {
173
- payment_method: details.method,
181
+ payment_method: paymentDetails.method,
174
182
  };
175
183
  }
176
184
  if (pay) {
177
- ((_b = details.billingDetails) === null || _b === void 0 ? void 0 : _b.email) && (cardDetails.receipt_email = details.billingDetails.email);
185
+ ((_b = paymentDetails.billingDetails) === null || _b === void 0 ? void 0 : _b.email) && (cardDetails.receipt_email = paymentDetails.billingDetails.email);
178
186
  save && (cardDetails.setup_future_usage = 'off_session');
179
- stripe.confirmCardPayment(clientSecret, cardDetails).then(resolve).catch(reject);
187
+ details.stripe.confirmCardPayment(clientSecret, cardDetails).then(resolve).catch(reject);
180
188
  }
181
189
  else {
182
- stripe.confirmCardSetup(clientSecret, cardDetails).then(resolve).catch(reject);
190
+ details.stripe.confirmCardSetup(clientSecret, cardDetails).then(resolve).catch(reject);
183
191
  }
184
192
  }).catch(reject);
185
193
  });
@@ -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<stripe.Stripe | null>;
27
+ WaitInstance(): Promise<IStripeDetails | null>;
23
28
  Mount(): void;
24
29
  }
@@ -1,13 +1,10 @@
1
- import { CustomElement } from "@benbraide/inlinejs-element";
2
- import { IStripeField, IStripePaymentDetails, StripeFieldChangeHandlerType } from "../types";
3
- export declare class StripeDetailElement extends CustomElement implements IStripeField {
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 { CustomElement, Property, RegisterCustomElement } from "@benbraide/inlinejs-element";
8
- export class StripeDetailElement extends CustomElement {
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,15 +1,14 @@
1
1
  /// <reference types="stripe-v3" />
2
2
  import { IElementScopeCreatedCallbackParams } from "@benbraide/inlinejs";
3
- import { CustomElement } from "@benbraide/inlinejs-element";
4
- import { IStripeElement, IStripeField, IStripePaymentDetails, StripeFieldChangeHandlerType } from "../types";
5
- export declare class StripeFieldElement extends CustomElement implements IStripeField {
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;
@@ -23,6 +22,5 @@ export declare class StripeFieldElement extends CustomElement implements IStripe
23
22
  Reset(): void;
24
23
  AddDetails(details: IStripePaymentDetails): void;
25
24
  protected HandleElementScopeCreated_({ scope, ...rest }: IElementScopeCreatedCallbackParams, postAttributesCallback?: () => void): void;
26
- protected GetStripe_(): IStripeElement | null;
27
25
  }
28
26
  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, FindAncestor, JournalTry } from "@benbraide/inlinejs";
19
- import { CustomElement, Property, RegisterCustomElement } from "@benbraide/inlinejs-element";
20
- export class StripeFieldElement extends CustomElement {
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,7 +27,6 @@ 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 = '';
@@ -58,16 +58,12 @@ export class StripeFieldElement extends CustomElement {
58
58
  }
59
59
  HandleElementScopeCreated_(_a, postAttributesCallback) {
60
60
  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
- });
61
+ super.HandleElementScopeCreated_(Object.assign({ scope }, rest), postAttributesCallback);
66
62
  scope.AddPostProcessCallback(() => {
67
63
  var _a;
68
- (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.WaitInstance().then((stripe) => {
64
+ (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.WaitInstance().then((details) => {
69
65
  var _a;
70
- if (!stripe) {
66
+ if (!(details === null || details === void 0 ? void 0 : details.stripe)) {
71
67
  return;
72
68
  }
73
69
  let type = '';
@@ -77,8 +73,8 @@ export class StripeFieldElement extends CustomElement {
77
73
  else if (['card', 'cardNumber', 'cardExpiry', 'cardCvc', 'postalCode', 'paymentRequestButton', 'iban', 'idealBank'].includes(this.type)) {
78
74
  type = this.type;
79
75
  }
80
- if (type) {
81
- this.stripeField_ = stripe.elements().create(type, (this.options || ((_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.options) || undefined));
76
+ if (type && details.elements) {
77
+ this.stripeField_ = details.elements.create(type, (this.options || ((_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.options) || undefined));
82
78
  this.stripeField_.on('ready', () => {
83
79
  this.isReady_ = true;
84
80
  this.onready && EvaluateLater({
@@ -121,13 +117,7 @@ export class StripeFieldElement extends CustomElement {
121
117
  this.stripeField_ = null;
122
118
  });
123
119
  }
124
- GetStripe_() {
125
- return (this.stripe || FindAncestor(this, ancestor => ('AddStripeField' in ancestor)));
126
- }
127
120
  }
128
- __decorate([
129
- Property({ type: 'object', checkStoredObject: true })
130
- ], StripeFieldElement.prototype, "stripe", void 0);
131
121
  __decorate([
132
122
  Property({ type: 'object', checkStoredObject: true })
133
123
  ], StripeFieldElement.prototype, "options", void 0);
@@ -0,0 +1,14 @@
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
+ WaitReady(): Promise<void>;
7
+ AddChangeListener(listener: StripeFieldChangeHandlerType): void;
8
+ RemoveChangeListener(listener: StripeFieldChangeHandlerType): void;
9
+ ToggleFocus(focused: boolean): void;
10
+ Reset(): void;
11
+ AddDetails(details: IStripePaymentDetails): void;
12
+ protected HandleElementScopeCreated_({ scope, ...rest }: IElementScopeCreatedCallbackParams, postAttributesCallback?: () => void): void;
13
+ protected GetStripe_(): IStripeElement | null;
14
+ }
@@ -0,0 +1,47 @@
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
+ WaitReady() {
26
+ return Promise.resolve();
27
+ }
28
+ AddChangeListener(listener) { }
29
+ RemoveChangeListener(listener) { }
30
+ ToggleFocus(focused) { }
31
+ Reset() { }
32
+ AddDetails(details) { }
33
+ HandleElementScopeCreated_(_a, postAttributesCallback) {
34
+ var { scope } = _a, rest = __rest(_a, ["scope"]);
35
+ super.HandleElementScopeCreated_(Object.assign({ scope }, rest), () => {
36
+ var _a;
37
+ (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.AddStripeField(this);
38
+ postAttributesCallback && postAttributesCallback();
39
+ });
40
+ }
41
+ GetStripe_() {
42
+ return (this.stripe || FindAncestor(this, ancestor => ('AddStripeField' in ancestor)));
43
+ }
44
+ }
45
+ __decorate([
46
+ Property({ type: 'object', checkStoredObject: true })
47
+ ], StripeGenericField.prototype, "stripe", void 0);
@@ -1,14 +1,9 @@
1
1
  /// <reference types="stripe-v3" />
2
- import { CustomElement } from "@benbraide/inlinejs-element";
3
- import { IStripeField, IStripePaymentDetails, StripeFieldChangeHandlerType } from "../types";
4
- export declare class StripePaymentMenthodElement extends CustomElement implements IStripeField {
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 { CustomElement, Property, RegisterCustomElement } from "@benbraide/inlinejs-element";
8
- export class StripePaymentMenthodElement extends CustomElement {
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
  }
@@ -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;
@@ -24,8 +25,9 @@ export declare class StripeElement extends CustomElement implements IStripeEleme
24
25
  AddStripeField(field: IStripeField): void;
25
26
  RemoveStripeField(field: IStripeField): void;
26
27
  FocusNextField(field: IStripeField): void;
28
+ GetDetails(): IStripeDetails;
27
29
  GetInstance(): stripe.Stripe | null;
28
- WaitInstance(): Promise<stripe.Stripe | null>;
30
+ WaitInstance(): Promise<IStripeDetails | null>;
29
31
  Mount(): void;
30
32
  Pay(clientSecret: string, save?: boolean): Promise<false | stripe.PaymentIntentResponse>;
31
33
  Setup(clientSecret: string): Promise<false | stripe.PaymentIntentResponse>;