Nylon PayNylon Pay

Configuration

Initialize the Nylon Pay SDK with your credentials

createNylonPay()

The factory function createNylonPay() returns a configured SDK instance.

import { createNylonPay } from '@nile-squad/nylonpay-ts';

const nylonpay = createNylonPay({
  apiKey: 'npk_test_...',
  apiSecret: 'nps_test_...',
  onError: (error) => {
    if (error.reason === 'SERVICES_DOWN') {
      console.error('Pause payment attempts:', error.message);
    }
  },
});

Test vs. live mode is selected by your API key. A sandbox key runs in the test environment. A live key processes real money.

Configuration Options

OptionTypeDefaultDescription
apiKeystringrequiredYour public Nylon Pay API key (starts with npk_...)
apiSecretstringrequiredYour private Nylon Pay API secret (starts with nps_...)
timeoutMsnumberabout 90 secondsMaximum time for one request
maxRetriesnumber3Maximum retry attempts for failed requests
maxPollDurationMsnumbernoneOptional ceiling on total wait() time. When unset, wait() polls until the transaction reaches a terminal state (see Status Polling)
maxPollAttemptsnumbernoneOptional ceiling on poll attempts for wait(). When unset, polling continues until the transaction reaches a terminal state
fetchtypeof fetchnoneCustom fetch implementation (for edge runtimes, Deno, etc.)
forcebooleanfalseForce a new SDK instance even if one already exists for this key + secret + base URL
hooksSdkHooksnoneLifecycle hooks for logging, enrichment, and analytics. See Hooks.
onErrorSdkErrorHandlernoneHandle structured operation errors for this SDK instance. See Error Handling.

Python: The fetch option is replaced by http_client (accepts an httpx.Client instance). onError becomes on_error. All other options use snake_case names (e.g., timeout_ms, max_retries, max_poll_duration_ms).

PHP: Options use camelCase array keys matching TypeScript (timeoutMs, maxRetries, …). Inject httpClient for tests instead of fetch.

Environment Setup

Sandbox (Development and Testing)

Use sandbox credentials for development and testing.

const nylonpay = createNylonPay({
  apiKey: 'npk_test_...',
  apiSecret: 'nps_test_...',
});

Production (Live payments)

Use live credentials for production transactions.

const nylonpay = createNylonPay({
  apiKey: 'npk_live_...',
  apiSecret: 'nps_live_...',
});

Note: Sandbox and live credentials are different. You cannot use sandbox keys in production or vice versa.

Adjusting Timeout and Polling

For long running payments or high traffic scenarios:

const nylonpay = createNylonPay({
  apiKey: 'npk_test_...',
  apiSecret: 'nps_test_...',
  maxPollDurationMs: 600000, // 10 minutes
  maxPollAttempts: 300,
  timeoutMs: 60000, // 1 minute per request
});

Offline and Nylon down

Pass onError when creating the client. See Offline and Nylon down.

See Also

On this page