Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@doodle/billing-client / dist / index.cjs.js / updateSubscriptionTermEnd.js
Size: Mime:
'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