UNPKG

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.

73 lines (72 loc) 3.74 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.initiatePortalTransaction = initiatePortalTransaction; exports.checkPortalStatus = checkPortalStatus; // src/portal.ts const axios_1 = __importDefault(require("axios")); const utils_1 = require("./utils"); const TRANSACTION_ENDPOINT = "/transaction"; // Endpoint: /transaction [cite: 11] const STATUS_CHECK_BASE_ENDPOINT = "/transaction"; // URL: /transaction/${OrderId}/checkStatus [cite: 24] /** * Creates a new payment transaction via the Nass Portal. * Merchants can initiate transactions once authenticated. [cite: 11] * @param baseUrl The base URL for the Nass Payment Gateway API (Portal). * @param accessToken The access token obtained from authentication. * @param transactionDetails Details of the transaction to initiate. * @returns A Promise that resolves to the transaction response containing the redirection URL. * @throws {Error} If the transaction initiation fails. */ function initiatePortalTransaction(baseUrl, accessToken, transactionDetails) { return __awaiter(this, void 0, void 0, function* () { try { const response = yield axios_1.default.post(`${baseUrl}${TRANSACTION_ENDPOINT}`, transactionDetails, { headers: { Authorization: `Bearer ${accessToken}`, // The access token must be included in all subsequent requests in the Authorization header [cite: 10] }, }); // Description: Creates a new payment transaction. [cite: 11] // Response (201 Created) [cite: 13] return response.data; } catch (error) { throw (0, utils_1.handleAxiosError)(error); } }); } /** * Checks the status of a transaction initiated via the Nass Portal. * Merchants can check the status of a transaction within 24 hours of its initiation. [cite: 23] * @param baseUrl The base URL for the Nass Payment Gateway API (Portal). * @param accessToken The access token obtained from authentication. * @param orderId The unique order identifier. * @returns A Promise that resolves to the transaction status response. * @throws {Error} If checking the status fails. */ function checkPortalStatus(baseUrl, accessToken, orderId) { return __awaiter(this, void 0, void 0, function* () { try { const response = yield axios_1.default.get(`${baseUrl}${STATUS_CHECK_BASE_ENDPOINT}/${orderId}/checkStatus`, { headers: { Authorization: `Bearer ${accessToken}`, // The access token must be included in all subsequent requests in the Authorization header [cite: 10] }, }); // Description: Retrieves the transaction status. [cite: 24] return response.data; } catch (error) { throw (0, utils_1.handleAxiosError)(error); } }); }