UNPKG

@arc-publishing/sdk-sales

Version:
48 lines 2.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var APIErrorResponse_1 = require("@arc-publishing/sdk-subs-core/lib/utils/APIErrorResponse"); var JSONResponseHandler_1 = tslib_1.__importDefault(require("@arc-publishing/sdk-subs-core/lib/utils/JSONResponseHandler")); var constants_1 = require("./constants"); var utils_1 = require("./utils"); var SingletonFetch_1 = tslib_1.__importDefault(require("../serviceHelpers/SingletonFetch")); var sales_1 = tslib_1.__importDefault(require("./sales")); function finalizeSubscriptionChange(sessionId, reasonCode) { return tslib_1.__awaiter(this, void 0, void 0, function () { var isLoggedIn, body, fetchOptions, url; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4, sales_1.default._Identity.isLoggedIn()]; case 1: isLoggedIn = _a.sent(); if (!isLoggedIn) { throw new Error("".concat(constants_1.logPrefix, " Missing or invalid jwt")); } body = JSON.stringify((0, utils_1.cleanPayload)({ sessionId: sessionId, reasonCode: reasonCode })); return [4, (0, utils_1.getOptions)({ method: 'PUT', headers: constants_1.headers, body: body })]; case 2: fetchOptions = _a.sent(); url = "".concat(sales_1.default.apiOrigin, "/sales/public/v1/subscription/upgradedowngrade"); return [2, (0, SingletonFetch_1.default)(url, fetchOptions, 'finalizePaymentUpdate') .then(JSONResponseHandler_1.default) .then(function (json) { if ((0, APIErrorResponse_1.isAPIErrorResponse)(json)) { throw json; } else { return json; } })]; } }); }); } exports.default = finalizeSubscriptionChange; //# sourceMappingURL=finalizeSubscriptionChange.js.map