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