UNPKG

cybersource-rest-client

Version:

Node.js SDK for the CyberSource REST API

192 lines (162 loc) 8.51 kB
/** * 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/CreateOrderRequest', 'model/PtsV2CreateOrderPost201Response', 'model/PtsV2CreateOrderPost400Response', 'model/PtsV2PaymentsPost502Response', 'model/PtsV2UpdateOrderPatch201Response', 'model/UpdateOrderRequest'], 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/CreateOrderRequest'), require('../model/PtsV2CreateOrderPost201Response'), require('../model/PtsV2CreateOrderPost400Response'), require('../model/PtsV2PaymentsPost502Response'), require('../model/PtsV2UpdateOrderPatch201Response'), require('../model/UpdateOrderRequest')); } else { // Browser globals (root is window) if (!root.CyberSource) { root.CyberSource = {}; } root.CyberSource.OrdersApi = factory(root.Authentication.MLEUtility, root.CyberSource.ApiClient, root.CyberSource.CreateOrderRequest, root.CyberSource.PtsV2CreateOrderPost201Response, root.CyberSource.PtsV2CreateOrderPost400Response, root.CyberSource.PtsV2PaymentsPost502Response, root.CyberSource.PtsV2UpdateOrderPatch201Response, root.CyberSource.UpdateOrderRequest); } }(this, function(MLEUtility, ApiClient, CreateOrderRequest, PtsV2CreateOrderPost201Response, PtsV2CreateOrderPost400Response, PtsV2PaymentsPost502Response, PtsV2UpdateOrderPatch201Response, UpdateOrderRequest) { 'use strict'; /** * Orders service. * @module api/OrdersApi * @version 0.0.1 */ /** * Constructs a new OrdersApi. * @alias module:api/OrdersApi * @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 createOrder operation. * @callback module:api/OrdersApi~createOrderCallback * @param {String} error Error message, if any. * @param {module:model/PtsV2CreateOrderPost201Response} data The data returned by the service call. * @param {String} response The complete HTTP response. */ /** * Create an Order * A create order request enables you to send the itemized details along with the order. This API can be used by merchants initiating their transactions with the create order API. * @param {module:model/CreateOrderRequest} createOrderRequest * @param {module:api/OrdersApi~createOrderCallback} callback The callback function, accepting three arguments: error, data, response * data is of type: {@link module:model/PtsV2CreateOrderPost201Response} */ this.createOrder = function(createOrderRequest, callback) { var postBody = createOrderRequest; // verify the required parameter 'createOrderRequest' is set if (createOrderRequest === undefined || createOrderRequest === null) { throw new Error("Missing the required parameter 'createOrderRequest' when calling createOrder"); } var SdkTracker = require('../utilities/tracking/SdkTracker'); var sdkTracker = new SdkTracker(); postBody = sdkTracker.insertDeveloperIdTracker(postBody, 'module:model/CreateOrderRequest', 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 = PtsV2CreateOrderPost201Response; //check isMLE for an api method 'this.createOrder' var isMLESupportedByCybsForApi = false; var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, isMLESupportedByCybsForApi, 'createOrder'); if (isMLEForApi === true) { MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => { return this.apiClient.callApi( '/pts/v2/intents', 'POST', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType, callback ); }); } else { return this.apiClient.callApi( '/pts/v2/intents', 'POST', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType, callback ); } } /** * Callback function to receive the result of the updateOrder operation. * @callback module:api/OrdersApi~updateOrderCallback * @param {String} error Error message, if any. * @param {module:model/PtsV2UpdateOrderPatch201Response} data The data returned by the service call. * @param {String} response The complete HTTP response. */ /** * Update an Order * This API can be used in two flavours - for updating the order as well as saving the order. * @param {String} id The ID returned from the original create order response. * @param {module:model/UpdateOrderRequest} updateOrderRequest * @param {module:api/OrdersApi~updateOrderCallback} callback The callback function, accepting three arguments: error, data, response * data is of type: {@link module:model/PtsV2UpdateOrderPatch201Response} */ this.updateOrder = function(id, updateOrderRequest, callback) { var postBody = updateOrderRequest; // verify the required parameter 'id' is set if (id === undefined || id === null) { throw new Error("Missing the required parameter 'id' when calling updateOrder"); } // verify the required parameter 'updateOrderRequest' is set if (updateOrderRequest === undefined || updateOrderRequest === null) { throw new Error("Missing the required parameter 'updateOrderRequest' when calling updateOrder"); } var SdkTracker = require('../utilities/tracking/SdkTracker'); var sdkTracker = new SdkTracker(); postBody = sdkTracker.insertDeveloperIdTracker(postBody, 'module:model/UpdateOrderRequest', 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 = PtsV2UpdateOrderPatch201Response; //check isMLE for an api method 'this.updateOrder' var isMLESupportedByCybsForApi = false; var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, isMLESupportedByCybsForApi, 'updateOrder'); if (isMLEForApi === true) { MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => { return this.apiClient.callApi( '/pts/v2/intents/{id}', 'PATCH', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType, callback ); }); } else { return this.apiClient.callApi( '/pts/v2/intents/{id}', 'PATCH', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType, callback ); } } }; return exports; }));