KS Pay API Documentation
KS Pay API Documentation
1. Introduction
Purpose
The KS Pay API allows businesses to integrate payment processing capabilities into their applications. It offers multi-gateway integration for seamless connections with multiple payment gateways supporting multiple currencies and a wide range of global payment methods to cater to diverse customer preferences, and simplifies payment reconciliation through automated and manual processes. KS Pay features smart routing, which optimizes transaction processing by selecting the most efficient pathways. This combination enhances operational efficiency, reduces costs, and improves customer satisfaction by providing a streamlined payment experience in multiple currencies.
Audience
This guide is intended for developers, DevOps engineers, and product managers who need to integrate Payment engine capabilities into their applications using the KS Pay API.
API Version
1.0.0
Postman Collection
For ease of use and testing, we provide a Postman collection with pre-configured requests:
Sandbox URL: https://pay-open-sandboxapi.kalp.studio
Live URL: https://pay-open-liveapi.kalp.studio
It is highly recommended to use the Sandbox environment for testing and development before moving to the Live environment.
2. Prerequisites
Accounts
To access the API, Enter the Access token & Referesh token.
Credentials
Merchant Token & Authorization key
Tools
Postman (Recommended for API testing)
cURL (Command-line request testing)
Permissions
Requires valid authentication credentials.
3. Authentication & Authorization & Error codes
Authentication
Authentication is handled via API key middleware guards. The API key ensures that the request is from a valid user with the correct permissions.
Steps to Authenticate
Obtain API Key: Request an API key from login API.
Include API Key in Request: Use the API key in the headers of your API requests.
Example Authentication Header
Request Payloads
The Payment Engine API supports the following types of request payloads:
Form-Encoded:
Content-Type: application/x-www-form-urlencodedRaw
Form Data
JSON
Responses
Each response payload is encoded into JSON and contains a result indicating success or an error message for failed or rejected requests.
Error Codes
Status codes other than 200 indicate an issue with the request. Here are some common error codes.
Common API Error Codes
Sandbox/Live API Error codes
API Reference
Server-to-Server (S2S) API Flow
1. Generate Token
This API generates an access token and refresh token for authentication. The access token is required for subsequent API calls.
Request
Method: POST
URL: {{baseURL}}/auth/generate-token/{{appId}}
Headers:
Body:
Response
Status Code: 201 Created
Body:
Description
Authenticates the user using
accessKeyandsecretKey.Returns an
accessTokenandrefreshToken.The
accessTokenis short-lived and must be refreshed using therefreshToken.
2. Generate Refresh Token
This API refreshes the access token using the refresh token.
Request
Method: POST
URL: {{baseURL}}/auth/refresh-token
Headers:
Body:
Response
Status Code: 201 Created
Body:
Description
Refreshes the
accessTokenusing therefreshToken.Returns a new
accessTokenandrefreshToken.
3. Fetch Currencies
This API retrieves a list of supported currencies.
Request
Method: GET
URL: {{baseURL}}/currencies
Headers:
Response
Status Code: 200 OK
Body:
Description
Returns a list of supported currencies, including their codes, symbols, and types.
4. Fetch Payment Methods for Currency
This API retrieves available payment methods for a specific currency.
Request
Method: GET
URL: {{baseURL}}/{{currencyId}}/payment-methods
Headers:
Response
Status Code: 200 OK
Body:
Description
Returns a list of available payment methods for a specific currency.
5. Initiate Transaction
This API initiates a payment transaction.
Request
Method: POST
URL: {{baseURL}}/transaction/initiate
Headers:
Body:
Response
Status Code: 201 Created
Body:
6. Process Transaction
API Name: Process Transaction
Description: Processes the initiated transaction using the generated signature.
Endpoint:
Request Headers:
Response:
Description
Initiates a payment transaction.
7. Fetch Transaction by ID
This API retrieves transaction details using its ID.
Request
Method: GET
URL: {{baseURL}}/transaction/txnId/{{txnId}}
Headers:
Response
Status Code: 200 OK
Description
Retrieves the details of a transaction using its unique ID.
8. Fetch All Transactions
This API retrieves all transactions.
Request
Method: GET
URL: {{baseURL}}/transaction
Headers:
Description
Retrieves a list of all transactions.
KS-PAY API Sequence to Use NPM Package
1. Generate Token
API Name: Generate Token
Description: This API generates an access token and refresh token for authentication.
Endpoint:
Request Headers:
Request Body:
Response:
2. Get Currencies
API Name: Get Available Currencies
Description: Retrieves a list of available currencies for transactions.
Endpoint:
Request Headers:
Response:
3. Get Payment Methods
API Name: Get Payment Methods
Description: Retrieves a list of available payment methods for a specific currency.
Endpoint:
Request Headers:
Response:
4. Initiate Transaction
API Name: Initiate Transaction
Description: Initiates a transaction by specifying currency, payment method, amount, and a reference number.
Endpoint:
Request Headers:
Request Body:
Response:
5. Process Transaction
API Name: Process Transaction
Description: Processes the initiated transaction using the generated signature.
Endpoint:
Request Headers:
Response:
6. Pass Order Object to NPM Package
API Name: Pass Order Object
Description: Pass the Order object received from the /transaction/process endpoint as a payload to the NPM package.
Payload:
7. Handle Payment Response
API Name: Handle Payment Response
Description: After the payment is processed, the user will be redirected to the specified redirectUrl with the following parameters:
payment_status: The status of the payment (e.g., "success", "failed").
kspay_id: The unique identifier for the transaction in KS-PAY.
provider_payment_id: The unique identifier for the transaction in the payment provider's system.
The user can then decide what to do next, such as making an API call or redirecting to another page.
This concludes the API sequence for integrating the KS-PAY payment gateway using the NPM package.

