UNPKG

cybersource-rest-client

Version:

Node.js SDK for the CyberSource REST API

192 lines (162 loc) 9.06 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/PtsV2PaymentsPost502Response', 'model/TaxRequest', 'model/VasV2PaymentsPost201Response', 'model/VasV2PaymentsPost400Response', 'model/VasV2TaxVoid200Response', 'model/VasV2TaxVoidsPost400Response', 'model/VoidTaxRequest'], 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/PtsV2PaymentsPost502Response'), require('../model/TaxRequest'), require('../model/VasV2PaymentsPost201Response'), require('../model/VasV2PaymentsPost400Response'), require('../model/VasV2TaxVoid200Response'), require('../model/VasV2TaxVoidsPost400Response'), require('../model/VoidTaxRequest')); } else { // Browser globals (root is window) if (!root.CyberSource) { root.CyberSource = {}; } root.CyberSource.TaxesApi = factory(root.Authentication.MLEUtility, root.CyberSource.ApiClient, root.CyberSource.PtsV2PaymentsPost502Response, root.CyberSource.TaxRequest, root.CyberSource.VasV2PaymentsPost201Response, root.CyberSource.VasV2PaymentsPost400Response, root.CyberSource.VasV2TaxVoid200Response, root.CyberSource.VasV2TaxVoidsPost400Response, root.CyberSource.VoidTaxRequest); } }(this, function(MLEUtility, ApiClient, PtsV2PaymentsPost502Response, TaxRequest, VasV2PaymentsPost201Response, VasV2PaymentsPost400Response, VasV2TaxVoid200Response, VasV2TaxVoidsPost400Response, VoidTaxRequest) { 'use strict'; /** * Taxes service. * @module api/TaxesApi * @version 0.0.1 */ /** * Constructs a new TaxesApi. * @alias module:api/TaxesApi * @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 calculateTax operation. * @callback module:api/TaxesApi~calculateTaxCallback * @param {String} error Error message, if any. * @param {module:model/VasV2PaymentsPost201Response} data The data returned by the service call. * @param {String} response The complete HTTP response. */ /** * Calculate Taxes * The tax calculation service provides real-time sales tax and VAT calculations for orders placed with your business worldwide. It enhances your ability to conduct business globally and enables you to avoid the risk and complexity of managing online tax calculation. The service supports product-based tax rules and exemptions for goods and services. The tax rates are updated twice a month and calculations include sub-level detail (rates per taxing jurisdiction, names and types of jurisdictions). Implementation guidance, list of supported countries, and information on tax reporting are in the [Tax User Guide](https://developer.cybersource.com/docs/cybs/en-us/tax-calculation/developer/all/rest/tax-calculation/tax-overview.html). The availability of API features for a merchant can depend on the portfolio configuration and may need to be enabled at the portfolio level before they can be added to merchant accounts. * @param {module:model/TaxRequest} taxRequest * @param {module:api/TaxesApi~calculateTaxCallback} callback The callback function, accepting three arguments: error, data, response * data is of type: {@link module:model/VasV2PaymentsPost201Response} */ this.calculateTax = function(taxRequest, callback) { var postBody = taxRequest; // verify the required parameter 'taxRequest' is set if (taxRequest === undefined || taxRequest === null) { throw new Error("Missing the required parameter 'taxRequest' when calling calculateTax"); } var SdkTracker = require('../utilities/tracking/SdkTracker'); var sdkTracker = new SdkTracker(); postBody = sdkTracker.insertDeveloperIdTracker(postBody, 'module:model/TaxRequest', 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 = VasV2PaymentsPost201Response; //check isMLE for an api method 'this.calculateTax' var inboundMLEStatus = 'false'; var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, inboundMLEStatus, 'calculateTax'); if (isMLEForApi === true) { MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => { return this.apiClient.callApi( '/vas/v2/tax', 'POST', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType, callback ); }); } else { return this.apiClient.callApi( '/vas/v2/tax', 'POST', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType, callback ); } } /** * Callback function to receive the result of the voidTax operation. * @callback module:api/TaxesApi~voidTaxCallback * @param {String} error Error message, if any. * @param {module:model/VasV2TaxVoid200Response} data The data returned by the service call. * @param {String} response The complete HTTP response. */ /** * Void Taxes * Pass the Tax Request ID in the PATCH request to void the committed tax calculation. * @param {module:model/VoidTaxRequest} voidTaxRequest * @param {String} id The tax ID returned from a previous request. * @param {module:api/TaxesApi~voidTaxCallback} callback The callback function, accepting three arguments: error, data, response * data is of type: {@link module:model/VasV2TaxVoid200Response} */ this.voidTax = function(voidTaxRequest, id, callback) { var postBody = voidTaxRequest; // verify the required parameter 'voidTaxRequest' is set if (voidTaxRequest === undefined || voidTaxRequest === null) { throw new Error("Missing the required parameter 'voidTaxRequest' when calling voidTax"); } // verify the required parameter 'id' is set if (id === undefined || id === null) { throw new Error("Missing the required parameter 'id' when calling voidTax"); } var SdkTracker = require('../utilities/tracking/SdkTracker'); var sdkTracker = new SdkTracker(); postBody = sdkTracker.insertDeveloperIdTracker(postBody, 'module:model/VoidTaxRequest', 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 = VasV2TaxVoid200Response; //check isMLE for an api method 'this.voidTax' var inboundMLEStatus = 'false'; var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, inboundMLEStatus, 'voidTax'); if (isMLEForApi === true) { MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => { return this.apiClient.callApi( '/vas/v2/tax/{id}', 'PATCH', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType, callback ); }); } else { return this.apiClient.callApi( '/vas/v2/tax/{id}', 'PATCH', pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType, callback ); } } }; return exports; }));