chargebee / chargebee-typescript

Typescript library for the Chargebee API.
https://apidocs.chargebee.com/docs/api?lang=typescript
MIT License
22 stars 16 forks source link

Does anyone have this successfully working in the browser? #8

Closed anderslyman closed 3 years ago

anderslyman commented 3 years ago

This library is written for node.js. Refer: https://github.com/chargebee/chargebee-typescript/blob/master/src/core.ts It requires http, https, os.

Does anyone have this working in the browser? I got this far:

import {Buffer} from 'buffer';
import {Core} from 'chargebee-typescript/lib/core';

(window as any).global = window;
(window as any).global.Buffer = (window as any).global.Buffer || Buffer;
(window as any).process = {version: '3.9.5'};
(Core as any).os = {
  platform() {
    return 'browser';
  },
  arch() {
    return 'x86';
  },
  release() {
    return '1';
  }
};

How did you shim/polyfill the http/https pieces for the request function?

sagar7993 commented 3 years ago

@anderslyman This library is specifically made to be used in a nodejs backend environment, and cannot be used in frontend code. If you want to integrate chargebee on your frontend, you'll have to use the chargebee checkout script.

There is NO installable npm package for this yet and the only officially supported way as of now is to include their script in your index.html and using the window.Chargebee object for initiating the checkout