@unchainedshop/plugins
Version:
Because of a Typescript issue with upstream "postfinancecheckout", the Postfinance plugin has been disabled from transpilation, import the source ts files from src and enable node_module tsc or copy over the src/payment/postfinance-checkout to your projec
64 lines • 2.51 kB
JavaScript
import makeFetcher from './makeFetcher.js';
const baseUrl = 'https://api.payrexx.com/v1.0/';
export var GatewayObjectStatus;
(function (GatewayObjectStatus) {
GatewayObjectStatus["waiting"] = "waiting";
GatewayObjectStatus["confirmed"] = "confirmed";
GatewayObjectStatus["cancelled"] = "cancelled";
GatewayObjectStatus["declined"] = "declined";
GatewayObjectStatus["authorized"] = "authorized";
GatewayObjectStatus["reserved"] = "reserved";
GatewayObjectStatus["refunded"] = "refunded";
GatewayObjectStatus["refundpending"] = "refundpending";
GatewayObjectStatus["partially-refunded"] = "partially-refunded";
GatewayObjectStatus["chargeback"] = "chargeback";
GatewayObjectStatus["error"] = "error";
GatewayObjectStatus["uncaptured"] = "_";
})(GatewayObjectStatus || (GatewayObjectStatus = {}));
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;
// where you want to consume the payrexx module:
// const payrexx = payrexx.init(instance, api_secret);
// const response = await payrexx.createGateway({
// amount: 100,
// // add more fields here
// });
// if (response.status === 200) {
// const gateway = response.data.data[0];
// // here you will get the gateway
// }
//# sourceMappingURL=index.js.map