41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
const midtransCore = require('../../../core/midtrans.service');
|
|
|
|
class TransactionService {
|
|
async getStatus(orderId) {
|
|
try {
|
|
const response = await midtransCore.getCoreApi().transaction.status(orderId);
|
|
return response;
|
|
} catch (error) {
|
|
throw new Error(`Gagal mengambil status transaksi: ${error.message}`);
|
|
}
|
|
}
|
|
|
|
async refund(payload) {
|
|
const { order_id, amount, reason, refund_key } = payload;
|
|
|
|
const parameter = {
|
|
refund_key: refund_key || `ref-${order_id}-${Date.now()}`,
|
|
amount: amount,
|
|
reason: reason || "Customer request"
|
|
};
|
|
|
|
try {
|
|
const response = await midtransCore.getCoreApi().transaction.refund(order_id, parameter);
|
|
return response;
|
|
} catch (error) {
|
|
throw new Error(`Gagal melakukan refund: ${error.message}`);
|
|
}
|
|
}
|
|
|
|
async cancel(orderId) {
|
|
try {
|
|
const response = await midtransCore.getCoreApi().transaction.cancel(orderId);
|
|
return response;
|
|
} catch (error) {
|
|
throw new Error(`Gagal membatalkan transaksi: ${error.message}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = new TransactionService();
|