Skip to content

Commit 9e21655

Browse files
committed
fix: linting fix
1 parent 15be925 commit 9e21655

File tree

8 files changed

+112
-117
lines changed

8 files changed

+112
-117
lines changed

src/common/data.ts

+20-20
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const PAY = 'PAY';
1414
export const BOOK = 'BOOK';
1515
export const DONATE = 'DONATE';
1616
export const CHECKOUT = 'CHECKOUT';
17-
export type CALL_TO_ACTION = typeof PAY | typeof BOOK | typeof DONATE | typeof CHECKOUT;
17+
// export type CALL_TO_ACTION = typeof PAY | typeof BOOK | typeof DONATE | typeof CHECKOUT;
1818

1919
export const CTA_TYPES = [PAY, BOOK, DONATE];
2020

@@ -97,14 +97,14 @@ export const defaultElementIds = {
9797
'card-present': 'pay-theory-card-present',
9898
};
9999

100-
export type achElementIds = {
100+
export interface achElementIds {
101101
'account-number': string;
102102
'account-name': string;
103103
'routing-number': string;
104104
'account-type': string;
105-
};
105+
}
106106

107-
export type cardElementIds = {
107+
export interface cardElementIds {
108108
'credit-card': string;
109109
'card-number': string;
110110
'card-exp': string;
@@ -115,12 +115,12 @@ export type cardElementIds = {
115115
'billing-city': string;
116116
'billing-state': string;
117117
'billing-zip': string;
118-
};
118+
}
119119

120-
export type cashElementIds = {
120+
export interface cashElementIds {
121121
'cash-name': string;
122122
'cash-contact': string;
123-
};
123+
}
124124

125125
export type ElementTypes = keyof achElementIds | keyof cardElementIds | keyof cashElementIds;
126126

@@ -129,32 +129,32 @@ export const checkoutQRField = 'pay-theory-checkout-qr';
129129
export const payTheoryOverlay = 'pay-theory-overlay';
130130

131131
export const achFieldTypes: {
132-
transacting: Array<keyof achElementIds>;
133-
siblings: Array<keyof achElementIds>;
132+
transacting: (keyof achElementIds)[];
133+
siblings: (keyof achElementIds)[];
134134
} = {
135135
transacting: ['account-number'],
136136
siblings: ['account-name', 'account-type', 'routing-number'],
137137
};
138138

139139
export const cashFieldTypes: {
140-
transacting: Array<keyof cashElementIds>;
141-
siblings: Array<keyof cashElementIds>;
140+
transacting: (keyof cashElementIds)[];
141+
siblings: (keyof cashElementIds)[];
142142
} = {
143143
transacting: ['cash-name'],
144144
siblings: ['cash-contact'],
145145
};
146146

147-
export const cardPresentFieldTypes: {
148-
transacting: Array<'card-present'>;
149-
siblings: Array<string>;
150-
} = {
151-
transacting: ['card-present'],
152-
siblings: [],
153-
};
147+
// export const cardPresentFieldTypes: {
148+
// transacting: 'card-present'[];
149+
// siblings: string[];
150+
// } = {
151+
// transacting: ['card-present'],
152+
// siblings: [],
153+
// };
154154

155155
export const cardFieldTypes: {
156-
transacting: Array<keyof cardElementIds>;
157-
siblings: Array<keyof cardElementIds>;
156+
transacting: (keyof cardElementIds)[];
157+
siblings: (keyof cardElementIds)[];
158158
} = {
159159
transacting: ['credit-card', 'card-number'],
160160
siblings: [

src/common/dom.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable security/detect-object-injection */
12
import { handleTypedError } from './message';
23
import {
34
achElementIds,
@@ -80,8 +81,8 @@ const findElementError = <T extends cashElementIds | cardElementIds | achElement
8081
export const processElements = <ET extends cashElementIds | cardElementIds | achElementIds>(
8182
elements: ET,
8283
fieldTypes: {
83-
transacting: Array<keyof ET>;
84-
siblings: Array<keyof ET>;
84+
transacting: (keyof ET)[];
85+
siblings: (keyof ET)[];
8586
},
8687
) => {
8788
const processed: {
@@ -102,7 +103,7 @@ export const processElements = <ET extends cashElementIds | cardElementIds | ach
102103
if (typeof result === 'string') {
103104
error = result;
104105
} else {
105-
// @ts-ignore
106+
//@ts-expect-error
106107
processed[key].push(result);
107108
}
108109
}
@@ -114,7 +115,7 @@ export const processElements = <ET extends cashElementIds | cardElementIds | ach
114115
return processed;
115116
};
116117

117-
export const isHidden = (element: HTMLElement): boolean => {
118+
export const isHidden = (element: HTMLElement | undefined): boolean => {
118119
if (!element) return true;
119120
const style = window.getComputedStyle(element);
120121
if (style.display === 'none') {

src/common/format.ts

+32-32
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const COMPLETE_STEP = 'pt-static:complete';
2626
export const ERROR_STEP = 'pt-static:error';
2727
export const FIELDS_READY_STEP = 'pt-static:fields-ready';
2828

29-
export type PayTheoryDataObject = {
29+
export interface PayTheoryDataObject {
3030
account_code: string | number;
3131
reference: string | number;
3232
payment_parameters: string;
@@ -40,7 +40,7 @@ export type PayTheoryDataObject = {
4040
billing_info?: BillingInfo;
4141
healthExpenseType?: HealthExpenseType;
4242
level3DataSummary?: Level3DataSummary;
43-
};
43+
}
4444

4545
export interface ModifiedTransactProps extends TransactProps {
4646
payTheoryData: PayTheoryDataObject;
@@ -56,23 +56,23 @@ export interface ModifiedCheckoutDetails extends CheckoutDetails {
5656
export const parseInputParams = (
5757
inputParams: TransactProps | CheckoutDetails,
5858
): ModifiedTransactProps | ModifiedCheckoutDetails => {
59-
//@ts-ignore this will just set billingInfo and fee to undefined if they don't exist
60-
const { payorId, invoiceId, recurringId, fee, metadata = {}, billingInfo } = inputParams;
59+
const { payorId, invoiceId, recurringId, metadata = {} } = inputParams;
6160
const inputCopy = JSON.parse(JSON.stringify(inputParams)) as ModifiedTransactProps;
6261
inputCopy.payTheoryData = {
63-
account_code: inputParams.accountCode || (metadata['pay-theory-account-code'] as string),
64-
billing_info: billingInfo,
65-
fee: fee,
66-
invoice_id: invoiceId,
62+
account_code: inputParams.accountCode ?? (metadata['pay-theory-account-code'] as string),
63+
billing_info: (inputParams as TransactProps).billingInfo as BillingInfo | undefined,
64+
fee: (inputParams as TransactProps).fee as number | undefined,
65+
invoice_id: invoiceId as string | undefined,
6766
payment_parameters:
68-
inputParams.paymentParameters || (metadata['payment-parameters-name'] as string),
69-
payor_id: payorId,
67+
inputParams.paymentParameters ?? (metadata['payment-parameters-name'] as string),
68+
payor_id: payorId as string | undefined,
7069
receipt_description:
71-
// @ts-expect-error this will just set receipt description to undefined if it doesn't exist
72-
inputParams.receiptDescription || (metadata['pay-theory-receipt-description'] as string),
73-
recurring_id: recurringId, //@ts-ignore this will just set reference to undefined if it doesn't exist
74-
reference: inputParams.reference || (metadata['pay-theory-reference'] as string), //@ts-ignore this will just set send receipt to undefined if it doesn't exist
75-
send_receipt: inputParams.sendReceipt || !!metadata['pay-theory-receipt'],
70+
(inputParams as TransactProps).receiptDescription ??
71+
(metadata['pay-theory-receipt-description'] as string),
72+
recurring_id: recurringId,
73+
reference:
74+
(inputParams as TransactProps).reference ?? (metadata['pay-theory-reference'] as string),
75+
send_receipt: (inputParams as TransactProps).sendReceipt ?? !!metadata['pay-theory-receipt'],
7676
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
7777
healthExpenseType: inputCopy.healthExpenseType,
7878
level3DataSummary: inputCopy.level3DataSummary,
@@ -81,17 +81,17 @@ export const parseInputParams = (
8181
return inputCopy;
8282
};
8383

84-
export type FieldsReadyMessage = {
84+
export interface FieldsReadyMessage {
8585
type: typeof FIELDS_READY_STEP;
86-
};
86+
}
8787

88-
export type ErrorMessage = {
88+
export interface ErrorMessage {
8989
type: typeof ERROR_STEP;
9090
error: string;
9191
element: ElementTypes;
92-
};
92+
}
9393

94-
export type ConfirmationMessage = {
94+
export interface ConfirmationMessage {
9595
type: typeof CONFIRMATION_STEP;
9696
body: {
9797
fee_mode: typeof MERCHANT_FEE | typeof SERVICE_FEE;
@@ -102,7 +102,7 @@ export type ConfirmationMessage = {
102102
amount: number;
103103
fee: number;
104104
};
105-
};
105+
}
106106

107107
export const parseConfirmationMessage = (message: ConfirmationMessage): ConfirmationResponse => {
108108
const fee = message.body.fee_mode === data.SERVICE_FEE ? message.body.fee : 0;
@@ -119,7 +119,7 @@ export const parseConfirmationMessage = (message: ConfirmationMessage): Confirma
119119
};
120120
};
121121

122-
export type SuccessfulTransactionMessage = {
122+
export interface SuccessfulTransactionMessage {
123123
type: typeof COMPLETE_STEP;
124124
paymentType: 'transfer';
125125
body: {
@@ -130,11 +130,11 @@ export type SuccessfulTransactionMessage = {
130130
amount: number;
131131
service_fee: number;
132132
state: 'PENDING' | 'SUCCESS';
133-
metadata: { [keys: string | number]: string | number | boolean };
133+
metadata: Record<string | number, string | number | boolean>;
134134
payor_id: string;
135135
payment_method_id: string;
136136
};
137-
};
137+
}
138138

139139
export const parseSuccessfulTransactionMessage = (
140140
message: SuccessfulTransactionMessage,
@@ -158,7 +158,7 @@ export const parseSuccessfulTransactionMessage = (
158158
};
159159
};
160160

161-
export type FailedTransactionMessage = {
161+
export interface FailedTransactionMessage {
162162
type: typeof COMPLETE_STEP;
163163
paymentType: 'transfer';
164164
body: {
@@ -176,7 +176,7 @@ export type FailedTransactionMessage = {
176176
};
177177
};
178178
};
179-
};
179+
}
180180

181181
export const parseFailedTransactionMessage = (
182182
message: FailedTransactionMessage,
@@ -198,16 +198,16 @@ export const parseFailedTransactionMessage = (
198198
};
199199
};
200200

201-
export type CashBarcodeMessage = {
201+
export interface CashBarcodeMessage {
202202
type: typeof CASH_BARCODE_STEP;
203203
body: CashBarcodeObject;
204-
};
204+
}
205205

206-
export type TokenizedPaymentMethodMessage = {
206+
export interface TokenizedPaymentMethodMessage {
207207
type: typeof COMPLETE_STEP;
208208
paymentType: 'tokenize';
209209
body: TokenizedPaymentMethodObject;
210-
};
210+
}
211211

212212
export const parseResponse = (
213213
message:
@@ -268,9 +268,9 @@ export const localizeCashBarcodeUrl = (
268268
resolve(response);
269269
};
270270

271-
function error() {
271+
const error = () => {
272272
resolve(response);
273-
}
273+
};
274274

275275
navigator.geolocation.getCurrentPosition(success, error, options);
276276
}

src/common/message.ts

+18-11
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,22 @@ const windowListenerHandler = (
2525
// If payTheory is not set to true on the event then ignore as it is not from one of our listeners
2626
if (!event.payTheory) return;
2727

28-
let message = event.data;
28+
let message = event.data as string | { type: unknown; element?: ElementTypes };
2929
if (typeof message !== 'object') {
3030
try {
3131
// Parse the message as JSON.
3232
// All PT messages have either an object or a stringified object as the data
33-
message = typeof message === 'string' ? JSON.parse(message) : message;
33+
message = JSON.parse(message) as { type: unknown; element?: ElementTypes };
3434
} catch (e) {
3535
// Do nothing
3636
return;
3737
}
3838
}
3939
if (validTarget(message)) {
40-
handleMessage(message);
40+
const response = handleMessage(message);
41+
if (response instanceof Promise) {
42+
response.catch((error: string) => handleError(error));
43+
}
4144
}
4245
};
4346

@@ -107,11 +110,11 @@ export const handleCheckoutMessage = (
107110
};
108111
};
109112

110-
export type AsyncMessage = {
113+
export interface AsyncMessage {
111114
type: string;
112115
data?: unknown;
113116
async: true;
114-
};
117+
}
115118

116119
export const sendAsyncPostMessage = <T>(message: AsyncMessage, iframe: HTMLIFrameElement) =>
117120
new Promise<T>(resolve => {
@@ -207,7 +210,7 @@ export const postMessageToHostedField = (id: string, message: object, channel?:
207210
if (channel) {
208211
element.contentWindow.postMessage(message, hostedFieldsEndpoint, [channel]);
209212
} else {
210-
element?.contentWindow?.postMessage(message, hostedFieldsEndpoint);
213+
element.contentWindow.postMessage(message, hostedFieldsEndpoint);
211214
}
212215
} else {
213216
console.log('Hosted Field not found');
@@ -242,12 +245,12 @@ export const sendObserverMessage = (
242245
| CashBarcodeResponse
243246
| TokenizedPaymentMethodResponse
244247
| ConfirmationResponse,
245-
confirmationResponse: boolean = false,
248+
confirmationResponse = false,
246249
) => {
247250
switch (message.type) {
248251
case ResponseMessageTypes.SUCCESS:
249252
case ResponseMessageTypes.TOKENIZED:
250-
case ResponseMessageTypes.FAILED:
253+
case ResponseMessageTypes.FAILED: {
251254
const messageType = confirmationResponse ? captureString : completeString;
252255
window.postMessage(
253256
{
@@ -257,7 +260,8 @@ export const sendObserverMessage = (
257260
window.location.origin,
258261
);
259262
break;
260-
case ResponseMessageTypes.CASH:
263+
}
264+
case ResponseMessageTypes.CASH: {
261265
window.postMessage(
262266
{
263267
type: cashString,
@@ -266,7 +270,8 @@ export const sendObserverMessage = (
266270
window.location.origin,
267271
);
268272
break;
269-
case ResponseMessageTypes.CONFIRMATION:
273+
}
274+
case ResponseMessageTypes.CONFIRMATION: {
270275
window.postMessage(
271276
{
272277
type: confirmString,
@@ -275,9 +280,11 @@ export const sendObserverMessage = (
275280
window.location.origin,
276281
);
277282
break;
278-
case ResponseMessageTypes.ERROR:
283+
}
284+
case ResponseMessageTypes.ERROR: {
279285
// Do nothing. Error message should have already been sent
280286
break;
287+
}
281288
default:
282289
// Do nothing
283290
break;

0 commit comments

Comments
 (0)