{"id":28254948,"url":"https://github.com/chargebee/chargebee-typescript","last_synced_at":"2025-06-16T06:31:49.242Z","repository":{"id":44878325,"uuid":"266730587","full_name":"chargebee/chargebee-typescript","owner":"chargebee","description":"Typescript library for the Chargebee API.","archived":false,"fork":false,"pushed_at":"2025-05-15T06:34:13.000Z","size":497,"stargazers_count":23,"open_issues_count":19,"forks_count":14,"subscribers_count":38,"default_branch":"master","last_synced_at":"2025-06-05T17:05:42.515Z","etag":null,"topics":["chargebee","nodejs","typescript"],"latest_commit_sha":null,"homepage":"https://apidocs.chargebee.com/docs/api?lang=typescript","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chargebee.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-05-25T08:53:24.000Z","updated_at":"2025-05-15T06:34:13.000Z","dependencies_parsed_at":"2024-01-04T17:43:24.550Z","dependency_job_id":"9dfa33af-3351-4715-b51b-36d271e7bbe6","html_url":"https://github.com/chargebee/chargebee-typescript","commit_stats":{"total_commits":63,"total_committers":14,"mean_commits":4.5,"dds":0.7619047619047619,"last_synced_commit":"5a94f8642496728a55ad1187a0d840ea034a145d"},"previous_names":[],"tags_count":65,"template":false,"template_full_name":null,"purl":"pkg:github/chargebee/chargebee-typescript","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chargebee%2Fchargebee-typescript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chargebee%2Fchargebee-typescript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chargebee%2Fchargebee-typescript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chargebee%2Fchargebee-typescript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chargebee","download_url":"https://codeload.github.com/chargebee/chargebee-typescript/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chargebee%2Fchargebee-typescript/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260114466,"owners_count":22960911,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chargebee","nodejs","typescript"],"created_at":"2025-05-19T20:16:31.363Z","updated_at":"2025-06-16T06:31:49.169Z","avatar_url":"https://github.com/chargebee.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e [!WARNING]  \n\u003e This repository contains the code for [chargebee-typescript](https://www.npmjs.com/package/chargebee-typescript) SDK which is deprecated. This will continue to receive updates till September 30, 2025. If you are using this, we request you to migrate to [chargebee](https://www.npmjs.com/package/chargebee) package by following [this migration guide](https://github.com/chargebee/chargebee-node/wiki/Migration-guide-for-v3) before September 30, 2025.\n\n# Chargebee Typescript Client Library - API V2\n\n[![npm](https://img.shields.io/npm/v/chargebee-typescript.svg?maxAge=2)](https://www.npmjs.com/package/chargebee-typescript)\n[![npm](https://img.shields.io/npm/dt/chargebee-typescript.svg?maxAge=2)](https://www.npmjs.com/package/chargebee-typescript)\n\nThis is a server-side [typescript](https://www.typescriptlang.org/) library for integrating with Chargebee. Sign up for a Chargebee account [here](https://www.chargebee.com).\n\n## Requirements\n\nNode 8 or higher.\n\n## Installation\n\nInstall the latest version of the library with:\n\n```sh\nnpm install chargebee-typescript\n# or\nyarn add chargebee-typescript\n# or\npnpm install chargebee-typescript\n```\n\n## Usage\n\nThe package needs to be configured with your site's API key, which is available under Configure Chargebee Section. Refer [here](https://www.chargebee.com/docs/2.0/api_keys.html) for more details.\n\n```typescript\nimport { ChargeBee } from 'chargebee-typescript';\nconst chargebee = new ChargeBee();\n\nchargebee.configure({\n  site: 'YOUR_SITE_NAME',\n  api_key: 'YOUR_API_KEY',\n});\n```\n\n### Using Async / Await\n\n```typescript\ntry {\n  const { customer } = await chargebee.customer\n    .create({\n      email: 'john@test.com',\n      // other params\n    })\n    .request();\n} catch (err) {\n  // handle error\n}\n```\n\n### Using Promises\n\n```typescript\nchargebee.customer\n  .create({\n    email: 'john@test.com',\n    // other params\n  })\n  .request()\n  .then((result) =\u003e {\n    // handle result\n    // access customer as result.customer;\n  })\n  .catch((err) =\u003e {\n    // handle error\n  });\n```\n\n### Using callbacks\n\n```typescript\nchargebee.customer\n  .create({\n    email: 'john@test.com',\n    // other params\n  })\n  .request(function (error, result) {\n    if (error) {\n      // handle error\n    } else {\n      // handle result\n    }\n  });\n```\n\n### Using typings\n\n```typescript\nimport { ChargeBee, _customer } from 'chargebee-typescript';\nconst chargebee = new ChargeBee();\n\nchargebee.configure({\n  site: 'YOUR_SITE_NAME',\n  api_key: 'YOUR_API_KEY',\n});\n\nconst createCustomer = async () =\u003e {\n  const params: _customer.create_params = {\n    email: 'john@test.com',\n    first_name: 'John',\n    last_name: 'Doe',\n  };\n\n  const { customer } = await chargebee.customer.create(params).request();\n  console.log(customer);\n};\n\ncreateCustomer();\n```\n\n### Accessing the response object\n\nThe response object returned by the `request()` method is generic response wrapper. You need to access the resource from it. For example,\n\n- To access customer object.\n\n```typescript\nconst result = await chargebee.customer.create({ email: 'john@test.com' }).request();\nconsole.log(result.customer);\n```\n\nOther resources can be accessed by the same approach. For subscription, it will be `result.subscription`\n\n- To access list response.\n\n```typescript\nconst result = await chargebee.subscription\n  .list({\n    /* params */\n  })\n  .request();\n\n// A list of Subscription objects\nconsole.log(result.list.map((obj) =\u003e obj.subscription));\n```\n\n**Note**\n\nIf you have a `result` (or children further down the line) and are unsure what properties are available, you can use `Object.keys` to get a list of available accessor properties. Using `Object.keys` in the previous example would yield\n\n```typescript\n// ['list', 'next_offset']\nconsole.log(Object.keys(result));\n// ['1', '2', '3'], e.g. `result.list` is an array with 3 entries\nconsole.log(Object.keys(result.list));\n// ['activated_at', 'base_currency_code', ...]\n// ['activated_at', 'base_currency_code', ...]\n// ['activated_at', 'base_currency_code', ...]\n// Which means we've reached the bottom and should have all the information available from this request\nconsole.log(result.list.map((obj) =\u003e obj.subscription));\n```\n\n#### Using filters in the List API\n\nFor pagination: `offset` is the parameter that is being used. The value used for this parameter must be the value returned for `next_offset` parameter in the previous API call.\n\n```typescript\nconst fetchCustomers = async (offset?: any) =\u003e {\n  const params: _customer.customer_list_params = {\n    offset,\n    limit: 2,\n    first_name: {\n      is: 'John',\n    },\n  };\n\n  const result = await chargebee.customer.list(params).request();\n\n  return {\n    customers: result.list.map((obj) =\u003e obj.customer),\n    next_offset: result.next_offset,\n  };\n};\n\nconst { customers, next_offset } = fetchCustomers();\n\n// Fetching next set of customers\nfetchCustomers(next_offset);\n```\n\n#### Using custom headers and custom fields:\n\n```typescript\nchargebee.customer\n  .create({ email: 'john@test.com' })\n  .param({\n    cf_host_url: 'http://xyz.com',\n  })\n  .headers({\n    'chargebee-event-email': 'all-disabled', // To disable webhooks\n    'chargebee-request-origin-ip': '192.168.1.2',\n  })\n  .request()\n  .then((result) =\u003e {\n    const customer = result.customer;\n    console.log(customer.cf_host_url);\n  });\n```\n\n#### Create an idempotent request\n\n[Idempotency keys](https://apidocs.chargebee.com/docs/api/idempotency?prod_cat_ver=2) are passed along with request headers to allow a safe retry of POST requests.\n\n```typescript\nimport { ChargeBee } from 'chargebee-typescript';\n\nchargebee.customer\n  .create({\n    email: 'john@test.com',\n  })\n  .setIdempotencyKey('\u003c\u003cUUID\u003e\u003e') // Replace \u003c\u003cUUID\u003e\u003e with a unique string\n  .request()\n  .then((result) =\u003e {\n    const customer: typeof chargebee.customer = result.customer;\n    const responseHeaders = result.getResponseHeaders(); // Retrieves response headers\n    console.log(responseHeaders);\n    const idempotencyReplayedValue = result.isIdempotencyReplayed(); // Retrieves idempotency replayed header value\n    console.log(idempotencyReplayedValue);\n  });\n```\n\nNote: `isIdempotencyReplayed()` method can be accessed to differentiate between original and replayed requests.\n\n### Error handling:\n\nAll asynchronous errors will be available as the first argument of `request()` method's callback or in the form of a rejected promise. Detailed documentation on error handling is available [here](https://apidocs.chargebee.com/docs/api/error-handling?prod_cat_ver=2).\n\n```typescript\n//The callback function that you provide needs to take in two arguments. The first being error object and the\n//second being the response. Incase of error, the error object is passed.\nchargebee.subscription\n  .create({\n    //create params...\n  })\n  .request(function (error, result) {\n    if (error) {\n      handleCreateSubscriptionError(error);\n    } else {\n      console.log(result.subscription);\n    }\n  });\n\nfunction handleCreateSubscriptionError(ex) {\n  if (ex.type == 'payment') {\n    // First check for card parameters entered by the user.\n    // We recommend you to validate the input at the client side itself to catch simple mistakes.\n    if ('card[number]' == ex.param) {\n      // Ask your user to recheck the card number. A better way is to use\n      // Stripe's https://github.com/stripe/jquery.payment for validating it in the client side itself.\n      //}else if(\u003cother card params\u003e == ex.param){\n      //Similarly check for other card parameters entered by the user.\n      //....\n    } else {\n      // Verfication or processing failures.\n      // Provide a standard message to your user to recheck his card details or provide a different card.\n      // Like  'Sorry,there was a problem when processing your card, please check the details and try again'.\n    }\n  } else if (ex.type == 'invalid_request') {\n    // For coupons you could decide to provide specific messages by using\n    // the 'api_error_code' attribute in the ex.\n    if ('coupon' == ex.param) {\n      if ('resource_not_found' == ex.api_error_code) {\n        // Inform user to recheck his coupon code.\n      } else if ('resource_limit_exhausted' == ex.api_error_code) {\n        // Inform user that the coupon code has expired.\n      } else if ('invalid_request' == ex.api_error_code) {\n        // Inform user that the coupon code is not applicable for his plan(/addons).\n      } else {\n        // Inform user to recheck his coupon code.\n      }\n    } else {\n      // Since you would have validated all other parameters on your side itself,\n      // this could probably be a bug in your code. Provide a generic message to your users.\n    }\n  } else if (ex.type == 'operation_failed') {\n    // Indicates that the request parameters were right but the request couldn't be completed.\n    // The reasons might be \"api_request_limit_exceeded\" or could be due to an issue in ChargeBee side.\n    // These should occur very rarely and mostly be of temporary nature.\n    // You could ask your user to retry after some time.\n  } else if (ex.type == 'io_error') {\n    // Handle IO exceptions such as connection timeout, request timeout etc.\n    // You could give a generic message to the customer retry after some time.\n  } else {\n    // These are unhandled exceptions (Could be due to a bug in your code or very rarely in client library).\n    // The errors from ChargeBee such as authentication failures will come here.\n    // You could ask users contact your support.\n  }\n}\n```\n\n## Documentation\n\nThe full documentation can be found on the Chargebee API Docs:\n\n[https://apidocs.chargebee.com/docs/api?lang=typescript](https://apidocs.chargebee.com/docs/api?lang=typescript)\n\n## License\n\nSee the [LICENSE](./LICENSE) file.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchargebee%2Fchargebee-typescript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchargebee%2Fchargebee-typescript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchargebee%2Fchargebee-typescript/lists"}