Repository URL to install this package:
|
Version:
2.0.0-rc.6 ▾
|
'use strict';
var fetch$1 = require('./helpers/fetch.js');
const fetch = require('fetch-everywhere');
/**
* Change the ending date of an existing subscription.
*
* @param {string} accessToken - The user's access-token
* @param {string} subscriptionId - The date when you want the subscription to end
* @param {string} endDate - ISO-8601 Date string i.e., new Date().toISOString()
* @returns {Promise}
*/
function updateSubscriptionTermEnd(accessToken, subscriptionId, endDate) {
if (typeof accessToken !== 'string') {
throw new TypeError(`accessToken param must be a string, got ${typeof accessToken}`);
}
if (typeof subscriptionId !== 'number') {
throw new TypeError(`subscriptionId param must be a number, got ${typeof subscriptionId}`);
}
if (typeof endDate !== 'string') {
throw new TypeError(`endDate param must be a string, got ${typeof endDate}`);
} // Convert the Date object to an encoded ISO-8601 Date string
const encodedDate = encodeURIComponent(endDate);
const url = `${process.env.SVC_BILLING_BASE_URL}/subscriptions/${subscriptionId}/term-end/${encodedDate}`;
const headers = {
'Content-Type': 'application/json',
Authorization: `Bearer ${accessToken}`,
Accept: 'application/json'
};
return fetch(url, {
method: 'POST',
headers
}).then(fetch$1.responseHandler).catch(fetch$1.errorHandler);
}
module.exports = updateSubscriptionTermEnd;
//# sourceMappingURL=updateSubscriptionTermEnd.js.map