UNPKG

bc-elavon-sdk

Version:

BetterCommerce's Elavon NodeJS SDK enables BC client applications to integrate with Elavon merchant API system. It publishes an interface to interact with [Elavon API](https://developer.elavon.com/products/checkout-js/v1/api-reference/) endpoints.

53 lines (52 loc) 2.47 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Session = void 0; // Package Imports const axios_1 = __importDefault(require("axios")); // Other Imports //import { Api } from "../api"; const RequestMethod_1 = require("../constants/enums/RequestMethod"); const ElavonEnvironment_1 = require("../base/config/ElavonEnvironment"); /** * Class {@link Session} representing a session. * * A session is a request to the Elavon API to create a session token. * The session token is a unique identifier that is generated and used to manage user sessions * and maintain stateful communication between client and server. * * The session token response is only valid for 15 minutes and can only be used once. * * @implements {ISession} */ class Session { /** * Creates a session token which is a unique identifier that is generated and used to manage user sessions * and maintain stateful communication between client and server. * * API Reference - https://developer.elavon.com/products/hosted-payment-page/v1/api-reference#tag/Request-Session-Token/operation/session-token * * @param data {any} The session data. * @returns A promise resolving to a session object or an error object. */ async create(data) { try { const computedUrl = new URL(`hosted-payments/transaction_token`, ElavonEnvironment_1.ElavonEnvironment.getBaseUrl()); const config = { url: computedUrl.href, method: RequestMethod_1.RequestMethod.POST, params: Object.assign(Object.assign({}, data), { ssl_account_id: ElavonEnvironment_1.ElavonEnvironment.getMerchantId(), ssl_user_id: ElavonEnvironment_1.ElavonEnvironment.getMerchantUserId(), ssl_pin: ElavonEnvironment_1.ElavonEnvironment.getMerchantPIN(), ssl_vendor_id: ElavonEnvironment_1.ElavonEnvironment.getVendorId() }), headers: { "Content-Type": "application/json", }, }; const { data: sessionTokenResult } = await (0, axios_1.default)(config); return sessionTokenResult; } catch (error) { console.log(error); return { hasError: true, error: error }; } } } exports.Session = Session;