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