@vtex/payment-provider-sdk
Version:
VTEX Payment Provider SDK
79 lines (78 loc) • 2.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildRoutes = void 0;
const api_1 = require("@vtex/api");
const co_body_1 = require("co-body");
const buildRoutes = (Connector) => {
return {
paymentMethods: api_1.method({
GET: [
async function getPaymentMethods(ctx, next) {
const connector = new Connector(ctx);
ctx.body = connector.paymentMethods();
ctx.status = 200;
await next();
},
],
}),
manifest: api_1.method({
GET: [
async function getManifest(ctx, next) {
const connector = new Connector(ctx);
ctx.body = connector.manifest();
ctx.status = 200;
await next();
},
],
}),
authorize: api_1.method({
POST: [
async function postAuthorizations(ctx, next) {
const connector = new Connector(ctx);
const reqBody = await co_body_1.json(ctx.req);
ctx.state.body = reqBody;
ctx.body = await connector.authorize(reqBody);
ctx.status = 200;
await next();
},
],
}),
settle: api_1.method({
POST: [
async function postSettlements(ctx, next) {
const connector = new Connector(ctx);
const reqBody = await co_body_1.json(ctx.req);
ctx.state.body = reqBody;
ctx.body = await connector.settle(reqBody);
ctx.status = 200;
await next();
},
],
}),
refund: api_1.method({
POST: [
async function postRefunds(ctx, next) {
const connector = new Connector(ctx);
const reqBody = await co_body_1.json(ctx.req);
ctx.state.body = reqBody;
ctx.body = await connector.refund(reqBody);
ctx.status = 200;
await next();
},
],
}),
cancel: api_1.method({
POST: [
async function postCancellations(ctx, next) {
const connector = new Connector(ctx);
const reqBody = await co_body_1.json(ctx.req);
ctx.state.body = reqBody;
ctx.body = await connector.cancel(reqBody);
ctx.status = 200;
await next();
},
],
}),
};
};
exports.buildRoutes = buildRoutes;