cybersource-rest-client
Version:
Node.js SDK for the CyberSource REST API
473 lines (396 loc) • 22.7 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/CreatePaymentRequest', 'model/CreateSessionReq', 'model/CreateSessionRequest', 'model/IncrementAuthRequest', 'model/OrderPaymentRequest', 'model/PtsV2IncrementalAuthorizationPatch201Response', 'model/PtsV2IncrementalAuthorizationPatch400Response', 'model/PtsV2PaymentsOrderPost201Response', 'model/PtsV2PaymentsPost201Response', 'model/PtsV2PaymentsPost201Response1', 'model/PtsV2PaymentsPost201Response2', 'model/PtsV2PaymentsPost400Response', 'model/PtsV2PaymentsPost502Response', 'model/RefreshPaymentStatusRequest'], 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/CreatePaymentRequest'), require('../model/CreateSessionReq'), require('../model/CreateSessionRequest'), require('../model/IncrementAuthRequest'), require('../model/OrderPaymentRequest'), require('../model/PtsV2IncrementalAuthorizationPatch201Response'), require('../model/PtsV2IncrementalAuthorizationPatch400Response'), require('../model/PtsV2PaymentsOrderPost201Response'), require('../model/PtsV2PaymentsPost201Response'), require('../model/PtsV2PaymentsPost201Response1'), require('../model/PtsV2PaymentsPost201Response2'), require('../model/PtsV2PaymentsPost400Response'), require('../model/PtsV2PaymentsPost502Response'), require('../model/RefreshPaymentStatusRequest'));
} else {
// Browser globals (root is window)
if (!root.CyberSource) {
root.CyberSource = {};
}
root.CyberSource.PaymentsApi = factory(root.Authentication.MLEUtility, root.CyberSource.ApiClient, root.CyberSource.CreatePaymentRequest, root.CyberSource.CreateSessionReq, root.CyberSource.CreateSessionRequest, root.CyberSource.IncrementAuthRequest, root.CyberSource.OrderPaymentRequest, root.CyberSource.PtsV2IncrementalAuthorizationPatch201Response, root.CyberSource.PtsV2IncrementalAuthorizationPatch400Response, root.CyberSource.PtsV2PaymentsOrderPost201Response, root.CyberSource.PtsV2PaymentsPost201Response, root.CyberSource.PtsV2PaymentsPost201Response1, root.CyberSource.PtsV2PaymentsPost201Response2, root.CyberSource.PtsV2PaymentsPost400Response, root.CyberSource.PtsV2PaymentsPost502Response, root.CyberSource.RefreshPaymentStatusRequest);
}
}(this, function(MLEUtility, ApiClient, CreatePaymentRequest, CreateSessionReq, CreateSessionRequest, IncrementAuthRequest, OrderPaymentRequest, PtsV2IncrementalAuthorizationPatch201Response, PtsV2IncrementalAuthorizationPatch400Response, PtsV2PaymentsOrderPost201Response, PtsV2PaymentsPost201Response, PtsV2PaymentsPost201Response1, PtsV2PaymentsPost201Response2, PtsV2PaymentsPost400Response, PtsV2PaymentsPost502Response, RefreshPaymentStatusRequest) {
'use strict';
/**
* Payments service.
* @module api/PaymentsApi
* @version 0.0.1
*/
/**
* Constructs a new PaymentsApi.
* @alias module:api/PaymentsApi
* @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 createOrderRequest operation.
* @callback module:api/PaymentsApi~createOrderRequestCallback
* @param {String} error Error message, if any.
* @param {module:model/PtsV2PaymentsOrderPost201Response} data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Create a Payment Order Request
* Create a Payment Order Request
* @param {module:model/OrderPaymentRequest} orderPaymentRequest
* @param {String} id Request identifier number for the order request.
* @param {module:api/PaymentsApi~createOrderRequestCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link module:model/PtsV2PaymentsOrderPost201Response}
*/
this.createOrderRequest = function(orderPaymentRequest, id, callback) {
var postBody = orderPaymentRequest;
// verify the required parameter 'orderPaymentRequest' is set
if (orderPaymentRequest === undefined || orderPaymentRequest === null) {
throw new Error("Missing the required parameter 'orderPaymentRequest' when calling createOrderRequest");
}
// verify the required parameter 'id' is set
if (id === undefined || id === null) {
throw new Error("Missing the required parameter 'id' when calling createOrderRequest");
}
var SdkTracker = require('../utilities/tracking/SdkTracker');
var sdkTracker = new SdkTracker();
postBody = sdkTracker.insertDeveloperIdTracker(postBody, 'module:model/OrderPaymentRequest', this.apiClient.merchantConfig.runEnvironment, this.apiClient.merchantConfig.defaultDeveloperId);
var pathParams = {
'id': id
};
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 = PtsV2PaymentsOrderPost201Response;
//check isMLE for an api method 'this.createOrderRequest'
var inboundMLEStatus = 'optional';
var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, inboundMLEStatus, 'createOrderRequest');
if (isMLEForApi === true) {
MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => {
return this.apiClient.callApi(
'/pts/v2/payment-references/{id}/intents', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
});
} else {
return this.apiClient.callApi(
'/pts/v2/payment-references/{id}/intents', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
}
/**
* Callback function to receive the result of the createPayment operation.
* @callback module:api/PaymentsApi~createPaymentCallback
* @param {String} error Error message, if any.
* @param {module:model/PtsV2PaymentsPost201Response} data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Process a Payment
* A payment authorizes the amount for the transaction. There are a number of supported payment features, such as E-commerce and Card Present - Credit Card/Debit Card, Echeck, e-Wallets, Level II/III Data, etc.. A payment response includes the status of the request. It also includes processor-specific information when the request is successful and errors if unsuccessful. See the [Payments Developer Guides Page](https://developer.cybersource.com/docs/cybs/en-us/payments/developer/ctv/rest/payments/payments-intro.html). Authorization can be requested with Capture, Decision Manager, Payer Authentication(3ds), and Token Creation.
* @param {module:model/CreatePaymentRequest} createPaymentRequest
* @param {module:api/PaymentsApi~createPaymentCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link module:model/PtsV2PaymentsPost201Response}
*/
this.createPayment = function(createPaymentRequest, callback) {
var postBody = createPaymentRequest;
// verify the required parameter 'createPaymentRequest' is set
if (createPaymentRequest === undefined || createPaymentRequest === null) {
throw new Error("Missing the required parameter 'createPaymentRequest' when calling createPayment");
}
var SdkTracker = require('../utilities/tracking/SdkTracker');
var sdkTracker = new SdkTracker();
postBody = sdkTracker.insertDeveloperIdTracker(postBody, 'module:model/CreatePaymentRequest', 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 = PtsV2PaymentsPost201Response;
//check isMLE for an api method 'this.createPayment'
var inboundMLEStatus = 'optional';
var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, inboundMLEStatus, 'createPayment');
if (isMLEForApi === true) {
MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => {
return this.apiClient.callApi(
'/pts/v2/payments', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
});
} else {
return this.apiClient.callApi(
'/pts/v2/payments', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
}
/**
* Callback function to receive the result of the createSessionRequest operation.
* @callback module:api/PaymentsApi~createSessionRequestCallback
* @param {String} error Error message, if any.
* @param {module:model/PtsV2PaymentsPost201Response2} data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Create Alternative Payments Sessions Request
* Create Alternative Payments Sessions Request
* @param {module:model/CreateSessionReq} createSessionReq
* @param {module:api/PaymentsApi~createSessionRequestCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link module:model/PtsV2PaymentsPost201Response2}
*/
this.createSessionRequest = function(createSessionReq, callback) {
var postBody = createSessionReq;
// verify the required parameter 'createSessionReq' is set
if (createSessionReq === undefined || createSessionReq === null) {
throw new Error("Missing the required parameter 'createSessionReq' when calling createSessionRequest");
}
var SdkTracker = require('../utilities/tracking/SdkTracker');
var sdkTracker = new SdkTracker();
postBody = sdkTracker.insertDeveloperIdTracker(postBody, 'module:model/CreateSessionReq', 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 = PtsV2PaymentsPost201Response2;
//check isMLE for an api method 'this.createSessionRequest'
var inboundMLEStatus = 'optional';
var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, inboundMLEStatus, 'createSessionRequest');
if (isMLEForApi === true) {
MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => {
return this.apiClient.callApi(
'/pts/v2/payment-references', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
});
} else {
return this.apiClient.callApi(
'/pts/v2/payment-references', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
}
/**
* Callback function to receive the result of the incrementAuth operation.
* @callback module:api/PaymentsApi~incrementAuthCallback
* @param {String} error Error message, if any.
* @param {module:model/PtsV2IncrementalAuthorizationPatch201Response} data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Increment an Authorization
* Use this service to authorize additional charges in a lodging or autorental transaction. Include the ID returned from the original authorization in the PATCH request to add additional charges to that authorization.
* @param {String} id The ID returned from the original authorization request.
* @param {module:model/IncrementAuthRequest} incrementAuthRequest
* @param {module:api/PaymentsApi~incrementAuthCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link module:model/PtsV2IncrementalAuthorizationPatch201Response}
*/
this.incrementAuth = function(id, incrementAuthRequest, callback) {
var postBody = incrementAuthRequest;
// verify the required parameter 'id' is set
if (id === undefined || id === null) {
throw new Error("Missing the required parameter 'id' when calling incrementAuth");
}
// verify the required parameter 'incrementAuthRequest' is set
if (incrementAuthRequest === undefined || incrementAuthRequest === null) {
throw new Error("Missing the required parameter 'incrementAuthRequest' when calling incrementAuth");
}
var SdkTracker = require('../utilities/tracking/SdkTracker');
var sdkTracker = new SdkTracker();
postBody = sdkTracker.insertDeveloperIdTracker(postBody, 'module:model/IncrementAuthRequest', this.apiClient.merchantConfig.runEnvironment, this.apiClient.merchantConfig.defaultDeveloperId);
var pathParams = {
'id': id
};
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 = PtsV2IncrementalAuthorizationPatch201Response;
//check isMLE for an api method 'this.incrementAuth'
var inboundMLEStatus = 'optional';
var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, inboundMLEStatus, 'incrementAuth');
if (isMLEForApi === true) {
MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => {
return this.apiClient.callApi(
'/pts/v2/payments/{id}', 'PATCH',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
});
} else {
return this.apiClient.callApi(
'/pts/v2/payments/{id}', 'PATCH',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
}
/**
* Callback function to receive the result of the refreshPaymentStatus operation.
* @callback module:api/PaymentsApi~refreshPaymentStatusCallback
* @param {String} error Error message, if any.
* @param {module:model/PtsV2PaymentsPost201Response1} data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Check a Payment Status
* Checks and updates the payment status
* @param {String} id The payment id whose status needs to be checked and updated.
* @param {module:model/RefreshPaymentStatusRequest} refreshPaymentStatusRequest
* @param {module:api/PaymentsApi~refreshPaymentStatusCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link module:model/PtsV2PaymentsPost201Response1}
*/
this.refreshPaymentStatus = function(id, refreshPaymentStatusRequest, callback) {
var postBody = refreshPaymentStatusRequest;
// verify the required parameter 'id' is set
if (id === undefined || id === null) {
throw new Error("Missing the required parameter 'id' when calling refreshPaymentStatus");
}
// verify the required parameter 'refreshPaymentStatusRequest' is set
if (refreshPaymentStatusRequest === undefined || refreshPaymentStatusRequest === null) {
throw new Error("Missing the required parameter 'refreshPaymentStatusRequest' when calling refreshPaymentStatus");
}
var SdkTracker = require('../utilities/tracking/SdkTracker');
var sdkTracker = new SdkTracker();
postBody = sdkTracker.insertDeveloperIdTracker(postBody, 'module:model/RefreshPaymentStatusRequest', this.apiClient.merchantConfig.runEnvironment, this.apiClient.merchantConfig.defaultDeveloperId);
var pathParams = {
'id': id
};
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 = PtsV2PaymentsPost201Response1;
//check isMLE for an api method 'this.refreshPaymentStatus'
var inboundMLEStatus = 'optional';
var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, inboundMLEStatus, 'refreshPaymentStatus');
if (isMLEForApi === true) {
MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => {
return this.apiClient.callApi(
'/pts/v2/refresh-payment-status/{id}', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
});
} else {
return this.apiClient.callApi(
'/pts/v2/refresh-payment-status/{id}', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
}
/**
* Callback function to receive the result of the updateSessionReq operation.
* @callback module:api/PaymentsApi~updateSessionReqCallback
* @param {String} error Error message, if any.
* @param {module:model/PtsV2PaymentsPost201Response2} data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Update Alternative Payments Sessions Request
* Update Alternative Payments Sessions Request
* @param {module:model/CreateSessionRequest} createSessionRequest
* @param {String} id The payment ID. This ID is returned from a previous payment request.
* @param {module:api/PaymentsApi~updateSessionReqCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link module:model/PtsV2PaymentsPost201Response2}
*/
this.updateSessionReq = function(createSessionRequest, id, callback) {
var postBody = createSessionRequest;
// verify the required parameter 'createSessionRequest' is set
if (createSessionRequest === undefined || createSessionRequest === null) {
throw new Error("Missing the required parameter 'createSessionRequest' when calling updateSessionReq");
}
// verify the required parameter 'id' is set
if (id === undefined || id === null) {
throw new Error("Missing the required parameter 'id' when calling updateSessionReq");
}
var SdkTracker = require('../utilities/tracking/SdkTracker');
var sdkTracker = new SdkTracker();
postBody = sdkTracker.insertDeveloperIdTracker(postBody, 'module:model/CreateSessionRequest', this.apiClient.merchantConfig.runEnvironment, this.apiClient.merchantConfig.defaultDeveloperId);
var pathParams = {
'id': id
};
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 = PtsV2PaymentsPost201Response2;
//check isMLE for an api method 'this.updateSessionReq'
var inboundMLEStatus = 'optional';
var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, inboundMLEStatus, 'updateSessionReq');
if (isMLEForApi === true) {
MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => {
return this.apiClient.callApi(
'/pts/v2/payment-references/{id}', 'PATCH',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
});
} else {
return this.apiClient.callApi(
'/pts/v2/payment-references/{id}', 'PATCH',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
}
};
return exports;
}));