@benbraide/inlinejs-stripe 2.0.0 → 2.0.2

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.
@@ -7311,6 +7311,8 @@ class StripeDetailElement extends inlinejs_element_1.CustomElement {
7311
7311
  WaitReady() {
7312
7312
  return Promise.resolve();
7313
7313
  }
7314
+ AddChangeListener(listener) { }
7315
+ RemoveChangeListener(listener) { }
7314
7316
  ToggleFocus(focused) {
7315
7317
  const input = this.GetInput_();
7316
7318
  input && (focused ? input.focus() : input.blur());
@@ -7321,7 +7323,7 @@ class StripeDetailElement extends inlinejs_element_1.CustomElement {
7321
7323
  }
7322
7324
  AddDetails(details) {
7323
7325
  const input = this.GetInput_();
7324
- if (!this.name || (!input && !this.value)) {
7326
+ if (!this.name || (!(input === null || input === void 0 ? void 0 : input.value) && !this.value)) {
7325
7327
  return;
7326
7328
  }
7327
7329
  details.billingDetails = (details.billingDetails || {});
@@ -7389,6 +7391,7 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
7389
7391
  this.stripeField_ = null;
7390
7392
  this.isReady_ = false;
7391
7393
  this.readyWaiters_ = new Array();
7394
+ this.changeListeners = new Array();
7392
7395
  this.stripe = null;
7393
7396
  this.options = null;
7394
7397
  this.type = '';
@@ -7401,6 +7404,13 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
7401
7404
  this.isReady_ ? resolve() : this.readyWaiters_.push(() => resolve());
7402
7405
  });
7403
7406
  }
7407
+ AddChangeListener(listener) {
7408
+ this.changeListeners.push(listener);
7409
+ }
7410
+ RemoveChangeListener(listener) {
7411
+ const index = this.changeListeners.indexOf(listener);
7412
+ (index >= 0) && this.changeListeners.splice(index, 1);
7413
+ }
7404
7414
  ToggleFocus(focused) {
7405
7415
  var _a, _b;
7406
7416
  (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()));
@@ -7437,6 +7447,12 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
7437
7447
  this.stripeField_ = stripe.elements().create(type, (this.options || ((_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.options) || undefined));
7438
7448
  this.stripeField_.on('ready', () => {
7439
7449
  this.isReady_ = true;
7450
+ this.onready && (0, inlinejs_1.EvaluateLater)({
7451
+ componentId: this.componentId_,
7452
+ contextElement: this,
7453
+ expression: this.onready,
7454
+ disableFunctionCall: false,
7455
+ })();
7440
7456
  this.readyWaiters_.splice(0).forEach(waiter => (0, inlinejs_1.JournalTry)(waiter));
7441
7457
  });
7442
7458
  this.stripeField_.on('change', (event) => {
@@ -7448,6 +7464,7 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
7448
7464
  expression: this.onerrors,
7449
7465
  disableFunctionCall: false,
7450
7466
  })(undefined, [], { error: event.error });
7467
+ this.changeListeners.forEach(listener => (0, inlinejs_1.JournalTry)(() => listener('error', event.error)));
7451
7468
  }
7452
7469
  else if (event === null || event === void 0 ? void 0 : event.complete) {
7453
7470
  (0, inlinejs_1.EvaluateLater)({
@@ -7456,8 +7473,15 @@ class StripeFieldElement extends inlinejs_element_1.CustomElement {
7456
7473
  expression: this.oncomplete,
7457
7474
  disableFunctionCall: false,
7458
7475
  })();
7476
+ this.changeListeners.forEach(listener => (0, inlinejs_1.JournalTry)(() => listener('complete', true)));
7459
7477
  (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.FocusNextField(this);
7460
7478
  }
7479
+ else {
7480
+ this.changeListeners.forEach((listener) => {
7481
+ (0, inlinejs_1.JournalTry)(() => listener('complete', false));
7482
+ (0, inlinejs_1.JournalTry)(() => listener('error', null));
7483
+ });
7484
+ }
7461
7485
  });
7462
7486
  this.stripeField_.mount(this);
7463
7487
  }
@@ -7527,6 +7551,8 @@ class StripePaymentMenthodElement extends inlinejs_element_1.CustomElement {
7527
7551
  WaitReady() {
7528
7552
  return Promise.resolve();
7529
7553
  }
7554
+ AddChangeListener(listener) { }
7555
+ RemoveChangeListener(listener) { }
7530
7556
  ToggleFocus(focused) { }
7531
7557
  Reset() { }
7532
7558
  AddDetails(details) {
@@ -7579,20 +7605,82 @@ class StripeElement extends inlinejs_element_1.CustomElement {
7579
7605
  this.stripe_ = null;
7580
7606
  this.mounting_ = false;
7581
7607
  this.mounted_ = false;
7608
+ this.isReady_ = false;
7609
+ this.readyWaiters_ = new Array();
7582
7610
  this.fields_ = null;
7611
+ this.readyFields_ = null;
7583
7612
  this.instanceWaiters_ = new Array();
7613
+ this.completeFields_ = null;
7614
+ this.errorFields_ = null;
7584
7615
  this.options = null;
7585
7616
  this.publicKey = '';
7586
7617
  this.onready = '';
7618
+ this.oncomplete = '';
7619
+ this.onerrors = '';
7587
7620
  this.defer = false;
7588
7621
  this.autofocus = false;
7589
7622
  }
7590
7623
  AddStripeField(field) {
7591
7624
  this.fields_ = (this.fields_ || []);
7592
7625
  this.fields_.push(field);
7626
+ field.WaitReady().then(() => {
7627
+ this.readyFields_ = (this.readyFields_ || []);
7628
+ this.readyFields_.push(field);
7629
+ (this.fields_ && this.readyFields_ && this.fields_.length <= this.readyFields_.length) && (0, inlinejs_1.JournalTry)(() => {
7630
+ this.isReady_ = true;
7631
+ this.onready && (0, inlinejs_1.EvaluateLater)({
7632
+ componentId: this.componentId_,
7633
+ contextElement: this,
7634
+ expression: this.onready,
7635
+ disableFunctionCall: false,
7636
+ })();
7637
+ this.readyWaiters_.splice(0).forEach(waiter => (0, inlinejs_1.JournalTry)(waiter));
7638
+ });
7639
+ });
7640
+ field.AddChangeListener((type, data) => {
7641
+ if (type === 'complete') {
7642
+ let changed = false;
7643
+ this.completeFields_ = (this.completeFields_ || []);
7644
+ if (data && !this.completeFields_.includes(field)) {
7645
+ this.completeFields_.push(field);
7646
+ changed = !!(this.readyFields_ && this.completeFields_.length == this.readyFields_.length);
7647
+ }
7648
+ else if (!data && this.completeFields_.includes(field)) {
7649
+ this.completeFields_ = this.completeFields_.filter(x => x !== field);
7650
+ changed = (this.completeFields_.length == 0);
7651
+ }
7652
+ changed && this.oncomplete && (0, inlinejs_1.EvaluateLater)({
7653
+ componentId: this.componentId_,
7654
+ contextElement: this,
7655
+ expression: this.oncomplete,
7656
+ disableFunctionCall: false,
7657
+ })(undefined, [!!data], { complete: !!data });
7658
+ }
7659
+ else if (type === 'error') {
7660
+ let changed = false;
7661
+ this.errorFields_ = (this.errorFields_ || []);
7662
+ this.errorFields_.push(field);
7663
+ this.errorFields_ = (this.errorFields_ || []);
7664
+ if (data && !this.errorFields_.includes(field)) {
7665
+ this.errorFields_.push(field);
7666
+ changed = (this.errorFields_.length == 1);
7667
+ }
7668
+ else if (!data && this.errorFields_.includes(field)) {
7669
+ this.errorFields_ = this.errorFields_.filter(x => x !== field);
7670
+ changed = (this.errorFields_.length == 0);
7671
+ }
7672
+ this.onerrors && (0, inlinejs_1.EvaluateLater)({
7673
+ componentId: this.componentId_,
7674
+ contextElement: this,
7675
+ expression: this.onerrors,
7676
+ disableFunctionCall: false,
7677
+ })(undefined, [data], { error: data });
7678
+ }
7679
+ });
7593
7680
  }
7594
7681
  RemoveStripeField(field) {
7595
7682
  this.fields_ && (this.fields_ = this.fields_.filter(x => x !== field));
7683
+ this.readyFields_ && (this.readyFields_ = this.readyFields_.filter(x => x !== field));
7596
7684
  }
7597
7685
  FocusNextField(field) {
7598
7686
  if (this.autofocus && this.fields_) {
@@ -7626,6 +7714,11 @@ class StripeElement extends inlinejs_element_1.CustomElement {
7626
7714
  Setup(clientSecret) {
7627
7715
  return this.PayOrSetup_(false, clientSecret);
7628
7716
  }
7717
+ WaitReady() {
7718
+ return new Promise(resolve => {
7719
+ this.isReady_ ? resolve() : this.readyWaiters_.push(() => resolve());
7720
+ });
7721
+ }
7629
7722
  HandleElementScopeCreated_(_a, postAttributesCallback) {
7630
7723
  var { scope } = _a, rest = __rest(_a, ["scope"]);
7631
7724
  super.HandleElementScopeCreated_(Object.assign({ scope }, rest), postAttributesCallback);
@@ -7679,6 +7772,12 @@ __decorate([
7679
7772
  __decorate([
7680
7773
  (0, inlinejs_element_1.Property)({ type: 'string' })
7681
7774
  ], StripeElement.prototype, "onready", void 0);
7775
+ __decorate([
7776
+ (0, inlinejs_element_1.Property)({ type: 'string' })
7777
+ ], StripeElement.prototype, "oncomplete", void 0);
7778
+ __decorate([
7779
+ (0, inlinejs_element_1.Property)({ type: 'string' })
7780
+ ], StripeElement.prototype, "onerrors", void 0);
7682
7781
  __decorate([
7683
7782
  (0, inlinejs_element_1.Property)({ type: 'boolean' })
7684
7783
  ], StripeElement.prototype, "defer", void 0);