fix: callback ppob

This commit is contained in:
ilham 2022-06-28 13:51:18 +07:00
parent 7aee976de6
commit 4befb8d9fd
5 changed files with 106 additions and 6 deletions

View 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;
}

View File

@ -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') @Get('history')
async getHistoryTransactionUser( async getHistoryTransactionUser(
@Query('page') page: number, @Query('page') page: number,

View File

@ -11,6 +11,7 @@ import { ProductModule } from '../product/product.module';
import { UsersModule } from 'src/users/users.module'; import { UsersModule } from 'src/users/users.module';
import { ConfigurableModule } from '../configurable/configurable.module'; import { ConfigurableModule } from '../configurable/configurable.module';
import { CheckBillHistory } from './entities/check-bill-history.entity'; import { CheckBillHistory } from './entities/check-bill-history.entity';
import { CallbackPartner } from './entities/callback-partner.entity';
@Module({ @Module({
imports: [ imports: [
@ -19,6 +20,7 @@ import { CheckBillHistory } from './entities/check-bill-history.entity';
TransactionJournal, TransactionJournal,
Transactions, Transactions,
CheckBillHistory, CheckBillHistory,
CallbackPartner,
]), ]),
ProductModule, ProductModule,
ConfigurableModule, ConfigurableModule,

View File

@ -29,6 +29,7 @@ import { doTransaction } from '../helper/irs-api';
import { ProductHistoryPrice } from '../product/entities/product-history-price.entity'; import { ProductHistoryPrice } from '../product/entities/product-history-price.entity';
import axios from 'axios'; import axios from 'axios';
import { CheckBillHistory } from './entities/check-bill-history.entity'; import { CheckBillHistory } from './entities/check-bill-history.entity';
import { CallbackPartner } from './entities/callback-partner.entity';
@Injectable() @Injectable()
export class TransactionService { export class TransactionService {
@ -43,6 +44,8 @@ export class TransactionService {
private coaRepository: Repository<COA>, private coaRepository: Repository<COA>,
@InjectRepository(CheckBillHistory) @InjectRepository(CheckBillHistory)
private checkBillHistoryRepository: Repository<CheckBillHistory>, private checkBillHistoryRepository: Repository<CheckBillHistory>,
@InjectRepository(CallbackPartner)
private callbackPartnerRepository: Repository<CallbackPartner>,
private coaService: CoaService, private coaService: CoaService,
private productService: ProductService, private productService: ProductService,
private productHistoryPriceService: ProductHistoryPriceService, private productHistoryPriceService: ProductHistoryPriceService,
@ -1135,7 +1138,7 @@ export class TransactionService {
if (userData.partner) { if (userData.partner) {
const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah gagal.`; const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah gagal.`;
this.callbackToPartner( this.callbackToPartner(
userData.id, userData.partner.id,
message, message,
dataTransaction.partner_trx_id, dataTransaction.partner_trx_id,
dataTransaction.amount, dataTransaction.amount,
@ -1219,7 +1222,7 @@ export class TransactionService {
if (userData.partner) { if (userData.partner) {
const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah berhasil.`; const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah berhasil.`;
this.callbackToPartner( this.callbackToPartner(
userData.id, userData.partner.id,
message, message,
dataTransaction.partner_trx_id, dataTransaction.partner_trx_id,
dataTransaction.amount, 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( async callbackToPartner(
partnerId: string, partnerId: string,
message: string, message: string,
@ -1242,9 +1292,14 @@ export class TransactionService {
status: string, status: string,
) { ) {
const partnerData = await this.userService.findPartner(partnerId); const partnerData = await this.userService.findPartner(partnerId);
const res = await axios.get( const url = `${partnerData.callback_url}?status=${status}&memberID=${partnerData.code}&trxid=${trxId}&harga=${harga}&product=${productCode}&dest=${destination}&seriNumber=${seriNumber}&message=${message}`;
`${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) { async withdrawBenefit(user) {

View File

@ -366,7 +366,7 @@ export class UsersService {
where: { where: {
id: id, id: id,
}, },
relations: ['superior', 'roles'], relations: ['superior', 'roles', 'partner'],
}); });
} catch (e) { } catch (e) {
if (e instanceof EntityNotFoundError) { if (e instanceof EntityNotFoundError) {