feat(SPG-423) Midtrans Integration
parent
2551521539
commit
8c9d0d6585
|
@ -30,10 +30,12 @@ export class BatchConfirmDataTransactionManager extends BaseBatchUpdateStatusMan
|
||||||
|
|
||||||
Object.assign(data, {
|
Object.assign(data, {
|
||||||
status: STATUS.WAITING,
|
status: STATUS.WAITING,
|
||||||
reconciliation_status:
|
reconciliation_status: [
|
||||||
data.payment_type == TransactionPaymentType.COUNTER
|
TransactionPaymentType.COUNTER,
|
||||||
? null
|
TransactionPaymentType.MIDTRANS,
|
||||||
: STATUS.PENDING,
|
].includes(data.payment_type)
|
||||||
|
? null
|
||||||
|
: STATUS.PENDING,
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -13,9 +13,13 @@ import {
|
||||||
UnprocessableEntityException,
|
UnprocessableEntityException,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||||
|
import { generateInvoiceCodeHelper } from './helpers/generate-invoice-code.helper';
|
||||||
|
import { TransactionPaymentType } from '../../../constants';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BatchConfirmTransactionManager extends BaseBatchUpdateStatusManager<TransactionEntity> {
|
export class BatchConfirmTransactionManager extends BaseBatchUpdateStatusManager<TransactionEntity> {
|
||||||
|
protected relations = ['items'];
|
||||||
|
|
||||||
async validateData(data: TransactionEntity): Promise<void> {
|
async validateData(data: TransactionEntity): Promise<void> {
|
||||||
if (data.status != STATUS.DRAFT) {
|
if (data.status != STATUS.DRAFT) {
|
||||||
throw new UnprocessableEntityException({
|
throw new UnprocessableEntityException({
|
||||||
|
@ -26,7 +30,26 @@ export class BatchConfirmTransactionManager extends BaseBatchUpdateStatusManager
|
||||||
}
|
}
|
||||||
|
|
||||||
const freeTransaction = data.payment_total < 1;
|
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, {
|
Object.assign(data, {
|
||||||
|
invoice_code: await generateInvoiceCodeHelper(this.dataService),
|
||||||
status: freeTransaction ? STATUS.ACTIVE : STATUS.PENDING,
|
status: freeTransaction ? STATUS.ACTIVE : STATUS.PENDING,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -39,10 +39,12 @@ export class ConfirmDataTransactionManager extends BaseUpdateStatusManager<Trans
|
||||||
|
|
||||||
Object.assign(this.data, {
|
Object.assign(this.data, {
|
||||||
status: STATUS.WAITING,
|
status: STATUS.WAITING,
|
||||||
reconciliation_status:
|
reconciliation_status: [
|
||||||
this.oldData.payment_type == TransactionPaymentType.COUNTER
|
TransactionPaymentType.COUNTER,
|
||||||
? null
|
TransactionPaymentType.MIDTRANS,
|
||||||
: STATUS.PENDING,
|
].includes(this.oldData.payment_type)
|
||||||
|
? null
|
||||||
|
: STATUS.PENDING,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue