bc-checkout-sdk
Version:
BetterCommerce's Checkout NodeJS SDK enables BC client applications to integrate with Checkout merchant API system. It publishes an interface to interact with [Checkout API](https://api-reference.checkout.com/#operation/getPaymentDetails/) endpoints.
62 lines (61 loc) • 2.4 kB
JavaScript
;
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
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 CheckoutEnvironment_1 = require("../base/config/CheckoutEnvironment");
/**
* Class representing a session.
*
* A session is a request to the Checkout.com API to create a session.
* The request includes the session details and the processing channel id.
*
* @class Session
* @implements {ISession}
*/
class Session {
/**
* Creates a session for the provided payment source.
*
* API Reference - https://api-reference.checkout.com/payments/payments
*
* @param data {any} The session data.
* @returns A promise resolving to a session object or an error object.
*/
async create(data) {
const { secretKey } = data, rest = __rest(data, ["secretKey"]);
try {
const computedUrl = new URL(`apms/klarna/credit-sessions`, CheckoutEnvironment_1.CheckoutEnvironment.getBaseUrl());
const config = {
url: computedUrl.href,
method: RequestMethod_1.RequestMethod.POST,
data: Object.assign({}, rest),
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${secretKey}` },
};
const { data: tokenResult } = await (0, axios_1.default)(config);
return tokenResult;
}
catch (error) {
console.log(error);
return { hasError: true, error: error };
}
}
}
exports.Session = Session;