UNPKG

paypal-custom-sdk

Version:

a minimalistic paypal sdk for custom integrations

62 lines (61 loc) 2.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const authorization_1 = tslib_1.__importDefault(require("./authorization")); const constants_1 = require("../configs/constants"); const request_1 = tslib_1.__importDefault(require("../utils/request")); const contexts_1 = require("../utils/contexts"); const withSingleton_1 = tslib_1.__importDefault(require("../utils/HOF/withSingleton")); const planServices = () => { const env = (0, contexts_1.getItem)('env'); const baseUrl = env === 'production' ? constants_1.BASE_URLS.PAYPAL : constants_1.BASE_URLS.SANDBOX; const request = (0, request_1.default)(baseUrl); const { getHeaders } = (0, authorization_1.default)(); const create = (body) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const headers = yield getHeaders(); const { data } = yield request.post(constants_1.PATHS.CREATE_PLAN, body, { headers, }); return data; }); const get = (planId) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const headers = yield getHeaders(); const { data } = yield request.get(constants_1.PATHS.CREATE_PLAN.replace('{plan_id}', planId), { headers, }); return data; }); const update = (planId, body) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const headers = yield getHeaders(); yield request.patch(constants_1.PATHS.CREATE_PLAN.replace('{plan_id}', planId), body, { headers, }); }); const activate = (planId) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const headers = yield getHeaders(); yield request.post(constants_1.PATHS.ACTIVATE_PLAN.replace('{plan_id}', planId), {}, { headers, }); }); const deactivate = (planId) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const headers = yield getHeaders(); yield request.post(constants_1.PATHS.DEACTIVATE_PLAN.replace('{plan_id}', planId), {}, { headers, }); }); const updatePricing = (planId, body) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const headers = yield getHeaders(); yield request.post(constants_1.PATHS.UPDATE_PLAN_PRICING.replace('{plan_id}', planId), body, { headers, }); }); return { create, get, update, activate, deactivate, updatePricing, }; }; exports.default = (0, withSingleton_1.default)(planServices);