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
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | required | Your public Nylon Pay API key (starts with npk_...) |
apiSecret | string | required | Your private Nylon Pay API secret (starts with nps_...) |
timeoutMs | number | about 90 seconds | Maximum time for one request |
maxRetries | number | 3 | Maximum retry attempts for failed requests |
maxPollDurationMs | number | none | Optional ceiling on total wait() time. When unset, wait() polls until the transaction reaches a terminal state (see Status Polling) |
maxPollAttempts | number | none | Optional ceiling on poll attempts for wait(). When unset, polling continues until the transaction reaches a terminal state |
fetch | typeof fetch | none | Custom fetch implementation (for edge runtimes, Deno, etc.) |
force | boolean | false | Force a new SDK instance even if one already exists for this key + secret + base URL |
hooks | SdkHooks | none | Lifecycle hooks for logging, enrichment, and analytics. See Hooks. |
onError | SdkErrorHandler | none | Handle structured operation errors for this SDK instance. See Error Handling. |
Python: The
fetchoption is replaced byhttp_client(accepts anhttpx.Clientinstance).onErrorbecomeson_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, …). InjecthttpClientfor tests instead offetch.
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
- Error Handling, handle offline and Nylon-down errors
- Rate Limits, request limits and retry guidance
- Payment Events, payment lifecycle
- Error Handling,
categoryandcode - Types,
SdkErrorand payment event data