UNPKG

@adyen/api-library

Version:

The Adyen API Library for NodeJS enables you to work with Adyen APIs.

205 lines 8.65 kB
"use strict"; /* * The version of the OpenAPI document: v54 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit this class manually. */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ObjectSerializer = void 0; __exportStar(require("./amount"), exports); __exportStar(require("./binDetail"), exports); __exportStar(require("./cardBin"), exports); __exportStar(require("./costEstimateAssumptions"), exports); __exportStar(require("./costEstimateRequest"), exports); __exportStar(require("./costEstimateResponse"), exports); __exportStar(require("./dSPublicKeyDetail"), exports); __exportStar(require("./merchantDetails"), exports); __exportStar(require("./recurring"), exports); __exportStar(require("./serviceError"), exports); __exportStar(require("./threeDS2CardRangeDetail"), exports); __exportStar(require("./threeDSAvailabilityRequest"), exports); __exportStar(require("./threeDSAvailabilityResponse"), exports); const amount_1 = require("./amount"); const binDetail_1 = require("./binDetail"); const cardBin_1 = require("./cardBin"); const costEstimateAssumptions_1 = require("./costEstimateAssumptions"); const costEstimateRequest_1 = require("./costEstimateRequest"); const costEstimateResponse_1 = require("./costEstimateResponse"); const dSPublicKeyDetail_1 = require("./dSPublicKeyDetail"); const merchantDetails_1 = require("./merchantDetails"); const recurring_1 = require("./recurring"); const serviceError_1 = require("./serviceError"); const threeDS2CardRangeDetail_1 = require("./threeDS2CardRangeDetail"); const threeDSAvailabilityRequest_1 = require("./threeDSAvailabilityRequest"); const threeDSAvailabilityResponse_1 = require("./threeDSAvailabilityResponse"); /* tslint:disable:no-unused-variable */ let primitives = [ "string", "boolean", "double", "integer", "long", "float", "number", "any" ]; let enumsMap = { "CostEstimateRequest.ShopperInteractionEnum": costEstimateRequest_1.CostEstimateRequest.ShopperInteractionEnum, "Recurring.ContractEnum": recurring_1.Recurring.ContractEnum, "Recurring.TokenServiceEnum": recurring_1.Recurring.TokenServiceEnum, }; let typeMap = { "Amount": amount_1.Amount, "BinDetail": binDetail_1.BinDetail, "CardBin": cardBin_1.CardBin, "CostEstimateAssumptions": costEstimateAssumptions_1.CostEstimateAssumptions, "CostEstimateRequest": costEstimateRequest_1.CostEstimateRequest, "CostEstimateResponse": costEstimateResponse_1.CostEstimateResponse, "DSPublicKeyDetail": dSPublicKeyDetail_1.DSPublicKeyDetail, "MerchantDetails": merchantDetails_1.MerchantDetails, "Recurring": recurring_1.Recurring, "ServiceError": serviceError_1.ServiceError, "ThreeDS2CardRangeDetail": threeDS2CardRangeDetail_1.ThreeDS2CardRangeDetail, "ThreeDSAvailabilityRequest": threeDSAvailabilityRequest_1.ThreeDSAvailabilityRequest, "ThreeDSAvailabilityResponse": threeDSAvailabilityResponse_1.ThreeDSAvailabilityResponse, }; class ObjectSerializer { static findCorrectType(data, expectedType) { if (data == undefined) { return expectedType; } else if (primitives.indexOf(expectedType.toLowerCase()) !== -1) { return expectedType; } else if (expectedType === "Date") { return expectedType; } else { if (enumsMap[expectedType]) { return expectedType; } if (!typeMap[expectedType]) { return expectedType; // w/e we don't know the type } // Check the discriminator let discriminatorProperty = typeMap[expectedType].discriminator; if (discriminatorProperty == null) { return expectedType; // the type does not have a discriminator. use it. } else { if (data[discriminatorProperty]) { var discriminatorType = data[discriminatorProperty]; if (typeMap[discriminatorType]) { return discriminatorType; // use the type given in the discriminator } else { return expectedType; // discriminator did not map to a type } } else { return expectedType; // discriminator was not present (or an empty string) } } } } static serialize(data, type) { if (data == undefined) { return data; } else if (primitives.indexOf(type.toLowerCase()) !== -1) { return data; } else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6 let subType = type.replace("Array<", ""); // Array<Type> => Type> subType = subType.substring(0, subType.length - 1); // Type> => Type let transformedData = []; for (let index = 0; index < data.length; index++) { let datum = data[index]; transformedData.push(ObjectSerializer.serialize(datum, subType)); } return transformedData; } else if (type === "Date") { return data.toISOString(); } else if (type === "SaleToAcquirerData") { const dataString = JSON.stringify(data); return Buffer.from(dataString).toString("base64"); } else { if (enumsMap[type]) { return data; } if (!typeMap[type]) { // in case we dont know the type return data; } // Get the actual type of this object type = this.findCorrectType(data, type); // get the map for the correct type. let attributeTypes = typeMap[type].getAttributeTypeMap(); let instance = {}; for (let index = 0; index < attributeTypes.length; index++) { let attributeType = attributeTypes[index]; instance[attributeType.baseName] = ObjectSerializer.serialize(data[attributeType.name], attributeType.type); } return instance; } } static deserialize(data, type) { // polymorphism may change the actual type. type = ObjectSerializer.findCorrectType(data, type); if (data == undefined) { return data; } else if (primitives.indexOf(type.toLowerCase()) !== -1) { return data; } else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6 let subType = type.replace("Array<", ""); // Array<Type> => Type> subType = subType.substring(0, subType.length - 1); // Type> => Type let transformedData = []; for (let index = 0; index < data.length; index++) { let datum = data[index]; transformedData.push(ObjectSerializer.deserialize(datum, subType)); } return transformedData; } else if (type === "Date") { return new Date(data); } else { if (enumsMap[type]) { // is Enum return data; } if (!typeMap[type]) { // dont know the type return data; } let instance = new typeMap[type](); let attributeTypes = typeMap[type].getAttributeTypeMap(); for (let index = 0; index < attributeTypes.length; index++) { let attributeType = attributeTypes[index]; instance[attributeType.name] = ObjectSerializer.deserialize(data[attributeType.baseName], attributeType.type); } return instance; } } } exports.ObjectSerializer = ObjectSerializer; //# sourceMappingURL=models.js.map