cybersource-rest-client
Version:
Node.js SDK for the CyberSource REST API
121 lines (103 loc) • 5.82 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/AgenticCardEnrollmentBadRequestResponse400', 'model/MppCredentialsRequest', 'model/MppCredentialsResponse200'], 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/AgenticCardEnrollmentBadRequestResponse400'), require('../model/MppCredentialsRequest'), require('../model/MppCredentialsResponse200'));
} else {
// Browser globals (root is window)
if (!root.CyberSource) {
root.CyberSource = {};
}
root.CyberSource.CredentialsApi = factory(root.Authentication.MLEUtility, root.CyberSource.ApiClient, root.CyberSource.AgenticCardEnrollmentBadRequestResponse400, root.CyberSource.MppCredentialsRequest, root.CyberSource.MppCredentialsResponse200);
}
}(this, function(MLEUtility, ApiClient, AgenticCardEnrollmentBadRequestResponse400, MppCredentialsRequest, MppCredentialsResponse200) {
'use strict';
/**
* Credentials service.
* @module api/CredentialsApi
* @version 0.0.1
*/
/**
* Constructs a new CredentialsApi.
* @alias module:api/CredentialsApi
* @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 provisionMppCredentials operation.
* @callback module:api/CredentialsApi~provisionMppCredentialsCallback
* @param {String} error Error message, if any.
* @param {module:model/MppCredentialsResponse200} data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Provision MPP credentials
* Provisions an encrypted MPP credential for use as the credential payload in an Authorization: Payment header (MPP spec Section 8.2). The caller provides an instrument identifier (referencing a stored card in TMS) and the challenge context from the merchant's 402 response, including the merchant's RSA public encryption key. This service: 1. Calls TMS to retrieve the network token and cryptogram for the instrument. 2. Builds the token plaintext (MPP spec Section 8.3, type: network_token). 3. Encrypts the plaintext using RSA-OAEP with SHA-256 and the merchant's public key. 4. Returns the MPP credential payload fields (MPP spec Section 8.2, Table 4).
* @param {module:model/MppCredentialsRequest} mppCredentialsRequest
* @param {module:api/CredentialsApi~provisionMppCredentialsCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link module:model/MppCredentialsResponse200}
*/
this.provisionMppCredentials = function(mppCredentialsRequest, callback) {
var postBody = mppCredentialsRequest;
// verify the required parameter 'mppCredentialsRequest' is set
if (mppCredentialsRequest === undefined || mppCredentialsRequest === null) {
throw new Error("Missing the required parameter 'mppCredentialsRequest' when calling provisionMppCredentials");
}
var SdkTracker = require('../utilities/tracking/SdkTracker');
var sdkTracker = new SdkTracker();
postBody = sdkTracker.insertDeveloperIdTracker(postBody, 'module:model/MppCredentialsRequest', this.apiClient.merchantConfig.runEnvironment, this.apiClient.merchantConfig.defaultDeveloperId);
var pathParams = {
};
var queryParams = {
};
var headerParams = {
};
var formParams = {
};
var authNames = [];
var contentTypes = ['application/json;charset=utf-8'];
var accepts = ['application/hal+json;charset=utf-8'];
var returnType = MppCredentialsResponse200;
//check isMLE for an api method 'this.provisionMppCredentials'
var inboundMLEStatus = 'mandatory';
var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, inboundMLEStatus, 'provisionMppCredentials');
const isResponseMLEForApi = MLEUtility.checkIsResponseMLEForAPI(this.apiClient.merchantConfig, ['provisionMppCredentials']);
if (isMLEForApi === true) {
MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => {
return this.apiClient.callApi(
'/acp/v1/mpp/credentials', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, isResponseMLEForApi, callback
);
});
} else {
return this.apiClient.callApi(
'/acp/v1/mpp/credentials', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, isResponseMLEForApi, callback
);
}
}
};
return exports;
}));