@benbraide/inlinejs-stripe 2.0.4 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,6 +21,7 @@ export class StripeElement extends CustomElement {
21
21
  constructor() {
22
22
  super();
23
23
  this.stripe_ = null;
24
+ this.elements_ = null;
24
25
  this.mounting_ = false;
25
26
  this.mounted_ = false;
26
27
  this.isReady_ = false;
@@ -107,12 +108,18 @@ export class StripeElement extends CustomElement {
107
108
  (index >= 0 && index < this.fields_.length - 1) && this.fields_[index + 1].ToggleFocus(true);
108
109
  }
109
110
  }
111
+ GetDetails() {
112
+ return {
113
+ stripe: this.stripe_,
114
+ elements: this.elements_,
115
+ };
116
+ }
110
117
  GetInstance() {
111
118
  return this.stripe_;
112
119
  }
113
120
  WaitInstance() {
114
121
  return new Promise(resolve => {
115
- this.mounted_ ? resolve(this.stripe_) : this.instanceWaiters_.push(() => resolve(this.stripe_));
122
+ this.mounted_ ? resolve(this.GetDetails()) : this.instanceWaiters_.push(() => resolve(this.GetDetails()));
116
123
  });
117
124
  }
118
125
  Mount() {
@@ -124,6 +131,7 @@ export class StripeElement extends CustomElement {
124
131
  this.mounting_ = false;
125
132
  this.mounted_ = true;
126
133
  this.stripe_ = Stripe(this.publicKey);
134
+ this.elements_ = this.stripe_.elements();
127
135
  this.instanceWaiters_.splice(0).forEach(waiter => JournalTry(waiter));
128
136
  });
129
137
  }
@@ -146,37 +154,37 @@ export class StripeElement extends CustomElement {
146
154
  }
147
155
  PayOrSetup_(pay, clientSecret, save = false) {
148
156
  return new Promise((resolve, reject) => {
149
- this.WaitInstance().then((stripe) => {
157
+ this.WaitInstance().then((details) => {
150
158
  var _a, _b;
151
- if (!stripe) {
159
+ if (!(details === null || details === void 0 ? void 0 : details.stripe)) {
152
160
  return resolve(false);
153
161
  }
154
- const details = {};
155
- (_a = this.fields_) === null || _a === void 0 ? void 0 : _a.forEach(field => field.AddDetails(details));
156
- if (!details.method) {
162
+ const paymentDetails = {};
163
+ (_a = this.fields_) === null || _a === void 0 ? void 0 : _a.forEach(field => field.AddDetails(paymentDetails));
164
+ if (!paymentDetails.method) {
157
165
  return resolve(false);
158
166
  }
159
167
  let cardDetails;
160
- if (typeof details.method !== 'string') {
168
+ if (typeof paymentDetails.method !== 'string') {
161
169
  cardDetails = {
162
170
  payment_method: {
163
- card: details.method,
164
- billing_details: details.billingDetails,
171
+ card: paymentDetails.method,
172
+ billing_details: paymentDetails.billingDetails,
165
173
  },
166
174
  };
167
175
  }
168
176
  else {
169
177
  cardDetails = {
170
- payment_method: details.method,
178
+ payment_method: paymentDetails.method,
171
179
  };
172
180
  }
173
181
  if (pay) {
174
- ((_b = details.billingDetails) === null || _b === void 0 ? void 0 : _b.email) && (cardDetails.receipt_email = details.billingDetails.email);
182
+ ((_b = paymentDetails.billingDetails) === null || _b === void 0 ? void 0 : _b.email) && (cardDetails.receipt_email = paymentDetails.billingDetails.email);
175
183
  save && (cardDetails.setup_future_usage = 'off_session');
176
- stripe.confirmCardPayment(clientSecret, cardDetails).then(resolve).catch(reject);
184
+ details.stripe.confirmCardPayment(clientSecret, cardDetails).then(resolve).catch(reject);
177
185
  }
178
186
  else {
179
- stripe.confirmCardSetup(clientSecret, cardDetails).then(resolve).catch(reject);
187
+ details.stripe.confirmCardSetup(clientSecret, cardDetails).then(resolve).catch(reject);
180
188
  }
181
189
  }).catch(reject);
182
190
  });
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@benbraide/inlinejs-stripe",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "Run javascript code by embedding them in your HTML using the element as context.",
5
5
  "main": "./lib/common/index.js",
6
6
  "module": "./lib/esm/index.js",