Skip to content

Commit 800a205

Browse files
feat(chore): sonar fix
sonar fix GH-27
1 parent 5cbb76a commit 800a205

3 files changed

Lines changed: 53 additions & 27 deletions

File tree

src/providers/sdk/chargebee/adapter/invoice.adapter.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ import {
33
TInvoicePaymentDetails,
44
TPaymentMethod,
55
} from '../../../../types';
6-
import {ChargebeeInvoice} from '../type';
6+
import {ChargebeeInvoice, ICharge, IChargeBeeInvoice, IDiscount} from '../type';
77
import {AnyObject} from '@loopback/repository';
8-
import {ICharge, IChargeBeeInvoice, IDiscount} from '../type';
98
export class InvoiceAdapter {
109
constructor() {}
1110

@@ -56,9 +55,11 @@ export class InvoiceAdapter {
5655
download: Record<string, unknown>,
5756
invoiceId: string,
5857
): TInvoicePdf {
58+
const downloadUrl = download['download_url'];
59+
const pdfUrl = typeof downloadUrl === 'string' ? downloadUrl : '';
5960
return {
6061
invoiceId: invoiceId,
61-
pdfUrl: String(download['download_url'] ?? ''),
62+
pdfUrl: pdfUrl,
6263
generatedAt: Math.floor(Date.now() / 1000), // Current timestamp in seconds
6364
expiresAt: download['expires_at'] as number | undefined,
6465
};

src/providers/sdk/chargebee/adapter/payment-intent.adapter.ts

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,20 @@ export class ChargebeePaymentIntentAdapter {
2525
transaction: ChargebeeTransaction,
2626
paymentMethod?: TPaymentMethod,
2727
): TPaymentIntent {
28-
const currencyCode =
29-
((transaction as Record<string, unknown>)['currency_code'] as
30-
| string
31-
| undefined) ??
32-
transaction.currencyCode ??
33-
'usd';
34-
const customerId =
35-
((transaction as Record<string, unknown>)['customer_id'] as
36-
| string
37-
| undefined) ?? transaction.customerId;
38-
const amountCapturable = (transaction as Record<string, unknown>)[
39-
'amount_capturable'
40-
] as number | undefined;
41-
const transactionType =
42-
((transaction as Record<string, unknown>)['type'] as
43-
| string
44-
| undefined) ?? 'transaction';
28+
const currencyCode = this.extractCurrencyCode(transaction);
29+
const customerId = this.extractCustomerId(transaction);
30+
const amountCapturable = this.extractAmountCapturable(transaction);
31+
const transactionType = this.extractTransactionType(transaction);
32+
const created = this.extractCreatedTimestamp(transaction);
4533

4634
return {
4735
id: transaction.id ?? '',
4836
amount: transaction.amount ?? 0,
49-
currency: String(currencyCode).toLowerCase(),
37+
currency: currencyCode.toLowerCase(),
5038
status: this.mapTransactionStatusToPaymentIntentStatus(
5139
transaction.status ?? 'in_progress',
5240
),
53-
created:
54-
typeof transaction.date === 'string'
55-
? Math.floor(new Date(transaction.date).getTime() / 1000)
56-
: (transaction.date ?? 0),
41+
created: created,
5742
customer: customerId,
5843
paymentMethod: paymentMethod,
5944
description: `ChargeBee ${transactionType} transaction`,
@@ -64,6 +49,47 @@ export class ChargebeePaymentIntentAdapter {
6449
};
6550
}
6651

52+
private extractCurrencyCode(transaction: ChargebeeTransaction): string {
53+
const currencyCode =
54+
((transaction as Record<string, unknown>)['currency_code'] as
55+
| string
56+
| undefined) ?? transaction.currencyCode;
57+
return currencyCode ?? 'usd';
58+
}
59+
60+
private extractCustomerId(
61+
transaction: ChargebeeTransaction,
62+
): string | undefined {
63+
return (
64+
((transaction as Record<string, unknown>)['customer_id'] as
65+
| string
66+
| undefined) ?? transaction.customerId
67+
);
68+
}
69+
70+
private extractAmountCapturable(
71+
transaction: ChargebeeTransaction,
72+
): number | undefined {
73+
return (transaction as Record<string, unknown>)['amount_capturable'] as
74+
| number
75+
| undefined;
76+
}
77+
78+
private extractTransactionType(transaction: ChargebeeTransaction): string {
79+
return (
80+
((transaction as Record<string, unknown>)['type'] as
81+
| string
82+
| undefined) ?? 'transaction'
83+
);
84+
}
85+
86+
private extractCreatedTimestamp(transaction: ChargebeeTransaction): number {
87+
if (typeof transaction.date === 'string') {
88+
return Math.floor(new Date(transaction.date).getTime() / 1000);
89+
}
90+
return transaction.date ?? 0;
91+
}
92+
6793
/**
6894
* Maps ChargeBee transaction status to PaymentIntent status.
6995
*

src/providers/sdk/stripe/adapter/payment-source.adapter.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Stripe from 'stripe';
22
import {AnyObject} from '@loopback/repository';
3-
import {TPaymentMethod} from '../../../../types';
4-
import {IAdapter} from '../../../../types';
3+
import {TPaymentMethod, IAdapter} from '../../../../types';
54
import {IStripePaymentSource, StripeLegacySource} from '../type';
65

76
// Payment method default values

0 commit comments

Comments
 (0)