Skip to content

Commit d9b6f58

Browse files
committed
chore: linting cleanup
1 parent 37adfad commit d9b6f58

File tree

10 files changed

+90
-88
lines changed

10 files changed

+90
-88
lines changed

src/common/observe.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/* eslint-disable @typescript-eslint/no-unused-vars */
1+
/* eslint-disable no-unused-vars */
2+
23
import * as messaging from './message';
34
import {
45
CashBarcodeObject,

src/common/pay_theory_types.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,10 @@ export interface CheckoutDetails {
222222
export interface PayTheoryQRInput {
223223
apiKey: string;
224224
checkoutDetails: CheckoutDetails;
225-
size: number;
226-
onReady: (ready: true) => void;
227-
onError: (error: string) => void;
228-
onSuccess: (result: SuccessfulTransactionObject) => void;
225+
size?: number;
226+
onReady?: (ready: true) => void;
227+
onError?: (error: string) => void;
228+
onSuccess?: (result: SuccessfulTransactionObject) => void;
229229
}
230230

231231
export interface ButtonStyle {
@@ -275,15 +275,15 @@ export interface StyleObject {
275275
}
276276

277277
export interface Level3DataSummary {
278-
tax_amt: number;
279-
tax_ind: TaxIndicatorType;
280-
purch_idfr: string;
281-
order_num: string;
282-
discnt_amt: number;
283-
frght_amt: number;
284-
duty_amt: number;
285-
dest_postal_code: string;
286-
prod_desc: string[];
278+
tax_amt?: number;
279+
tax_ind?: TaxIndicatorType;
280+
purch_idfr?: string;
281+
order_num?: string;
282+
discnt_amt?: number;
283+
frght_amt?: number;
284+
duty_amt?: number;
285+
dest_postal_code?: string;
286+
prod_desc?: string[];
287287
}
288288

289289
export enum TaxIndicatorType {

src/components/pay-theory-checkout-button/index.ts

+13-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/* global HTMLElement */
2+
/* eslint-disable no-unused-vars */
3+
24
import common from '../../common';
35
import { SuccessfulTransactionObject } from '../../common/pay_theory_types';
46

@@ -8,22 +10,18 @@ class PayTheoryCheckoutButton extends HTMLElement {
810
protected _onClick: () => void;
911
protected _onError: (error: string) => void;
1012
protected _onSuccess: (message: { data: SuccessfulTransactionObject }) => void;
11-
protected _clearReadyListener: () => void | undefined;
12-
protected _clearClickListener: () => void | undefined;
13-
protected _clearErrorListener: () => void | undefined;
14-
protected _clearSuccessListener: () => void | undefined;
15-
protected _clearBarcodeReceivedListener: () => void | undefined;
13+
protected _clearReadyListener: (() => void) | undefined;
14+
protected _clearClickListener: (() => void) | undefined;
15+
protected _clearErrorListener: (() => void) | undefined;
16+
protected _clearSuccessListener: (() => void) | undefined;
17+
protected _clearBarcodeReceivedListener: (() => void) | undefined;
1618
protected _closeInterval: ReturnType<typeof setInterval> | undefined;
1719
protected _checkoutWindow: Window | undefined;
1820
protected _buttonBarcode: string | undefined;
1921
protected _session: string | undefined;
2022

2123
constructor() {
2224
super();
23-
this._onReady = () => {};
24-
this._onClick = () => {};
25-
this._onError = () => {};
26-
this._onSuccess = () => {};
2725
}
2826

2927
defineButton() {
@@ -68,14 +66,12 @@ class PayTheoryCheckoutButton extends HTMLElement {
6866
}
6967

7068
disconnectedCallback() {
71-
this._clearErrorListener();
72-
this._clearSuccessListener();
73-
this._clearReadyListener();
74-
this._clearClickListener();
75-
this._clearBarcodeReceivedListener();
76-
if (this._closeInterval) {
77-
clearInterval(this._closeInterval);
78-
}
69+
if (this._clearErrorListener) this._clearErrorListener();
70+
if (this._clearSuccessListener) this._clearSuccessListener();
71+
if (this._clearReadyListener) this._clearReadyListener();
72+
if (this._clearClickListener) this._clearClickListener();
73+
if (this._clearBarcodeReceivedListener) this._clearBarcodeReceivedListener();
74+
if (this._closeInterval) clearInterval(this._closeInterval);
7975
}
8076

8177
// Only want to allow event listeners to be set from outside the class

src/components/pay-theory-checkout-qr/index.ts

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
/* global HTMLElement */
2+
/* eslint-disable no-unused-vars */
3+
24
import common from '../../common';
35

46
class PayTheoryCheckoutQR extends HTMLElement {
57
protected _token: string | undefined;
68
protected _size: number | undefined;
7-
protected _onReady: (message: unknown) => void;
8-
protected _onClick: (message: unknown) => void;
9-
protected _onError: (message: unknown) => void;
10-
protected _onSuccess: (message: unknown) => void;
11-
protected _clearReadyListener: () => void | undefined;
12-
protected _clearSuccessListener: () => void | undefined;
13-
protected _clearErrorListener: () => void | undefined;
9+
protected _onReady: ((message: unknown) => void) | undefined;
10+
protected _onClick: ((message: unknown) => void) | undefined;
11+
protected _onError: ((message: unknown) => void) | undefined;
12+
protected _onSuccess: ((message: unknown) => void) | undefined;
13+
protected _clearReadyListener: (() => void) | undefined;
14+
protected _clearSuccessListener: (() => void) | undefined;
15+
protected _clearErrorListener: (() => void) | undefined;
1416

1517
constructor() {
1618
super();
17-
this._onReady = () => {};
18-
this._onClick = () => {};
19-
this._onError = () => {};
20-
this._onSuccess = () => {};
2119
}
2220

2321
defineQR() {
@@ -51,9 +49,9 @@ class PayTheoryCheckoutQR extends HTMLElement {
5149
}
5250

5351
disconnectedCallback() {
54-
this._clearSuccessListener();
55-
this._clearReadyListener();
56-
this._clearErrorListener();
52+
if (this._clearSuccessListener) this._clearSuccessListener();
53+
if (this._clearReadyListener) this._clearReadyListener();
54+
if (this._clearErrorListener) this._clearErrorListener();
5755
}
5856

5957
// Only want to allow event listeners to be set from outside the class

src/components/pay-theory-hosted-field-transactional/index.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable no-unused-vars */
2-
32
/* eslint-disable no-empty-function */
43

54
import PayTheoryHostedField from '../pay-theory-hosted-field';
@@ -121,10 +120,10 @@ class PayTheoryHostedFieldTransactional extends PayTheoryHostedField {
121120
protected _transactingType: TransactingType;
122121

123122
// Function used to remove event listeners
124-
protected _removeEventListeners: () => void = () => {};
125-
protected _removeHostTokenListener: () => void = () => {};
126-
protected _removeFeeListener: () => void = () => {};
127-
protected _removeFeeCalcReconnect: () => void = () => {};
123+
protected _removeEventListeners: (() => void) | undefined;
124+
protected _removeHostTokenListener: (() => void) | undefined;
125+
protected _removeFeeListener: (() => void) | undefined;
126+
protected _removeFeeCalcReconnect: (() => void) | undefined;
128127

129128
// Used for backwards compatibility with feeMode
130129
protected _feeMode: typeof common.SERVICE_FEE | typeof common.MERCHANT_FEE | undefined;
@@ -283,10 +282,10 @@ class PayTheoryHostedFieldTransactional extends PayTheoryHostedField {
283282
}
284283

285284
disconnectedCallback() {
286-
this._removeEventListeners();
287-
this._removeHostTokenListener();
288-
this._removeFeeListener();
289-
this._removeFeeCalcReconnect();
285+
if (this._removeEventListeners) this._removeEventListeners();
286+
if (this._removeHostTokenListener) this._removeHostTokenListener();
287+
if (this._removeFeeListener) this._removeFeeListener();
288+
if (this._removeFeeCalcReconnect) this._removeFeeCalcReconnect();
290289
}
291290

292291
async transact(data: TransactDataObject, element: PayTheoryHostedFieldTransactional) {

src/components/pay-theory-overlay/index.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ import common from '../../common';
33

44
class PayTheoryOverlay extends HTMLElement {
55
protected _token: string | undefined;
6-
protected _onFocus: () => void;
7-
protected _onCancel: () => void;
8-
protected _clearFocusListener: () => void = () => {};
9-
protected _clearCancelListener: () => void = () => {};
6+
protected _onFocus: (() => void) | undefined;
7+
protected _onCancel: (() => void) | undefined;
8+
protected _clearFocusListener: (() => void) | undefined;
9+
protected _clearCancelListener: (() => void) | undefined;
1010

1111
constructor() {
1212
super();
13-
this._onFocus = () => {};
14-
this._onCancel = () => {};
1513
}
1614

1715
defineOverlay() {
@@ -28,17 +26,21 @@ class PayTheoryOverlay extends HTMLElement {
2826
// Adding the event listeners for the overlay
2927
this._clearCancelListener = common.handleHostedFieldMessage(
3028
common.overlayCancelTypeMessage,
31-
this._onCancel,
29+
() => {
30+
if (this._onCancel) this._onCancel();
31+
},
3232
);
3333
this._clearFocusListener = common.handleHostedFieldMessage(
3434
common.overlayRelaunchTypeMessage,
35-
this._onFocus,
35+
() => {
36+
if (this._onFocus) this._onFocus();
37+
},
3638
);
3739
}
3840

3941
disconnectedCallback() {
40-
this._clearCancelListener();
41-
this._clearFocusListener();
42+
if (this._clearCancelListener) this._clearCancelListener();
43+
if (this._clearFocusListener) this._clearFocusListener();
4244
}
4345

4446
// Only want to allow event listeners to be set from outside the class

src/field-set/actions.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ const updateElementFromAction = (
3434
) => {
3535
if (message.type === ResponseMessageTypes.ERROR || message.type === ResponseMessageTypes.FAILED) {
3636
iframe.initialized = false;
37-
iframe.resetToken();
37+
iframe.resetToken().catch(e => {
38+
console.error(e);
39+
});
3840
} else if (message.type !== ResponseMessageTypes.CONFIRMATION) {
3941
iframe.complete = true;
4042
}
@@ -43,7 +45,7 @@ const updateElementFromAction = (
4345
const reconnectIfDisconnected = async (
4446
iframe: PayTheoryHostedFieldTransactional,
4547
): Promise<ErrorResponse | null> => {
46-
if (iframe.connected == false) {
48+
if (!iframe.connected) {
4749
const result = await iframe.resetToken();
4850
if (result.type === ResponseMessageTypes.ERROR) {
4951
return common.handleTypedError(ErrorType.SOCKET_ERROR, result.error);
@@ -76,9 +78,9 @@ export const transact = async (
7678
ErrorType.ACTION_IN_PROGRESS,
7779
'this function has already been called',
7880
);
79-
} else if (transactingElement.valid == false) {
81+
} else if (!transactingElement.valid) {
8082
return common.handleTypedError(ErrorType.NOT_VALID, 'The transaction element is invalid');
81-
} else if (transactingElement.ready == false) {
83+
} else if (!transactingElement.ready) {
8284
return common.handleTypedError(ErrorType.NOT_READY, 'The transaction element is not ready');
8385
} else {
8486
const reconnectError = await reconnectIfDisconnected(transactingElement);
@@ -87,14 +89,14 @@ export const transact = async (
8789
transactingElement.initialized = true;
8890
const newProps = common.parseInputParams(props) as ModifiedTransactProps;
8991
const { payorInfo, customerInfo, shippingDetails } = newProps;
90-
newProps.payorInfo = payorInfo || customerInfo || shippingDetails || {};
92+
newProps.payorInfo = payorInfo ?? customerInfo ?? shippingDetails ?? {};
9193
// Adding line for backwards compatability. Default to what was passed into the transact function, then the one passed into create, then the default
9294
newProps.feeMode = newProps.feeMode
9395
? newProps.feeMode
9496
: transactingElement.feeMode
9597
? transactingElement.feeMode
9698
: MERCHANT_FEE;
97-
// @ts-ignore Adding line for backwards compatibility
99+
// @ts-expect-error Adding line for backwards compatibility
98100
newProps.feeMode = newProps.feeMode === 'interchange' ? MERCHANT_FEE : newProps.feeMode;
99101
// Check for validity of the transaction parameters
100102
const validity = valid.validTransactionParams(newProps);
@@ -125,7 +127,8 @@ export const transact = async (
125127
sendObserverMessage(parsedResponse);
126128
return parsedResponse;
127129
} catch (e) {
128-
return common.handleError(e?.error || e?.message || e);
130+
const errorString: string = e?.error || e?.message || e;
131+
return common.handleError(errorString);
129132
}
130133
}
131134
} else {
@@ -163,7 +166,6 @@ export const confirm = async (): Promise<
163166
}
164167
};
165168

166-
// @ts-ignore
167169
export const cancel = async (): Promise<true | ErrorResponse> => {
168170
const transactingElement = findTransactingElement();
169171
if (transactingElement) {
@@ -237,7 +239,7 @@ export const tokenizePaymentMethod = async (
237239
}
238240
};
239241

240-
export const activateCardPresentDevice = async (): Promise<ErrorResponse | true> => {
242+
export const activateCardPresentDevice = (): ErrorResponse | true => {
241243
return true;
242244
};
243245

@@ -253,7 +255,7 @@ export const updateAmount = async (amount: number): Promise<ErrorResponse | true
253255
const elements = document.getElementsByName(id);
254256
if (elements.length) {
255257
const transactingElement = elements[0] as PayTheoryHostedFieldTransactional;
256-
if (transactingElement.ready == false) {
258+
if (!transactingElement.ready) {
257259
return common.handleTypedError(
258260
ErrorType.NOT_READY,
259261
'Not all fields are ready to update the amount',

src/field-set/payment-button.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
/* eslint no-console: ["error", { allow: ["warn", "error"] }] */
22
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3-
/*global navigator*/
43
import common from '../common';
54
import * as valid from './validation';
65
import {
76
PayTheoryButtonInput,
87
SuccessfulTransactionObject,
98
ErrorResponse,
9+
CashBarcodeObject,
1010
} from '../common/pay_theory_types';
1111
import { ModifiedCheckoutDetails } from '../common/format';
1212
import PayTheoryCheckoutButton from '../components/pay-theory-checkout-button';
1313
import PayTheoryOverlay from '../components/pay-theory-overlay';
1414

1515
const PopupCenter = (url: string, title: string, w: number, h: number) => {
1616
// Fixes dual-screen position Most browsers Firefox
17-
// @ts-ignore ignore screen error for firefox
18-
const dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
19-
// @ts-ignore ignore screen error for firefox
20-
const dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;
17+
// @ts-expect-error ignore screen error for firefox
18+
const dualScreenLeft: number = window.screenLeft ?? screen.left;
19+
// @ts-expect-error ignore screen error for firefox
20+
const dualScreenTop: number = window.screenTop ?? screen.top;
2121

2222
const width = window.innerWidth
2323
? window.innerWidth
@@ -112,7 +112,7 @@ export default async (inputParams: PayTheoryButtonInput) => {
112112
// Remove the error listener because we added it to the button iFrame and do not want it to be called twice
113113
removeErrorListener();
114114
removeHostedErrorListener();
115-
if (data && data?.sessionId) {
115+
if (data && data.sessionId) {
116116
const buttonElement = getCheckoutButton();
117117
buttonElement.session = data.sessionId;
118118
}
@@ -126,7 +126,7 @@ export default async (inputParams: PayTheoryButtonInput) => {
126126
// Check to see if a barcode response was sent back to tell which callback to call
127127
const buttonElement = getCheckoutButton();
128128
if (buttonElement?.buttonBarcode) {
129-
if (onBarcode) onBarcode(JSON.parse(buttonElement.buttonBarcode));
129+
if (onBarcode) onBarcode(JSON.parse(buttonElement.buttonBarcode) as CashBarcodeObject);
130130
} else {
131131
if (onCancel) onCancel();
132132
}

src/field-set/payment-qr.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* eslint no-console: ["error", { allow: ["warn", "error"] }] */
22
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3-
/*global navigator*/
3+
44
import common from '../common';
55
import * as valid from './validation';
66
import PayTheoryCheckoutQR from '../components/pay-theory-checkout-qr';
7-
import { PayTheoryQRInput } from '../common/pay_theory_types';
7+
import { PayTheoryQRInput, SuccessfulTransactionObject } from '../common/pay_theory_types';
88
import { ErrorMessage, ModifiedCheckoutDetails } from '../common/format';
99

1010
export default async (inputParams: PayTheoryQRInput) => {
@@ -59,7 +59,11 @@ export default async (inputParams: PayTheoryQRInput) => {
5959
tagFrame.setAttribute('id', `${common.checkoutQRField}-wrapper`);
6060
tagFrame.size = finalSize;
6161
tagFrame.onReady = onReadyWrapper;
62-
if (onSuccess) tagFrame.onSuccess = (message: MessageEvent) => onSuccess(message.data);
62+
if (onSuccess) {
63+
tagFrame.onSuccess = (message: MessageEvent) => {
64+
onSuccess(message.data as SuccessfulTransactionObject);
65+
};
66+
}
6367
if (onError) tagFrame.onError = onError;
6468
// Append the button div to the wrapper div
6569
const qrDiv = document.getElementById(common.checkoutQRField);

0 commit comments

Comments
 (0)