Add the Payments SDK to your project, load your API key from the environment variable you created in Step 1, and verify the installation with a single test request.
# npm npm install @paymentsapi/sdk # or yarn yarn add @paymentsapi/sdk # Verify installation node -e "const p = require('@paymentsapi/sdk'); console.log(p.VERSION);"
# pip pip install paymentsapi # or with uv / pipenv uv add paymentsapi # Verify installation python -c "import paymentsapi; print(paymentsapi.__version__)"
fetch in Node and httpx in Python for async support.
Create a single client instance and reuse it across your application. Never instantiate it inside a request handler โ that needlessly creates connections on every call.
// src/lib/payments.js โ instantiate once, export, import everywhere require('dotenv').config(); const { PaymentsClient } = require('@paymentsapi/sdk'); const apiKey = process.env.PAYMENTS_SECRET_KEY; if (!apiKey) { throw new Error('PAYMENTS_SECRET_KEY environment variable is not set'); } const payments = new PaymentsClient({ apiKey }); module.exports = { payments };
# src/lib/payments.py โ instantiate once, import everywhere import os from dotenv import load_dotenv from paymentsapi import PaymentsClient load_dotenv() api_key = os.environ.get("PAYMENTS_SECRET_KEY") if not api_key: raise EnvironmentError("PAYMENTS_SECRET_KEY environment variable is not set") payments = PaymentsClient(api_key=api_key)
Run a lightweight credential check against the sandbox before building anything further. This confirms your key is valid and the SDK is configured correctly.
const { payments } = require('./lib/payments'); async function verify() { const result = await payments.ping(); console.log(result); // Expected: { status: 'ok', environment: 'sandbox', account_id: 'acct_...' } } verify();
from src.lib.payments import payments result = payments.ping() print(result) # Expected: {'status': 'ok', 'environment': 'sandbox', 'account_id': 'acct_...'}
curl https://api.paymentsapi.dev/v1/ping \ -H "Authorization: Bearer $PAYMENTS_SECRET_KEY" # Expected response: # { # "status": "ok", # "environment": "sandbox", # "account_id": "acct_..." # }
{ "status": "ok", "environment": "sandbox" } โ your SDK is correctly installed and authenticated. Proceed to Step 3.
npm install or pip install){"status": "ok"}