fix(SPG-1218): sync midtrans status
parent
e1d8975dda
commit
58e062dd6c
|
@ -21,6 +21,19 @@ export class MidtransService {
|
|||
return diffInHours > 24;
|
||||
}
|
||||
|
||||
isCreatedMoreThan24HoursAgo(unixTimestamp) {
|
||||
const date = moment.unix(unixTimestamp);
|
||||
const now = moment();
|
||||
const diffInHours = now.diff(date, 'hours');
|
||||
return diffInHours > 24;
|
||||
}
|
||||
|
||||
isBookingDateExpired(bookingDate) {
|
||||
const bookingDateMoment = moment(bookingDate);
|
||||
const today = moment().startOf('day');
|
||||
return bookingDateMoment.isBefore(today);
|
||||
}
|
||||
|
||||
get midtransInstance() {
|
||||
return new Snap({
|
||||
isProduction: false,
|
||||
|
@ -38,16 +51,18 @@ export class MidtransService {
|
|||
const responses = [];
|
||||
|
||||
for (const transaction of pendingIds) {
|
||||
const { id, invoice_date } = transaction;
|
||||
const { id, booking_date, created_at } = transaction;
|
||||
let status;
|
||||
try {
|
||||
status = await this.getStatus(id);
|
||||
} catch (error) {
|
||||
status = {
|
||||
order_id: id,
|
||||
transaction_status: this.isMoreThan24HoursAgo(invoice_date)
|
||||
? 'cancel'
|
||||
: 'pending',
|
||||
transaction_status:
|
||||
this.isCreatedMoreThan24HoursAgo(created_at) ||
|
||||
this.isBookingDateExpired(booking_date)
|
||||
? 'expired'
|
||||
: 'pending',
|
||||
};
|
||||
}
|
||||
responses.push(status);
|
||||
|
|
|
@ -8,7 +8,7 @@ import {
|
|||
} from 'src/core/strings/constants/base.constants';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseReadService } from 'src/core/modules/data/service/base-read.service';
|
||||
import { TransactionPaymentType } from '../../constants';
|
||||
import { TransactionPaymentType, TransactionType } from '../../constants';
|
||||
|
||||
@Injectable()
|
||||
export class TransactionReadService extends BaseReadService<TransactionEntity> {
|
||||
|
@ -24,8 +24,9 @@ export class TransactionReadService extends BaseReadService<TransactionEntity> {
|
|||
where: {
|
||||
status: STATUS.PENDING,
|
||||
payment_type: TransactionPaymentType.MIDTRANS,
|
||||
type: TransactionType.ONLINE,
|
||||
},
|
||||
select: ['id', 'invoice_date'],
|
||||
select: ['id', 'invoice_date', 'created_at', 'booking_date'],
|
||||
});
|
||||
|
||||
return transactions;
|
||||
|
|
Loading…
Reference in New Issue