Merge branch 'development' of https://gitlab.com/empatnusabangsa/ppob/ppob-backend into devops-staging
This commit is contained in:
		| @@ -1,5 +1,6 @@ | ||||
| import axios from 'axios'; | ||||
| import {HttpException, HttpStatus, NotFoundException} from "@nestjs/common"; | ||||
| import {createHmac} from "crypto"; | ||||
|  | ||||
| const irs_url = 'http://h2h.elangpixiu.com/api/h2h'; | ||||
| const irs_id = 'PT0005'; | ||||
| @@ -15,6 +16,8 @@ export const doTransaction = async ( | ||||
|     authorization, | ||||
|     typePaid, | ||||
|     billTrxId, | ||||
|     productVocaSubCategoryId, | ||||
|     productPrice | ||||
| ) => { | ||||
|   try { | ||||
|     if (supplier.code == 'IRS') { | ||||
| @@ -29,6 +32,62 @@ export const doTransaction = async ( | ||||
|       ); | ||||
|  | ||||
|       return res.data; | ||||
|     } else if (supplier.code == 'Vocagame') { | ||||
|       const merchantId = supplier.irs_user; | ||||
|       const reference = idtrx | ||||
|       const endpoint = `/transaction/${reference}`; | ||||
|       const secretKey = supplier.irs_pass; | ||||
|       const signature = createHmac('sha256', secretKey) | ||||
|           .update(merchantId + endpoint) | ||||
|           .digest('hex'); | ||||
|  | ||||
|         const options = { | ||||
|           headers: {'Content-Type': 'application/json'}, | ||||
|         }; | ||||
|  | ||||
|       const mergedDestination = destination; | ||||
|       const regex = /\(([^)]+)\)/; | ||||
|       const match = regex.exec(mergedDestination); | ||||
|  | ||||
|       let productDestination = "" | ||||
|       let productRegion = "" | ||||
|       if (match) { | ||||
|         productDestination = match[0] | ||||
|         const insideBrackets = match[1]; | ||||
|         productRegion = insideBrackets // This will print inside brackets | ||||
|       } else { | ||||
|         productDestination = destination | ||||
|       } | ||||
|  | ||||
|         const data = | ||||
|             { | ||||
|               productId: productVocaSubCategoryId, // Sub Kategori ID | ||||
|               productItemId: productCode, // Product Code | ||||
|               data: { // Get object from user input within endpoint /products/detail | ||||
|                 userId: productDestination, | ||||
|                 zoneId: productRegion // Optional | ||||
|               }, | ||||
|               price: productPrice, // Price equals from items | ||||
|               reference: reference, // Your reference I | ||||
|               callbackUrl: "https://ppob-backend.k3s.bangun-kreatif.com/v1/ppob_callback/vocagame" // Set your endpoint callback | ||||
|             } | ||||
|  | ||||
|         const res = await axios.post( | ||||
|             `${supplier.url}/v1/core/transaction?signature=${signature}`, | ||||
|             data, | ||||
|             options, | ||||
|         ); | ||||
|  | ||||
|         var responseVoca = res.data; | ||||
|  | ||||
|     if (responseVoca != null) { | ||||
|       const resDetail = await axios.get( | ||||
|           `${supplier.url}/v1/core/transaction/${responseVoca.invoiceId}/detail?signature=${signature}`, | ||||
|           options, | ||||
|       ); | ||||
|  | ||||
|       return resDetail | ||||
|     } | ||||
|     } else if (supplier.code == 'Digiflazz') { | ||||
|       if (typePaid == 'INQUIRY') { | ||||
|         const md5HashDigiflazz = `${supplier.irs_user}${supplier.irs_pass}${idtrx}`; | ||||
|   | ||||
| @@ -16,6 +16,11 @@ export class ProductSubCategories extends BaseModel { | ||||
|   }) | ||||
|   code: string; | ||||
|  | ||||
|   @Column({ | ||||
|     nullable: true, | ||||
|   }) | ||||
|   code_voca: string; | ||||
|  | ||||
|   @ManyToOne(() => ProductCategories, (categories) => categories.sub_categories) | ||||
|   category: ProductCategories; | ||||
|  | ||||
|   | ||||
| @@ -174,4 +174,24 @@ export class PpobCallbackController { | ||||
|       ); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   @Public() | ||||
|   @Post('/vocagame') | ||||
|   async getVoca(@Req() request: FastifyRequest) { | ||||
|     const response = request.body; | ||||
|     console.log('responsevocagame', response); | ||||
|     if (response['status'] != 'Success') { | ||||
|       //TODO: UPDATE GAGAL | ||||
|       await this.transactionService.checkCallbackOrderFailed( | ||||
|           response['reference'], | ||||
|           response, | ||||
|       ); | ||||
|     } else { | ||||
|       //TODO: UPDATE BERHASIL | ||||
|       await this.transactionService.checkCallbackOrderSuccess( | ||||
|           response['reference'], | ||||
|           response, | ||||
|       ); | ||||
|     } | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -90,16 +90,16 @@ export class TransactionController { | ||||
|     @Body() orderTransactionDto: OrderTransactionDto, | ||||
|     @Request() req, | ||||
|   ) { | ||||
|     if (req.get('host').includes('ppob-backend.k3s.bangun-kreatif.com')) { | ||||
|       return { | ||||
|         data: await this.transactionService.orderTransaction( | ||||
|             orderTransactionDto, | ||||
|             req.user, | ||||
|         ), | ||||
|         statusCode: HttpStatus.CREATED, | ||||
|         message: 'success', | ||||
|       }; | ||||
|     } else { | ||||
|     // if (req.get('host').includes('ppob-backend.k3s.bangun-kreatif.com')) { | ||||
|     //   return { | ||||
|     //     data: await this.transactionService.orderTransaction( | ||||
|     //         orderTransactionDto, | ||||
|     //         req.user, | ||||
|     //     ), | ||||
|     //     statusCode: HttpStatus.CREATED, | ||||
|     //     message: 'success', | ||||
|     //   }; | ||||
|     // } else { | ||||
|       return { | ||||
|         data: await this.transactionService.orderTransactionProd( | ||||
|             orderTransactionDto, | ||||
| @@ -108,7 +108,7 @@ export class TransactionController { | ||||
|         statusCode: HttpStatus.CREATED, | ||||
|         message: 'success', | ||||
|       }; | ||||
|     } | ||||
|     // } | ||||
|   } | ||||
|  | ||||
|   @Post('order-bill-prod') | ||||
|   | ||||
| @@ -637,7 +637,9 @@ export class TransactionService { | ||||
|               supplier, | ||||
|               hitLoginHemat.data, | ||||
|               product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT', | ||||
|               orderTransactionDto.bill_trx_id | ||||
|               orderTransactionDto.bill_trx_id, | ||||
|               product.sub_categories.code_voca, | ||||
|               product_price.price | ||||
|           ) : await doTransaction( | ||||
|               orderTransactionDto.productCode, | ||||
|               orderTransactionDto.destination, | ||||
| @@ -645,7 +647,9 @@ export class TransactionService { | ||||
|               supplier, | ||||
|               "", | ||||
|               product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT', | ||||
|               orderTransactionDto.bill_trx_id | ||||
|               orderTransactionDto.bill_trx_id, | ||||
|               product.sub_categories.code_voca, | ||||
|               product_price.price | ||||
|           ); | ||||
|  | ||||
|       // let hitSupplier; | ||||
| @@ -672,6 +676,16 @@ export class TransactionService { | ||||
|         if (orderTransactionDto.bill_trx_id !== null) { | ||||
|           hitSupplier.harga = product_price.price; | ||||
|         } | ||||
|       } else if (supplier.code == 'Vocagame') { | ||||
|         const newHitSupplier = { | ||||
|           status: hitSupplier.data.status, | ||||
|           success: hitSupplier.data.status.includes('Success') || hitSupplier.data.status.includes('Processing'), | ||||
|           harga: hitSupplier.data.totalAmount, | ||||
|           msg: hitSupplier.message, | ||||
|           sn: hitSupplier.data.sn, | ||||
|         }; | ||||
|  | ||||
|         hitSupplier = newHitSupplier; | ||||
|       } else if (supplier.code == 'Hemat') { | ||||
|         const newHitSupplier = { | ||||
|           success: hitSupplier.success, | ||||
| @@ -786,6 +800,20 @@ export class TransactionService { | ||||
|           } else { | ||||
|             transactionData.balance_remaining = | ||||
|                 coaAccount.amount - product_price.mark_up_price - costInventory; | ||||
|             if (supplier.code == 'Vocagame') { | ||||
|  | ||||
|               if (hitSupplier.status == 'Processing') { | ||||
|                 transactionData.status = statusTransaction.PENDING; | ||||
|                 status = statusTransaction[transactionData.status]; | ||||
|               } else { | ||||
|                 transactionData.seri_number = hitSupplier.sn; | ||||
|                 transactionData.status = statusTransaction.SUCCESS; | ||||
|                 status = statusTransaction[transactionData.status]; | ||||
|               } | ||||
|  | ||||
|             } else { | ||||
|  | ||||
|  | ||||
|             if ( | ||||
|                 hitSupplier.sn == null || | ||||
|                 hitSupplier.sn == '' || | ||||
| @@ -798,6 +826,9 @@ export class TransactionService { | ||||
|               transactionData.status = statusTransaction.SUCCESS; | ||||
|               status = statusTransaction[transactionData.status]; | ||||
|             } | ||||
|  | ||||
|             } | ||||
|  | ||||
|           } | ||||
|  | ||||
|           await manager.insert(Transactions, transactionData); | ||||
| @@ -921,7 +952,9 @@ export class TransactionService { | ||||
|             supplier, | ||||
|             hitLoginHemat.data, | ||||
|             product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT', | ||||
|             orderTransactionDto.bill_trx_id | ||||
|             orderTransactionDto.bill_trx_id, | ||||
|             product.sub_categories.code_voca, | ||||
|             product_price.price | ||||
|         ) : await doTransaction( | ||||
|             orderTransactionDto.productCode, | ||||
|             orderTransactionDto.destination, | ||||
| @@ -929,7 +962,9 @@ export class TransactionService { | ||||
|             supplier, | ||||
|             "", | ||||
|             product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT', | ||||
|             orderTransactionDto.bill_trx_id | ||||
|             orderTransactionDto.bill_trx_id, | ||||
|             product.sub_categories.code_voca, | ||||
|             product_price.price | ||||
|         ); | ||||
|  | ||||
|     if (supplier.code != 'IRS') { | ||||
| @@ -1081,7 +1116,9 @@ export class TransactionService { | ||||
|           supplier, | ||||
|           hitLoginHemat.data, | ||||
|           'INQUIRY', | ||||
|             orderTransactionDto.bill_trx_id | ||||
|             orderTransactionDto.bill_trx_id, | ||||
|             product.sub_categories.code_voca, | ||||
|             product_price.price | ||||
|       ) | ||||
|     } else if (supplier.code == 'Digiflazz') { | ||||
|         hitSupplier = await doTransaction( | ||||
| @@ -1091,7 +1128,9 @@ export class TransactionService { | ||||
|             supplier, | ||||
|             hitLoginHemat.data, | ||||
|             'INQUIRY', | ||||
|             orderTransactionDto.bill_trx_id | ||||
|             orderTransactionDto.bill_trx_id, | ||||
|             product.sub_categories.code_voca, | ||||
|             product_price.price | ||||
|         ) | ||||
|       } else { | ||||
|         hitSupplier = await doTransaction( | ||||
| @@ -1101,7 +1140,9 @@ export class TransactionService { | ||||
|           supplier, | ||||
|           "", | ||||
|           'INQUIRY', | ||||
|           orderTransactionDto.bill_trx_id | ||||
|           orderTransactionDto.bill_trx_id, | ||||
|             product.sub_categories.code_voca, | ||||
|             product_price.price | ||||
|       ); | ||||
|     } | ||||
|       // const parsingResponse = hitSupplier.split(' '); | ||||
| @@ -1590,6 +1631,10 @@ export class TransactionService { | ||||
|       if (callback['sn']) { | ||||
|         dataTransaction.seri_number = callback['sn']; | ||||
|       } | ||||
|     } else if (supplier.code == 'Vocagame') { | ||||
|       if (callback['sn']) { | ||||
|         dataTransaction.seri_number = callback['sn']; | ||||
|       } | ||||
|     } else { | ||||
|       if (callback['sn']) { | ||||
|         dataTransaction.seri_number = callback['sn']; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user