@benbraide/inlinejs-stripe 2.2.0 → 2.3.1

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.
@@ -4,18 +4,7 @@ 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
- 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 { EvaluateLater, JournalTry } from "@benbraide/inlinejs";
7
+ import { EvaluateLater, JournalError, JournalTry, JournalWarn } from "@benbraide/inlinejs";
19
8
  import { Property, RegisterCustomElement } from "@benbraide/inlinejs-element";
20
9
  import { StripeGenericField } from "./generic-field";
21
10
  export class StripeFieldElement extends StripeGenericField {
@@ -29,9 +18,9 @@ export class StripeFieldElement extends StripeGenericField {
29
18
  this.changeListeners = new Array();
30
19
  this.options = null;
31
20
  this.type = '';
32
- this.onready = '';
33
- this.oncomplete = '';
34
- this.onerrors = '';
21
+ this.oncustomready = '';
22
+ this.oncustomcomplete = '';
23
+ this.oncustomerror = '';
35
24
  }
36
25
  IsInteractive() {
37
26
  return true;
@@ -59,66 +48,66 @@ export class StripeFieldElement extends StripeGenericField {
59
48
  AddDetails(details) {
60
49
  (this.stripeField_ && (this.type === 'card' || this.type === 'number' || this.type === 'cardNumber')) && (details.method = this.stripeField_);
61
50
  }
62
- HandleElementScopeCreated_(_a, postAttributesCallback) {
63
- var { scope } = _a, rest = __rest(_a, ["scope"]);
64
- super.HandleElementScopeCreated_(Object.assign({ scope }, rest), postAttributesCallback);
65
- scope.AddPostProcessCallback(() => {
51
+ HandleElementScopeDestroyed_(scope) {
52
+ var _a;
53
+ super.HandleElementScopeDestroyed_(scope);
54
+ (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.RemoveStripeField(this);
55
+ this.stripeField_ = null;
56
+ }
57
+ HandlePostProcess_() {
58
+ var _a;
59
+ super.HandlePostProcess_();
60
+ (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.WaitInstance().then((details) => {
66
61
  var _a;
67
- (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.WaitInstance().then((details) => {
68
- var _a;
69
- if (!(details === null || details === void 0 ? void 0 : details.stripe)) {
70
- return;
71
- }
72
- let type = '';
73
- if (['number', 'expiry', 'cvc'].includes(this.type)) {
74
- type = `card${this.type.substring(0, 1).toUpperCase()}${this.type.substring(1)}`;
75
- }
76
- else if (['card', 'cardNumber', 'cardExpiry', 'cardCvc', 'postalCode', 'paymentRequestButton', 'iban', 'idealBank'].includes(this.type)) {
77
- type = this.type;
62
+ if (!(details === null || details === void 0 ? void 0 : details.stripe) || !details.elements) {
63
+ return;
64
+ }
65
+ let type = '';
66
+ if (['number', 'expiry', 'cvc'].includes(this.type)) {
67
+ type = `card${this.type.substring(0, 1).toUpperCase()}${this.type.substring(1)}`;
68
+ }
69
+ else if (['card', 'cardNumber', 'cardExpiry', 'cardCvc', 'postalCode', 'paymentRequestButton', 'iban', 'idealBank'].includes(this.type)) {
70
+ type = this.type;
71
+ }
72
+ if (!type) {
73
+ JournalWarn('The element type provided is invalid.', 'StripeField.Mount', this);
74
+ return;
75
+ }
76
+ this.stripeField_ = details.elements.create(type, (this.options || ((_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.options) || undefined));
77
+ this.stripeField_.on('ready', () => {
78
+ this.isReady_ = true;
79
+ this.oncustomready && EvaluateLater({
80
+ componentId: this.componentId_,
81
+ contextElement: this,
82
+ expression: this.oncustomready,
83
+ disableFunctionCall: false,
84
+ })();
85
+ this.readyWaiters_.splice(0).forEach(waiter => JournalTry(waiter));
86
+ });
87
+ this.stripeField_.on('change', (event) => {
88
+ if (((event === null || event === void 0 ? void 0 : event.error) || null) !== this.lastError_) {
89
+ this.lastError_ = ((event === null || event === void 0 ? void 0 : event.error) || null);
90
+ this.oncustomerror && EvaluateLater({
91
+ componentId: this.componentId_,
92
+ contextElement: this,
93
+ expression: this.oncustomerror,
94
+ disableFunctionCall: false,
95
+ })(undefined, [this.lastError_], { error: this.lastError_ });
96
+ this.changeListeners.forEach(listener => JournalTry(() => listener('error', this.lastError_)));
78
97
  }
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));
81
- this.stripeField_.on('ready', () => {
82
- this.isReady_ = true;
83
- this.onready && EvaluateLater({
84
- componentId: this.componentId_,
85
- contextElement: this,
86
- expression: this.onready,
87
- disableFunctionCall: false,
88
- })();
89
- this.readyWaiters_.splice(0).forEach(waiter => JournalTry(waiter));
90
- });
91
- this.stripeField_.on('change', (event) => {
92
- if (((event === null || event === void 0 ? void 0 : event.error) || null) !== this.lastError_) {
93
- this.lastError_ = ((event === null || event === void 0 ? void 0 : event.error) || null);
94
- EvaluateLater({
95
- componentId: this.componentId_,
96
- contextElement: this,
97
- expression: this.onerrors,
98
- disableFunctionCall: false,
99
- })(undefined, [this.lastError_], { error: this.lastError_ });
100
- this.changeListeners.forEach(listener => JournalTry(() => listener('error', this.lastError_)));
101
- }
102
- if (((event === null || event === void 0 ? void 0 : event.complete) || false) != this.isComplete_) {
103
- this.isComplete_ = ((event === null || event === void 0 ? void 0 : event.complete) || false);
104
- EvaluateLater({
105
- componentId: this.componentId_,
106
- contextElement: this,
107
- expression: this.oncomplete,
108
- disableFunctionCall: false,
109
- })(undefined, [this.isComplete_], { complete: this.isComplete_ });
110
- this.changeListeners.forEach(listener => JournalTry(() => listener('complete', this.isComplete_)));
111
- }
112
- });
113
- this.stripeField_.mount(this);
98
+ if (((event === null || event === void 0 ? void 0 : event.complete) || false) != this.isComplete_) {
99
+ this.isComplete_ = ((event === null || event === void 0 ? void 0 : event.complete) || false);
100
+ this.oncustomcomplete && EvaluateLater({
101
+ componentId: this.componentId_,
102
+ contextElement: this,
103
+ expression: this.oncustomcomplete,
104
+ disableFunctionCall: false,
105
+ })(undefined, [this.isComplete_], { complete: this.isComplete_ });
106
+ this.changeListeners.forEach(listener => JournalTry(() => listener('complete', this.isComplete_)));
114
107
  }
115
108
  });
116
- });
117
- scope.AddUninitCallback(() => {
118
- var _a;
119
- (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.RemoveStripeField(this);
120
- this.stripeField_ = null;
121
- });
109
+ this.stripeField_.mount(this);
110
+ }).catch(err => JournalError(err, 'StripeField.Mount', this));
122
111
  }
123
112
  }
124
113
  __decorate([
@@ -129,13 +118,13 @@ __decorate([
129
118
  ], StripeFieldElement.prototype, "type", void 0);
130
119
  __decorate([
131
120
  Property({ type: 'string' })
132
- ], StripeFieldElement.prototype, "onready", void 0);
121
+ ], StripeFieldElement.prototype, "oncustomready", void 0);
133
122
  __decorate([
134
123
  Property({ type: 'string' })
135
- ], StripeFieldElement.prototype, "oncomplete", void 0);
124
+ ], StripeFieldElement.prototype, "oncustomcomplete", void 0);
136
125
  __decorate([
137
126
  Property({ type: 'string' })
138
- ], StripeFieldElement.prototype, "onerrors", void 0);
127
+ ], StripeFieldElement.prototype, "oncustomerror", void 0);
139
128
  export function StripeFieldElementCompact() {
140
129
  RegisterCustomElement(StripeFieldElement, 'stripe-field');
141
130
  }
@@ -1,4 +1,3 @@
1
- import { IElementScopeCreatedCallbackParams } from "@benbraide/inlinejs";
2
1
  import { CustomElement } from "@benbraide/inlinejs-element";
3
2
  import { IStripeElement, IStripeField, IStripePaymentDetails, StripeFieldChangeHandlerType } from "../types";
4
3
  export declare class StripeGenericField extends CustomElement implements IStripeField {
@@ -10,6 +9,6 @@ export declare class StripeGenericField extends CustomElement implements IStripe
10
9
  ToggleFocus(focused: boolean): void;
11
10
  Reset(): void;
12
11
  AddDetails(details: IStripePaymentDetails): void;
13
- protected HandleElementScopeCreated_({ scope, ...rest }: IElementScopeCreatedCallbackParams, postAttributesCallback?: () => void): void;
12
+ protected HandlePostAttributesProcessPostfix_(): void;
14
13
  protected GetStripe_(): IStripeElement | null;
15
14
  }
@@ -4,17 +4,6 @@ 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
- 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
7
  import { FindAncestor } from "@benbraide/inlinejs";
19
8
  import { CustomElement, Property } from "@benbraide/inlinejs-element";
20
9
  export class StripeGenericField extends CustomElement {
@@ -33,13 +22,10 @@ export class StripeGenericField extends CustomElement {
33
22
  ToggleFocus(focused) { }
34
23
  Reset() { }
35
24
  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
- });
25
+ HandlePostAttributesProcessPostfix_() {
26
+ var _a;
27
+ super.HandlePostAttributesProcessPostfix_();
28
+ (_a = this.GetStripe_()) === null || _a === void 0 ? void 0 : _a.AddStripeField(this);
43
29
  }
44
30
  GetStripe_() {
45
31
  return (this.stripe || FindAncestor(this, ancestor => ('AddStripeField' in ancestor)));
@@ -1,5 +1,5 @@
1
1
  /// <reference types="stripe-v3" />
2
- import { IElementScopeCreatedCallbackParams } from "@benbraide/inlinejs";
2
+ import { IElementScope } from "@benbraide/inlinejs";
3
3
  import { CustomElement } from "@benbraide/inlinejs-element";
4
4
  import { IStripeDetails, IStripeElement, IStripeField } from "../types";
5
5
  export declare class StripeElement extends CustomElement implements IStripeElement {
@@ -17,9 +17,9 @@ export declare class StripeElement extends CustomElement implements IStripeEleme
17
17
  protected errorFields_: Array<IStripeField> | null;
18
18
  options: stripe.elements.ElementsOptions | null;
19
19
  publicKey: string;
20
- onready: string;
21
- oncomplete: string;
22
- onerrors: string;
20
+ oncustomready: string;
21
+ oncustomcomplete: string;
22
+ oncustomerror: string;
23
23
  defer: boolean;
24
24
  focusnext: boolean;
25
25
  constructor();
@@ -33,7 +33,8 @@ export declare class StripeElement extends CustomElement implements IStripeEleme
33
33
  Pay(clientSecret: string, save?: boolean): Promise<false | stripe.PaymentIntentResponse>;
34
34
  Setup(clientSecret: string): Promise<false | stripe.PaymentIntentResponse>;
35
35
  WaitReady(): Promise<void>;
36
- protected HandleElementScopeCreated_({ scope, ...rest }: IElementScopeCreatedCallbackParams, postAttributesCallback?: () => void): void;
36
+ protected HandleElementScopeDestroyed_(scope: IElementScope): void;
37
+ protected HandlePostProcess_(): void;
37
38
  protected PayOrSetup_(pay: boolean, clientSecret: string, save?: boolean): Promise<false | stripe.PaymentIntentResponse>;
38
39
  }
39
40
  export declare function StripeElementCompact(): void;
@@ -4,17 +4,6 @@ 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
- 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
7
  import { EvaluateLater, JournalTry } from "@benbraide/inlinejs";
19
8
  import { CustomElement, Property, RegisterCustomElement } from "@benbraide/inlinejs-element";
20
9
  export class StripeElement extends CustomElement {
@@ -34,9 +23,9 @@ export class StripeElement extends CustomElement {
34
23
  this.errorFields_ = null;
35
24
  this.options = null;
36
25
  this.publicKey = '';
37
- this.onready = '';
38
- this.oncomplete = '';
39
- this.onerrors = '';
26
+ this.oncustomready = '';
27
+ this.oncustomcomplete = '';
28
+ this.oncustomerror = '';
40
29
  this.defer = false;
41
30
  this.focusnext = false;
42
31
  }
@@ -52,10 +41,10 @@ export class StripeElement extends CustomElement {
52
41
  }
53
42
  (this.fields_ && this.readyFields_ && this.fields_.length <= this.readyFields_.length) && JournalTry(() => {
54
43
  this.isReady_ = true;
55
- this.onready && EvaluateLater({
44
+ this.oncustomready && EvaluateLater({
56
45
  componentId: this.componentId_,
57
46
  contextElement: this,
58
- expression: this.onready,
47
+ expression: this.oncustomready,
59
48
  disableFunctionCall: false,
60
49
  })();
61
50
  this.readyWaiters_.splice(0).forEach(waiter => JournalTry(waiter));
@@ -73,10 +62,10 @@ export class StripeElement extends CustomElement {
73
62
  this.completeFields_ = this.completeFields_.filter(x => x !== field);
74
63
  changed = !!(this.interactiveFields_ && (this.completeFields_.length == (this.interactiveFields_.length - 1)));
75
64
  }
76
- changed && this.oncomplete && EvaluateLater({
65
+ changed && this.oncustomcomplete && EvaluateLater({
77
66
  componentId: this.componentId_,
78
67
  contextElement: this,
79
- expression: this.oncomplete,
68
+ expression: this.oncustomcomplete,
80
69
  disableFunctionCall: false,
81
70
  })(undefined, [!!data], { complete: !!data });
82
71
  !!data && this.focusnext && this.FocusNextField(field);
@@ -94,10 +83,10 @@ export class StripeElement extends CustomElement {
94
83
  this.errorFields_ = this.errorFields_.filter(x => x !== field);
95
84
  changed = (this.errorFields_.length == 0);
96
85
  }
97
- changed && this.onerrors && EvaluateLater({
86
+ changed && this.oncustomerror && EvaluateLater({
98
87
  componentId: this.componentId_,
99
88
  contextElement: this,
100
- expression: this.onerrors,
89
+ expression: this.oncustomerror,
101
90
  disableFunctionCall: false,
102
91
  })(undefined, [data], { error: data });
103
92
  }
@@ -154,11 +143,13 @@ export class StripeElement extends CustomElement {
154
143
  this.isReady_ ? resolve() : this.readyWaiters_.push(() => resolve());
155
144
  });
156
145
  }
157
- HandleElementScopeCreated_(_a, postAttributesCallback) {
158
- var { scope } = _a, rest = __rest(_a, ["scope"]);
159
- super.HandleElementScopeCreated_(Object.assign({ scope }, rest), postAttributesCallback);
160
- scope.AddPostProcessCallback(() => (!this.defer && this.Mount()));
161
- scope.AddUninitCallback(() => (this.stripe_ = null));
146
+ HandleElementScopeDestroyed_(scope) {
147
+ super.HandleElementScopeDestroyed_(scope);
148
+ this.stripe_ = null;
149
+ }
150
+ HandlePostProcess_() {
151
+ super.HandlePostProcess_();
152
+ !this.defer && this.Mount();
162
153
  }
163
154
  PayOrSetup_(pay, clientSecret, save = false) {
164
155
  return new Promise((resolve, reject) => {
@@ -173,7 +164,12 @@ export class StripeElement extends CustomElement {
173
164
  return resolve(false);
174
165
  }
175
166
  let cardDetails;
176
- if (typeof paymentDetails.method !== 'string') {
167
+ if (typeof paymentDetails.method === 'string') { // Payment Method ID
168
+ cardDetails = {
169
+ payment_method: paymentDetails.method,
170
+ };
171
+ }
172
+ else { // Stripe Element (e.g., CardElement)
177
173
  cardDetails = {
178
174
  payment_method: {
179
175
  card: paymentDetails.method,
@@ -181,11 +177,6 @@ export class StripeElement extends CustomElement {
181
177
  },
182
178
  };
183
179
  }
184
- else {
185
- cardDetails = {
186
- payment_method: paymentDetails.method,
187
- };
188
- }
189
180
  if (pay) {
190
181
  ((_b = paymentDetails.billingDetails) === null || _b === void 0 ? void 0 : _b.email) && (cardDetails.receipt_email = paymentDetails.billingDetails.email);
191
182
  save && (cardDetails.setup_future_usage = 'off_session');
@@ -206,13 +197,13 @@ __decorate([
206
197
  ], StripeElement.prototype, "publicKey", void 0);
207
198
  __decorate([
208
199
  Property({ type: 'string' })
209
- ], StripeElement.prototype, "onready", void 0);
200
+ ], StripeElement.prototype, "oncustomready", void 0);
210
201
  __decorate([
211
202
  Property({ type: 'string' })
212
- ], StripeElement.prototype, "oncomplete", void 0);
203
+ ], StripeElement.prototype, "oncustomcomplete", void 0);
213
204
  __decorate([
214
205
  Property({ type: 'string' })
215
- ], StripeElement.prototype, "onerrors", void 0);
206
+ ], StripeElement.prototype, "oncustomerror", void 0);
216
207
  __decorate([
217
208
  Property({ type: 'boolean' })
218
209
  ], StripeElement.prototype, "defer", void 0);
@@ -2,5 +2,4 @@ export * from './components/stripe';
2
2
  export * from './components/field';
3
3
  export * from './components/detail';
4
4
  export * from './components/payment-method';
5
- export * from './directive/stripe';
6
5
  export * from './entry';
package/lib/esm/index.js CHANGED
@@ -2,5 +2,4 @@ export * from './components/stripe';
2
2
  export * from './components/field';
3
3
  export * from './components/detail';
4
4
  export * from './components/payment-method';
5
- export * from './directive/stripe';
6
5
  export * from './entry';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@benbraide/inlinejs-stripe",
3
- "version": "2.2.0",
3
+ "version": "2.3.1",
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",
@@ -54,8 +54,8 @@
54
54
  "webpack": "^5.41.0"
55
55
  },
56
56
  "dependencies": {
57
- "@benbraide/inlinejs": "^1.3.1",
58
- "@benbraide/inlinejs-element": "^2.2.0",
57
+ "@benbraide/inlinejs": "^1.4.7",
58
+ "@benbraide/inlinejs-element": "^2.2.3",
59
59
  "webpack-cli": "^4.7.2"
60
60
  }
61
61
  }
@@ -1,24 +0,0 @@
1
- /// <reference types="stripe-v3" />
2
- export interface IStripeStyle {
3
- base?: stripe.elements.Style;
4
- complete?: stripe.elements.Style;
5
- empty?: stripe.elements.Style;
6
- invalid?: stripe.elements.Style;
7
- paymentRequestButton?: stripe.elements.PaymentRequestButtonStyleOptions;
8
- }
9
- export interface IStripeClass {
10
- base?: string;
11
- complete?: string;
12
- empty?: string;
13
- focus?: string;
14
- invalid?: string;
15
- webkitAutofill?: string;
16
- }
17
- export interface IStripeBillingDetails {
18
- name: string;
19
- email?: string;
20
- phone?: string;
21
- address?: string;
22
- }
23
- export declare const StripeDirectiveHandler: import("@benbraide/inlinejs").IDirectiveHandlerCallbackDetails;
24
- export declare function StripeDirectiveHandlerCompact(): void;