@benbraide/inlinejs-stripe 2.0.4 → 2.0.6

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.
@@ -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,13 +7391,15 @@ 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 = '';
7401
7397
  this.oncomplete = '';
7402
7398
  this.onerrors = '';
7403
7399
  }
7400
+ IsInteractive() {
7401
+ return true;
7402
+ }
7404
7403
  WaitReady() {
7405
7404
  return new Promise(resolve => {
7406
7405
  this.isReady_ ? resolve() : this.readyWaiters_.push(() => resolve());
@@ -7426,16 +7425,12 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
7426
7425
  }
7427
7426
  HandleElementScopeCreated_(_a, postAttributesCallback) {
7428
7427
  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
- });
7428
+ super.HandleElementScopeCreated_(Object.assign({ scope }, rest), postAttributesCallback);
7434
7429
  scope.AddPostProcessCallback(() => {
7435
7430
  var _a;
7436
- (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.WaitInstance().then((stripe) => {
7431
+ (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.WaitInstance().then((details) => {
7437
7432
  var _a;
7438
- if (!stripe) {
7433
+ if (!(details === null || details === void 0 ? void 0 : details.stripe)) {
7439
7434
  return;
7440
7435
  }
7441
7436
  let type = '';
@@ -7445,8 +7440,8 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
7445
7440
  else if (['card', 'cardNumber', 'cardExpiry', 'cardCvc', 'postalCode', 'paymentRequestButton', 'iban', 'idealBank'].includes(this.type)) {
7446
7441
  type = this.type;
7447
7442
  }
7448
- if (type) {
7449
- this.stripeField_ = stripe.elements().create(type, (this.options || ((_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.options) || undefined));
7443
+ if (type && details.elements) {
7444
+ this.stripeField_ = details.elements.create(type, (this.options || ((_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.options) || undefined));
7450
7445
  this.stripeField_.on('ready', () => {
7451
7446
  this.isReady_ = true;
7452
7447
  this.onready && (0, inlinejs_1.EvaluateLater)({
@@ -7489,13 +7484,7 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
7489
7484
  this.stripeField_ = null;
7490
7485
  });
7491
7486
  }
7492
- GetStripe_() {
7493
- return (this.stripe || (0, inlinejs_1.FindAncestor)(this, ancestor => ('AddStripeField' in ancestor)));
7494
- }
7495
7487
  }
7496
- __decorate([
7497
- (0, inlinejs_element_1.Property)({ type: 'object', checkStoredObject: true })
7498
- ], StripeFieldElement.prototype, "stripe", void 0);
7499
7488
  __decorate([
7500
7489
  (0, inlinejs_element_1.Property)({ type: 'object', checkStoredObject: true })
7501
7490
  ], StripeFieldElement.prototype, "options", void 0);
@@ -7518,6 +7507,70 @@ function StripeFieldElementCompact() {
7518
7507
  exports.StripeFieldElementCompact = StripeFieldElementCompact;
7519
7508
 
7520
7509
 
7510
+ /***/ }),
7511
+
7512
+ /***/ "./src/components/generic-field.ts":
7513
+ /*!*****************************************!*\
7514
+ !*** ./src/components/generic-field.ts ***!
7515
+ \*****************************************/
7516
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
7517
+
7518
+
7519
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
7520
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7521
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7522
+ 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;
7523
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7524
+ };
7525
+ var __rest = (this && this.__rest) || function (s, e) {
7526
+ var t = {};
7527
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
7528
+ t[p] = s[p];
7529
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7530
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7531
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
7532
+ t[p[i]] = s[p[i]];
7533
+ }
7534
+ return t;
7535
+ };
7536
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
7537
+ exports.StripeGenericField = void 0;
7538
+ const inlinejs_1 = __webpack_require__(/*! @benbraide/inlinejs */ "./node_modules/@benbraide/inlinejs/lib/esm/index.js");
7539
+ const inlinejs_element_1 = __webpack_require__(/*! @benbraide/inlinejs-element */ "./node_modules/@benbraide/inlinejs-element/lib/esm/index.js");
7540
+ class StripeGenericField extends inlinejs_element_1.CustomElement {
7541
+ constructor() {
7542
+ super(...arguments);
7543
+ this.stripe = null;
7544
+ }
7545
+ IsInteractive() {
7546
+ return false;
7547
+ }
7548
+ WaitReady() {
7549
+ return Promise.resolve();
7550
+ }
7551
+ AddChangeListener(listener) { }
7552
+ RemoveChangeListener(listener) { }
7553
+ ToggleFocus(focused) { }
7554
+ Reset() { }
7555
+ AddDetails(details) { }
7556
+ HandleElementScopeCreated_(_a, postAttributesCallback) {
7557
+ var { scope } = _a, rest = __rest(_a, ["scope"]);
7558
+ super.HandleElementScopeCreated_(Object.assign({ scope }, rest), () => {
7559
+ var _a;
7560
+ (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.AddStripeField(this);
7561
+ postAttributesCallback && postAttributesCallback();
7562
+ });
7563
+ }
7564
+ GetStripe_() {
7565
+ return (this.stripe || (0, inlinejs_1.FindAncestor)(this, ancestor => ('AddStripeField' in ancestor)));
7566
+ }
7567
+ }
7568
+ __decorate([
7569
+ (0, inlinejs_element_1.Property)({ type: 'object', checkStoredObject: true })
7570
+ ], StripeGenericField.prototype, "stripe", void 0);
7571
+ exports.StripeGenericField = StripeGenericField;
7572
+
7573
+
7521
7574
  /***/ }),
7522
7575
 
7523
7576
  /***/ "./src/components/payment-method.ts":
@@ -7536,7 +7589,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7536
7589
  Object.defineProperty(exports, "__esModule", ({ value: true }));
7537
7590
  exports.StripePaymentMenthodElementCompact = exports.StripePaymentMenthodElement = void 0;
7538
7591
  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 {
7592
+ const generic_field_1 = __webpack_require__(/*! ./generic-field */ "./src/components/generic-field.ts");
7593
+ class StripePaymentMenthodElement extends generic_field_1.StripeGenericField {
7540
7594
  constructor() {
7541
7595
  super({
7542
7596
  isTemplate: true,
@@ -7544,13 +7598,6 @@ class StripePaymentMenthodElement extends inlinejs_element_1.CustomElement {
7544
7598
  });
7545
7599
  this.value = '';
7546
7600
  }
7547
- WaitReady() {
7548
- return Promise.resolve();
7549
- }
7550
- AddChangeListener(listener) { }
7551
- RemoveChangeListener(listener) { }
7552
- ToggleFocus(focused) { }
7553
- Reset() { }
7554
7601
  AddDetails(details) {
7555
7602
  this.value && (details.method = this.value);
7556
7603
  }
@@ -7599,6 +7646,7 @@ class StripeElement extends inlinejs_element_1.CustomElement {
7599
7646
  constructor() {
7600
7647
  super();
7601
7648
  this.stripe_ = null;
7649
+ this.elements_ = null;
7602
7650
  this.mounting_ = false;
7603
7651
  this.mounted_ = false;
7604
7652
  this.isReady_ = false;
@@ -7606,6 +7654,7 @@ class StripeElement extends inlinejs_element_1.CustomElement {
7606
7654
  this.fields_ = null;
7607
7655
  this.readyFields_ = null;
7608
7656
  this.instanceWaiters_ = new Array();
7657
+ this.interactiveFields_ = null;
7609
7658
  this.completeFields_ = null;
7610
7659
  this.errorFields_ = null;
7611
7660
  this.options = null;
@@ -7622,6 +7671,10 @@ class StripeElement extends inlinejs_element_1.CustomElement {
7622
7671
  field.WaitReady().then(() => {
7623
7672
  this.readyFields_ = (this.readyFields_ || []);
7624
7673
  this.readyFields_.push(field);
7674
+ if (field.IsInteractive()) {
7675
+ this.interactiveFields_ = (this.interactiveFields_ || []);
7676
+ this.interactiveFields_.push(field);
7677
+ }
7625
7678
  (this.fields_ && this.readyFields_ && this.fields_.length <= this.readyFields_.length) && (0, inlinejs_1.JournalTry)(() => {
7626
7679
  this.isReady_ = true;
7627
7680
  this.onready && (0, inlinejs_1.EvaluateLater)({
@@ -7639,11 +7692,11 @@ class StripeElement extends inlinejs_element_1.CustomElement {
7639
7692
  this.completeFields_ = (this.completeFields_ || []);
7640
7693
  if (data && !this.completeFields_.includes(field)) {
7641
7694
  this.completeFields_.push(field);
7642
- changed = !!(this.readyFields_ && this.completeFields_.length == this.readyFields_.length);
7695
+ changed = !!(this.interactiveFields_ && this.completeFields_.length == this.interactiveFields_.length);
7643
7696
  }
7644
7697
  else if (!data && this.completeFields_.includes(field)) {
7645
7698
  this.completeFields_ = this.completeFields_.filter(x => x !== field);
7646
- changed = !!(this.readyFields_ && (this.completeFields_.length == (this.readyFields_.length - 1)));
7699
+ changed = !!(this.interactiveFields_ && (this.completeFields_.length == (this.interactiveFields_.length - 1)));
7647
7700
  }
7648
7701
  changed && this.oncomplete && (0, inlinejs_1.EvaluateLater)({
7649
7702
  componentId: this.componentId_,
@@ -7678,6 +7731,9 @@ class StripeElement extends inlinejs_element_1.CustomElement {
7678
7731
  RemoveStripeField(field) {
7679
7732
  this.fields_ && (this.fields_ = this.fields_.filter(x => x !== field));
7680
7733
  this.readyFields_ && (this.readyFields_ = this.readyFields_.filter(x => x !== field));
7734
+ this.interactiveFields_ && (this.interactiveFields_ = this.interactiveFields_.filter(x => x !== field));
7735
+ this.completeFields_ && (this.completeFields_ = this.completeFields_.filter(x => x !== field));
7736
+ this.errorFields_ && (this.errorFields_ = this.errorFields_.filter(x => x !== field));
7681
7737
  }
7682
7738
  FocusNextField(field) {
7683
7739
  if (this.fields_) {
@@ -7685,12 +7741,18 @@ class StripeElement extends inlinejs_element_1.CustomElement {
7685
7741
  (index >= 0 && index < this.fields_.length - 1) && this.fields_[index + 1].ToggleFocus(true);
7686
7742
  }
7687
7743
  }
7744
+ GetDetails() {
7745
+ return {
7746
+ stripe: this.stripe_,
7747
+ elements: this.elements_,
7748
+ };
7749
+ }
7688
7750
  GetInstance() {
7689
7751
  return this.stripe_;
7690
7752
  }
7691
7753
  WaitInstance() {
7692
7754
  return new Promise(resolve => {
7693
- this.mounted_ ? resolve(this.stripe_) : this.instanceWaiters_.push(() => resolve(this.stripe_));
7755
+ this.mounted_ ? resolve(this.GetDetails()) : this.instanceWaiters_.push(() => resolve(this.GetDetails()));
7694
7756
  });
7695
7757
  }
7696
7758
  Mount() {
@@ -7702,6 +7764,7 @@ class StripeElement extends inlinejs_element_1.CustomElement {
7702
7764
  this.mounting_ = false;
7703
7765
  this.mounted_ = true;
7704
7766
  this.stripe_ = Stripe(this.publicKey);
7767
+ this.elements_ = this.stripe_.elements();
7705
7768
  this.instanceWaiters_.splice(0).forEach(waiter => (0, inlinejs_1.JournalTry)(waiter));
7706
7769
  });
7707
7770
  }
@@ -7724,37 +7787,37 @@ class StripeElement extends inlinejs_element_1.CustomElement {
7724
7787
  }
7725
7788
  PayOrSetup_(pay, clientSecret, save = false) {
7726
7789
  return new Promise((resolve, reject) => {
7727
- this.WaitInstance().then((stripe) => {
7790
+ this.WaitInstance().then((details) => {
7728
7791
  var _a, _b;
7729
- if (!stripe) {
7792
+ if (!(details === null || details === void 0 ? void 0 : details.stripe)) {
7730
7793
  return resolve(false);
7731
7794
  }
7732
- const details = {};
7733
- (_a = this.fields_) === null || _a === void 0 ? void 0 : _a.forEach(field => field.AddDetails(details));
7734
- if (!details.method) {
7795
+ const paymentDetails = {};
7796
+ (_a = this.fields_) === null || _a === void 0 ? void 0 : _a.forEach(field => field.AddDetails(paymentDetails));
7797
+ if (!paymentDetails.method) {
7735
7798
  return resolve(false);
7736
7799
  }
7737
7800
  let cardDetails;
7738
- if (typeof details.method !== 'string') {
7801
+ if (typeof paymentDetails.method !== 'string') {
7739
7802
  cardDetails = {
7740
7803
  payment_method: {
7741
- card: details.method,
7742
- billing_details: details.billingDetails,
7804
+ card: paymentDetails.method,
7805
+ billing_details: paymentDetails.billingDetails,
7743
7806
  },
7744
7807
  };
7745
7808
  }
7746
7809
  else {
7747
7810
  cardDetails = {
7748
- payment_method: details.method,
7811
+ payment_method: paymentDetails.method,
7749
7812
  };
7750
7813
  }
7751
7814
  if (pay) {
7752
- ((_b = details.billingDetails) === null || _b === void 0 ? void 0 : _b.email) && (cardDetails.receipt_email = details.billingDetails.email);
7815
+ ((_b = paymentDetails.billingDetails) === null || _b === void 0 ? void 0 : _b.email) && (cardDetails.receipt_email = paymentDetails.billingDetails.email);
7753
7816
  save && (cardDetails.setup_future_usage = 'off_session');
7754
- stripe.confirmCardPayment(clientSecret, cardDetails).then(resolve).catch(reject);
7817
+ details.stripe.confirmCardPayment(clientSecret, cardDetails).then(resolve).catch(reject);
7755
7818
  }
7756
7819
  else {
7757
- stripe.confirmCardSetup(clientSecret, cardDetails).then(resolve).catch(reject);
7820
+ details.stripe.confirmCardSetup(clientSecret, cardDetails).then(resolve).catch(reject);
7758
7821
  }
7759
7822
  }).catch(reject);
7760
7823
  });