0.0.8 • Published 9 months ago

@fern-api/cashfree v0.0.8

Weekly downloads
-
License
-
Repository
github
Last release
9 months ago

Cashfree Node Library

npm shield fern shield

The Cashfree Node.js library provides access to the Cashfree API from JavaScript/TypeScript.

Documentation

API reference documentation is available here.

Installation

npm install --save @flatfile/api
# or
yarn add @flatfile/api

Usage

Try it out

import { CashfreeClient } from '@fern-api/cashfree';

const cashfree = new CashfreeClient({
    clientId: 'CLIENT_ID',
    clientSecret: 'CLIENT_SECRET',
});

const order = await cashfree.orders.createOrder({
    orderAmount: 10,
    orderCurrency: 'INR',
    customerDetails: {
        customerId: 'cus_1234',
        customerPhone: '912434675',
    },
});

Handling errors

When the API returns a non-success status code (4xx or 5xx response), a subclass of CashfreeError will be thrown:

import { CashfreeError, BadRequestError } from '@fern-api/cashfree';

try {
  await cashfree.orders.getOrder("orderId");
} catch (err) {
  if (err instanceof BadRequestError) {
    console.log(err.statusCode);
    console.log(err.message);
    console.log(err.body);
  } elif (err instanceof CashfreeError) {
    console.log(err.statusCode);
    console.log(err.message);
    console.log(err.body);
  }
}

Error codes are as followed:

Status CodeError Type
400BadRequestError
401UnauthorizedError
404NotFoundError
429TooManyRequestsError
500InternalServerError

Sandbox Environment

By default, the client will use the Production Environment. Below is an example of how you can specify using the Sandbox Environment:

import { CashfreeClient, CashfreeEnvironment } from '@fern-api/cashfree';

const cashfree = new CashfreeClient({
    environment: CashfreeEnvironment.Sandbox, // <---------- Specify environment
    clientId: 'CLIENT_ID',
    clientSecret: 'CLIENT_SECRET',
});

Request Options

Every SDK method accepts an optional RequestOptions parameter where you can configure a custom timeout for the method call.

import { CashfreeClient } from '@fern-api/cashfree';

await cashfree.orders.getOrder("orderId", {
    timeoutInSeconds: 15 // <------------- configure custom timeout
});

Beta status

This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning the package version to a specific version in your package.json file. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.

Contributing

While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!

0.0.8

9 months ago

0.0.7

9 months ago

0.0.6

9 months ago

0.0.5

9 months ago