How to use the chargebee.subscription function in chargebee

To help you get started, we’ve selected a few chargebee examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github WorldBrain / Memex / functions / src / index.ts View on Github external
const _refreshUserSubscriptionStatus = async (userId: string) => {
    chargebee.configure(getChargebeeOptions())

    const claims: Claims = {
        subscriptions: {},
        lastSubscribed: null,
    }

    const subscriptionQuery = {
        customer_id: userId,
        'sort_by[asc]': 'created_at',
    }

    // Query the Chargebee API for this user's subscriptions, adding every active/in_trial sub to the claims object.
    // any past subscription updates the lastSubscribed property to know whether a user has subscribed in the past.
    await chargebee.subscription
        .list(subscriptionQuery)
        .request(function(error: any, result: any) {
            if (error) {
                return errorResponse('Provider', error)
            } else {
                for (const entry of result.list) {
                    if (
                        entry.subscription.status === 'active' ||
                        entry.subscription.status === 'in_trial'
                    ) {
                        // TODO: verify `next_billing_at` is the right thing to refresh on and not `current_term_end`
                        claims.subscriptions[entry.subscription.plan_id] = {
                            refreshAt: entry.subscription.next_billing_at,
                        }
                    }
                    claims.lastSubscribed = entry.subscription.createdAt
github staart / api / src / helpers / stripe.ts View on Github external
new Promise((resolve, reject) => {
    chargebee.subscription
      .list({
        "customer_id[is]": id
      })
      .request((error: any, result: any) => {
        if (error) return reject(error);
        resolve(result.list as any);
      });
  });
github rrecuero / fstack-ethdapp-template / backend / subscriptions / subscriptionsManager.js View on Github external
reactivateSubscription(subscriptionId, cb) {
    chargebee.subscription.reactivate(subscriptionId).request(cb);
  }
github staart / api / src / helpers / stripe.ts View on Github external
new Promise((resolve, reject) => {
    chargebee.subscription
      .retrieve(sourceId)
      .request((error: any, result: any) => {
        if (error) return reject(error);
        resolve(result as any);
      });
  });

chargebee

A library for integrating with Chargebee.

MIT
Latest version published 8 days ago

Package Health Score

78 / 100
Full package analysis