Merge branch 'development' into 'devops-staging'
Development See merge request empatnusabangsa/ppob/ppob-backend!184
This commit is contained in:
		
							
								
								
									
										18
									
								
								src/transaction/entities/callback-partner.entity.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								src/transaction/entities/callback-partner.entity.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| import { Column, Entity, ManyToOne, OneToMany } from 'typeorm'; | ||||
| import { BaseModel } from '../../config/basemodel.entity'; | ||||
| import { statusTransaction, typeTransaction } from '../../helper/enum-list'; | ||||
| import { ProductHistoryPrice } from '../../product/entities/product-history-price.entity'; | ||||
| import { UserDetail } from '../../users/entities/user_detail.entity'; | ||||
| import { TransactionJournal } from './transaction-journal.entity'; | ||||
|  | ||||
| @Entity() | ||||
| export class CallbackPartner extends BaseModel { | ||||
|   @Column() | ||||
|   trx_id: string; | ||||
|  | ||||
|   @Column() | ||||
|   partner_trx_id: string; | ||||
|  | ||||
|   @Column() | ||||
|   url: string; | ||||
| } | ||||
| @@ -132,6 +132,31 @@ export class TransactionController { | ||||
|     }; | ||||
|   } | ||||
|  | ||||
|   @Get('resend-partner/success/:code') | ||||
|   async resendSuccess(@Request() req, @Param('code') code: string) { | ||||
|     const data = await this.transactionService.resendOrderToPartner(code, true); | ||||
|  | ||||
|     return { | ||||
|       data, | ||||
|       statusCode: HttpStatus.OK, | ||||
|       message: 'success', | ||||
|     }; | ||||
|   } | ||||
|  | ||||
|   @Get('resend-partner/failed/:code') | ||||
|   async resendFailed(@Request() req, @Param('code') code: string) { | ||||
|     const data = await this.transactionService.resendOrderToPartner( | ||||
|       code, | ||||
|       false, | ||||
|     ); | ||||
|  | ||||
|     return { | ||||
|       data, | ||||
|       statusCode: HttpStatus.OK, | ||||
|       message: 'success', | ||||
|     }; | ||||
|   } | ||||
|  | ||||
|   @Get('history') | ||||
|   async getHistoryTransactionUser( | ||||
|     @Query('page') page: number, | ||||
|   | ||||
| @@ -11,6 +11,7 @@ import { ProductModule } from '../product/product.module'; | ||||
| import { UsersModule } from 'src/users/users.module'; | ||||
| import { ConfigurableModule } from '../configurable/configurable.module'; | ||||
| import { CheckBillHistory } from './entities/check-bill-history.entity'; | ||||
| import { CallbackPartner } from './entities/callback-partner.entity'; | ||||
|  | ||||
| @Module({ | ||||
|   imports: [ | ||||
| @@ -19,6 +20,7 @@ import { CheckBillHistory } from './entities/check-bill-history.entity'; | ||||
|       TransactionJournal, | ||||
|       Transactions, | ||||
|       CheckBillHistory, | ||||
|       CallbackPartner, | ||||
|     ]), | ||||
|     ProductModule, | ||||
|     ConfigurableModule, | ||||
|   | ||||
| @@ -29,6 +29,7 @@ import { doTransaction } from '../helper/irs-api'; | ||||
| import { ProductHistoryPrice } from '../product/entities/product-history-price.entity'; | ||||
| import axios from 'axios'; | ||||
| import { CheckBillHistory } from './entities/check-bill-history.entity'; | ||||
| import { CallbackPartner } from './entities/callback-partner.entity'; | ||||
|  | ||||
| @Injectable() | ||||
| export class TransactionService { | ||||
| @@ -43,6 +44,8 @@ export class TransactionService { | ||||
|     private coaRepository: Repository<COA>, | ||||
|     @InjectRepository(CheckBillHistory) | ||||
|     private checkBillHistoryRepository: Repository<CheckBillHistory>, | ||||
|     @InjectRepository(CallbackPartner) | ||||
|     private callbackPartnerRepository: Repository<CallbackPartner>, | ||||
|     private coaService: CoaService, | ||||
|     private productService: ProductService, | ||||
|     private productHistoryPriceService: ProductHistoryPriceService, | ||||
| @@ -1135,7 +1138,7 @@ export class TransactionService { | ||||
|     if (userData.partner) { | ||||
|       const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah gagal.`; | ||||
|       this.callbackToPartner( | ||||
|         userData.id, | ||||
|         userData.partner.id, | ||||
|         message, | ||||
|         dataTransaction.partner_trx_id, | ||||
|         dataTransaction.amount, | ||||
| @@ -1219,7 +1222,7 @@ export class TransactionService { | ||||
|     if (userData.partner) { | ||||
|       const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah berhasil.`; | ||||
|       this.callbackToPartner( | ||||
|         userData.id, | ||||
|         userData.partner.id, | ||||
|         message, | ||||
|         dataTransaction.partner_trx_id, | ||||
|         dataTransaction.amount, | ||||
| @@ -1231,6 +1234,53 @@ export class TransactionService { | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   async resendOrderToPartner(supplier_trx_id: string, status: boolean){ | ||||
|     const dataTransaction = await this.transactionRepository.findOne({ | ||||
|       where: { | ||||
|         supplier_trx_id: supplier_trx_id, | ||||
|       }, | ||||
|       relations: ['product_price'], | ||||
|     }); | ||||
|  | ||||
|     const userData = await this.userService.findExist(dataTransaction.user); | ||||
|  | ||||
|     const product_price = await this.productHistoryPriceService.findById( | ||||
|       dataTransaction.product_price.id, | ||||
|     ); | ||||
|  | ||||
|     const product = await this.productService.findOneById( | ||||
|       product_price.product.id, | ||||
|     ); | ||||
|  | ||||
|     if (status) { | ||||
|       const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah berhasil.`; | ||||
|       await this.callbackToPartner( | ||||
|         userData.partner.id, | ||||
|         message, | ||||
|         dataTransaction.partner_trx_id, | ||||
|         dataTransaction.amount, | ||||
|         product.code, | ||||
|         dataTransaction.destination, | ||||
|         dataTransaction.seri_number, | ||||
|         'berhasil', | ||||
|       ); | ||||
|     } else { | ||||
|       const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah gagal.`; | ||||
|       this.callbackToPartner( | ||||
|         userData.partner.id, | ||||
|         message, | ||||
|         dataTransaction.partner_trx_id, | ||||
|         dataTransaction.amount, | ||||
|         product.code, | ||||
|         dataTransaction.destination, | ||||
|         '-', | ||||
|         'gagal', | ||||
|       ); | ||||
|     } | ||||
|  | ||||
|  | ||||
|   } | ||||
|  | ||||
|   async callbackToPartner( | ||||
|     partnerId: string, | ||||
|     message: string, | ||||
| @@ -1242,9 +1292,14 @@ export class TransactionService { | ||||
|     status: string, | ||||
|   ) { | ||||
|     const partnerData = await this.userService.findPartner(partnerId); | ||||
|     const res = await axios.get( | ||||
|       `${partnerData.callback_url}?status=${status}&memberID=${partnerData.code}&trxid=${trxId}&harga=${harga}&product=${productCode}&dest=${destination}&seriNumber=${seriNumber}&message=${message}`, | ||||
|     ); | ||||
|     const url = `${partnerData.callback_url}?status=${status}&memberID=${partnerData.code}&trxid=${trxId}&harga=${harga}&product=${productCode}&dest=${destination}&seriNumber=${seriNumber}&message=${message}`; | ||||
|     const result = await this.callbackPartnerRepository.insert({ | ||||
|       partner_trx_id: partnerId, | ||||
|       trx_id: trxId, | ||||
|       url: url, | ||||
|     }); | ||||
|     const res = await axios.get(url); | ||||
|     return res; | ||||
|   } | ||||
|  | ||||
|   async withdrawBenefit(user) { | ||||
| @@ -1862,7 +1917,12 @@ export class TransactionService { | ||||
|         trx_id: trxId, | ||||
|       }, | ||||
|       { | ||||
|         amount: status ? amount + product_price.partner_fee + product_price.mark_up_price : 0, | ||||
|         amount: status | ||||
|           ? amount - | ||||
|             admin + | ||||
|             product_price.partner_fee + | ||||
|             product_price.mark_up_price | ||||
|           : 0, | ||||
|         admin_price: admin, | ||||
|         status: status ? 'SUCCESS' : 'FAILED', | ||||
|         callback_json: JSON.stringify(message), | ||||
|   | ||||
| @@ -366,7 +366,7 @@ export class UsersService { | ||||
|         where: { | ||||
|           id: id, | ||||
|         }, | ||||
|         relations: ['superior', 'roles'], | ||||
|         relations: ['superior', 'roles', 'partner'], | ||||
|       }); | ||||
|     } catch (e) { | ||||
|       if (e instanceof EntityNotFoundError) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user