feat(SPG-423) Midtrans Integration
parent
2551521539
commit
8c9d0d6585
|
@ -30,8 +30,10 @@ export class BatchConfirmDataTransactionManager extends BaseBatchUpdateStatusMan
|
|||
|
||||
Object.assign(data, {
|
||||
status: STATUS.WAITING,
|
||||
reconciliation_status:
|
||||
data.payment_type == TransactionPaymentType.COUNTER
|
||||
reconciliation_status: [
|
||||
TransactionPaymentType.COUNTER,
|
||||
TransactionPaymentType.MIDTRANS,
|
||||
].includes(data.payment_type)
|
||||
? null
|
||||
: STATUS.PENDING,
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -39,8 +39,10 @@ export class ConfirmDataTransactionManager extends BaseUpdateStatusManager<Trans
|
|||
|
||||
Object.assign(this.data, {
|
||||
status: STATUS.WAITING,
|
||||
reconciliation_status:
|
||||
this.oldData.payment_type == TransactionPaymentType.COUNTER
|
||||
reconciliation_status: [
|
||||
TransactionPaymentType.COUNTER,
|
||||
TransactionPaymentType.MIDTRANS,
|
||||
].includes(this.oldData.payment_type)
|
||||
? null
|
||||
: STATUS.PENDING,
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue