From aa8764ff2b26fa1262c5c395274796b72fd3066d Mon Sep 17 00:00:00 2001 From: ilham Date: Sun, 26 Dec 2021 23:01:44 +0700 Subject: [PATCH] fix: callback transaction --- src/product/history-price/history-price.service.ts | 7 ++++++- src/transaction/entities/transactions.entity.ts | 10 ++++++++++ src/transaction/ppob_callback.controller.ts | 8 +++++++- src/transaction/transaction.service.ts | 9 ++++++--- src/users/users.service.ts | 7 ++++++- 5 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/product/history-price/history-price.service.ts b/src/product/history-price/history-price.service.ts index 694dedd..698b369 100644 --- a/src/product/history-price/history-price.service.ts +++ b/src/product/history-price/history-price.service.ts @@ -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( diff --git a/src/transaction/entities/transactions.entity.ts b/src/transaction/entities/transactions.entity.ts index c9b4c74..ba5c342 100644 --- a/src/transaction/entities/transactions.entity.ts +++ b/src/transaction/entities/transactions.entity.ts @@ -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; diff --git a/src/transaction/ppob_callback.controller.ts b/src/transaction/ppob_callback.controller.ts index e7064ec..f208388 100644 --- a/src/transaction/ppob_callback.controller.ts +++ b/src/transaction/ppob_callback.controller.ts @@ -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({ diff --git a/src/transaction/transaction.service.ts b/src/transaction/transaction.service.ts index e94d45a..bbcfcc3 100644 --- a/src/transaction/transaction.service.ts +++ b/src/transaction/transaction.service.ts @@ -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, diff --git a/src/users/users.service.ts b/src/users/users.service.ts index c34752f..939af19 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -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(