fix: callback transaction
This commit is contained in:
parent
342c9902ca
commit
aa8764ff2b
|
@ -42,7 +42,12 @@ export class ProductHistoryPriceService {
|
||||||
|
|
||||||
async findById(id: string) {
|
async findById(id: string) {
|
||||||
try {
|
try {
|
||||||
return await this.productHistoryPriceService.findOneOrFail(id);
|
return await this.productHistoryPriceService.findOneOrFail({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
relations: ['product'],
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof EntityNotFoundError) {
|
if (e instanceof EntityNotFoundError) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
|
|
|
@ -58,6 +58,16 @@ export class Transactions extends BaseModel {
|
||||||
})
|
})
|
||||||
phone_number: string;
|
phone_number: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
request_json: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
callback_json: string;
|
||||||
|
|
||||||
mark_up_price: number;
|
mark_up_price: number;
|
||||||
|
|
||||||
userData: UserDetail;
|
userData: UserDetail;
|
||||||
|
|
|
@ -13,6 +13,7 @@ import {
|
||||||
import { TransactionService } from './transaction.service';
|
import { TransactionService } from './transaction.service';
|
||||||
import { DistributeTransactionDto } from './dto/distribute-transaction.dto';
|
import { DistributeTransactionDto } from './dto/distribute-transaction.dto';
|
||||||
import { FastifyRequest } from 'fastify';
|
import { FastifyRequest } from 'fastify';
|
||||||
|
import { Public } from '../auth/public.decorator';
|
||||||
|
|
||||||
@Controller({
|
@Controller({
|
||||||
path: 'ppob_callback',
|
path: 'ppob_callback',
|
||||||
|
@ -23,6 +24,7 @@ export class PpobCallbackController {
|
||||||
|
|
||||||
constructor(private readonly transactionService: TransactionService) {}
|
constructor(private readonly transactionService: TransactionService) {}
|
||||||
|
|
||||||
|
@Public()
|
||||||
@Get()
|
@Get()
|
||||||
async get(@Req() request: FastifyRequest) {
|
async get(@Req() request: FastifyRequest) {
|
||||||
const response = request.query;
|
const response = request.query;
|
||||||
|
@ -30,12 +32,16 @@ export class PpobCallbackController {
|
||||||
if (response['statuscode'] == 2) {
|
if (response['statuscode'] == 2) {
|
||||||
//TODO: UPDATE GAGAL
|
//TODO: UPDATE GAGAL
|
||||||
const updateTransaction =
|
const updateTransaction =
|
||||||
await this.transactionService.callbackOrderFailed(response['clientid']);
|
await this.transactionService.callbackOrderFailed(
|
||||||
|
response['clientid'],
|
||||||
|
response,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
//TODO: UPDATE BERHASIL
|
//TODO: UPDATE BERHASIL
|
||||||
const updateTransaction =
|
const updateTransaction =
|
||||||
await this.transactionService.callbackOrderSuccess(
|
await this.transactionService.callbackOrderSuccess(
|
||||||
response['clientid'],
|
response['clientid'],
|
||||||
|
response,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
this.logger.log({
|
this.logger.log({
|
||||||
|
|
|
@ -647,24 +647,27 @@ export class TransactionService {
|
||||||
return transactionData;
|
return transactionData;
|
||||||
}
|
}
|
||||||
|
|
||||||
async callbackOrderFailed(supplier_trx_id: string) {
|
async callbackOrderFailed(supplier_trx_id: string, callback: any) {
|
||||||
const dataTransaction = await this.transactionRepository.findOne({
|
const dataTransaction = await this.transactionRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
supplier_trx_id: supplier_trx_id,
|
supplier_trx_id: supplier_trx_id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
dataTransaction.status = statusTransaction.FAILED;
|
dataTransaction.status = statusTransaction.FAILED;
|
||||||
|
dataTransaction.callback_json = callback;
|
||||||
|
|
||||||
await this.transactionRepository.save(dataTransaction);
|
await this.transactionRepository.save(dataTransaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
async callbackOrderSuccess(supplier_trx_id: string) {
|
async callbackOrderSuccess(supplier_trx_id: string, callback: any) {
|
||||||
const dataTransaction = await this.transactionRepository.findOne({
|
const dataTransaction = await this.transactionRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
supplier_trx_id: supplier_trx_id,
|
supplier_trx_id: supplier_trx_id,
|
||||||
},
|
},
|
||||||
|
relations: ['product_price'],
|
||||||
});
|
});
|
||||||
dataTransaction.status = statusTransaction.FAILED;
|
dataTransaction.status = statusTransaction.FAILED;
|
||||||
|
dataTransaction.callback_json = callback;
|
||||||
|
|
||||||
const userData = await this.userService.findExist(dataTransaction.user);
|
const userData = await this.userService.findExist(dataTransaction.user);
|
||||||
|
|
||||||
|
@ -702,7 +705,7 @@ export class TransactionService {
|
||||||
`${coaType[coaType.EXPENSE]}-SYSTEM`,
|
`${coaType[coaType.EXPENSE]}-SYSTEM`,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!userData.partner) {
|
if (userData.partner) {
|
||||||
//GET SALES
|
//GET SALES
|
||||||
supervisorData = await this.calculateCommission(
|
supervisorData = await this.calculateCommission(
|
||||||
supervisorData,
|
supervisorData,
|
||||||
|
|
|
@ -220,7 +220,12 @@ export class UsersService {
|
||||||
|
|
||||||
async findExist(id: string) {
|
async findExist(id: string) {
|
||||||
try {
|
try {
|
||||||
return await this.usersRepository.findOneOrFail(id);
|
return await this.usersRepository.findOneOrFail({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
relations: ['superior'],
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof EntityNotFoundError) {
|
if (e instanceof EntityNotFoundError) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user