@unchainedshop/plugins
Version:
Official plugin collection for the Unchained Engine with payment, delivery, and pricing adapters
53 lines (52 loc) • 1.78 kB
JavaScript
import makeFetcher from "./makeFetcher.js";
const baseUrl = 'https://api.payrexx.com/v1.0/';
export const GatewayObjectStatus = {
waiting: 'waiting',
confirmed: 'confirmed',
cancelled: 'cancelled',
declined: 'declined',
authorized: 'authorized',
reserved: 'reserved',
refunded: 'refunded',
refundpending: 'refundpending',
'partially-refunded': 'partially-refunded',
chargeback: 'chargeback',
error: 'error',
uncaptured: '_',
};
const createPayrexxAPI = (instance, secret) => {
const fetchPayrexx = makeFetcher(baseUrl, instance, secret);
return {
async chargePreAuthorized(id, params) {
const result = await fetchPayrexx(`Transaction/${id}`, 'POST', params);
if (result.ok) {
return result.json();
}
throw new Error(await result.text());
},
async deleteReservation(id) {
const result = await fetchPayrexx(`Transaction/${id}`, 'DELETE');
if (result.ok) {
return result.json();
}
throw new Error(await result.text());
},
async getGateway(id) {
const result = await fetchPayrexx(`Gateway/${id}`, 'GET');
if (!result.ok)
throw new Error(await result.text());
const { status, data } = await result.json();
if (status !== 'success')
return null;
return data?.[0];
},
async createGateway(params) {
const result = await fetchPayrexx('Gateway', 'POST', params);
if (result.ok) {
return result.json();
}
throw new Error(await result.text());
},
};
};
export default createPayrexxAPI;