@arc-publishing/sdk-sales
Version:
JS Sales SDK for working with Arc Subs Sales API
47 lines • 2.25 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 initializeSubscriptionChange(subscriptionId, newPriceCode, productChanges, currentTerm) {
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({
subscriptionId: subscriptionId,
newPriceCode: newPriceCode,
productChanges: productChanges,
currentTerm: currentTerm
}));
return [4, getOptions({
method: 'POST',
headers: headers,
body: body
})];
case 2:
fetchOptions = _a.sent();
url = "".concat(Sales.apiOrigin, "/sales/public/v1/subscription/upgradedowngrade");
return [2, SingletonFetch(url, fetchOptions, 'initializePaymentUpdate')
.then(JSONResponseHandler)
.then(function (json) {
if (isAPIErrorResponse(json)) {
throw json;
}
else {
return json;
}
})];
}
});
});
}
//# sourceMappingURL=initializeSubscriptionChange.js.map