UNPKG

privacy.com

Version:

Wrapper for the Privacy.com API using Axios and TypeScript

47 lines (46 loc) 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("../../utils"); const _1 = require("."); /** * Get iframe data to display card details * @remarks The iframe body will provide consistent markup of the following form. * It is up to the API client to provide css styles for these elements in the EmbedRequest. * ```html * <div id="card"> * <div id="pan">{PAN}</div> * <div id="expiry"> * <span id="month">{expMonth}</span> * <span id="separator">/</span> * <span id="year">{expYear}</span> * </div> * <div id="cvv">{CVV}</div> * </div> * ``` */ class HostedCardUiRequest extends _1.GetEndpoint { constructor(params) { super(); this.path = "/embed/card"; this.originalParams = params; } /** * Formats parameters for the request, i.e. creates an hmac with the API key and serializes the embed_request object * @param manager PrivacyApi from which to extract the API Key */ beforeExecute(manager) { /** * @dev JSON must be encoded alphabetically, not too bad for not-deeply-nested objects like this one */ const data = { css: this.originalParams.embed_request.css, expiration: this.originalParams.embed_request.expiration, token: this.originalParams.embed_request.token, }; this.params = { embed_request: Buffer.from(JSON.stringify(data)).toString("base64"), hmac: utils_1.createHmac(manager.apiKey, data), }; } } exports.HostedCardUiRequest = HostedCardUiRequest;