Compare commits
No commits in common. "13895394b31a2e8c3fb87aa6fee10c9bdcf897b2" and "b36e35ea001ef6c65598afbcb21950ee967f8f0e" have entirely different histories.
13895394b3
...
b36e35ea00
|
@ -10,7 +10,6 @@ import { TransactionUpdatedEvent } from 'src/modules/transaction/transaction/dom
|
||||||
import { RefundChangeStatusEvent } from 'src/modules/transaction/refund/domain/entities/event/refund-change-status.event';
|
import { RefundChangeStatusEvent } from 'src/modules/transaction/refund/domain/entities/event/refund-change-status.event';
|
||||||
import { RefundCreatedEvent } from 'src/modules/transaction/refund/domain/entities/event/refund-created.event';
|
import { RefundCreatedEvent } from 'src/modules/transaction/refund/domain/entities/event/refund-created.event';
|
||||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
import { Logger } from '@nestjs/common';
|
|
||||||
|
|
||||||
@EventsHandler(
|
@EventsHandler(
|
||||||
TransactionChangeStatusEvent,
|
TransactionChangeStatusEvent,
|
||||||
|
@ -39,7 +38,7 @@ export class PaymentTransactionHandler
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let transaction = await this.dataService.getOneByOptions({
|
const transaction = await this.dataService.getOneByOptions({
|
||||||
where: {
|
where: {
|
||||||
id: data_id,
|
id: data_id,
|
||||||
},
|
},
|
||||||
|
@ -51,20 +50,6 @@ export class PaymentTransactionHandler
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!transaction) {
|
|
||||||
transaction = await this.dataService.getOneByOptions({
|
|
||||||
where: {
|
|
||||||
id: event.data.id,
|
|
||||||
},
|
|
||||||
relations: [
|
|
||||||
'items',
|
|
||||||
'refunds',
|
|
||||||
'refunds.refund_items',
|
|
||||||
'refunds.refund_items.transaction_item',
|
|
||||||
],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.assign(transaction, {
|
Object.assign(transaction, {
|
||||||
booking_date: new Date(transaction.booking_date).toDateString(),
|
booking_date: new Date(transaction.booking_date).toDateString(),
|
||||||
booking_date_before: new Date(
|
booking_date_before: new Date(
|
||||||
|
@ -116,7 +101,6 @@ export class PaymentTransactionHandler
|
||||||
transaction['refund'] &&
|
transaction['refund'] &&
|
||||||
[STATUS.DRAFT].includes(transaction['refund'].status)
|
[STATUS.DRAFT].includes(transaction['refund'].status)
|
||||||
) {
|
) {
|
||||||
Logger.verbose('Send Refund Request', 'PaymentTransaction');
|
|
||||||
const pdf = await GeneratePdf(
|
const pdf = await GeneratePdf(
|
||||||
transaction,
|
transaction,
|
||||||
InvoiceType.REFUND_REQUEST,
|
InvoiceType.REFUND_REQUEST,
|
||||||
|
@ -146,7 +130,6 @@ export class PaymentTransactionHandler
|
||||||
transaction['refund'] &&
|
transaction['refund'] &&
|
||||||
transaction['refund'].status == STATUS.REFUNDED
|
transaction['refund'].status == STATUS.REFUNDED
|
||||||
) {
|
) {
|
||||||
Logger.verbose('Send Refund Confirmation', 'PaymentTransaction');
|
|
||||||
const pdf = await GeneratePdf(
|
const pdf = await GeneratePdf(
|
||||||
transaction,
|
transaction,
|
||||||
InvoiceType.REFUND_CONFIRMATION,
|
InvoiceType.REFUND_CONFIRMATION,
|
||||||
|
@ -176,7 +159,6 @@ export class PaymentTransactionHandler
|
||||||
old_data.status != current_data.status &&
|
old_data.status != current_data.status &&
|
||||||
[STATUS.ACTIVE, STATUS.SETTLED].includes(current_data.status)
|
[STATUS.ACTIVE, STATUS.SETTLED].includes(current_data.status)
|
||||||
) {
|
) {
|
||||||
Logger.verbose('Send Payment Settled', 'PaymentTransaction');
|
|
||||||
const pdf = await GeneratePdf(
|
const pdf = await GeneratePdf(
|
||||||
transaction,
|
transaction,
|
||||||
InvoiceType.PAYMENT_CONFIRMATION,
|
InvoiceType.PAYMENT_CONFIRMATION,
|
||||||
|
@ -206,7 +188,6 @@ export class PaymentTransactionHandler
|
||||||
old_data.status != current_data.status &&
|
old_data.status != current_data.status &&
|
||||||
[STATUS.PENDING].includes(current_data.status)
|
[STATUS.PENDING].includes(current_data.status)
|
||||||
) {
|
) {
|
||||||
Logger.verbose('Send Confirmation to Pending', 'PaymentTransaction');
|
|
||||||
const pdf = await GeneratePdf(
|
const pdf = await GeneratePdf(
|
||||||
transaction,
|
transaction,
|
||||||
InvoiceType.BOOKING_INVOICE,
|
InvoiceType.BOOKING_INVOICE,
|
||||||
|
@ -229,13 +210,13 @@ export class PaymentTransactionHandler
|
||||||
pdf,
|
pdf,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// payment expired
|
// payment expired
|
||||||
else if (
|
else if (
|
||||||
!from_refund &&
|
!from_refund &&
|
||||||
old_data.status != current_data.status &&
|
old_data.status != current_data.status &&
|
||||||
[STATUS.PENDING, STATUS.EXPIRED].includes(current_data.status)
|
[STATUS.PENDING].includes(current_data.status)
|
||||||
) {
|
) {
|
||||||
Logger.verbose('Send Payment Expired', 'PaymentTransaction');
|
|
||||||
const pdf = await GeneratePdf(
|
const pdf = await GeneratePdf(
|
||||||
transaction,
|
transaction,
|
||||||
InvoiceType.INVOICE_EXPIRED,
|
InvoiceType.INVOICE_EXPIRED,
|
||||||
|
@ -267,7 +248,6 @@ export class PaymentTransactionHandler
|
||||||
current_data.status,
|
current_data.status,
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
Logger.verbose('Send Change Booking Date', 'PaymentTransaction');
|
|
||||||
const pdf = await GeneratePdf(
|
const pdf = await GeneratePdf(
|
||||||
transaction,
|
transaction,
|
||||||
InvoiceType.BOOKING_DATE_CHANGE,
|
InvoiceType.BOOKING_DATE_CHANGE,
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { EventBus } from '@nestjs/cqrs';
|
import { EventBus } from '@nestjs/cqrs';
|
||||||
import { mappingMidtransTransaction } from '../../domain/usecases/helpers/mapping-transaction.helper';
|
import { mappingMidtransTransaction } from '../../domain/usecases/helpers/mapping-transaction.helper';
|
||||||
import { Snap } from 'midtrans-client';
|
const midtransClient = require('midtrans-client');
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MidtransService {
|
export class MidtransService {
|
||||||
constructor(private eventBus: EventBus) {}
|
constructor(private eventBus: EventBus) {}
|
||||||
|
|
||||||
get midtransInstance() {
|
get midtransInstance() {
|
||||||
return new Snap({
|
return new midtransClient.Snap({
|
||||||
isProduction: false,
|
isProduction: false,
|
||||||
serverKey: process.env.MIDTRANS_SERVER_KEY,
|
serverKey: process.env.MIDTRANS_SERVER_KEY,
|
||||||
clientKey: process.env.MIDTRANS_CLIENT_KEY,
|
clientKey: process.env.MIDTRANS_CLIENT_KEY,
|
||||||
|
@ -19,10 +19,6 @@ export class MidtransService {
|
||||||
return await this.midtransInstance.transaction.status(orderId);
|
return await this.midtransInstance.transaction.status(orderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async cancelOrder(orderId: string): Promise<any> {
|
|
||||||
return await this.midtransInstance.transaction.cancel(orderId);
|
|
||||||
}
|
|
||||||
|
|
||||||
async create(body): Promise<any> {
|
async create(body): Promise<any> {
|
||||||
const data = mappingMidtransTransaction(body);
|
const data = mappingMidtransTransaction(body);
|
||||||
return await this.midtransInstance.createTransaction(data);
|
return await this.midtransInstance.createTransaction(data);
|
||||||
|
|
|
@ -2,7 +2,7 @@ export function mappingMidtransTransaction(transaction) {
|
||||||
const item_details = transaction.items?.map((item) => {
|
const item_details = transaction.items?.map((item) => {
|
||||||
return {
|
return {
|
||||||
quantity: Number(item.qty),
|
quantity: Number(item.qty),
|
||||||
price: Number(item.total_price) / Number(item.qty),
|
price: Number(item.total_price),
|
||||||
name: item.item_name,
|
name: item.item_name,
|
||||||
category: item.item_category_name,
|
category: item.item_category_name,
|
||||||
};
|
};
|
||||||
|
|
|
@ -34,17 +34,6 @@ export class MidtransController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id/cancel')
|
|
||||||
async cancel(@Param('id') id: string) {
|
|
||||||
try {
|
|
||||||
const data = await this.dataService.cancelOrder(id);
|
|
||||||
return data;
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error.message);
|
|
||||||
throw new Error('Gagal update status transaksi');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post('callback')
|
@Post('callback')
|
||||||
async callback(@Body() callback: MidtransDto) {
|
async callback(@Body() callback: MidtransDto) {
|
||||||
const data = await this.dataService.getStatus(callback?.order_id);
|
const data = await this.dataService.getStatus(callback?.order_id);
|
||||||
|
|
|
@ -60,7 +60,7 @@ export class MidtransCallbackHandler
|
||||||
new TransactionChangeStatusEvent({
|
new TransactionChangeStatusEvent({
|
||||||
id: data_id,
|
id: data_id,
|
||||||
old: old_data,
|
old: old_data,
|
||||||
data: { ...data, status: transaction.status },
|
data: data,
|
||||||
user: BLANK_USER,
|
user: BLANK_USER,
|
||||||
description: 'Midtrans Callback',
|
description: 'Midtrans Callback',
|
||||||
module: TABLE_NAME.TRANSACTION,
|
module: TABLE_NAME.TRANSACTION,
|
||||||
|
|
|
@ -14,7 +14,6 @@ import { TransactionChangeStatusEvent } from '../../entities/event/transaction-c
|
||||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||||
import { generateInvoiceCodeHelper } from './helpers/generate-invoice-code.helper';
|
import { generateInvoiceCodeHelper } from './helpers/generate-invoice-code.helper';
|
||||||
import { TransactionPaymentType } from '../../../constants';
|
import { TransactionPaymentType } from '../../../constants';
|
||||||
import { apm } from 'src/core/apm';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ConfirmTransactionManager extends BaseUpdateStatusManager<TransactionEntity> {
|
export class ConfirmTransactionManager extends BaseUpdateStatusManager<TransactionEntity> {
|
||||||
|
@ -48,7 +47,6 @@ export class ConfirmTransactionManager extends BaseUpdateStatusManager<Transacti
|
||||||
payment_midtrans_url: redirect_url,
|
payment_midtrans_url: redirect_url,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
apm.captureError(error);
|
|
||||||
throw new UnprocessableEntityException({
|
throw new UnprocessableEntityException({
|
||||||
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
|
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
|
||||||
message: `Gagal! transaksi telah terbuat, silahkan periksa email untuk melanjutkan pembayaran`,
|
message: `Gagal! transaksi telah terbuat, silahkan periksa email untuk melanjutkan pembayaran`,
|
||||||
|
|
|
@ -81,8 +81,6 @@ export class DetailTransactionManager extends BaseDetailManager<TransactionEntit
|
||||||
`${this.tableName}.payment_discount_total`,
|
`${this.tableName}.payment_discount_total`,
|
||||||
`${this.tableName}.payment_total`,
|
`${this.tableName}.payment_total`,
|
||||||
|
|
||||||
`${this.tableName}.payment_midtrans_url`,
|
|
||||||
|
|
||||||
'items',
|
'items',
|
||||||
'item_refunds',
|
'item_refunds',
|
||||||
'item_refunds_refund.id',
|
'item_refunds_refund.id',
|
||||||
|
|
|
@ -83,8 +83,6 @@ export class IndexTransactionManager extends BaseIndexManager<TransactionEntity>
|
||||||
`${this.tableName}.payment_type_method_name`,
|
`${this.tableName}.payment_type_method_name`,
|
||||||
`${this.tableName}.payment_type_method_number`,
|
`${this.tableName}.payment_type_method_number`,
|
||||||
|
|
||||||
`${this.tableName}.payment_midtrans_url`,
|
|
||||||
|
|
||||||
`refunds.id`,
|
`refunds.id`,
|
||||||
`refunds.code`,
|
`refunds.code`,
|
||||||
`refunds.refund_date`,
|
`refunds.refund_date`,
|
||||||
|
|
Loading…
Reference in New Issue