first commit
This commit is contained in:
32
app/core/midtrans.service.js
Normal file
32
app/core/midtrans.service.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const midtransClient = require('midtrans-client');
|
||||
require('dotenv').config();
|
||||
|
||||
class MidtransCoreService {
|
||||
constructor() {
|
||||
this.isProduction = process.env.MIDTRANS_IS_PRODUCTION === 'true';
|
||||
this.serverKey = process.env.MIDTRANS_SERVER_KEY;
|
||||
this.clientKey = process.env.MIDTRANS_CLIENT_KEY;
|
||||
|
||||
this.coreApi = new midtransClient.CoreApi({
|
||||
isProduction: this.isProduction,
|
||||
serverKey: this.serverKey,
|
||||
clientKey: this.clientKey
|
||||
});
|
||||
|
||||
this.snap = new midtransClient.Snap({
|
||||
isProduction: this.isProduction,
|
||||
serverKey: this.serverKey,
|
||||
clientKey: this.clientKey
|
||||
});
|
||||
}
|
||||
|
||||
getCoreApi() {
|
||||
return this.coreApi;
|
||||
}
|
||||
|
||||
getSnap() {
|
||||
return this.snap;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new MidtransCoreService();
|
||||
24
app/core/payment.service.js
Normal file
24
app/core/payment.service.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const MidtransConfig = require('../../config/midtrans');
|
||||
const coreApi = MidtransConfig.getCoreApiClient();
|
||||
|
||||
class BasePaymentService {
|
||||
static async charge(payload) {
|
||||
try {
|
||||
const response = await coreApi.charge(payload);
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error('Midtrans Charge Error:', error.ApiResponse || error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
static async getStatus(orderId) {
|
||||
try {
|
||||
return await coreApi.transaction.status(orderId);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BasePaymentService;
|
||||
Reference in New Issue
Block a user