feat(SPG-423) Midtrans Integration

pull/31/head
Aswin Ashar Abdullah 2024-07-18 12:45:46 +07:00
parent 2551521539
commit 8c9d0d6585
3 changed files with 35 additions and 8 deletions

View File

@ -30,10 +30,12 @@ export class BatchConfirmDataTransactionManager extends BaseBatchUpdateStatusMan
Object.assign(data, {
status: STATUS.WAITING,
reconciliation_status:
data.payment_type == TransactionPaymentType.COUNTER
? null
: STATUS.PENDING,
reconciliation_status: [
TransactionPaymentType.COUNTER,
TransactionPaymentType.MIDTRANS,
].includes(data.payment_type)
? null
: STATUS.PENDING,
});
return;

View File

@ -13,9 +13,13 @@ import {
UnprocessableEntityException,
} from '@nestjs/common';
import { STATUS } from 'src/core/strings/constants/base.constants';
import { generateInvoiceCodeHelper } from './helpers/generate-invoice-code.helper';
import { TransactionPaymentType } from '../../../constants';
@Injectable()
export class BatchConfirmTransactionManager extends BaseBatchUpdateStatusManager<TransactionEntity> {
protected relations = ['items'];
async validateData(data: TransactionEntity): Promise<void> {
if (data.status != STATUS.DRAFT) {
throw new UnprocessableEntityException({
@ -26,7 +30,26 @@ export class BatchConfirmTransactionManager extends BaseBatchUpdateStatusManager
}
const freeTransaction = data.payment_total < 1;
if (data.payment_type == TransactionPaymentType.MIDTRANS) {
try {
const { token, redirect_url } = await this.dataServiceFirstOpt.create(
data,
);
Object.assign(data, {
payment_midtrans_token: token,
payment_midtrans_url: redirect_url,
});
} catch (error) {
throw new UnprocessableEntityException({
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
message: `Failed! this transaction already created, please check your email to continue payment`,
error: 'Unprocessable Entity',
});
}
}
Object.assign(data, {
invoice_code: await generateInvoiceCodeHelper(this.dataService),
status: freeTransaction ? STATUS.ACTIVE : STATUS.PENDING,
});
return;

View File

@ -39,10 +39,12 @@ export class ConfirmDataTransactionManager extends BaseUpdateStatusManager<Trans
Object.assign(this.data, {
status: STATUS.WAITING,
reconciliation_status:
this.oldData.payment_type == TransactionPaymentType.COUNTER
? null
: STATUS.PENDING,
reconciliation_status: [
TransactionPaymentType.COUNTER,
TransactionPaymentType.MIDTRANS,
].includes(this.oldData.payment_type)
? null
: STATUS.PENDING,
});
return;
}