GithubHelp home page GithubHelp logo

chargebee / chargebee-node Goto Github PK

View Code? Open in Web Editor NEW
46.0 36.0 29.0 1.45 MB

Node.js library for the Chargebee API.

Home Page: https://apidocs.chargebee.com/docs/api?lang=node

License: MIT License

JavaScript 100.00%
chargebee javascript nodejs

chargebee-node's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chargebee-node's Issues

Convenient list endpoints func

I wanted a convenient way to use JS intellisense to see the functions available. I edited the bottom of lib/chargebee like so to produce a JSON output here which outlines the functions in a slightly easier to read way. (run node lib/chargebee.js) (this is based on 2.6.5)

const fs = require('fs')
let methods = {}
;(function() {
  module.exports.configure = ChargeBee.configure
  for (var res in ChargeBee._endpoints) {
    module.exports[res] = {}
    methods[res] = {}
    var apiCalls = ChargeBee._endpoints[res]
    for (var apiIdx = 0; apiIdx < apiCalls.length; apiIdx++) {
      var metaArr = apiCalls[apiIdx]
      var apiCall = {
        methodName: metaArr[0],
        httpMethod: metaArr[1],
        urlPrefix: metaArr[2],
        urlSuffix: metaArr[3],
        hasIdInUrl: metaArr[4],
        isListReq: metaArr[0] === 'list',
      }
      methods[res][apiCall.methodName] = {
        methodName: metaArr[0],
        httpMethod: metaArr[1],
        urlPrefix: metaArr[2],
        urlSuffix: metaArr[3],
        hasIdInUrl: metaArr[4],
        isListReq: metaArr[0] === 'list',
      }

      module.exports[res][apiCall.methodName] = createApiFunc(apiCall)
    }
  }
  fs.writeFileSync('./exports.json', JSON.stringify(methods), 'utf-8')
  module.exports.time_machine.wait_for_time_travel_completion = ChargeBee._timeMachineWait
  module.exports.export.wait_for_export_completion = ChargeBee._waitForExport
})()

Typescript types produce many errors

When using version v2.25.1 in a Typescript environment, tsc reports many errors from the Typescript types.

Example:

import Chargebee from 'chargebee';

export async function printCustomer(customerId: string): Promise<void> {
    Chargebee.configure({ site: 'mySite', api_key: 'myApiKey' });
    const response = await Chargebee.customer.retrieve(customerId);
    console.log(JSON.stringify(response, null, 4));
}

Running tsc on this input results in the following errors:

node_modules/chargebee/types/resources/Card.d.ts:43:34 - error TS2304: Cannot find name 'ThirdPartyPaymentMethod'.

43       third_party_payment_method:ThirdPartyPaymentMethod;
                                    ~~~~~~~~~~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/CreditNote.d.ts:175:17 - error TS2304: Cannot find name 'Download'.

175       downloads:Download[];
                    ~~~~~~~~

node_modules/chargebee/types/resources/CreditNote.d.ts:179:16 - error TS2304: Cannot find name 'Download'.

179       download:Download;
                   ~~~~~~~~

node_modules/chargebee/types/resources/Customer.d.ts:143:19 - error TS2304: Cannot find name 'Hierarchy'.

143       hierarchies:Hierarchy[];
                      ~~~~~~~~~

node_modules/chargebee/types/resources/Estimate.d.ts:6:28 - error TS2304: Cannot find name 'SubscriptionEstimate'.

6     subscription_estimate?:SubscriptionEstimate;
                             ~~~~~~~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/Estimate.d.ts:7:29 - error TS2304: Cannot find name 'SubscriptionEstimate'.

7     subscription_estimates?:SubscriptionEstimate[];
                              ~~~~~~~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/Estimate.d.ts:8:23 - error TS2304: Cannot find name 'InvoiceEstimate'.

8     invoice_estimate?:InvoiceEstimate;
                        ~~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/Estimate.d.ts:9:24 - error TS2304: Cannot find name 'InvoiceEstimate'.

9     invoice_estimates?:InvoiceEstimate[];
                         ~~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/Estimate.d.ts:10:28 - error TS2304: Cannot find name 'InvoiceEstimate'.

10     next_invoice_estimate?:InvoiceEstimate;
                              ~~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/Estimate.d.ts:11:28 - error TS2304: Cannot find name 'CreditNoteEstimate'.

11     credit_note_estimates?:CreditNoteEstimate[];
                              ~~~~~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/Invoice.d.ts:356:38 - error TS2304: Cannot find name 'PaymentReferenceNumber'.

356       list:{payment_reference_number:PaymentReferenceNumber}[];
                                         ~~~~~~~~~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/Invoice.d.ts:407:16 - error TS2304: Cannot find name 'Download'.

407       download:Download;
                   ~~~~~~~~

node_modules/chargebee/types/resources/Invoice.d.ts:414:17 - error TS2304: Cannot find name 'Download'.

414       downloads:Download[];
                    ~~~~~~~~

node_modules/chargebee/types/resources/PaymentSource.d.ts:101:34 - error TS2304: Cannot find name 'ThirdPartyPaymentMethod'.

101       third_party_payment_method:ThirdPartyPaymentMethod;
                                     ~~~~~~~~~~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/Quote.d.ts:63:28 - error TS2304: Cannot find name 'QuotedSubscription'.

63       quoted_subscription?:QuotedSubscription;
                              ~~~~~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/Quote.d.ts:84:28 - error TS2304: Cannot find name 'QuotedSubscription'.

84       quoted_subscription?:QuotedSubscription;
                              ~~~~~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/Quote.d.ts:85:22 - error TS2304: Cannot find name 'QuotedCharge'.

85       quoted_charge?:QuotedCharge;
                        ~~~~~~~~~~~~

node_modules/chargebee/types/resources/Quote.d.ts:90:28 - error TS2304: Cannot find name 'QuotedSubscription'.

90       quoted_subscription?:QuotedSubscription;
                              ~~~~~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/Quote.d.ts:110:28 - error TS2304: Cannot find name 'QuotedSubscription'.

110       quoted_subscription?:QuotedSubscription;
                               ~~~~~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/Quote.d.ts:111:22 - error TS2304: Cannot find name 'QuotedCharge'.

111       quoted_charge?:QuotedCharge;
                         ~~~~~~~~~~~~

node_modules/chargebee/types/resources/Quote.d.ts:120:28 - error TS2304: Cannot find name 'QuotedSubscription'.

120       quoted_subscription?:QuotedSubscription;
                               ~~~~~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/Quote.d.ts:149:30 - error TS2304: Cannot find name 'QuoteLineGroup'.

149       list:{quote_line_group:QuoteLineGroup}[];
                                 ~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/Quote.d.ts:159:28 - error TS2304: Cannot find name 'QuotedSubscription'.

159       quoted_subscription?:QuotedSubscription;
                               ~~~~~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/Quote.d.ts:160:22 - error TS2304: Cannot find name 'QuotedCharge'.

160       quoted_charge?:QuotedCharge;
                         ~~~~~~~~~~~~

node_modules/chargebee/types/resources/Quote.d.ts:168:22 - error TS2304: Cannot find name 'QuotedCharge'.

168       quoted_charge?:QuotedCharge;
                         ~~~~~~~~~~~~

node_modules/chargebee/types/resources/Quote.d.ts:186:28 - error TS2304: Cannot find name 'QuotedSubscription'.

186       quoted_subscription?:QuotedSubscription;
                               ~~~~~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/Quote.d.ts:214:46 - error TS2304: Cannot find name 'QuotedSubscription'.

214       list:{quote:Quote,quoted_subscription?:QuotedSubscription}[];
                                                 ~~~~~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/Quote.d.ts:231:16 - error TS2304: Cannot find name 'Download'.

231       download:Download;
                   ~~~~~~~~

node_modules/chargebee/types/resources/Quote.d.ts:240:28 - error TS2304: Cannot find name 'QuotedSubscription'.

240       quoted_subscription?:QuotedSubscription;
                               ~~~~~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/Quote.d.ts:241:22 - error TS2304: Cannot find name 'QuotedCharge'.

241       quoted_charge?:QuotedCharge;
                         ~~~~~~~~~~~~

node_modules/chargebee/types/resources/Quote.d.ts:257:22 - error TS2304: Cannot find name 'QuotedCharge'.

257       quoted_charge?:QuotedCharge;
                         ~~~~~~~~~~~~

node_modules/chargebee/types/resources/Quote.d.ts:277:28 - error TS2304: Cannot find name 'QuotedSubscription'.

277       quoted_subscription?:QuotedSubscription;
                               ~~~~~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/Quote.d.ts:278:22 - error TS2304: Cannot find name 'QuotedCharge'.

278       quoted_charge?:QuotedCharge;
                         ~~~~~~~~~~~~

node_modules/chargebee/types/resources/Subscription.d.ts:98:34 - error TS2304: Cannot find name 'AdvanceInvoiceSchedule'.

98       advance_invoice_schedules?:AdvanceInvoiceSchedule[];
                                    ~~~~~~~~~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/Subscription.d.ts:288:33 - error TS2304: Cannot find name 'AdvanceInvoiceSchedule'.

288       advance_invoice_schedules:AdvanceInvoiceSchedule[];
                                    ~~~~~~~~~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/Subscription.d.ts:332:34 - error TS2304: Cannot find name 'AdvanceInvoiceSchedule'.

332       advance_invoice_schedules?:AdvanceInvoiceSchedule[];
                                     ~~~~~~~~~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/Subscription.d.ts:471:33 - error TS2304: Cannot find name 'AdvanceInvoiceSchedule'.

471       advance_invoice_schedules:AdvanceInvoiceSchedule[];
                                    ~~~~~~~~~~~~~~~~~~~~~~

node_modules/chargebee/types/resources/Usage.d.ts:27:16 - error TS2304: Cannot find name 'Download'.

27       download:Download;
                  ~~~~~~~~


Found 38 errors in 9 files.

Errors  Files
     1  node_modules/chargebee/types/resources/Card.d.ts:43
     2  node_modules/chargebee/types/resources/CreditNote.d.ts:175
     1  node_modules/chargebee/types/resources/Customer.d.ts:143
     6  node_modules/chargebee/types/resources/Estimate.d.ts:6
     3  node_modules/chargebee/types/resources/Invoice.d.ts:356
     1  node_modules/chargebee/types/resources/PaymentSource.d.ts:101
    19  node_modules/chargebee/types/resources/Quote.d.ts:63
     4  node_modules/chargebee/types/resources/Subscription.d.ts:98
     1  node_modules/chargebee/types/resources/Usage.d.ts:27

Usage documentation?

I have a node script that takes in a CSV and processes it before we send it off to our fulfillment center.

https://github.com/holstee/node-chargebee-csv

I'd love to hook this up to the api so I don't have to download the CSV manually. It can just pull the data and export my own CSV.

How can I achieve a pull of all subscriptions in chargebee with this library?

API won't estimate contract_end when change term end

What problem does your feature request address?

With this method we get a estimate object when changing the term end:
https://apidocs.chargebee.com/docs/api/estimates?lang=node#subscription_change_term_end_estimate

But currently there is no way to get the estimated ContractTerm.contract_end. For example a customer that wants to change their next billing date should be able to get the new estimated contract_end since their contract duration would change.

Describe the desired solution

The ideal scenario would be to add that estimated ContractTerm.contract_end to the current method: subscription_change_term_end_estimate since it makes sense.

Alternatives considered

No response

Additional context

No response

Use of deprecated method new Buffer()

'Authorization': 'Basic ' + new Buffer(env.api_key + ':').toString('base64'),

The above line of code is utilizing new Buffer(). new Buffer was deprecated as of NodeJS 8. See here for more info.

This line should simply be able to be replaced with Buffer.from(string).

This issue raises warnings and sometimes errors when running in newer versions of node.

Remove .DSstore

Hi,
i think that it could be useful to remove .DStore file from repo and in general add to .gitignore all files auto generated by OS.

Error handler doesn't work in proper way. Unhandled exception rises

node v10.14.0
chargebee module v2.4.8

return chargebee.subscription.create_for_customer(cbCustomerId, {
	plan_id: planId,
}).request((error, result) => {
	// runs second
	if (error) return next(new Error(`Chargebee error::${error.message}`));
	const resultSubscription = _.get(result, 'subscription', {});
	return res.status(201).json({
		data: {
			type: 'subscriptions',
			id: resultSubscription.id,
			attributes: resultSubscription,
		},
	});
}).catch((error) => {
	// runs first
	// if do not use this catch - unhandled error will throw
	return next(error);
});

Upgrade portal_sessions

I want to send the min and max quantity selection options, also known as quantity_metadata, through Chargebee.portal_session.create for each portal session that Chargebee has created.

  const { portal_session: initialPortalSession } =
        await Chargebee.portal_session
          .create({
            customer: {
              id: customerId,
            },

      // want to send quantity metadata

        })
        .request();

Use Promises?

Would it be possible to make this module use promises for all requests? Maybe there's a way to implement that backwards-compatible to the current API?

Add new endpoints from the May 2019 update

The documentation lists several methods that are not actually available in the current version. e.g. Get Hierarchy (chargebee.customer.hierarchy) will result in an error.

I'm sure adding these is in the pipeline and I'm submitting this issue more as a reminder for myself, so I can remove my manual:

[ 
 "hierarchy",
 "GET",
 "/customers",
 "/hierarchy",
 true
]

when the update comes out / issue is closed.

That said, I can submit a PR with some of the added endpoints if you'd like.

**Question** Dynamic API Keys

Hello!

I am in the process of integrating ChargeBee into a multi-tenant node application. My clients all have their own ChargeBee accounts. What is the best way for my app to switch ChargeBee accounts on the fly?

Do I just call chargebee.configure({ site: "clients-site-name", api_key: "clients-api-key"}) before making any call to the chargebee api?

Thanks!

Filtering subscriptions by custom fields

When using the .list() function, how do I specify a custom field to search by?

Naive approach (does not filter subscriptions):

  chargebee.subscription
      .list({
        limit: 2,
        plan_id: {in: ['my-app', 'my-app-(premium)']}
        cf_custom_field: { is: customValue }
      })
      .request((error, result) => {
        if (error) {
          console.log(error);
        } else {
          // Do something
        }
      });

Refer: https://support.chargebee.com/support/discussions/topics/316925
Note that I have contacted support to enable this feature on our account - just need some direction performing the search with this library.

Alternatively, I'd be happy to use the typescript library in node.js (which supposedly does support custom field filtering), but to date all .list requests return empty objects: [{}, {}]

How to enable subscription pause feature for test site

Hello i'm trying to test subscription pause and resume feature in Node.js for that i execute CURL request to check that how this feature is actually work. CURL request is given bellow

curl  https://flow-test.chargebee.com/api/v2/subscriptions/5a5**a92450**00124*cf/pause \
>      -X POST  \
>      -u test_HW**mVhdJd**ucdK0**GC60p4**yi6x2AF:

So, i'm getting this error

{"message":"Subscription pause feature is currently disabled for you. Contact [email protected] to know more.","type":"invalid_request","api_error_code":"invalid_request","error_code":"pause_feature_not_enabled"}

plan w/ price that is decimal, is returned without the dot

Hi,

i'm not sure if it's the actual API that returned a price that is w/o the dot, or there's a parsing issue with the library. But regardless, i'd like to let you know so maybe there's something that we can do about it here on the library.

sample plan price on dashboard interface
AUD 114.32

what
const { list } = await chargebee.plan.list({ limit: 100 }).request();
returns:

[
{
  plan: {
    ...
    id: 'test-ID',
    price: 11432, // w/o decimal :(
  }
}
]

invoice.create_for_charge_items_and_charges asks for billing_address

Description of the Bug

When calling this function: 'invoice.create_for_charge_items_and_charges asks for billing_address', I get an error stating: 'billing_address should be specified'. Even though I provide a customer_id.

I just want to create an invoice for an existing customer for an existing charge, by it's unique id.

Steps to reproduce

Just call the function like in the code snippit.

Expected Behavior

When I use the REST/CURL api https://{site}.chargebee.com/api/v2/invoices/create_for_charge_items_and_charges I don't get this error and it works as expected.

Code Snippets (if applicable)

await chargebee.invoice
      .create_for_charge_items_and_charges({
        customer_id: "123",
        item_tiers: [
          {
            item_price_id: 'sample-charge-1',
          },
        ],
        discounts: [], // This field is mandatory, which is also weird
      })
      .request();

Operating System

macOS

Language version

Node 20.11.0

Library version

2.34.0

Additional context

No response

subscriptions_for_customer method

Hi,
I found the method (subscriptions_for_customer method) in the code of this module and for me it's ok use it, but i don't know if it's official and if it will be removed in the next releases. So please give me a clarification about that also because there is not any references to it in official documentation.
Thanks in advance.

Can't add PayPal as a payment source.

I'm trying to add a new payment source with a type "paypal_express_checkout" to an existing customer, but I get an error saying that the billing agreement id format is incorrect. I've found out that Chargebee is expecting it to start with B, but PayPal billing agreements start with I.

I'm not sure if this is a problem with this library or Chargebee service itself.

Customer update billing info

Hi, i'm using chargebee.customer.update_billing_info method, but i've anything back from chargebee. Have you some informations about that?

Error in mobile browser when chargebee popup blocked

I was searching for a proper forum/discussion for this issue, if you think this issue was misplaced please guide me.

My web is using next js and we use chargebee payment. The payment work flawlessly in desktop device. I notice the behavior is in desktop browser it open chargebee window in same tab, but for mobile browser it open a new tab/popup. This error occurred in mobile browser with popup blocked by default. I can show a warning to user to enable their popup in browser, but this error still occurred in the background.

image

it seems the error source is from this js file:
<script src="https://js.chargebee.com/v2/chargebee.js" />

I'm simulating it in a safari with user agent below:
"Mozilla/5.0 (iPhone; CPU iPhone OS 13_1_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.1 Mobile/15E148 Safari/604.1"

estimate.invoiceEstimate should return undefined instead of empty {} if none are found

Description of the Bug

I believe we should get null instead of { } in the cases of no invoices estimate. That object can cause trouble for notNullable fields. That would make the field invoice_estimate.sub_total be undefined, when it's not an optional parameter in your documentation.

Steps to reproduce

Check the output for a subscription which has no next invoice, so no invoice_estimate

const response = await chargebee.estimate.renewal_estimate(subscriptionId).request();
console.log(response.estimate.invoice_estimate) // {}, instead of undefined

Expected Behavior

Estimate {
  created_at: 1718879521,
  object: 'estimate',
  subscription_estimate: SubscriptionEstimate {
    id: '12C9UGDmLHI2CC',
    status: 'non_renewing',
    object: 'subscription_estimate',
    currency_code: 'EUR',
    shipping_address: ShippingAddress {
      first_name: 'John',
      last_name: 'Doe',
     ...
      validation_status: 'not_validated',
      object: 'shipping_address'
    }
  },
  invoice_estimate: undefined <---- Shouldn't this be the response?
  next_invoice_estimate: null
}

Code Snippets (if applicable)

Estimate {
  created_at: 1718879521,
  object: 'estimate',
  subscription_estimate: SubscriptionEstimate {
    id: '12C9UGDmLHI2CC',
    status: 'non_renewing',
    object: 'subscription_estimate',
    currency_code: 'EUR',
    shipping_address: ShippingAddress {
      first_name: 'John',
      last_name: 'Doe',
      validation_status: 'not_validated',
      object: 'shipping_address'
    }
  },
  invoice_estimate: InvoiceEstimate {},<---- CB response instead of undefined ?
  next_invoice_estimate: InvoiceEstimate {}
}

Operating System

macOS

Language version

Node 18.17.0

Library version

2.32.1

Additional context

This incurs in error if we are returning estimate via graphql where the field invoice_estimate.sub_total was set as NonNegativeInt!.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.