From 7958231883c753a50338df75903b6d3b8512c4cd Mon Sep 17 00:00:00 2001 From: Fadli Date: Wed, 12 Oct 2022 11:50:16 +0700 Subject: [PATCH 01/10] - fix total commision query --- src/transaction/transaction.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transaction/transaction.service.ts b/src/transaction/transaction.service.ts index 668e42a..59f38d8 100644 --- a/src/transaction/transaction.service.ts +++ b/src/transaction/transaction.service.ts @@ -2121,7 +2121,7 @@ export class TransactionService { total_transaction: parseInt(data.total_transaction), total_modal: parseInt(data.total_modal), total_profit: parseInt(data.total_profit), - total_commission: parseInt(total_expense) - parseInt(data.total_profit), + total_commission: parseInt(data.total_profit) - parseInt(total_expense), }; } From bc456172117bd9eb425aac5d0f7a413f63805ae3 Mon Sep 17 00:00:00 2001 From: Fadli Date: Tue, 18 Oct 2022 13:04:26 +0700 Subject: [PATCH 02/10] - fix callback hemat --- src/transaction/ppob_callback.controller.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/transaction/ppob_callback.controller.ts b/src/transaction/ppob_callback.controller.ts index 99f3cc7..016abf9 100644 --- a/src/transaction/ppob_callback.controller.ts +++ b/src/transaction/ppob_callback.controller.ts @@ -131,4 +131,24 @@ export class PpobCallbackController { } } } + + @Public() + @Get('/hemat') + async getHemat(@Req() request: FastifyRequest) { + const response = request.query; + + if (response['statuscode'] == 2) { + //TODO: UPDATE GAGAL + await this.transactionService.checkCallbackOrderFailed( + response['clientid'], + response, + ); + } else { + //TODO: UPDATE BERHASIL + await this.transactionService.checkCallbackOrderSuccess( + response['clientid'], + response, + ); + } + } } From cff473abd9fdc9ebaf684078f33822efa54b84fc Mon Sep 17 00:00:00 2001 From: Fadli Date: Tue, 18 Oct 2022 13:06:48 +0700 Subject: [PATCH 03/10] - fix callback hemat --- src/transaction/ppob_callback.controller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transaction/ppob_callback.controller.ts b/src/transaction/ppob_callback.controller.ts index 016abf9..502380c 100644 --- a/src/transaction/ppob_callback.controller.ts +++ b/src/transaction/ppob_callback.controller.ts @@ -137,7 +137,7 @@ export class PpobCallbackController { async getHemat(@Req() request: FastifyRequest) { const response = request.query; - if (response['statuscode'] == 2) { + if (response['msg'] != 'Transaksi Sukses') { //TODO: UPDATE GAGAL await this.transactionService.checkCallbackOrderFailed( response['clientid'], From 7dcb7d30f6107ee9cc1ed3498bc76c79218d738e Mon Sep 17 00:00:00 2001 From: Fadli Date: Wed, 19 Oct 2022 16:53:12 +0700 Subject: [PATCH 04/10] - fix trx id test for hemat --- src/helper/irs-api.ts | 3 ++- src/transaction/transaction.service.ts | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/helper/irs-api.ts b/src/helper/irs-api.ts index 0e5fa6e..063c9e6 100644 --- a/src/helper/irs-api.ts +++ b/src/helper/irs-api.ts @@ -10,6 +10,7 @@ export const doTransaction = async ( productCode, destination, idtrx, + idtrxhemat, supplier, authorization, typePaid, @@ -35,7 +36,7 @@ export const doTransaction = async ( 'Authorization': 'Bearer ' + authorization} }; const data = { - idtransaction: idtrx, + idtransaction: idtrxhemat, destination: `${destination}`, code: `${productCode}`, type: `${typePaid}`, diff --git a/src/transaction/transaction.service.ts b/src/transaction/transaction.service.ts index 59f38d8..cdb7815 100644 --- a/src/transaction/transaction.service.ts +++ b/src/transaction/transaction.service.ts @@ -605,6 +605,8 @@ export class TransactionService { }) .join(''); + const trxIdHemat = orderTransactionDto.trx_id; + let hitLoginHemat; if (supplier.code == 'Hemat') { @@ -616,6 +618,7 @@ export class TransactionService { orderTransactionDto.productCode, orderTransactionDto.destination, trxId, + trxIdHemat, supplier, hitLoginHemat.data, product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT', @@ -623,6 +626,7 @@ export class TransactionService { orderTransactionDto.productCode, orderTransactionDto.destination, trxId, + trxIdHemat, supplier, "", product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT', @@ -852,6 +856,7 @@ export class TransactionService { }) .join(''); + const trxIdHemat = orderTransactionDto.trx_id; let hitLoginHemat; if (supplier.code == 'Hemat') { @@ -863,6 +868,7 @@ export class TransactionService { orderTransactionDto.productCode, orderTransactionDto.destination, trxId, + trxIdHemat, supplier, hitLoginHemat.data, product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT', @@ -870,6 +876,7 @@ export class TransactionService { orderTransactionDto.productCode, orderTransactionDto.destination, trxId, + trxIdHemat, supplier, "", product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT', @@ -1003,7 +1010,7 @@ export class TransactionService { return Math.round(Math.random() * 16).toString(16); }) .join(''); - + const trxIdHemat = orderTransactionDto.trx_id; let status; try { @@ -1018,6 +1025,7 @@ export class TransactionService { orderTransactionDto.productCode, orderTransactionDto.destination, trxId, + trxIdHemat, supplier, hitLoginHemat.data, 'INQUIRY' @@ -1025,6 +1033,7 @@ export class TransactionService { `CEK${orderTransactionDto.productCode.slice(3)}`, orderTransactionDto.destination, trxId, + trxIdHemat, supplier, "", 'INQUIRY' From c6d143487c96807bc318ff0a0db38d02535c2aab Mon Sep 17 00:00:00 2001 From: Fadli Date: Fri, 21 Oct 2022 17:26:05 +0700 Subject: [PATCH 05/10] - fix trx id test for hemat --- src/helper/irs-api.ts | 3 +- src/transaction/transaction.service.ts | 535 ++++++++++++------------- 2 files changed, 264 insertions(+), 274 deletions(-) diff --git a/src/helper/irs-api.ts b/src/helper/irs-api.ts index 063c9e6..0e5fa6e 100644 --- a/src/helper/irs-api.ts +++ b/src/helper/irs-api.ts @@ -10,7 +10,6 @@ export const doTransaction = async ( productCode, destination, idtrx, - idtrxhemat, supplier, authorization, typePaid, @@ -36,7 +35,7 @@ export const doTransaction = async ( 'Authorization': 'Bearer ' + authorization} }; const data = { - idtransaction: idtrxhemat, + idtransaction: idtrx, destination: `${destination}`, code: `${productCode}`, type: `${typePaid}`, diff --git a/src/transaction/transaction.service.ts b/src/transaction/transaction.service.ts index cdb7815..8f70ea8 100644 --- a/src/transaction/transaction.service.ts +++ b/src/transaction/transaction.service.ts @@ -523,271 +523,267 @@ export class TransactionService { ); const statusProduct = await this.productHistoryStatusService.findOneActive( - product.id, + product.id, userData.partner == null ? null : userData.partner.id, ); if (statusProduct.status == 'NOT ACTIVE') { - throw new HttpException( - { - statusCode: HttpStatus.INTERNAL_SERVER_ERROR, - error: `Transaction Failed because product is not active`, - }, - HttpStatus.INTERNAL_SERVER_ERROR, - ); - } else { - console.log('userdatapartnerid', userData.partner?.id); - - let product_price = await this.productHistoryPriceService.findOne( - product.id, - userData.partner?.id, - ); - - //GET COA - console.log('coamsk5', product_price.id); - - const coaAccount = await this.coaService.findByUser( - userData.id, - coaType.WALLET, - ); - - const coaInventory = await this.coaService.findByName( - `${coaType[coaType.INVENTORY]}-${product.supplier.code}`, - ); - - const coaCostOfSales = await this.coaService.findByName( - `${coaType[coaType.COST_OF_SALES]}-${product.supplier.code}`, - ); - - const coaSales = await this.coaService.findByName( - `${coaType[coaType.SALES]}-SYSTEM`, - ); - - if (orderTransactionDto.bill_trx_id) { - try { - const billId = await this.checkBillHistoryRepository.findOneOrFail({ - where: { - trx_id: orderTransactionDto.bill_trx_id, - }, - }); - - product_price.price = billId.amount; - } catch (e) { - if (e instanceof EntityNotFoundError) { - throw new HttpException( - { - statusCode: HttpStatus.NOT_FOUND, - error: 'Bill not found', - }, - HttpStatus.NOT_FOUND, - ); - } else { - throw e; - } - } - } - - if (coaAccount.amount < product_price.mark_up_price + product_price.price) { throw new HttpException( { statusCode: HttpStatus.INTERNAL_SERVER_ERROR, - error: `Transaction Failed because saldo not enough`, + error: `Transaction Failed because product is not active`, }, HttpStatus.INTERNAL_SERVER_ERROR, ); - } + } else { + console.log('userdatapartnerid', userData.partner?.id); - //HIT API SUPPLIER - const trxId = Array(6) - .fill(null) - .map(() => { - return Math.round(Math.random() * 16).toString(16); - }) - .join(''); + let product_price = await this.productHistoryPriceService.findOne( + product.id, + userData.partner?.id, + ); - const trxIdHemat = orderTransactionDto.trx_id; + //GET COA + console.log('coamsk5', product_price.id); - let hitLoginHemat; + const coaAccount = await this.coaService.findByUser( + userData.id, + coaType.WALLET, + ); - if (supplier.code == 'Hemat') { - hitLoginHemat = await doAuthorizeHemat(supplier.irs_user, supplier.irs_pass, supplier); - } + const coaInventory = await this.coaService.findByName( + `${coaType[coaType.INVENTORY]}-${product.supplier.code}`, + ); - let hitSupplier = supplier.code == 'Hemat' ? - await doTransaction( - orderTransactionDto.productCode, - orderTransactionDto.destination, - trxId, - trxIdHemat, - supplier, - hitLoginHemat.data, - product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT', - ) : await doTransaction( - orderTransactionDto.productCode, - orderTransactionDto.destination, - trxId, - trxIdHemat, - supplier, - "", - product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT', - ); + const coaCostOfSales = await this.coaService.findByName( + `${coaType[coaType.COST_OF_SALES]}-${product.supplier.code}`, + ); - // let hitSupplier; + const coaSales = await this.coaService.findByName( + `${coaType[coaType.SALES]}-SYSTEM`, + ); - console.log('iniresponsupplierharga', hitSupplier) - console.log('iniresponsupplier', hitSupplier.harga) - console.log(supplier.code, 'sdkfjsd'); - console.log(product_price, 'price'); + if (orderTransactionDto.bill_trx_id) { + try { + const billId = await this.checkBillHistoryRepository.findOneOrFail({ + where: { + trx_id: orderTransactionDto.bill_trx_id, + }, + }); - - if (supplier.code == 'metro') { - const parsingResponse = hitSupplier.split(' '); - console.log('parsingResponse', parsingResponse) - const newHitSupplier = { - success: hitSupplier.includes('diproses'), - harga: parseInt( - parsingResponse[parsingResponse.length - 2].replace(/\./g, ' '), - ), - msg: hitSupplier, - }; - - hitSupplier = newHitSupplier; - - if (orderTransactionDto.bill_trx_id !== null) { - hitSupplier.harga = product_price.price; - } - } else if (supplier.code == 'Hemat') { - const newHitSupplier = { - success: hitSupplier.success, - harga: product_price.price, - msg: hitSupplier.msg, - }; - - hitSupplier = newHitSupplier; - - if (orderTransactionDto.bill_trx_id !== null) { - hitSupplier.harga = product_price.price; - } - } - - console.log(hitSupplier, 'newhitSupplier'); - - // const hitSupplier = { - // harga: 2000, - // success: true, - // msg: 'Berhasil', - // }; - - this.logger.log({ - responseAPISupplier: hitSupplier, - }); - - let costInventory = product_price.price; - - if (hitSupplier.harga != undefined) { - if (hitSupplier.harga != product_price.price) { - console.log('priceupdate1supplier', hitSupplier.harga); - console.log('priceupdate1normal', product_price.price); - product_price.endDate = new Date(); - costInventory = hitSupplier.harga; - - const listActivePrice = - await this.productHistoryPriceService.getAllActivePriceByProduct( - product.id, + product_price.price = billId.amount; + } catch (e) { + if (e instanceof EntityNotFoundError) { + throw new HttpException( + { + statusCode: HttpStatus.NOT_FOUND, + error: 'Bill not found', + }, + HttpStatus.NOT_FOUND, ); - - await this.productHistoryPriceService.updateEndDate(product.id); - - listActivePrice.map(async (x) => { - const newProductPrice = new ProductHistoryPrice(); - - newProductPrice.id = uuid.v4(); - newProductPrice.type = x.type; - newProductPrice.price = hitSupplier.harga; - newProductPrice.mark_up_price = x.mark_up_price; - newProductPrice.startDate = new Date(); - newProductPrice.product = product; - newProductPrice.partner = x.partner; - await this.productHistoryPriceService.create(newProductPrice); - - product_price = newProductPrice; - }); - } - } - - try { - //TRANSACTION DATA - await this.connection.transaction(async (manager) => { - const transactionData = new Transactions(); - - transactionData.id = uuid.v4(); - transactionData.amount = - product_price.mark_up_price + product_price.price; - transactionData.user = userData.id; - transactionData.type = typeTransaction.ORDER; - transactionData.product_price = product_price; - transactionData.destination = orderTransactionDto.destination; - transactionData.partner_trx_id = orderTransactionDto.trx_id; - transactionData.supplier_trx_id = trxId; - transactionData.check_bill = orderTransactionDto.bill_trx_id; - transactionData.balance_remaining = - coaAccount.amount - product_price.mark_up_price - costInventory; - - if (!hitSupplier.success) { - transactionData.status = statusTransaction.FAILED; - status = statusTransaction[transactionData.status]; - await this.transactionRepository.insert(transactionData); - throw new HttpException( - { - statusCode: HttpStatus.INTERNAL_SERVER_ERROR, - error: hitSupplier.msg, - }, - HttpStatus.INTERNAL_SERVER_ERROR, - ); - } else { - transactionData.status = statusTransaction.PENDING; - status = statusTransaction[transactionData.status]; + } else { + throw e; + } } + } - await manager.insert(Transactions, transactionData); + if (coaAccount.amount < product_price.mark_up_price + product_price.price) { + throw new HttpException( + { + statusCode: HttpStatus.INTERNAL_SERVER_ERROR, + error: `Transaction Failed because saldo not enough`, + }, + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } - await this.accountingTransaction({ - createTransaction: false, - transactionalEntityManager: manager, - transaction: transactionData, - amount: transactionData.amount, - journals: [ - { - coa_id: coaInventory.id, - credit: costInventory, - }, - { - coa_id: coaCostOfSales.id, - debit: costInventory, - }, - { - coa_id: coaAccount.id, - debit: product_price.mark_up_price + costInventory, - }, - { - // eslint-disable-next-line camelcase - coa_id: coaSales.id, - credit: product_price.mark_up_price + costInventory, - }, - ], - }); + //HIT API SUPPLIER + const trxId = Array(6) + .fill(null) + .map(() => { + return Math.round(Math.random() * 16).toString(16); + }) + .join(''); + + let hitLoginHemat; + + if (supplier.code == 'Hemat') { + hitLoginHemat = await doAuthorizeHemat(supplier.irs_user, supplier.irs_pass, supplier); + } + + let hitSupplier = supplier.code == 'Hemat' ? + await doTransaction( + orderTransactionDto.productCode, + orderTransactionDto.destination, + trxId, + supplier, + hitLoginHemat.data, + product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT', + ) : await doTransaction( + orderTransactionDto.productCode, + orderTransactionDto.destination, + trxId, + supplier, + "", + product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT', + ); + + // let hitSupplier; + + console.log('iniresponsupplierharga', hitSupplier) + console.log('iniresponsupplier', hitSupplier.harga) + console.log(supplier.code, 'sdkfjsd'); + console.log(product_price, 'price'); + + + if (supplier.code == 'metro') { + const parsingResponse = hitSupplier.split(' '); + console.log('parsingResponse', parsingResponse) + const newHitSupplier = { + success: hitSupplier.includes('diproses'), + harga: parseInt( + parsingResponse[parsingResponse.length - 2].replace(/\./g, ' '), + ), + msg: hitSupplier, + }; + + hitSupplier = newHitSupplier; + + if (orderTransactionDto.bill_trx_id !== null) { + hitSupplier.harga = product_price.price; + } + } else if (supplier.code == 'Hemat') { + const newHitSupplier = { + success: hitSupplier.success, + harga: product_price.price, + msg: hitSupplier.msg, + }; + + hitSupplier = newHitSupplier; + + if (orderTransactionDto.bill_trx_id !== null) { + hitSupplier.harga = product_price.price; + } + } + + console.log(hitSupplier, 'newhitSupplier'); + + // const hitSupplier = { + // harga: 2000, + // success: true, + // msg: 'Berhasil', + // }; + + this.logger.log({ + responseAPISupplier: hitSupplier, }); - } catch (e) { - throw e; - } - return { - trx_id: trxId, - client_trx_id: orderTransactionDto.trx_id, - product: orderTransactionDto.productCode, - amount: product_price.mark_up_price + product_price.price, - status: status, - }; + let costInventory = product_price.price; + + if (hitSupplier.harga != undefined) { + if (hitSupplier.harga != product_price.price) { + console.log('priceupdate1supplier', hitSupplier.harga); + console.log('priceupdate1normal', product_price.price); + product_price.endDate = new Date(); + costInventory = hitSupplier.harga; + + const listActivePrice = + await this.productHistoryPriceService.getAllActivePriceByProduct( + product.id, + ); + + await this.productHistoryPriceService.updateEndDate(product.id); + + listActivePrice.map(async (x) => { + const newProductPrice = new ProductHistoryPrice(); + + newProductPrice.id = uuid.v4(); + newProductPrice.type = x.type; + newProductPrice.price = hitSupplier.harga; + newProductPrice.mark_up_price = x.mark_up_price; + newProductPrice.startDate = new Date(); + newProductPrice.product = product; + newProductPrice.partner = x.partner; + await this.productHistoryPriceService.create(newProductPrice); + + product_price = newProductPrice; + }); + } + } + + try { + //TRANSACTION DATA + await this.connection.transaction(async (manager) => { + const transactionData = new Transactions(); + + transactionData.id = uuid.v4(); + transactionData.amount = + product_price.mark_up_price + product_price.price; + transactionData.user = userData.id; + transactionData.type = typeTransaction.ORDER; + transactionData.product_price = product_price; + transactionData.destination = orderTransactionDto.destination; + transactionData.partner_trx_id = orderTransactionDto.trx_id; + transactionData.supplier_trx_id = trxId; + transactionData.check_bill = orderTransactionDto.bill_trx_id; + transactionData.balance_remaining = + coaAccount.amount - product_price.mark_up_price - costInventory; + + if (!hitSupplier.success) { + transactionData.status = statusTransaction.FAILED; + status = statusTransaction[transactionData.status]; + await this.transactionRepository.insert(transactionData); + throw new HttpException( + { + statusCode: HttpStatus.INTERNAL_SERVER_ERROR, + error: hitSupplier.msg, + }, + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } else { + transactionData.status = statusTransaction.PENDING; + status = statusTransaction[transactionData.status]; + } + + await manager.insert(Transactions, transactionData); + + await this.accountingTransaction({ + createTransaction: false, + transactionalEntityManager: manager, + transaction: transactionData, + amount: transactionData.amount, + journals: [ + { + coa_id: coaInventory.id, + credit: costInventory, + }, + { + coa_id: coaCostOfSales.id, + debit: costInventory, + }, + { + coa_id: coaAccount.id, + debit: product_price.mark_up_price + costInventory, + }, + { + // eslint-disable-next-line camelcase + coa_id: coaSales.id, + credit: product_price.mark_up_price + costInventory, + }, + ], + }); + }); + } catch (e) { + throw e; + } + + return { + trx_id: trxId, + client_trx_id: orderTransactionDto.trx_id, + product: orderTransactionDto.productCode, + amount: product_price.mark_up_price + product_price.price, + status: status, + }; } } @@ -856,7 +852,6 @@ export class TransactionService { }) .join(''); - const trxIdHemat = orderTransactionDto.trx_id; let hitLoginHemat; if (supplier.code == 'Hemat') { @@ -868,7 +863,6 @@ export class TransactionService { orderTransactionDto.productCode, orderTransactionDto.destination, trxId, - trxIdHemat, supplier, hitLoginHemat.data, product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT', @@ -876,7 +870,6 @@ export class TransactionService { orderTransactionDto.productCode, orderTransactionDto.destination, trxId, - trxIdHemat, supplier, "", product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT', @@ -1010,7 +1003,7 @@ export class TransactionService { return Math.round(Math.random() * 16).toString(16); }) .join(''); - const trxIdHemat = orderTransactionDto.trx_id; + let status; try { @@ -1018,14 +1011,13 @@ export class TransactionService { let hitLoginHemat; if (supplier.code == 'Hemat') { - hitLoginHemat = await doAuthorizeHemat(supplier.irs_user, supplier.irs_pass, supplier); + hitLoginHemat = await doAuthorizeHemat(supplier.irs_user, supplier.irs_pass, supplier); } let hitSupplier = supplier.code == 'Hemat' ? await doTransaction( orderTransactionDto.productCode, orderTransactionDto.destination, trxId, - trxIdHemat, supplier, hitLoginHemat.data, 'INQUIRY' @@ -1033,7 +1025,6 @@ export class TransactionService { `CEK${orderTransactionDto.productCode.slice(3)}`, orderTransactionDto.destination, trxId, - trxIdHemat, supplier, "", 'INQUIRY' @@ -1266,19 +1257,19 @@ export class TransactionService { // } else { - const updateTransaction = await this.callbackOrderFailed( - supplier_trx_id, - callback, - ); + const updateTransaction = await this.callbackOrderFailed( + supplier_trx_id, + callback, + ); - throw new HttpException( - { - updateTransaction, - statusCode: HttpStatus.BAD_REQUEST, - error: 'updated transaction to failed', - }, - HttpStatus.BAD_REQUEST, - ); + throw new HttpException( + { + updateTransaction, + statusCode: HttpStatus.BAD_REQUEST, + error: 'updated transaction to failed', + }, + HttpStatus.BAD_REQUEST, + ); // } } @@ -1304,19 +1295,19 @@ export class TransactionService { // HttpStatus.BAD_REQUEST, // ); // } else { - const updateTransaction = await this.callbackOrderSuccess( - supplier_trx_id, - callback, - ); + const updateTransaction = await this.callbackOrderSuccess( + supplier_trx_id, + callback, + ); - throw new HttpException( - { - updateTransaction, - statusCode: HttpStatus.OK, - error: 'success', - }, - HttpStatus.OK, - ); + throw new HttpException( + { + updateTransaction, + statusCode: HttpStatus.OK, + error: 'success', + }, + HttpStatus.OK, + ); // } } From e26194ac4e3f681aa317da6e245bf3406432f403 Mon Sep 17 00:00:00 2001 From: Fadli Date: Tue, 25 Oct 2022 13:00:25 +0700 Subject: [PATCH 06/10] -push logs --- src/transaction/ppob_callback.controller.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/transaction/ppob_callback.controller.ts b/src/transaction/ppob_callback.controller.ts index 502380c..77138f4 100644 --- a/src/transaction/ppob_callback.controller.ts +++ b/src/transaction/ppob_callback.controller.ts @@ -136,7 +136,8 @@ export class PpobCallbackController { @Get('/hemat') async getHemat(@Req() request: FastifyRequest) { const response = request.query; - + console.log('responsehemat', response); + console.log('responsehemat2', request); if (response['msg'] != 'Transaksi Sukses') { //TODO: UPDATE GAGAL await this.transactionService.checkCallbackOrderFailed( From f8accba15dda7229173095aff623939456a5c092 Mon Sep 17 00:00:00 2001 From: Fadli Date: Wed, 26 Oct 2022 12:09:18 +0700 Subject: [PATCH 07/10] -fix callback hemat to post --- src/transaction/ppob_callback.controller.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/transaction/ppob_callback.controller.ts b/src/transaction/ppob_callback.controller.ts index 77138f4..476d2cd 100644 --- a/src/transaction/ppob_callback.controller.ts +++ b/src/transaction/ppob_callback.controller.ts @@ -3,7 +3,7 @@ import { Get, HttpException, HttpStatus, - Logger, + Logger, Post, Req, } from '@nestjs/common'; import { TransactionService } from './transaction.service'; @@ -133,7 +133,7 @@ export class PpobCallbackController { } @Public() - @Get('/hemat') + @Post('/hemat') async getHemat(@Req() request: FastifyRequest) { const response = request.query; console.log('responsehemat', response); From 7f76d10062f9558c73227e10ba11c70d31687df4 Mon Sep 17 00:00:00 2001 From: Fadli Date: Wed, 26 Oct 2022 12:33:58 +0700 Subject: [PATCH 08/10] -fix callback hemat to post -fix getting callback --- src/transaction/ppob_callback.controller.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/transaction/ppob_callback.controller.ts b/src/transaction/ppob_callback.controller.ts index 476d2cd..3e37d07 100644 --- a/src/transaction/ppob_callback.controller.ts +++ b/src/transaction/ppob_callback.controller.ts @@ -135,9 +135,9 @@ export class PpobCallbackController { @Public() @Post('/hemat') async getHemat(@Req() request: FastifyRequest) { - const response = request.query; + const response = request.body; console.log('responsehemat', response); - console.log('responsehemat2', request); + console.log('responsehemat2', request.body); if (response['msg'] != 'Transaksi Sukses') { //TODO: UPDATE GAGAL await this.transactionService.checkCallbackOrderFailed( From ead1a6efa443d95f1316720c0e6c4dd160de9edd Mon Sep 17 00:00:00 2001 From: Fadli Date: Thu, 27 Oct 2022 00:12:24 +0700 Subject: [PATCH 09/10] - add hemat when transaction failed or success update to db --- src/transaction/ppob_callback.controller.ts | 4 +- src/transaction/transaction.service.ts | 75 +++++++++++---------- 2 files changed, 42 insertions(+), 37 deletions(-) diff --git a/src/transaction/ppob_callback.controller.ts b/src/transaction/ppob_callback.controller.ts index 3e37d07..caef626 100644 --- a/src/transaction/ppob_callback.controller.ts +++ b/src/transaction/ppob_callback.controller.ts @@ -141,13 +141,13 @@ export class PpobCallbackController { if (response['msg'] != 'Transaksi Sukses') { //TODO: UPDATE GAGAL await this.transactionService.checkCallbackOrderFailed( - response['clientid'], + response['data']['idtransaction'], response, ); } else { //TODO: UPDATE BERHASIL await this.transactionService.checkCallbackOrderSuccess( - response['clientid'], + response['data']['idtransaction'], response, ); } diff --git a/src/transaction/transaction.service.ts b/src/transaction/transaction.service.ts index 8f70ea8..164a211 100644 --- a/src/transaction/transaction.service.ts +++ b/src/transaction/transaction.service.ts @@ -1361,13 +1361,9 @@ export class TransactionService { product_price.product.id, ); - console.log('inipricetable', dataTransaction.product_price.price); - console.log('inipricecallback', callback['price']); - if (callback['message']) { if (callback['message'].includes('METRO')) { if (callback['price'] != dataTransaction.product_price.price) { - console.log('mskupdt', 'msk'); dataTransaction.product_price.price = parseInt(callback['price']); } } @@ -1463,37 +1459,6 @@ export class TransactionService { }, }); - dataTransaction.status = statusTransaction.SUCCESS; - - if (callback['sn']) { - dataTransaction.seri_number = callback['sn']; - console.log('msksn1', dataTransaction.seri_number); - } else { - const response = callback['message']; - const responseBaru = response.split(' '); - - dataTransaction.seri_number = - responseBaru[10].length > 1 ? responseBaru[10] : responseBaru[9]; - - if (dataTransaction.seri_number == 'SN:') { - dataTransaction.seri_number = responseBaru[11]; - } - } - - dataTransaction.callback_json = callback; - - if (callback['message']) { - if (callback['message'].includes('METRO')) { - if (callback['price'] != dataTransaction.product_price.price) { - dataProductHistoryPrice.price = parseInt(callback['price']); - } - } - } - - const userData = await this.userService.findExist(dataTransaction.user); - - let supervisorData = []; - const product_price = await this.productHistoryPriceService.findById( dataTransaction.product_price.id, ); @@ -1502,6 +1467,46 @@ export class TransactionService { product_price.product.id, ); + const supplier = await this.supplierService.findByCode( + product.supplier.code, + ); + + dataTransaction.status = statusTransaction.SUCCESS; + + if (supplier.code == 'Hemat') { + dataTransaction.seri_number = callback['data']['serial_number']; + dataProductHistoryPrice.price = parseInt(callback['data']['additional']['harga']); + } else { + if (callback['sn']) { + dataTransaction.seri_number = callback['sn']; + console.log('msksn1', dataTransaction.seri_number); + } else { + const response = callback['message']; + const responseBaru = response.split(' '); + + dataTransaction.seri_number = + responseBaru[10].length > 1 ? responseBaru[10] : responseBaru[9]; + + if (dataTransaction.seri_number == 'SN:') { + dataTransaction.seri_number = responseBaru[11]; + } + } + + dataTransaction.callback_json = callback; + + if (callback['message']) { + if (callback['message'].includes('METRO')) { + if (callback['price'] != dataTransaction.product_price.price) { + dataProductHistoryPrice.price = parseInt(callback['price']); + } + } + } + } + + const userData = await this.userService.findExist(dataTransaction.user); + + let supervisorData = []; + let profit = product_price.mark_up_price; //GET COA From 0e61523dabf3dbe625e2f1d8ca7bdbd8ca5de10b Mon Sep 17 00:00:00 2001 From: Fadli Date: Fri, 28 Oct 2022 11:10:50 +0700 Subject: [PATCH 10/10] - push total commision --- src/transaction/transaction.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transaction/transaction.service.ts b/src/transaction/transaction.service.ts index 164a211..87160b1 100644 --- a/src/transaction/transaction.service.ts +++ b/src/transaction/transaction.service.ts @@ -2126,7 +2126,7 @@ export class TransactionService { total_transaction: parseInt(data.total_transaction), total_modal: parseInt(data.total_modal), total_profit: parseInt(data.total_profit), - total_commission: parseInt(data.total_profit) - parseInt(total_expense), + total_commission: parseInt(total_expense) - parseInt(data.total_profit), }; }