feat: fixed midtrans

pull/71/head
Firman Ramdhani 2024-08-12 19:40:54 +07:00
parent 08e018e16b
commit be7c74ec72
3 changed files with 76 additions and 71 deletions

View File

@ -97,9 +97,9 @@ export class ChangeStatusBookingHandler
}, },
relations: ['items'], relations: ['items'],
}); });
mappingTransaction(booking);
console.log('change status', { dataID, couchData, booking }); console.log('change status', { dataID, couchData, booking });
mappingTransaction(booking);
console.log('after mapping');
if (!couchData) { if (!couchData) {
console.log('save data to couch'); console.log('save data to couch');

View File

@ -32,6 +32,7 @@ export class PaymentTransactionHandler
const current_data = event.data.data; const current_data = event.data.data;
const data_id = current_data.transaction_id ?? event.data.id; const data_id = current_data.transaction_id ?? event.data.id;
const from_refund = event.data.module == TABLE_NAME.REFUND; const from_refund = event.data.module == TABLE_NAME.REFUND;
console.log('payment handlet', { data_id });
const payments = await this.paymentService.getManyByOptions({ const payments = await this.paymentService.getManyByOptions({
where: { where: {

View File

@ -5,86 +5,90 @@ import {
} from 'src/modules/transaction/transaction/constants'; } from 'src/modules/transaction/transaction/constants';
export function mappingTransaction(data, refundId?: string) { export function mappingTransaction(data, refundId?: string) {
let payment_type_bank: any = null; try {
const season_period = { let payment_type_bank: any = null;
id: data.season_period_id, const season_period = {
holiday_name: data.season_period_name, id: data.season_period_id,
season_type: { holiday_name: data.season_period_name,
id: data.season_period_type_id, season_type: {
name: data.season_period_type_name, id: data.season_period_type_id,
}, name: data.season_period_type_name,
}; },
if (data.payment_type_method_id || data.payment_type_method_name) {
payment_type_bank = {
id: data.payment_type_method_id,
issuer_name: data.payment_type_method_name,
account_number: data.payment_type_method_number,
qr_image: data.payment_type_method_qr,
}; };
}
const items = data?.['items']?.map((itemData) => { if (data.payment_type_method_id || data.payment_type_method_name) {
let tenant; payment_type_bank = {
let refund = itemData.refunds?.find( id: data.payment_type_method_id,
(item) => ![STATUS.CANCEL].includes(item.refund.status), issuer_name: data.payment_type_method_name,
); account_number: data.payment_type_method_number,
qr_image: data.payment_type_method_qr,
if (itemData.item_tenant_id) {
tenant = {
id: itemData.item_tenant_id,
name: itemData.item_tenant_name,
share_margin: itemData.item_tenant_share_margin,
}; };
} }
if (refundId) const items = data?.['items']?.map((itemData) => {
refund = itemData.refunds?.find((item) => item.refund.id == refundId); let tenant;
let refund = itemData.refunds?.find(
(item) => ![STATUS.CANCEL].includes(item.refund.status),
);
return { if (itemData.item_tenant_id) {
item: { tenant = {
id: itemData.item_id, id: itemData.item_tenant_id,
name: itemData.item_name, name: itemData.item_tenant_name,
item_type: itemData.item_type, share_margin: itemData.item_tenant_share_margin,
base_price: itemData.item_price, };
hpp: itemData.item_hpp, }
tenant: tenant,
item_category: { if (refundId)
id: itemData.item_category_id, refund = itemData.refunds?.find((item) => item.refund.id == refundId);
name: itemData.item_category_name,
return {
item: {
id: itemData.item_id,
name: itemData.item_name,
item_type: itemData.item_type,
base_price: itemData.item_price,
hpp: itemData.item_hpp,
tenant: tenant,
item_category: {
id: itemData.item_category_id,
name: itemData.item_category_name,
},
}, },
}, id: itemData.id,
id: itemData.id, refund: refund,
qty: itemData.qty,
qty_remaining: itemData.qty_remaining,
total_price_refund: refund?.refund_total ?? 0,
total_price: itemData.total_price,
};
});
const refund = data.refunds?.find(
(refund) => ![STATUS.CANCEL].includes(refund.status),
);
Object.assign(data, {
season_period: season_period,
items: items,
payment_type_bank: payment_type_bank,
refund: refund, refund: refund,
qty: itemData.qty, });
qty_remaining: itemData.qty_remaining,
total_price_refund: refund?.refund_total ?? 0,
total_price: itemData.total_price,
};
});
const refund = data.refunds?.find( delete data.refunds;
(refund) => ![STATUS.CANCEL].includes(refund.status),
);
Object.assign(data, { delete data.season_period_id;
season_period: season_period, delete data.season_period_name;
items: items, delete data.season_period_type_id;
payment_type_bank: payment_type_bank, delete data.season_period_type_name;
refund: refund,
});
delete data.refunds; delete data.payment_type_method_id;
delete data.payment_type_method_name;
delete data.season_period_id; delete data.payment_type_method_number;
delete data.season_period_name; delete data.payment_type_method_qr;
delete data.season_period_type_id; } catch (error) {
delete data.season_period_type_name; console.log('error mapping transactin', error);
}
delete data.payment_type_method_id;
delete data.payment_type_method_name;
delete data.payment_type_method_number;
delete data.payment_type_method_qr;
} }
export function mappingRevertTransaction(data, type) { export function mappingRevertTransaction(data, type) {