Skip to main content
This library provides convenient access to the Fingo Pay REST API from server-side TypeScript or JavaScript. It is generated with Stainless.

Installation

Install the Fingo Pay TypeScript SDK using your preferred package manager:

Quick start

Initialize the SDK with your API key and make your first request:
Never expose your secret API key in client-side code or version control. Use environment variables.

Request & response types

This library includes TypeScript definitions for all request params and response fields. Import and use them for full type safety:
Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.

Handling errors

When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), a subclass of APIError will be thrown:

Error codes

Retries

Certain errors are automatically retried 2 times by default, with a short exponential backoff. The following errors are retried:
  • Connection errors (e.g., network connectivity problems)
  • 408 Request Timeout
  • 409 Conflict
  • 429 Rate Limit
  • =500 Internal errors
Configure or disable retries using the maxRetries option:

Timeouts

Requests time out after 1 minute by default. Configure this with the timeout option:
On timeout, an APIConnectionTimeoutError is thrown. Requests that time out will be retried twice by default.

Advanced usage

Accessing raw response data

The “raw” Response returned by fetch() can be accessed through the .asResponse() method on the APIPromise type. This method returns as soon as the headers for a successful response are received and does not consume the response body, allowing custom parsing or streaming logic. Use .withResponse() to get the raw Response along with the parsed data:

Logging

All log messages are intended for debugging only. The format and content of log messages may change between releases.

Log levels

Configure the log level in two ways:
  1. Via the FINGO_PAY_LOG environment variable
  2. Using the logLevel client option (overrides the environment variable)
Available log levels, from most to least verbose:
At the debug level, all HTTP requests and responses are logged, including headers and bodies. Some authentication-related headers are redacted, but sensitive data in request and response bodies may still be visible.

Custom logger

Provide a custom logger instead of the default globalThis.console. Most logging libraries are supported, including pino, winston, bunyan, consola, signale, and @std/log.

Making custom/undocumented requests

Undocumented endpoints

Make requests to undocumented endpoints using client.get, client.post, and other HTTP verbs:

Undocumented request params

Use // @ts-expect-error for undocumented parameters:

Customizing the fetch client

By default, this library expects a global fetch function. You can polyfill it globally or pass a custom one:

Fetch options

Provide custom fetch options when instantiating the client or making a request:

Configuring proxies

Provide custom fetchOptions to add runtime-specific proxy options:

Requirements

TypeScript >= 4.9 is supported.
The following runtimes are supported:
React Native is not supported at this time. The jsdom environment in Jest is also not supported.

Semantic versioning

This package generally follows SemVer conventions, though certain backwards-incompatible changes may be released as minor versions:
  • Changes that only affect static types, without breaking runtime behavior
  • Changes to library internals which are technically public but not intended or documented for external use
  • Changes that we do not expect to impact the vast majority of users in practice

SDK Source Code

View the SDK source code and contribute on GitHub

npm Package

View the package on npm