cybersource-rest-client
Version:
Node.js SDK for the CyberSource REST API
413 lines (347 loc) • 23.8 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/AgenticCancelPurchaseIntentRequest', 'model/AgenticCardEnrollmentBadRequestResponse400', 'model/AgenticConfirmTransactionEventsRequest', 'model/AgenticConfirmTransactionEventsResponse202', 'model/AgenticCreatePurchaseIntentRequest', 'model/AgenticCreatePurchaseIntentResponse200', 'model/AgenticPendingPurchaseIntentResponse202', 'model/AgenticRetrievePaymentCredentialsRequest', 'model/AgenticRetrievePaymentCredentialsResponse200', 'model/AgenticUpdatePurchaseIntentRequest'], 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/AgenticCancelPurchaseIntentRequest'), require('../model/AgenticCardEnrollmentBadRequestResponse400'), require('../model/AgenticConfirmTransactionEventsRequest'), require('../model/AgenticConfirmTransactionEventsResponse202'), require('../model/AgenticCreatePurchaseIntentRequest'), require('../model/AgenticCreatePurchaseIntentResponse200'), require('../model/AgenticPendingPurchaseIntentResponse202'), require('../model/AgenticRetrievePaymentCredentialsRequest'), require('../model/AgenticRetrievePaymentCredentialsResponse200'), require('../model/AgenticUpdatePurchaseIntentRequest'));
} else {
// Browser globals (root is window)
if (!root.CyberSource) {
root.CyberSource = {};
}
root.CyberSource.InstructionsApi = factory(root.Authentication.MLEUtility, root.CyberSource.ApiClient, root.CyberSource.AgenticCancelPurchaseIntentRequest, root.CyberSource.AgenticCardEnrollmentBadRequestResponse400, root.CyberSource.AgenticConfirmTransactionEventsRequest, root.CyberSource.AgenticConfirmTransactionEventsResponse202, root.CyberSource.AgenticCreatePurchaseIntentRequest, root.CyberSource.AgenticCreatePurchaseIntentResponse200, root.CyberSource.AgenticPendingPurchaseIntentResponse202, root.CyberSource.AgenticRetrievePaymentCredentialsRequest, root.CyberSource.AgenticRetrievePaymentCredentialsResponse200, root.CyberSource.AgenticUpdatePurchaseIntentRequest);
}
}(this, function(MLEUtility, ApiClient, AgenticCancelPurchaseIntentRequest, AgenticCardEnrollmentBadRequestResponse400, AgenticConfirmTransactionEventsRequest, AgenticConfirmTransactionEventsResponse202, AgenticCreatePurchaseIntentRequest, AgenticCreatePurchaseIntentResponse200, AgenticPendingPurchaseIntentResponse202, AgenticRetrievePaymentCredentialsRequest, AgenticRetrievePaymentCredentialsResponse200, AgenticUpdatePurchaseIntentRequest) {
'use strict';
/**
* Instructions service.
* @module api/InstructionsApi
* @version 0.0.1
*/
/**
* Constructs a new InstructionsApi.
* @alias module:api/InstructionsApi
* @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 cancelPurchaseIntent operation.
* @callback module:api/InstructionsApi~cancelPurchaseIntentCallback
* @param {String} error Error message, if any.
* @param {module:model/AgenticCreatePurchaseIntentResponse200} data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Cancel a purchase intent
* Cancel an existing purchase intent (instruction) identified by its instructionId. The agent calls this endpoint when the consumer decides to abandon the purchase before payment credentials have been used. Requires device information and assurance data for identity verification. Returns status CANCELLED (HTTP 200) on success, or PENDING (HTTP 202) with pendingEvents if cardholder authentication is required before cancellation can proceed.
* @param {String} instructionId
* @param {module:model/AgenticCancelPurchaseIntentRequest} agenticCancelPurchaseIntentRequest Unique identifier for the purchase intent instruction.
* @param {module:api/InstructionsApi~cancelPurchaseIntentCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link module:model/AgenticCreatePurchaseIntentResponse200}
*/
this.cancelPurchaseIntent = function(instructionId, agenticCancelPurchaseIntentRequest, callback) {
var postBody = agenticCancelPurchaseIntentRequest;
// verify the required parameter 'instructionId' is set
if (instructionId === undefined || instructionId === null) {
throw new Error("Missing the required parameter 'instructionId' when calling cancelPurchaseIntent");
}
// verify the required parameter 'agenticCancelPurchaseIntentRequest' is set
if (agenticCancelPurchaseIntentRequest === undefined || agenticCancelPurchaseIntentRequest === null) {
throw new Error("Missing the required parameter 'agenticCancelPurchaseIntentRequest' when calling cancelPurchaseIntent");
}
var SdkTracker = require('../utilities/tracking/SdkTracker');
var sdkTracker = new SdkTracker();
postBody = sdkTracker.insertDeveloperIdTracker(postBody, 'module:model/AgenticCancelPurchaseIntentRequest', this.apiClient.merchantConfig.runEnvironment, this.apiClient.merchantConfig.defaultDeveloperId);
var pathParams = {
'instructionId': instructionId
};
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 = AgenticCreatePurchaseIntentResponse200;
//check isMLE for an api method 'this.cancelPurchaseIntent'
var inboundMLEStatus = 'mandatory';
var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, inboundMLEStatus, 'cancelPurchaseIntent');
const isResponseMLEForApi = MLEUtility.checkIsResponseMLEForAPI(this.apiClient.merchantConfig, ['cancelPurchaseIntent']);
if (isMLEForApi === true) {
MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => {
return this.apiClient.callApi(
'/acp/v1/instructions/{instructionId}/cancel', 'PUT',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, isResponseMLEForApi, callback
);
});
} else {
return this.apiClient.callApi(
'/acp/v1/instructions/{instructionId}/cancel', 'PUT',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, isResponseMLEForApi, callback
);
}
}
/**
* Callback function to receive the result of the confirmTransactionEvents operation.
* @callback module:api/InstructionsApi~confirmTransactionEventsCallback
* @param {String} error Error message, if any.
* @param {module:model/AgenticConfirmTransactionEventsResponse202} data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Confirm transaction events
* Confirm transaction events for a completed purchase. The agent calls this endpoint after the payment has been submitted to notify the Intelligent Commerce Connect of the transaction outcome. The request includes processor information (transaction type, status, approval codes), order details (shipping, tracking, product information), and merchant information. Returns HTTP 202 acknowledging receipt of the confirmation.
* @param {String} instructionId Unique identifier for the purchase intent instruction.
* @param {module:model/AgenticConfirmTransactionEventsRequest} agenticConfirmTransactionEventsRequest
* @param {module:api/InstructionsApi~confirmTransactionEventsCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link module:model/AgenticConfirmTransactionEventsResponse202}
*/
this.confirmTransactionEvents = function(instructionId, agenticConfirmTransactionEventsRequest, callback) {
var postBody = agenticConfirmTransactionEventsRequest;
// verify the required parameter 'instructionId' is set
if (instructionId === undefined || instructionId === null) {
throw new Error("Missing the required parameter 'instructionId' when calling confirmTransactionEvents");
}
// verify the required parameter 'agenticConfirmTransactionEventsRequest' is set
if (agenticConfirmTransactionEventsRequest === undefined || agenticConfirmTransactionEventsRequest === null) {
throw new Error("Missing the required parameter 'agenticConfirmTransactionEventsRequest' when calling confirmTransactionEvents");
}
var SdkTracker = require('../utilities/tracking/SdkTracker');
var sdkTracker = new SdkTracker();
postBody = sdkTracker.insertDeveloperIdTracker(postBody, 'module:model/AgenticConfirmTransactionEventsRequest', this.apiClient.merchantConfig.runEnvironment, this.apiClient.merchantConfig.defaultDeveloperId);
var pathParams = {
'instructionId': instructionId
};
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 = AgenticConfirmTransactionEventsResponse202;
//check isMLE for an api method 'this.confirmTransactionEvents'
var inboundMLEStatus = 'mandatory';
var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, inboundMLEStatus, 'confirmTransactionEvents');
const isResponseMLEForApi = MLEUtility.checkIsResponseMLEForAPI(this.apiClient.merchantConfig, ['confirmTransactionEvents']);
if (isMLEForApi === true) {
MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => {
return this.apiClient.callApi(
'/acp/v1/instructions/{instructionId}/confirmations', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, isResponseMLEForApi, callback
);
});
} else {
return this.apiClient.callApi(
'/acp/v1/instructions/{instructionId}/confirmations', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, isResponseMLEForApi, callback
);
}
}
/**
* Callback function to receive the result of the initiatePurchaseIntent operation.
* @callback module:api/InstructionsApi~initiatePurchaseIntentCallback
* @param {String} error Error message, if any.
* @param {module:model/AgenticCreatePurchaseIntentResponse200} data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Initiate a purchase intent
* Create a new purchase intent (instruction) for an agentic transaction. The agent calls this endpoint after a card has been enrolled to define what the consumer wants to buy. The request includes payment instrument references, device and assurance data, mandates (spending limits, merchant preferences, and product descriptions), and optional buyer information. Return an instructionId (HTTP 200) if the intent is created immediately, or PENDING (HTTP 202) with pendingEvents if cardholder authentication is required. The instructionId returned is used in all subsequent operations - update, cancel, retrieve credentials, and confirm transaction.
* @param {module:model/AgenticCreatePurchaseIntentRequest} agenticCreatePurchaseIntentRequest
* @param {module:api/InstructionsApi~initiatePurchaseIntentCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link module:model/AgenticCreatePurchaseIntentResponse200}
*/
this.initiatePurchaseIntent = function(agenticCreatePurchaseIntentRequest, callback) {
var postBody = agenticCreatePurchaseIntentRequest;
// verify the required parameter 'agenticCreatePurchaseIntentRequest' is set
if (agenticCreatePurchaseIntentRequest === undefined || agenticCreatePurchaseIntentRequest === null) {
throw new Error("Missing the required parameter 'agenticCreatePurchaseIntentRequest' when calling initiatePurchaseIntent");
}
var SdkTracker = require('../utilities/tracking/SdkTracker');
var sdkTracker = new SdkTracker();
postBody = sdkTracker.insertDeveloperIdTracker(postBody, 'module:model/AgenticCreatePurchaseIntentRequest', 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 = AgenticCreatePurchaseIntentResponse200;
//check isMLE for an api method 'this.initiatePurchaseIntent'
var inboundMLEStatus = 'mandatory';
var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, inboundMLEStatus, 'initiatePurchaseIntent');
const isResponseMLEForApi = MLEUtility.checkIsResponseMLEForAPI(this.apiClient.merchantConfig, ['initiatePurchaseIntent']);
if (isMLEForApi === true) {
MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => {
return this.apiClient.callApi(
'/acp/v1/instructions', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, isResponseMLEForApi, callback
);
});
} else {
return this.apiClient.callApi(
'/acp/v1/instructions', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, isResponseMLEForApi, callback
);
}
}
/**
* Callback function to receive the result of the retrievePaymentCredentials operation.
* @callback module:api/InstructionsApi~retrievePaymentCredentialsCallback
* @param {String} error Error message, if any.
* @param {module:model/AgenticRetrievePaymentCredentialsResponse200} data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Retrieve payment credentials
* Retrieve tokenized payment credentials for a purchase intent to complete the transaction at a merchant. The agent calls this endpoint after a purchase intent has been created and approved, providing transaction-level details including order information, merchant details, payment options, and production information. Returns COMPLETED (HTTP 200) with a signed payload containing encrypted payment credentials (authorization token and JWS-signed payload), or PENDING (HTTP 202) with pendingEvents if additional cardholder authentication is required. The signed payload is used by the merchant's payment processor to complete the transaction.
* @param {String} instructionId Unique identifier for the purchase intent instruction.
* @param {module:model/AgenticRetrievePaymentCredentialsRequest} agenticRetrievePaymentCredentialsRequest
* @param {module:api/InstructionsApi~retrievePaymentCredentialsCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link module:model/AgenticRetrievePaymentCredentialsResponse200}
*/
this.retrievePaymentCredentials = function(instructionId, agenticRetrievePaymentCredentialsRequest, callback) {
var postBody = agenticRetrievePaymentCredentialsRequest;
// verify the required parameter 'instructionId' is set
if (instructionId === undefined || instructionId === null) {
throw new Error("Missing the required parameter 'instructionId' when calling retrievePaymentCredentials");
}
// verify the required parameter 'agenticRetrievePaymentCredentialsRequest' is set
if (agenticRetrievePaymentCredentialsRequest === undefined || agenticRetrievePaymentCredentialsRequest === null) {
throw new Error("Missing the required parameter 'agenticRetrievePaymentCredentialsRequest' when calling retrievePaymentCredentials");
}
var SdkTracker = require('../utilities/tracking/SdkTracker');
var sdkTracker = new SdkTracker();
postBody = sdkTracker.insertDeveloperIdTracker(postBody, 'module:model/AgenticRetrievePaymentCredentialsRequest', this.apiClient.merchantConfig.runEnvironment, this.apiClient.merchantConfig.defaultDeveloperId);
var pathParams = {
'instructionId': instructionId
};
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 = AgenticRetrievePaymentCredentialsResponse200;
//check isMLE for an api method 'this.retrievePaymentCredentials'
var inboundMLEStatus = 'mandatory';
var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, inboundMLEStatus, 'retrievePaymentCredentials');
const isResponseMLEForApi = MLEUtility.checkIsResponseMLEForAPI(this.apiClient.merchantConfig, ['retrievePaymentCredentials']);
if (isMLEForApi === true) {
MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => {
return this.apiClient.callApi(
'/acp/v1/instructions/{instructionId}/credentials', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, isResponseMLEForApi, callback
);
});
} else {
return this.apiClient.callApi(
'/acp/v1/instructions/{instructionId}/credentials', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, isResponseMLEForApi, callback
);
}
}
/**
* Callback function to receive the result of the updatePurchaseIntent operation.
* @callback module:api/InstructionsApi~updatePurchaseIntentCallback
* @param {String} error Error message, if any.
* @param {module:model/AgenticCreatePurchaseIntentResponse200} data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Update a purchase intent
* Update an existing purchase intent (instruction) identified by its instructionId. The agent calls this endpoint when the consumer modifies their order — for example, changing the quantity, updating mandates, switching payment instruments, or changing shipping details. The request body has the same structure as the initiate request. Returns the same instructionId (HTTP 200) on success, or PENDING (HTTP 202) with pendingEvents if additional cardholder authentication is required for the updated intent.
* @param {String} instructionId Unique identifier for the purchase intent instruction.
* @param {module:model/AgenticUpdatePurchaseIntentRequest} agenticUpdatePurchaseIntentRequest
* @param {module:api/InstructionsApi~updatePurchaseIntentCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link module:model/AgenticCreatePurchaseIntentResponse200}
*/
this.updatePurchaseIntent = function(instructionId, agenticUpdatePurchaseIntentRequest, callback) {
var postBody = agenticUpdatePurchaseIntentRequest;
// verify the required parameter 'instructionId' is set
if (instructionId === undefined || instructionId === null) {
throw new Error("Missing the required parameter 'instructionId' when calling updatePurchaseIntent");
}
// verify the required parameter 'agenticUpdatePurchaseIntentRequest' is set
if (agenticUpdatePurchaseIntentRequest === undefined || agenticUpdatePurchaseIntentRequest === null) {
throw new Error("Missing the required parameter 'agenticUpdatePurchaseIntentRequest' when calling updatePurchaseIntent");
}
var SdkTracker = require('../utilities/tracking/SdkTracker');
var sdkTracker = new SdkTracker();
postBody = sdkTracker.insertDeveloperIdTracker(postBody, 'module:model/AgenticUpdatePurchaseIntentRequest', this.apiClient.merchantConfig.runEnvironment, this.apiClient.merchantConfig.defaultDeveloperId);
var pathParams = {
'instructionId': instructionId
};
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 = AgenticCreatePurchaseIntentResponse200;
//check isMLE for an api method 'this.updatePurchaseIntent'
var inboundMLEStatus = 'mandatory';
var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, inboundMLEStatus, 'updatePurchaseIntent');
const isResponseMLEForApi = MLEUtility.checkIsResponseMLEForAPI(this.apiClient.merchantConfig, ['updatePurchaseIntent']);
if (isMLEForApi === true) {
MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => {
return this.apiClient.callApi(
'/acp/v1/instructions/{instructionId}', 'PUT',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, isResponseMLEForApi, callback
);
});
} else {
return this.apiClient.callApi(
'/acp/v1/instructions/{instructionId}', 'PUT',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, isResponseMLEForApi, callback
);
}
}
};
return exports;
}));