cybersource-rest-client
Version:
Node.js SDK for the CyberSource REST API
124 lines (106 loc) • 6.64 kB
JavaScript
/**
* CyberSource Merged Spec
* All CyberSource API specs merged together. These are available at https://developer.cybersource.com/api/reference/api-reference.html
*
* OpenAPI spec version: 0.0.1
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
*
* Swagger Codegen version: 2.4.38
*
* Do not edit the class manually.
*
*/
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['Authentication/MLEUtility', 'ApiClient', 'model/InlineResponse200', 'model/InlineResponse400', 'model/InlineResponse403', 'model/InlineResponse424', 'model/InlineResponse500', 'model/PostTokenizeRequest'], factory);
} else if (typeof module === 'object' && module.exports) {
// CommonJS-like environments that support module.exports, like Node.
module.exports = factory(require('../authentication/util/MLEUtility'), require('../ApiClient'), require('../model/InlineResponse200'), require('../model/InlineResponse400'), require('../model/InlineResponse403'), require('../model/InlineResponse424'), require('../model/InlineResponse500'), require('../model/PostTokenizeRequest'));
} else {
// Browser globals (root is window)
if (!root.CyberSource) {
root.CyberSource = {};
}
root.CyberSource.TokenizeApi = factory(root.Authentication.MLEUtility, root.CyberSource.ApiClient, root.CyberSource.InlineResponse200, root.CyberSource.InlineResponse400, root.CyberSource.InlineResponse403, root.CyberSource.InlineResponse424, root.CyberSource.InlineResponse500, root.CyberSource.PostTokenizeRequest);
}
}(this, function(MLEUtility, ApiClient, InlineResponse200, InlineResponse400, InlineResponse403, InlineResponse424, InlineResponse500, PostTokenizeRequest) {
'use strict';
/**
* Tokenize service.
* @module api/TokenizeApi
* @version 0.0.1
*/
/**
* Constructs a new TokenizeApi.
* @alias module:api/TokenizeApi
* @class
* @param {module:ApiClient} apiClient Optional API client implementation to use,
* default to {@link module:ApiClient#instance} if unspecified.
*/
var exports = function(configObject, apiClient) {
this.apiClient = apiClient || ApiClient.instance;
this.apiClient.setConfiguration(configObject);
/**
* Callback function to receive the result of the tokenize operation.
* @callback module:api/TokenizeApi~tokenizeCallback
* @param {String} error Error message, if any.
* @param {module:model/InlineResponse200} data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Tokenize
* | | | | | --- | --- | --- | |The **Tokenize API** endpoint facilitates the creation of various TMS tokens such as Customers, Payment Instruments, Shipping Addresses, and Instrument Identifiers in a single operation. The request includes a processingInformation object, which specifies **\"TOKEN_CREATE\"** and the types of tokens to be created. The **tokenInformation** section of the request includes detailed information relevant to each token type. This includes attributes for Customers, Payment Instruments, Shipping Addresses, Instrument Identifiers and Transient Token data. The payload is flexible, allowing for different combinations of tokens to be created in a single request.| |The **API response** includes a responses array, which details the outcome of the tokenization process for each requested resource type, such as Customer, Payment Instrument, Shipping Address, and Instrument Identifier. Each entry in this array provides an HTTP status code such as **201/200 for successful creations**, and a unique identifier for the newly created token.<br>In cases where token creation encounters issues, the response includes a **non-2XX** status code and an errors array for the affected resource. Each error object in the array details the **error type and a descriptive message** providing insight into why a particular token creation was not attempted or failed.
* @param {module:model/PostTokenizeRequest} postTokenizeRequest
* @param {Object} opts Optional parameters
* @param {String} opts.profileId The Id of a profile containing user specific TMS configuration.
* @param {module:api/TokenizeApi~tokenizeCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link module:model/InlineResponse200}
*/
this.tokenize = function(postTokenizeRequest, opts, callback) {
opts = opts || {};
var postBody = postTokenizeRequest;
// verify the required parameter 'postTokenizeRequest' is set
if (postTokenizeRequest === undefined || postTokenizeRequest === null) {
throw new Error("Missing the required parameter 'postTokenizeRequest' when calling tokenize");
}
var SdkTracker = require('../utilities/tracking/SdkTracker');
var sdkTracker = new SdkTracker();
postBody = sdkTracker.insertDeveloperIdTracker(postBody, 'module:model/PostTokenizeRequest', this.apiClient.merchantConfig.runEnvironment, this.apiClient.merchantConfig.defaultDeveloperId);
var pathParams = {
};
var queryParams = {
};
var headerParams = {
'profile-id': opts['profileId']
};
var formParams = {
};
var authNames = [];
var contentTypes = ['application/json;charset=utf-8'];
var accepts = ['application/json;charset=utf-8'];
var returnType = InlineResponse200;
//check isMLE for an api method 'this.tokenize'
var inboundMLEStatus = 'mandatory';
var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, inboundMLEStatus, 'tokenize');
if (isMLEForApi === true) {
MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => {
return this.apiClient.callApi(
'/tms/v2/tokenize', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
});
} else {
return this.apiClient.callApi(
'/tms/v2/tokenize', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
}
};
return exports;
}));