Skip to content

Commit

Permalink
remove lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyagi-Sunny committed Oct 17, 2024
1 parent 60e3afd commit abf51f6
Show file tree
Hide file tree
Showing 17 changed files with 7,892 additions and 1,091 deletions.
7,593 changes: 7,593 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions src/component.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import {
Application,
injectable,
Component,
config,
ContextTags,
CoreBindings,
inject,
injectable,
ProviderMap,
} from '@loopback/core';
import {BillingComponentBindings} from './keys';
import {DEFAULT_BILLING_OPTIONS, BillingComponentOptions} from './types';
import {RestApplication} from '@loopback/rest';
import { BillingProvider } from './providers';
import {BillingComponentBindings} from './keys';
import {BillingProvider} from './providers';
import {BillingComponentOptions, DEFAULT_BILLING_OPTIONS} from './types';

// Configure the binding for BillingComponent
@injectable({tags: {[ContextTags.KEY]: BillingComponentBindings.COMPONENT}})
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './component';
export * from './keys';
export * from './types';
export * from './providers';
export * from './providers';
21 changes: 6 additions & 15 deletions src/keys.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BindingKey, CoreBindings } from '@loopback/core';
import { BillingComponent } from './component';
import { IService } from './types';
import {BindingKey, CoreBindings} from '@loopback/core';
import {BillingComponent} from './component';
import {IService} from './types';

/**
* Binding keys used by this component.
Expand All @@ -9,16 +9,7 @@ export namespace BillingComponentBindings {
export const COMPONENT = BindingKey.create<BillingComponent>(
`${CoreBindings.COMPONENTS}.BillingComponent`,
);
export const BillingProvider =
BindingKey.create<IService>(
'sf.billing',
);
export const SDKProvider =
BindingKey.create<IService>(
'sf.billing.sdk',
);
export const RestProvider =
BindingKey.create<IService>(
'sf.billing.rest',
);
export const BillingProvider = BindingKey.create<IService>('sf.billing');
export const SDKProvider = BindingKey.create<IService>('sf.billing.sdk');
export const RestProvider = BindingKey.create<IService>('sf.billing.rest');
}
84 changes: 47 additions & 37 deletions src/providers/billing.provider.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
import {inject, Provider} from '@loopback/core';

import {BillingComponentBindings} from '../keys';
import {HttpErrors} from '@loopback/rest';
import { IService, TCustomer, TPaymentSource, TInvoice, Transaction } from '../types';
// import { Transaction } from 'chargebee';


export class BillingProvider
implements Provider<IService>
{
import {BillingComponentBindings} from '../keys';
import {
IService,
TCustomer,
TInvoice,
TPaymentSource,
Transaction,
} from '../types';

export class BillingProvider implements Provider<IService> {
constructor(
@inject(BillingComponentBindings.RestProvider, {optional: true})
private readonly restProvider?: IService,
@inject(BillingComponentBindings.SDKProvider, {optional: true})
private readonly sdkProvider?:IService
private readonly sdkProvider?: IService,
) {}

getProvider(){
if(this.sdkProvider && this.restProvider){
getProvider() {
if (this.sdkProvider && this.restProvider) {
throw new HttpErrors.NotAcceptable();
}else if(this.sdkProvider){
} else if (this.sdkProvider) {
return this.sdkProvider;
}else if(this.restProvider){
} else if (this.restProvider) {
return this.restProvider;
}
else{
throw new HttpErrors.UnprocessableEntity(
"ProviderNotFound"
);
} else {
throw new HttpErrors.UnprocessableEntity('ProviderNotFound');
}
}



async createCustomer(customerDto: TCustomer): Promise<TCustomer> {
return this.getProvider().createCustomer(customerDto);
}
Expand All @@ -43,7 +40,7 @@ export class BillingProvider

async updateCustomerById(
tenantId: string,
customerDto: Partial<TCustomer>
customerDto: Partial<TCustomer>,
): Promise<void> {
return this.getProvider().updateCustomerById(tenantId, customerDto);
}
Expand All @@ -52,18 +49,25 @@ export class BillingProvider
return this.getProvider().deleteCustomer(customerId);
}

async createPaymentSource(paymentDto: TPaymentSource): Promise<TPaymentSource> {
async createPaymentSource(
paymentDto: TPaymentSource,
): Promise<TPaymentSource> {
return this.getProvider().createPaymentSource(paymentDto);
}

async applyPaymentSourceForInvoice(
invoiceId: string,
transaction: Transaction,
): Promise<TInvoice> {
return this.getProvider().applyPaymentSourceForInvoice(invoiceId, transaction);
return this.getProvider().applyPaymentSourceForInvoice(
invoiceId,
transaction,
);
}

async retrievePaymentSource(paymentSourceId: string): Promise<TPaymentSource> {
async retrievePaymentSource(
paymentSourceId: string,
): Promise<TPaymentSource> {
return this.getProvider().retrievePaymentSource(paymentSourceId);
}

Expand All @@ -81,7 +85,7 @@ export class BillingProvider

async updateInvoice(
invoiceId: string,
invoice: Partial<TInvoice>
invoice: Partial<TInvoice>,
): Promise<TInvoice> {
return this.getProvider().updateInvoice(invoiceId, invoice);
}
Expand All @@ -94,24 +98,30 @@ export class BillingProvider
return this.getProvider().getPaymentStatus(invoiceId);
}




value() {
return {
createCustomer: async (customerDto: TCustomer) => this.createCustomer(customerDto),
createCustomer: async (customerDto: TCustomer) =>
this.createCustomer(customerDto),
getCustomers: (customerId: string) => this.getCustomers(customerId),
updateCustomerById: (tenantId: string, customerDto: Partial<TCustomer>) => this.updateCustomerById(tenantId, customerDto),
updateCustomerById: (tenantId: string, customerDto: Partial<TCustomer>) =>
this.updateCustomerById(tenantId, customerDto),
deleteCustomer: (customerId: string) => this.deleteCustomer(customerId),
createPaymentSource: (paymentDto: TPaymentSource) => this.createPaymentSource(paymentDto),
applyPaymentSourceForInvoice: (invoiceId: string, transaction: Transaction,) => this.applyPaymentSourceForInvoice(invoiceId, transaction),
retrievePaymentSource: (paymentSourceId: string) => this.retrievePaymentSource(paymentSourceId),
deletePaymentSource: (paymentSourceId: string) => this.deletePaymentSource(paymentSourceId),
createPaymentSource: (paymentDto: TPaymentSource) =>
this.createPaymentSource(paymentDto),
applyPaymentSourceForInvoice: (
invoiceId: string,
transaction: Transaction,
) => this.applyPaymentSourceForInvoice(invoiceId, transaction),
retrievePaymentSource: (paymentSourceId: string) =>
this.retrievePaymentSource(paymentSourceId),
deletePaymentSource: (paymentSourceId: string) =>
this.deletePaymentSource(paymentSourceId),
createInvoice: (invoice: TInvoice) => this.createInvoice(invoice),
retrieveInvoice: (invoiceId: string) => this.retrieveInvoice(invoiceId),
updateInvoice: (invoiceId: string, invoice: Partial<TInvoice>) => this.updateInvoice(invoiceId, invoice),
updateInvoice: (invoiceId: string, invoice: Partial<TInvoice>) =>
this.updateInvoice(invoiceId, invoice),
deleteInvoice: (invoiceId: string) => this.deleteInvoice(invoiceId),
getPaymentStatus: (invoiceId: string) => this.getPaymentStatus(invoiceId),
}
};
}
}
}
2 changes: 1 addition & 1 deletion src/providers/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './billing.provider';
export * from './sdk';
export * from './sdk';
43 changes: 21 additions & 22 deletions src/providers/sdk/chargebee/adapter/customer.adapter.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { IChargeBeeCustomer, IChargeBeeInvoice, ICustomer, IDiscount, IInvoice } from "../type";
import {AnyObject} from '@loopback/repository';
import {IChargeBeeCustomer} from '../type';
export class CustomerAdapter {
constructor() {}

export class CustomerAdapter{
constructor(){}

convert(customer:ICustomer):IChargeBeeCustomer{

const res:IChargeBeeCustomer={
id:customer.id,
firstName:customer.first_name??"",
lastName:customer.last_name??"",
email:customer.email??"",
company:customer.company,
phone:customer.phone,
billingAddress:{
...customer.billing_address,
firstName:customer.billing_address?.first_name,
lastName:customer.billing_address?.last_name
}
}
return res;
}
}
convert(customer: AnyObject): IChargeBeeCustomer {
const res: IChargeBeeCustomer = {
id: customer.id,
firstName: customer.first_name ?? '',
lastName: customer.last_name ?? '',
email: customer.email ?? '',
company: customer.company,
phone: customer.phone,
billingAddress: {
...customer.billing_address,
firstName: customer.billing_address?.first_name,
lastName: customer.billing_address?.last_name,
},
};
return res;
}
}
2 changes: 1 addition & 1 deletion src/providers/sdk/chargebee/adapter/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './customer.adapter';
export * from './invoice.adapter';
export * from './payment-source.adapter';
export * from './payment-source.adapter';
74 changes: 38 additions & 36 deletions src/providers/sdk/chargebee/adapter/invoice.adapter.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
import { ICharge, IChargeBeeInvoice, IDiscount, IInvoice } from "../type";
import {AnyObject} from '@loopback/repository';
import {ICharge, IChargeBeeInvoice, IDiscount} from '../type';
export class InvoiceAdapter {
constructor() {}

export class InvoiceAdapter{
constructor(){}

convert(invoice:IInvoice):IChargeBeeInvoice{
let discounts:IDiscount[]=[];
if(invoice.discounts){
invoice.discounts.forEach(discount=>{
if(discount.entity_type==='document_level_coupon'){
discounts.push({apply_on:'invoice_amount'});
}else{
discounts.push({apply_on:'specific_item_price'});
}
})
}
const charges:ICharge[]=invoice.line_items?.map(item=>{
const charge:ICharge={
amount:item.amount?item.amount/100:0,
description:item.description,
convert(invoice: AnyObject): IChargeBeeInvoice {
const discounts: IDiscount[] = [];
if (invoice.discounts) {
/* eslint-disable-next-line @typescript-eslint/naming-convention */
invoice.discounts.forEach((discount: {entity_type: string}) => {
if (discount.entity_type === 'document_level_coupon') {
discounts.push({applyOn: 'invoice_amount'});
} else {
discounts.push({applyOn: 'specific_item_price'});
}
return charge
})??[];
const res:IChargeBeeInvoice={
id:invoice.id,
customerId:invoice.customer_id,
shippingAddress:{
...invoice.shipping_address,
firstName:invoice.shipping_address?.first_name,
lastName:invoice.shipping_address?.last_name
},
status:invoice.status,
options:{discounts:discounts},
charges:charges,
currencyCode:invoice.currency_code
}
return res;
});
}
}
const charges: ICharge[] =
invoice.line_items?.map((item: {amount: number; description: string}) => {
const charge: ICharge = {
amount: item.amount ? item.amount / 100 : 0,
description: item.description,
};
return charge;
}) ?? [];
const res: IChargeBeeInvoice = {
id: invoice.id,
customerId: invoice.customer_id,
shippingAddress: {
...invoice.shipping_address,
firstName: invoice.shipping_address?.first_name,
lastName: invoice.shipping_address?.last_name,
},
status: invoice.status,
options: {discounts: discounts},
charges: charges,
currencyCode: invoice.currency_code,
};
return res;
}
}
31 changes: 16 additions & 15 deletions src/providers/sdk/chargebee/adapter/payment-source.adapter.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { IChargeBeePaymentSource, IPaymentSource } from "../type";
import {AnyObject} from '@loopback/repository';
import {IChargeBeePaymentSource} from '../type';

export class PaymentSourceAdapter {
constructor() {}
constructor() {}

convert(paymentSource: IPaymentSource): IChargeBeePaymentSource {
return {
id: paymentSource.id,
customerId: paymentSource.customer_id,
card: {
gatewayAccountId: paymentSource.gateway_account_id ?? '',
number: paymentSource.card?.masked_number ?? '',
expiryMonth: paymentSource.card?.expiry_month ?? 0,
expiryYear: paymentSource.card?.expiry_year ?? 0,
cvv: "***"
}
};
}
convert(paymentSource: AnyObject): IChargeBeePaymentSource {
return {
id: paymentSource.id,
customerId: paymentSource.customer_id,
card: {
gatewayAccountId: paymentSource.gateway_account_id ?? '',
number: paymentSource.card?.masked_number ?? '',
expiryMonth: paymentSource.card?.expiry_month ?? 0,
expiryYear: paymentSource.card?.expiry_year ?? 0,
cvv: '***',
},
};
}
}
Loading

0 comments on commit abf51f6

Please sign in to comment.