set invoke in nama
This commit is contained in:
@@ -0,0 +1,195 @@
|
||||
import {
|
||||
CustomerType,
|
||||
InvoiceTemplateType,
|
||||
PaymentMethodType,
|
||||
TspProviderCustomerType,
|
||||
TspProviderRequestType,
|
||||
TspProviderResponseStatus,
|
||||
} from '@/generated/prisma/enums'
|
||||
import {
|
||||
CustomerInfoDto,
|
||||
PaymentInfoDto,
|
||||
TspProviderRevokePayloadDto,
|
||||
TspProviderSendPayloadDto,
|
||||
} from '../../dto/provider-switch.dto'
|
||||
import {
|
||||
NamaProviderPaymentInfoDto,
|
||||
NamaProviderRequestDto,
|
||||
NamaProviderResponseStatus,
|
||||
NamaProviderRevokeRequestDto,
|
||||
} from './nama-provider.dto'
|
||||
|
||||
export class NamaProviderUtils {
|
||||
mapResponseStatus(status: NamaProviderResponseStatus): TspProviderResponseStatus {
|
||||
switch (status.toUpperCase()) {
|
||||
case NamaProviderResponseStatus.SUCCESS:
|
||||
case NamaProviderResponseStatus.POSTED:
|
||||
return TspProviderResponseStatus.SUCCESS
|
||||
case NamaProviderResponseStatus.PENDING:
|
||||
case NamaProviderResponseStatus.IN_PROGRESS:
|
||||
return TspProviderResponseStatus.QUEUED
|
||||
case NamaProviderResponseStatus.FAILED:
|
||||
return TspProviderResponseStatus.FAILURE
|
||||
default:
|
||||
return TspProviderResponseStatus.QUEUED
|
||||
}
|
||||
}
|
||||
|
||||
mapToNamaRequestDto(payload: TspProviderSendPayloadDto): NamaProviderRequestDto {
|
||||
return {
|
||||
uuid: payload.invoice_id,
|
||||
economic_code: payload.economic_code,
|
||||
fiscal_id: payload.fiscal_id,
|
||||
payment: this.mapPayments(payload.payments),
|
||||
header: {
|
||||
ins: this.mapTspProviderRequestType(payload.type),
|
||||
inp: this.mapInvoiceTemplate(payload.invoice_template),
|
||||
inty: this.mapTspProviderCustomerType(payload.customer_type),
|
||||
inno: payload.invoice_number.toString(),
|
||||
tins: '',
|
||||
indatim: payload.invoice_date.getTime() + '',
|
||||
setm: '1',
|
||||
...this.mapCustomerInfo(payload.customer),
|
||||
},
|
||||
body: payload.items.map(item => ({
|
||||
sstid: item.sku,
|
||||
vra: item.sku_vat,
|
||||
// sstt: item.unit_type,
|
||||
fee: String(item.unit_price),
|
||||
dis: String(item.discount),
|
||||
mu: item.measure_unit,
|
||||
am: String(item.quantity),
|
||||
consfee: '0',
|
||||
bros: '0',
|
||||
spro: '0',
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
mapRevokeToNamaRequestDto(
|
||||
payload: TspProviderRevokePayloadDto,
|
||||
): NamaProviderRevokeRequestDto {
|
||||
return {
|
||||
uuid: payload.invoice_id,
|
||||
economic_code: payload.economic_code,
|
||||
fiscal_id: payload.fiscal_id,
|
||||
header: {
|
||||
inno: payload.invoice_number.toString(),
|
||||
ins: this.mapTspProviderRequestType(TspProviderRequestType.REVOKE),
|
||||
irtaxid: payload.last_attempt_tax_id,
|
||||
},
|
||||
body: {},
|
||||
}
|
||||
}
|
||||
|
||||
private mapTspProviderRequestType(type: TspProviderRequestType) {
|
||||
switch (type) {
|
||||
case TspProviderRequestType.MAIN:
|
||||
return '1'
|
||||
case TspProviderRequestType.UPDATE:
|
||||
return '2'
|
||||
case TspProviderRequestType.REVOKE:
|
||||
return '3'
|
||||
case TspProviderRequestType.RETURN:
|
||||
return '4'
|
||||
}
|
||||
}
|
||||
|
||||
private mapInvoiceTemplate(template: InvoiceTemplateType) {
|
||||
switch (template) {
|
||||
case InvoiceTemplateType.SALE:
|
||||
return '1'
|
||||
case InvoiceTemplateType.FX_SALE:
|
||||
return '2'
|
||||
case InvoiceTemplateType.GOLD_JEWELRY:
|
||||
return '3'
|
||||
case InvoiceTemplateType.CONTRACT:
|
||||
return '4'
|
||||
case InvoiceTemplateType.UTILITY:
|
||||
return '5'
|
||||
case InvoiceTemplateType.AIR_TICKET:
|
||||
return '6'
|
||||
case InvoiceTemplateType.EXPORT:
|
||||
return '7'
|
||||
case InvoiceTemplateType.BILL_OF_LADING:
|
||||
return '8'
|
||||
case InvoiceTemplateType.PETROCHEMICAL:
|
||||
return '9'
|
||||
case InvoiceTemplateType.COMMODITY_EXCHANGE:
|
||||
return '11'
|
||||
case InvoiceTemplateType.INSURANCE:
|
||||
return '13'
|
||||
}
|
||||
}
|
||||
|
||||
private mapTspProviderCustomerType(type?: TspProviderCustomerType) {
|
||||
switch (type) {
|
||||
case TspProviderCustomerType.Known:
|
||||
return '1'
|
||||
case TspProviderCustomerType.Unknown:
|
||||
return '2'
|
||||
default:
|
||||
return '3'
|
||||
}
|
||||
}
|
||||
|
||||
private mapCustomerType(type?: CustomerType) {
|
||||
switch (type) {
|
||||
case CustomerType.INDIVIDUAL:
|
||||
return '1'
|
||||
case CustomerType.LEGAL:
|
||||
return '2'
|
||||
default:
|
||||
return '5'
|
||||
}
|
||||
}
|
||||
|
||||
private mapCustomerInfo(customer?: CustomerInfoDto) {
|
||||
const info = {} as any
|
||||
info.tob = this.mapCustomerType(customer?.type)
|
||||
if (customer?.type === CustomerType.LEGAL && customer.legal_info) {
|
||||
info.name = customer.legal_info.name
|
||||
info.bid = customer.legal_info.economic_code
|
||||
info.address = ''
|
||||
} else if (customer?.type === CustomerType.INDIVIDUAL && customer.individual_info) {
|
||||
info.name = `${customer.individual_info?.first_name || ''} ${
|
||||
customer.individual_info?.last_name || ''
|
||||
}`.trim()
|
||||
info.bid = customer.individual_info.national_id
|
||||
info.mobile = customer.individual_info.mobile_number
|
||||
info.address = ''
|
||||
}
|
||||
return info
|
||||
}
|
||||
|
||||
private mapPaymentMethod(method: PaymentMethodType): number {
|
||||
switch (method) {
|
||||
case PaymentMethodType.CHEQUE:
|
||||
return 1
|
||||
case PaymentMethodType.SET_OFF:
|
||||
return 2
|
||||
case PaymentMethodType.CASH:
|
||||
return 3
|
||||
case PaymentMethodType.TERMINAL:
|
||||
return 4
|
||||
case PaymentMethodType.PAYMENT_GATEWAY:
|
||||
return 5
|
||||
case PaymentMethodType.CARD:
|
||||
return 6
|
||||
case PaymentMethodType.BANK:
|
||||
return 7
|
||||
case PaymentMethodType.OTHER:
|
||||
return 8
|
||||
}
|
||||
}
|
||||
|
||||
private mapPayments(payments: PaymentInfoDto[]): NamaProviderPaymentInfoDto[] {
|
||||
return payments.map(payment => ({
|
||||
pmt: this.mapPaymentMethod(payment.payment_method),
|
||||
pv: payment.amount,
|
||||
trn: payment.tracking_code,
|
||||
pcn: payment.card_number,
|
||||
pdt: payment.paid_at ? String(payment.paid_at.getTime()) : undefined,
|
||||
}))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user