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 / cancelSubscriptionForUser.js
Size: Mime:
'use strict';

const fetch = require('fetch-everywhere');

const {
  errorHandler,
  responseHandler
} = require('./helpers/fetch');
/**
 * Cancel a subscription for a user by subscriptionId.
 *
 * @param {string} accessToken - The user's access-token
 * @param {number} subscriptionId - The subscription id you want to delete
 * @returns {Promise<object>}
 */


function cancelSubscriptionForUser(accessToken, subscriptionId) {
  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}`);
  }

  const url = `${process.env.SVC_BILLING_BASE_URL}/subscriptions/${subscriptionId}`;
  const headers = {
    'Content-Type': 'application/json',
    Authorization: `Bearer ${accessToken}`,
    Accept: 'application/json'
  };
  return fetch(url, {
    method: 'DELETE',
    headers
  }).then(responseHandler).catch(errorHandler);
}

module.exports = cancelSubscriptionForUser;
//# sourceMappingURL=cancelSubscriptionForUser.js.map