@arc-publishing/sdk-sales
Version:
JS Sales SDK for working with Arc Subs Sales API
45 lines • 2.09 kB
JavaScript
import { __awaiter, __generator } from "tslib";
import { isAPIErrorResponse } from '@arc-publishing/sdk-subs-core/lib/utils/APIErrorResponse';
import JSONResponseHandler from '@arc-publishing/sdk-subs-core/lib/utils/JSONResponseHandler';
import { headers, logPrefix } from './constants';
import { getOptions, cleanPayload } from './utils';
import SingletonFetch from '../serviceHelpers/SingletonFetch';
import Sales from './sales';
export default function finalizeSubscriptionChange(sessionId, reasonCode) {
return __awaiter(this, void 0, void 0, function () {
var isLoggedIn, body, fetchOptions, url;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, Sales._Identity.isLoggedIn()];
case 1:
isLoggedIn = _a.sent();
if (!isLoggedIn) {
throw new Error("".concat(logPrefix, " Missing or invalid jwt"));
}
body = JSON.stringify(cleanPayload({
sessionId: sessionId,
reasonCode: reasonCode
}));
return [4, getOptions({
method: 'PUT',
headers: headers,
body: body
})];
case 2:
fetchOptions = _a.sent();
url = "".concat(Sales.apiOrigin, "/sales/public/v1/subscription/upgradedowngrade");
return [2, SingletonFetch(url, fetchOptions, 'finalizePaymentUpdate')
.then(JSONResponseHandler)
.then(function (json) {
if (isAPIErrorResponse(json)) {
throw json;
}
else {
return json;
}
})];
}
});
});
}
//# sourceMappingURL=finalizeSubscriptionChange.js.map