Quickstart
This guide creates a product, a price, a customer, and a subscription — all in test mode.
You’ll need a merchant account and a nep_test_ API key (see Authentication).
Pick cURL or the TypeScript SDK with the toggle on each step — your choice syncs across the page.
-
Set your key (cURL) or create a client (SDK).
Terminal window export TRILE_KEY="nep_test_your_key_here"export TRILE_API="https://api.trile.app"Terminal window npm install @trilehq/sdkimport { Configuration, CatalogApi, CustomersApi, SubscriptionsApi } from '@trilehq/sdk'const config = new Configuration({ apiKey: process.env.TRILE_KEY })const catalog = new CatalogApi(config)const customers = new CustomersApi(config)const subscriptions = new SubscriptionsApi(config) -
Create a product. Note the
Idempotency-Key— it’s required on every write.Terminal window curl -s "$TRILE_API/v1/catalog/products" \-H "x-api-key: $TRILE_KEY" \-H "Idempotency-Key: $(uuidgen)" \-H "Content-Type: application/json" \-d '{ "name": "Pro plan" }'const { data: product } = await catalog.createProduct({createProduct: { name: 'Pro plan' },idempotencyKey: crypto.randomUUID(),})// product.id → "prod_…"Every response is enveloped — the object is in
data(the SDK returns it typed):{"success": true,"data": { "id": "prod_01ARZ3NDEKTSV4RRFFQ69G5FAX", "name": "Pro plan", "active": true },"meta": { "requestId": "req_aBcDeFgHiJkL" }} -
Create a monthly price. Amounts are in paisa (NPR 499.00 →
"49900"), as a string.Terminal window curl -s "$TRILE_API/v1/catalog/prices" \-H "x-api-key: $TRILE_KEY" \-H "Idempotency-Key: $(uuidgen)" \-H "Content-Type: application/json" \-d '{"productId": "prod_01ARZ3NDEKTSV4RRFFQ69G5FAX","amountPaisa": "49900","interval": "month"}'const { data: price } = await catalog.createPrice({createPrice: { productId: product.id, amountPaisa: '49900', interval: 'month' },idempotencyKey: crypto.randomUUID(),})// price.id → "price_…" -
Create a customer.
Terminal window curl -s "$TRILE_API/v1/customers" \-H "x-api-key: $TRILE_KEY" \-H "Idempotency-Key: $(uuidgen)" \-H "Content-Type: application/json" \-d '{ "email": "asha@example.com", "name": "Asha K." }'const { data: customer } = await customers.createCustomer({createCustomer: { email: 'asha@example.com', name: 'Asha K.' },idempotencyKey: crypto.randomUUID(),})// customer.id → "cus_…" -
Fund the wallet (test mode). A subscription’s first cycle charges immediately, so the customer’s wallet must hold at least the cycle amount. In production the customer tops up via hosted checkout; in test mode you can drive the customer wallet flow or start the subscription via a checkout session. The simplest path for a first integration is to send the customer through a checkout session, which combines top-up and subscribe.
-
Create the subscription (direct API path — assumes a funded wallet):
Terminal window curl -s "$TRILE_API/v1/subscriptions" \-H "x-api-key: $TRILE_KEY" \-H "Idempotency-Key: $(uuidgen)" \-H "Content-Type: application/json" \-d '{"customerId": "cus_01ARZ3NDEKTSV4RRFFQ69G5FAW","priceId": "price_01ARZ3NDEKTSV4RRFFQ69G5FAY"}'const { data: subscription } = await subscriptions.createSubscription({createSubscription: { customerId: customer.id, priceId: price.id },idempotencyKey: crypto.randomUUID(),})// subscription.status → "active"A
201returns asub_…withstatus: "active". If the wallet is short you get a400witherror.code: "insufficient_funds". -
Listen for events. Register a webhook endpoint and handle
subscription.created,invoice.paid, andinvoice.payment_failedso your app reacts to renewals without polling.
What just happened
Section titled “What just happened”You modeled a plan (product + price), a buyer (customer + wallet), and a recurring
commitment (subscription). From here Trile’s billing engine generates an
invoice each cycle and deducts the wallet automatically.
Next steps
Section titled “Next steps”- TypeScript SDK — typed clients for every endpoint.
- Hosted checkout — the recommended way to onboard real customers (handles top-up + KYC + subscribe).
- Webhooks — verify signatures and react to billing events.
- Going live — swap
nep_test_fornep_live_.