1. Client Options Configuration

First, define your merchant API credentials obtained from the OneKhusa Portal.
using OneKhusa.SDK; 
using OneKhusa.SDK.Models.Configurations; 
var options = new OneKhusaOptions  
{ 
    ApiKey = "your_api_key", 
    ApiSecret = "your_api_secret", 
    OrganisationId = "ORG123456789", 
    MerchantAccountNumber = 12345678, 
    IsSandbox = true 
}; 
Note that by default IsSandbox is set to true, so you can omit this if you are using sandbox environment. Likewise, with ApiVersion is defaulted to v1, for any new version change it to something like v2, v3 etc.

2. Initializing the Client

Option 1: Using Dependency Injection

This is recommended for web apps and web APIs and in your Program.cs, register the service as below. This automatically manages connection pooling and logging.
using OneKhusa.SDK.Extensions; 

//code omitted for brevity 
builder.Services.AddOneKhusaClient(options =>
{ 
    options.ApiKey = "your_api_key"; 
    options.ApiSecret = "your_api_secret"; 
    options.OrganisationId = "ORG123456789"; 
    options.MerchantAccountNumber = 12345678; 
    options.IsSandbox = true;
}); 

Usage: Sample Code

This code shows how to inject OneKhusaClient into your services, controllers etc. as follows:
using OneKhusa.SDK; 

//code omitted for brevity 
private readonly IOneKhusaClient _client; 
public PaymentService(IOneKhusaClient client) 
{ 
    _client = client; 
} 

Option 2: Manual Instantiation

This is recommended for console apps. Use this code below to create a client. Do not create new OneKhusaClient instance on every API request, create it once, reuse it for subsequent API calls. var client = new OneKhusaClient(options);