The Clink Node.js SDK provides convenient access to the Clink API from applications written in server-side JavaScript or TypeScript. It includes TypeScript definitions for all request parameters and response fields.
NPM Package View the package on npmjs.com
Installation
Install the package with your preferred package manager:
npm install clink-typescript-sdk
Quick Start
To start using the SDK, you need to initialize the client with your API Key. You can find your secret keys in the Developers section of your Clink dashboard.
Security Note: The SDK is intended for server-side use only. Never expose your Secret API keys in client-side code (browsers) or public repositories.
import { ClinkPayClient } from 'clink-typescript-sdk' ;
const client = new ClinkPayClient ({
apiKey: 'YOUR_API_KEY' ,
env: 'sandbox' ,
});
async function main () {
const session = await client . createCheckoutSession ({
originalAmount: 1999 ,
originalCurrency: 'USD' ,
successUrl: 'https://merchant.example.com/success' ,
cancelUrl: 'https://merchant.example.com/cancel' ,
allowPromotionCodes: true ,
});
console . log ( session . sessionId );
console . log ( session . url );
}
main ();
API Overview
createCheckoutSession(options): Create a checkout session and get the redirect url.
getCheckoutSession(sessionId): Retrieve checkout session details.
getOrder(orderId): Retrieve order details.
getRefund(refundId): Retrieve refund details.
getSubscription(subscriptionId): Retrieve subscription details.
getInvoice(invoiceId): Retrieve subscription invoice details.
customerPortalSession(options): Create a customer portal session and get the access link.
All methods are asynchronous and throw on errors.
Error Handling
When the API returns a non-success status code (4xx or 5xx), the SDK throws an error. You should wrap your API calls in try/catch blocks.
import { ClinkPayClient } from 'clink-typescript-sdk' ;
const client = new ClinkPayClient ({ apiKey: 'YOUR_API_KEY' , env: 'sandbox' });
async function demo () {
try {
const order = await client . getOrder ( 'ord_123' );
console . log ( order . status );
} catch ( e ) {
if ( e instanceof ClinkApiError ) {
const { code , message } = e ;
// your code here
}
// handle other errors
}
}
demo ();
References