@nkhind/vivawallet-sdk
Version:
Non-Official VivaWallet API SDK
114 lines (113 loc) • 3.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const axiosInstance_ts_1 = require("../../utils/axiosInstance.ts");
const VivaAuth_class_1 = require("../../vivabases/VivaAuth.class");
class IsvPosTransactions extends VivaAuth_class_1.VivaAuthISV {
constructor(datas) {
super(datas);
}
/** Init POS Card reader sale request for the merchant, return `ISVInitPosReturn` */
async initSale(options) {
try {
const vivaToken = (await this.getVivaToken()).data;
await axiosInstance_ts_1.useAxios.post(this.endpoints.isv.pos.transaction.create.url, options, {
headers: {
Authorization: 'Bearer ' + vivaToken,
},
});
return {
success: true,
message: 'Sale initialized successfully',
data: null,
};
}
catch (e) {
if (this.errorLogs)
console.error('IsvPos.initSale', e);
return {
success: false,
message: 'Failed to init sale',
code: 'error',
data: null,
};
}
}
async refundTransaction(options) {
try {
const vivaToken = (await this.getVivaToken()).data;
await axiosInstance_ts_1.useAxios.post(this.endpoints.isv.pos.transaction.refund.url, options, {
headers: {
Authorization: 'Bearer ' + vivaToken,
},
});
return {
success: true,
message: 'Transaction refunded successfully',
data: null,
};
}
catch (e) {
if (this.errorLogs)
console.error('IsvPos.refundTransaction', e);
return {
success: false,
message: 'Failed to refund transaction',
code: 'error',
data: null,
};
}
}
/** Get details of a previously created action */
async getActionDatas(options) {
try {
const vivaToken = (await this.getVivaToken()).data;
const response = await axiosInstance_ts_1.useAxios.get(this.endpoints.isv.pos.action.get.url.replace('{actionId}', options.actionId), {
headers: {
Authorization: 'Bearer ' + vivaToken,
},
});
return {
success: true,
message: 'Action details retrieved successfully',
data: response.data,
};
}
catch (e) {
if (this.errorLogs)
console.error('IsvPos.getActionDatas', e);
return {
success: false,
message: 'Failed to get action details',
code: 'error',
data: null,
};
}
}
/** Create an action to be executed on a terminal */
async createAction(options) {
try {
const vivaToken = (await this.getVivaToken()).data;
const response = await axiosInstance_ts_1.useAxios.post(this.endpoints.isv.pos.action.create.url, options, {
headers: {
Authorization: 'Bearer ' + vivaToken,
},
});
return {
success: true,
message: 'Action created successfully',
data: response.data,
};
}
catch (e) {
if (this.errorLogs)
console.error('IsvPos.createAction', e);
return {
success: false,
message: 'Failed to create action',
code: 'error',
data: null,
};
}
}
}
exports.default = IsvPosTransactions;