first commit
This commit is contained in:
40
app/modules/transaction/services/transaction.service.js
Normal file
40
app/modules/transaction/services/transaction.service.js
Normal file
@@ -0,0 +1,40 @@
|
||||
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();
|
||||
Reference in New Issue
Block a user