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.

42 lines (41 loc) 2.13 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.authenticate = authenticate; // src/auth.ts const axios_1 = __importDefault(require("axios")); const utils_1 = require("./utils"); const AUTH_ENDPOINT = "/auth/merchant/login"; // Endpoint: /auth/merchant/login [cite: 9] /** * Authenticates the merchant and returns a session token. * @param baseUrl The base URL for the Nass Payment Gateway API. * @param credentials Merchant username and password. * @returns An object containing the access token. * @throws {Error} If authentication fails (e.g., 401 Unauthorized, 400 Bad Request). */ function authenticate(baseUrl, credentials) { return __awaiter(this, void 0, void 0, function* () { try { const response = yield axios_1.default.post(`${baseUrl}${AUTH_ENDPOINT}`, credentials); // Authenticates the merchant and returns a session token. [cite: 9] // Response (200 OK): { "access_token": "your_access_token" } [cite: 10] return response.data; } catch (error) { // 401 Unauthorized: Invalid authentication credentials. [cite: 49] // 400 Bad Request: Missing or invalid parameters. [cite: 48] throw (0, utils_1.handleAxiosError)(error); } }); }