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.
58 lines (57 loc) • 2.38 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.Token = void 0;
// Package Imports
const axios_1 = __importDefault(require("axios"));
// Other Imports
const RequestMethod_1 = require("../constants/enums/RequestMethod");
const CheckoutEnvironment_1 = require("../base/config/CheckoutEnvironment");
/**
* Class representing a token.
*
* A token is a request to the Checkout.com API to create a secure token to be used in payments.
* The request includes the public key and the payment method details.
*
* @class Token
* @implements {IToken}
*/
class Token {
/**
* Request a token
* @param data {Object} - The token request data. Needs to contain a publicKey.
* @returns {Promise<Object>} - A promise resolving to the token request result or an error object.
*/
async requestToken(data) {
const { publicKey } = data, rest = __rest(data, ["publicKey"]);
try {
const computedUrl = new URL(`tokens`, CheckoutEnvironment_1.CheckoutEnvironment.getBaseUrl());
const config = {
url: computedUrl.href,
method: RequestMethod_1.RequestMethod.POST,
data: Object.assign({}, rest),
headers: { "Authorization": `Bearer ${publicKey}` },
};
const { data: tokenResult } = await (0, axios_1.default)(config);
/*const tokenResult = await Api.call(`tokens`, RequestMethod.POST, { ...rest }, {}, { "Authorization": `Bearer ${publicKey}` });*/
return tokenResult;
}
catch (error) {
return { hasError: true, error: error };
}
}
}
exports.Token = Token;