@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.
@@ -7301,18 +7301,14 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7301
7301
  Object.defineProperty(exports, "__esModule", ({ value: true }));
7302
7302
  exports.StripeDetailElementCompact = exports.StripeDetailElement = void 0;
7303
7303
  const inlinejs_element_1 = __webpack_require__(/*! @benbraide/inlinejs-element */ "./node_modules/@benbraide/inlinejs-element/lib/esm/index.js");
7304
- class StripeDetailElement extends inlinejs_element_1.CustomElement {
7304
+ const generic_field_1 = __webpack_require__(/*! ./generic-field */ "./src/components/generic-field.ts");
7305
+ class StripeDetailElement extends generic_field_1.StripeGenericField {
7305
7306
  constructor() {
7306
7307
  super();
7307
7308
  this.input = null;
7308
7309
  this.name = '';
7309
7310
  this.value = '';
7310
7311
  }
7311
- WaitReady() {
7312
- return Promise.resolve();
7313
- }
7314
- AddChangeListener(listener) { }
7315
- RemoveChangeListener(listener) { }
7316
7312
  ToggleFocus(focused) {
7317
7313
  const input = this.GetInput_();
7318
7314
  input && (focused ? input.focus() : input.blur());
@@ -7385,7 +7381,8 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
7385
7381
  exports.StripeFieldElementCompact = exports.StripeFieldElement = void 0;
7386
7382
  const inlinejs_1 = __webpack_require__(/*! @benbraide/inlinejs */ "./node_modules/@benbraide/inlinejs/lib/esm/index.js");
7387
7383
  const inlinejs_element_1 = __webpack_require__(/*! @benbraide/inlinejs-element */ "./node_modules/@benbraide/inlinejs-element/lib/esm/index.js");
7388
- class StripeFieldElement extends inlinejs_element_1.CustomElement {
7384
+ const generic_field_1 = __webpack_require__(/*! ./generic-field */ "./src/components/generic-field.ts");
7385
+ class StripeFieldElement extends generic_field_1.StripeGenericField {
7389
7386
  constructor() {
7390
7387
  super();
7391
7388
  this.stripeField_ = null;
@@ -7394,7 +7391,6 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
7394
7391
  this.lastError_ = null;
7395
7392
  this.readyWaiters_ = new Array();
7396
7393
  this.changeListeners = new Array();
7397
- this.stripe = null;
7398
7394
  this.options = null;
7399
7395
  this.type = '';
7400
7396
  this.onready = '';
@@ -7426,16 +7422,12 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
7426
7422
  }
7427
7423
  HandleElementScopeCreated_(_a, postAttributesCallback) {
7428
7424
  var { scope } = _a, rest = __rest(_a, ["scope"]);
7429
- super.HandleElementScopeCreated_(Object.assign({ scope }, rest), () => {
7430
- var _a;
7431
- (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.AddStripeField(this);
7432
- postAttributesCallback && postAttributesCallback();
7433
- });
7425
+ super.HandleElementScopeCreated_(Object.assign({ scope }, rest), postAttributesCallback);
7434
7426
  scope.AddPostProcessCallback(() => {
7435
7427
  var _a;
7436
- (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.WaitInstance().then((stripe) => {
7428
+ (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.WaitInstance().then((details) => {
7437
7429
  var _a;
7438
- if (!stripe) {
7430
+ if (!(details === null || details === void 0 ? void 0 : details.stripe)) {
7439
7431
  return;
7440
7432
  }
7441
7433
  let type = '';
@@ -7445,8 +7437,8 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
7445
7437
  else if (['card', 'cardNumber', 'cardExpiry', 'cardCvc', 'postalCode', 'paymentRequestButton', 'iban', 'idealBank'].includes(this.type)) {
7446
7438
  type = this.type;
7447
7439
  }
7448
- if (type) {
7449
- this.stripeField_ = stripe.elements().create(type, (this.options || ((_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.options) || undefined));
7440
+ if (type && details.elements) {
7441
+ this.stripeField_ = details.elements.create(type, (this.options || ((_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.options) || undefined));
7450
7442
  this.stripeField_.on('ready', () => {
7451
7443
  this.isReady_ = true;
7452
7444
  this.onready && (0, inlinejs_1.EvaluateLater)({
@@ -7489,13 +7481,7 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
7489
7481
  this.stripeField_ = null;
7490
7482
  });
7491
7483
  }
7492
- GetStripe_() {
7493
- return (this.stripe || (0, inlinejs_1.FindAncestor)(this, ancestor => ('AddStripeField' in ancestor)));
7494
- }
7495
7484
  }
7496
- __decorate([
7497
- (0, inlinejs_element_1.Property)({ type: 'object', checkStoredObject: true })
7498
- ], StripeFieldElement.prototype, "stripe", void 0);
7499
7485
  __decorate([
7500
7486
  (0, inlinejs_element_1.Property)({ type: 'object', checkStoredObject: true })
7501
7487
  ], StripeFieldElement.prototype, "options", void 0);
@@ -7518,6 +7504,67 @@ function StripeFieldElementCompact() {
7518
7504
  exports.StripeFieldElementCompact = StripeFieldElementCompact;
7519
7505
 
7520
7506
 
7507
+ /***/ }),
7508
+
7509
+ /***/ "./src/components/generic-field.ts":
7510
+ /*!*****************************************!*\
7511
+ !*** ./src/components/generic-field.ts ***!
7512
+ \*****************************************/
7513
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
7514
+
7515
+
7516
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
7517
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7518
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7519
+ 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;
7520
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7521
+ };
7522
+ var __rest = (this && this.__rest) || function (s, e) {
7523
+ var t = {};
7524
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
7525
+ t[p] = s[p];
7526
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7527
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7528
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
7529
+ t[p[i]] = s[p[i]];
7530
+ }
7531
+ return t;
7532
+ };
7533
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
7534
+ exports.StripeGenericField = void 0;
7535
+ const inlinejs_1 = __webpack_require__(/*! @benbraide/inlinejs */ "./node_modules/@benbraide/inlinejs/lib/esm/index.js");
7536
+ const inlinejs_element_1 = __webpack_require__(/*! @benbraide/inlinejs-element */ "./node_modules/@benbraide/inlinejs-element/lib/esm/index.js");
7537
+ class StripeGenericField extends inlinejs_element_1.CustomElement {
7538
+ constructor() {
7539
+ super(...arguments);
7540
+ this.stripe = null;
7541
+ }
7542
+ WaitReady() {
7543
+ return Promise.resolve();
7544
+ }
7545
+ AddChangeListener(listener) { }
7546
+ RemoveChangeListener(listener) { }
7547
+ ToggleFocus(focused) { }
7548
+ Reset() { }
7549
+ AddDetails(details) { }
7550
+ HandleElementScopeCreated_(_a, postAttributesCallback) {
7551
+ var { scope } = _a, rest = __rest(_a, ["scope"]);
7552
+ super.HandleElementScopeCreated_(Object.assign({ scope }, rest), () => {
7553
+ var _a;
7554
+ (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.AddStripeField(this);
7555
+ postAttributesCallback && postAttributesCallback();
7556
+ });
7557
+ }
7558
+ GetStripe_() {
7559
+ return (this.stripe || (0, inlinejs_1.FindAncestor)(this, ancestor => ('AddStripeField' in ancestor)));
7560
+ }
7561
+ }
7562
+ __decorate([
7563
+ (0, inlinejs_element_1.Property)({ type: 'object', checkStoredObject: true })
7564
+ ], StripeGenericField.prototype, "stripe", void 0);
7565
+ exports.StripeGenericField = StripeGenericField;
7566
+
7567
+
7521
7568
  /***/ }),
7522
7569
 
7523
7570
  /***/ "./src/components/payment-method.ts":
@@ -7536,7 +7583,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7536
7583
  Object.defineProperty(exports, "__esModule", ({ value: true }));
7537
7584
  exports.StripePaymentMenthodElementCompact = exports.StripePaymentMenthodElement = void 0;
7538
7585
  const inlinejs_element_1 = __webpack_require__(/*! @benbraide/inlinejs-element */ "./node_modules/@benbraide/inlinejs-element/lib/esm/index.js");
7539
- class StripePaymentMenthodElement extends inlinejs_element_1.CustomElement {
7586
+ const generic_field_1 = __webpack_require__(/*! ./generic-field */ "./src/components/generic-field.ts");
7587
+ class StripePaymentMenthodElement extends generic_field_1.StripeGenericField {
7540
7588
  constructor() {
7541
7589
  super({
7542
7590
  isTemplate: true,
@@ -7544,13 +7592,6 @@ class StripePaymentMenthodElement extends inlinejs_element_1.CustomElement {
7544
7592
  });
7545
7593
  this.value = '';
7546
7594
  }
7547
- WaitReady() {
7548
- return Promise.resolve();
7549
- }
7550
- AddChangeListener(listener) { }
7551
- RemoveChangeListener(listener) { }
7552
- ToggleFocus(focused) { }
7553
- Reset() { }
7554
7595
  AddDetails(details) {
7555
7596
  this.value && (details.method = this.value);
7556
7597
  }
@@ -7599,6 +7640,7 @@ class StripeElement extends inlinejs_element_1.CustomElement {
7599
7640
  constructor() {
7600
7641
  super();
7601
7642
  this.stripe_ = null;
7643
+ this.elements_ = null;
7602
7644
  this.mounting_ = false;
7603
7645
  this.mounted_ = false;
7604
7646
  this.isReady_ = false;
@@ -7685,12 +7727,18 @@ class StripeElement extends inlinejs_element_1.CustomElement {
7685
7727
  (index >= 0 && index < this.fields_.length - 1) && this.fields_[index + 1].ToggleFocus(true);
7686
7728
  }
7687
7729
  }
7730
+ GetDetails() {
7731
+ return {
7732
+ stripe: this.stripe_,
7733
+ elements: this.elements_,
7734
+ };
7735
+ }
7688
7736
  GetInstance() {
7689
7737
  return this.stripe_;
7690
7738
  }
7691
7739
  WaitInstance() {
7692
7740
  return new Promise(resolve => {
7693
- this.mounted_ ? resolve(this.stripe_) : this.instanceWaiters_.push(() => resolve(this.stripe_));
7741
+ this.mounted_ ? resolve(this.GetDetails()) : this.instanceWaiters_.push(() => resolve(this.GetDetails()));
7694
7742
  });
7695
7743
  }
7696
7744
  Mount() {
@@ -7702,6 +7750,7 @@ class StripeElement extends inlinejs_element_1.CustomElement {
7702
7750
  this.mounting_ = false;
7703
7751
  this.mounted_ = true;
7704
7752
  this.stripe_ = Stripe(this.publicKey);
7753
+ this.elements_ = this.stripe_.elements();
7705
7754
  this.instanceWaiters_.splice(0).forEach(waiter => (0, inlinejs_1.JournalTry)(waiter));
7706
7755
  });
7707
7756
  }
@@ -7724,37 +7773,37 @@ class StripeElement extends inlinejs_element_1.CustomElement {
7724
7773
  }
7725
7774
  PayOrSetup_(pay, clientSecret, save = false) {
7726
7775
  return new Promise((resolve, reject) => {
7727
- this.WaitInstance().then((stripe) => {
7776
+ this.WaitInstance().then((details) => {
7728
7777
  var _a, _b;
7729
- if (!stripe) {
7778
+ if (!(details === null || details === void 0 ? void 0 : details.stripe)) {
7730
7779
  return resolve(false);
7731
7780
  }
7732
- const details = {};
7733
- (_a = this.fields_) === null || _a === void 0 ? void 0 : _a.forEach(field => field.AddDetails(details));
7734
- if (!details.method) {
7781
+ const paymentDetails = {};
7782
+ (_a = this.fields_) === null || _a === void 0 ? void 0 : _a.forEach(field => field.AddDetails(paymentDetails));
7783
+ if (!paymentDetails.method) {
7735
7784
  return resolve(false);
7736
7785
  }
7737
7786
  let cardDetails;
7738
- if (typeof details.method !== 'string') {
7787
+ if (typeof paymentDetails.method !== 'string') {
7739
7788
  cardDetails = {
7740
7789
  payment_method: {
7741
- card: details.method,
7742
- billing_details: details.billingDetails,
7790
+ card: paymentDetails.method,
7791
+ billing_details: paymentDetails.billingDetails,
7743
7792
  },
7744
7793
  };
7745
7794
  }
7746
7795
  else {
7747
7796
  cardDetails = {
7748
- payment_method: details.method,
7797
+ payment_method: paymentDetails.method,
7749
7798
  };
7750
7799
  }
7751
7800
  if (pay) {
7752
- ((_b = details.billingDetails) === null || _b === void 0 ? void 0 : _b.email) && (cardDetails.receipt_email = details.billingDetails.email);
7801
+ ((_b = paymentDetails.billingDetails) === null || _b === void 0 ? void 0 : _b.email) && (cardDetails.receipt_email = paymentDetails.billingDetails.email);
7753
7802
  save && (cardDetails.setup_future_usage = 'off_session');
7754
- stripe.confirmCardPayment(clientSecret, cardDetails).then(resolve).catch(reject);
7803
+ details.stripe.confirmCardPayment(clientSecret, cardDetails).then(resolve).catch(reject);
7755
7804
  }
7756
7805
  else {
7757
- stripe.confirmCardSetup(clientSecret, cardDetails).then(resolve).catch(reject);
7806
+ details.stripe.confirmCardSetup(clientSecret, cardDetails).then(resolve).catch(reject);
7758
7807
  }
7759
7808
  }).catch(reject);
7760
7809
  });