chargebee / chargebee-node Goto Github PK
View Code? Open in Web Editor NEWNode.js library for the Chargebee API.
Home Page: https://apidocs.chargebee.com/docs/api?lang=node
License: MIT License
Node.js library for the Chargebee API.
Home Page: https://apidocs.chargebee.com/docs/api?lang=node
License: MIT License
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
})()
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
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?
I'm just noticing that there are two missing methods in this v2 API.
the hosted_page endpoints for the following seem to be missing:
am I missing something?
https://apidocs.chargebee.com/docs/api/hosted_pages#retrieve_a_hosted_page
Furthermore will this method be supporting the other Payment Gateways if it will even exist in the v2 API?
See #22.
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.
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.
No response
No response
chargebee-node/lib/chargebee.js
Line 222 in f0cf59c
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.
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.
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);
});
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();
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?
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.
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!
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: [{}, {}]
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"}
I have got like this issue
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 :(
}
}
]
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.
Just call the function like in the code snippit.
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.
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();
macOS
Node 20.11.0
2.34.0
No response
Hi, are there typescript typings?
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.
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.
Hi, i'm using chargebee.customer.update_billing_info method, but i've anything back from chargebee. Have you some informations about that?
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.
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"
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.
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
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
}
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 {}
}
macOS
Node 18.17.0
2.32.1
This incurs in error if we are returning estimate via graphql where the field invoice_estimate.sub_total was set as NonNegativeInt!
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.