nasspay
Version:
TypeScript/JavaScript SDK for integrating with the Nass Merchant Payment Gateway. Supports both Portal and Direct API integration methods with comprehensive type definitions.
92 lines (91 loc) • 6.05 kB
TypeScript
import { AuthResponse, PortalTransactionResponse, StatusCheckResponse, DirectApiTransactionInitResponse, CardDetails } from "./types";
export interface NassGatewayConfig {
username: string;
password: string;
environment?: "UAT" | "PRODUCTION";
portalBaseUrl?: string;
directApiTransactionUrl?: string;
}
declare class NassPaymentGateway {
private username;
private password;
private environment;
private portalBaseUrl;
private directApiTransactionUrl;
private accessToken;
constructor(config: NassGatewayConfig);
/**
* Authenticates the merchant with the Nass Payment Gateway.
* Upon successful authentication, the API returns an access token, which must be included in the Authorization header of all subsequent requests. [cite: 29]
* @returns A Promise that resolves to the authentication response containing the access token.
*/
authenticate(): Promise<AuthResponse>;
/**
* Initiates a new payment transaction using the Nass Payment Gateway Portal method.
* Once authenticated, merchants can initiate transactions. [cite: 11]
* @param orderId Unique order identifier generated by the merchant. [cite: 12]
* @param orderDesc Order description. [cite: 12]
* @param amount Order total amount. [cite: 12]
* @param currency Order currency (3-character ISO currency code). [cite: 12]
* @param transactionType Transaction type ('1' for sale, etc.). [cite: 12]
* @param backRef Frontend Redirect URL. [cite: 12]
* @param notifyUrl HTTP Backend URL for sending POS request callbacks. [cite: 12]
* @returns A Promise that resolves to the transaction response, including a URL to redirect the customer to complete the payment.
* @throws {Error} If not authenticated or if the transaction initiation fails.
*/
createPortalTransaction(orderId: string, orderDesc: string, amount: number, currency: string, transactionType: string, backRef: string, notifyUrl?: string): Promise<PortalTransactionResponse>;
/**
* Checks the status of a transaction initiated via the Nass Portal method.
* Merchants can check the status of a transaction within 24 hours of its initiation. [cite: 23]
* @param orderId The unique order identifier of the transaction to check.
* @returns A Promise that resolves to the transaction status response.
* @throws {Error} If not authenticated or if checking the status fails.
*/
checkPortalTransactionStatus(orderId: string): Promise<StatusCheckResponse>;
/**
* Initiates the first step of a Direct API transaction.
* Sends a POST request to /transaction to initiate a transaction. [cite: 30]
* @param orderId Unique order identifier generated by the merchant. [cite: 31]
* @param orderDesc Order description.
* @param amount Order total amount. [cite: 31]
* @param currency Order currency (3-character ISO currency code). [cite: 31]
* @param transactionType Transaction type ('1' for sale, etc.). [cite: 31]
* @returns A Promise that resolves to the initial transaction response containing `pSign` and `transactionParams` (including `nonce` and `timestamp`), which are required for the next step of Direct API Integration. [cite: 32]
* @throws {Error} If not authenticated or if the initiation fails.
*/
createDirectApiTransaction(orderId: string, orderDesc: string, amount: number, currency: string, transactionType: string): Promise<DirectApiTransactionInitResponse>;
/**
* Sends cardholder data directly to the payment gateway for authorization (second step of Direct API).
* This method requires merchants to securely transmit cardholder data. [cite: 27]
* @param pSign The `pSign` received from the `createDirectApiTransaction` response. [cite: 34]
* @param nonce The `nonce` received from the `createDirectApiTransaction` response's `transactionParams`. [cite: 34]
* @param cardDetails Object containing card number (PAN), expiration month/year, CVV, and optional cardholder name and CVC2 reason code. [cite: 34, 46]
* @param orderDetails Object containing order number, amount (in minor units), currency, transaction type, terminal ID, order description, timestamp, and back reference URL. [cite: 35, 46]
* @returns A Promise that resolves to an HTML string which, if rendered, will redirect the user back to the merchant's website. [cite: 37]
* @throws {Error} If sending cardholder data fails.
*/
sendDirectApiCardholderData(pSign: string, // pSign: The signature from the initial transaction response [cite: 34]
nonce: string, // NONCE: A unique identifier for the transaction [cite: 34]
cardDetails: CardDetails, // Cardholder details (PAN, expiry date, CVV). [cite: 34]
orderDetails: {
orderId: string;
amount: string;
currency: string;
transactionType: string;
terminalId: string;
orderDesc: string;
timestamp: string;
backRefUrl: string;
}): Promise<string>;
/**
* Checks the status of a transaction initiated via Direct API Integration.
* Merchants can check the status of a transaction within 24 hours of initiation. [cite: 44]
* @param orderId The unique order identifier of the transaction to check.
* @returns A Promise that resolves to the transaction status response.
* @throws {Error} If not authenticated or if checking the status fails.
*/
checkDirectApiTransactionStatus(orderId: string): Promise<StatusCheckResponse>;
}
export default NassPaymentGateway;
export { AuthResponse, PortalTransactionRequest, PortalTransactionResponse, StatusCheckResponse, DirectApiTransactionInitRequest, DirectApiTransactionInitResponse, CardDetails, Environment, AuthCredentials, CallbackResponse, DirectApiTransactionInitResponseData, DirectApiCardholderDataRequest, TransactionError, NassErrorResponse, } from "./types";
export { UAT_BASE_URL_PORTAL, UAT_BASE_URL_DIRECT_API_TRANSACTION_PROCESSING, } from "./utils";