cybersource-rest-client
Version:
Node.js SDK for the CyberSource REST API
339 lines (289 loc) • 21.5 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/InlineResponse400', 'model/InlineResponse403', 'model/InlineResponse409', 'model/InlineResponse410', 'model/InlineResponse412', 'model/InlineResponse424', 'model/InlineResponse500', 'model/PatchCustomerRequest', 'model/PostCustomerRequest'], 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/InlineResponse400'), require('../model/InlineResponse403'), require('../model/InlineResponse409'), require('../model/InlineResponse410'), require('../model/InlineResponse412'), require('../model/InlineResponse424'), require('../model/InlineResponse500'), require('../model/PatchCustomerRequest'), require('../model/PostCustomerRequest'));
} else {
// Browser globals (root is window)
if (!root.CyberSource) {
root.CyberSource = {};
}
root.CyberSource.CustomerApi = factory(root.Authentication.MLEUtility, root.CyberSource.ApiClient, root.CyberSource.InlineResponse400, root.CyberSource.InlineResponse403, root.CyberSource.InlineResponse409, root.CyberSource.InlineResponse410, root.CyberSource.InlineResponse412, root.CyberSource.InlineResponse424, root.CyberSource.InlineResponse500, root.CyberSource.PatchCustomerRequest, root.CyberSource.PostCustomerRequest);
}
}(this, function(MLEUtility, ApiClient, InlineResponse400, InlineResponse403, InlineResponse409, InlineResponse410, InlineResponse412, InlineResponse424, InlineResponse500, PatchCustomerRequest, PostCustomerRequest) {
'use strict';
/**
* Customer service.
* @module api/CustomerApi
* @version 0.0.1
*/
/**
* Constructs a new CustomerApi.
* @alias module:api/CustomerApi
* @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 deleteCustomer operation.
* @callback module:api/CustomerApi~deleteCustomerCallback
* @param {String} error Error message, if any.
* @param data This operation does not return a value.
* @param {String} response The complete HTTP response.
*/
/**
* Delete a Customer
* | | | | | --- | --- | --- | |**Customers**<br>A Customer represents your tokenized customer information.<br>You should associate the Customer Id with the customer account on your systems.<br>A Customer can have one or more [Payment Instruments](#token-management_customer-payment-instrument_create-a-customer-payment-instrumentl) or [Shipping Addresses](#token-management_customer-shipping-address_create-a-customer-shipping-address) with one allocated as the Customers default.| |**Deleting a Customer**<br>Your system can use this API to delete a complete Customer.<br>When a Customer is deleted all associated Payment Instruments & Shipping Addresses are deleted.<br>Any Instrument Identifiers representing the card number will also be deleted if they are not associated with any other Payment Instruments.<br>Note: Individual [Payment Instruments](#token-management_customer-payment-instrument_delete-a-customer-payment-instrument) or [Shipping Addresses](#token-management_customer-shipping-address_delete-a-customer-shipping-address) can be deleted via their own dedicated API resources.
* @param {String} customerId The Id of a Customer.
* @param {Object} opts Optional parameters
* @param {String} opts.profileId The Id of a profile containing user specific TMS configuration.
* @param {module:api/CustomerApi~deleteCustomerCallback} callback The callback function, accepting three arguments: error, data, response
*/
this.deleteCustomer = function(customerId, opts, callback) {
opts = opts || {};
var postBody = null;
if ('DELETE' == 'POST') {
postBody = '{}';
}
// verify the required parameter 'customerId' is set
if (customerId === undefined || customerId === null) {
throw new Error("Missing the required parameter 'customerId' when calling deleteCustomer");
}
var pathParams = {
'customerId': customerId
};
var queryParams = {
};
var headerParams = {
'profile-id': opts['profileId']
};
var formParams = {
};
var authNames = [];
var contentTypes = ['application/json;charset=utf-8'];
var accepts = ['application/json;charset=utf-8'];
var returnType = null;
//check isMLE for an api method 'this.deleteCustomer'
var inboundMLEStatus = 'false';
var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, inboundMLEStatus, 'deleteCustomer');
if (isMLEForApi === true) {
MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => {
return this.apiClient.callApi(
'/tms/v2/customers/{customerId}', 'DELETE',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
});
} else {
return this.apiClient.callApi(
'/tms/v2/customers/{customerId}', 'DELETE',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
}
/**
* Callback function to receive the result of the getCustomer operation.
* @callback module:api/CustomerApi~getCustomerCallback
* @param {String} error Error message, if any.
* @param {module:model/PostCustomerRequest} data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Retrieve a Customer
* | | | | | --- | --- | --- | |**Customers**<br>A Customer represents your tokenized customer information.<br>You should associate the Customer Id with the customer account on your systems.<br>A Customer can have one or more [Payment Instruments](#token-management_customer-payment-instrument_create-a-customer-payment-instrumentl) or [Shipping Addresses](#token-management_customer-shipping-address_create-a-customer-shipping-address) with one allocated as the Customers default.<br><br>**Retrieving a Customer**<br>When your customer signs into their account, your system can use this API to retrieve the Customers default Payment Instrument and Shipping Address.<br>**Note: the actual card data will be masked.**<br>If your customer wants to see other available Payment Instruments, your system can [retrieve all Payment Instruments](#token-management_customer-payment-instrument_list-payment-instruments-for-a-customer) associated with the Customer.<br>The same applies to [Shipping Addresses](#token-management_customer-shipping-address_list-shipping-addresses-for-a-customer).| |**Payment Network Tokens**<br>Network tokens perform better than regular card numbers and they are not necessarily invalidated when a cardholder loses their card, or it expires.<br>A Payment Network Token will be automatically created and used in future payments if you are enabled for the service.<br>A Payment Network Token can also be [provisioned for an existing Instrument Identifier](#token-management_instrument-identifier_enroll-an-instrument-identifier-for-payment-network-token).<br>For more information about Payment Network Tokens see the Developer Guide.<br><br>**Payments with Customers**<br>To perform a payment with the Customers default details specify the [Customer Id in the payments request](#payments_payments_process-a-payment_samplerequests-dropdown_authorization-using-tokens_authorization-with-customer-token-id_liveconsole-tab-request-body).<br>To perform a payment with a particular Payment Instrument or Shipping Address <br>specify the [Payment Instrument or Shipping Address Ids in the payments request](#payments_payments_process-a-payment_samplerequests-dropdown_authorization-using-tokens_authorization-with-customer-payment-instrument-and-shipping-address-token-id_liveconsole-tab-request-body).
* @param {String} customerId The Id of a Customer.
* @param {Object} opts Optional parameters
* @param {String} opts.profileId The Id of a profile containing user specific TMS configuration.
* @param {module:api/CustomerApi~getCustomerCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link module:model/PostCustomerRequest}
*/
this.getCustomer = function(customerId, opts, callback) {
opts = opts || {};
var postBody = null;
if ('GET' == 'POST') {
postBody = '{}';
}
// verify the required parameter 'customerId' is set
if (customerId === undefined || customerId === null) {
throw new Error("Missing the required parameter 'customerId' when calling getCustomer");
}
var pathParams = {
'customerId': customerId
};
var queryParams = {
};
var headerParams = {
'profile-id': opts['profileId']
};
var formParams = {
};
var authNames = [];
var contentTypes = ['application/json;charset=utf-8'];
var accepts = ['application/json;charset=utf-8'];
var returnType = PostCustomerRequest;
//check isMLE for an api method 'this.getCustomer'
var inboundMLEStatus = 'false';
var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, inboundMLEStatus, 'getCustomer');
if (isMLEForApi === true) {
MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => {
return this.apiClient.callApi(
'/tms/v2/customers/{customerId}', 'GET',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
});
} else {
return this.apiClient.callApi(
'/tms/v2/customers/{customerId}', 'GET',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
}
/**
* Callback function to receive the result of the patchCustomer operation.
* @callback module:api/CustomerApi~patchCustomerCallback
* @param {String} error Error message, if any.
* @param {module:model/PatchCustomerRequest} data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Update a Customer
* | | | | | --- | --- | --- | |**Customers**<br>A Customer represents your tokenized customer information.<br>You should associate the Customer Id with the customer account on your systems.<br>A Customer can have one or more [Payment Instruments](#token-management_customer-payment-instrument_create-a-customer-payment-instrumentl) or [Shipping Addresses](#token-management_customer-shipping-address_create-a-customer-shipping-address) with one allocated as the Customers default.| |**Updating a Customer**<br>Your system can use this API to update a Customers details including selecting a [default Payment Instrument](#token-management_customer_update-a-customer_samplerequests-dropdown_update-customers-default-payment-instrument_liveconsole-tab-request-body) or [default Shipping Address](#token-management_customer_update-a-customer_samplerequests-dropdown_update-customers-default-shipping-address_liveconsole-tab-request-body) for use in payments.<br>Note: Updating a Customers [Payment Instrument](#token-management_customer-payment-instrument_update-a-customer-payment-instrument) or [Shipping Address](#token-management_customer-shipping-address_update-a-customer-shipping-address) details is performed using their own dedicated API resources.
* @param {String} customerId The Id of a Customer.
* @param {module:model/PatchCustomerRequest} patchCustomerRequest
* @param {Object} opts Optional parameters
* @param {String} opts.profileId The Id of a profile containing user specific TMS configuration.
* @param {String} opts.ifMatch Contains an ETag value from a GET request to make the request conditional.
* @param {module:api/CustomerApi~patchCustomerCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link module:model/PatchCustomerRequest}
*/
this.patchCustomer = function(customerId, patchCustomerRequest, opts, callback) {
opts = opts || {};
var postBody = patchCustomerRequest;
// verify the required parameter 'customerId' is set
if (customerId === undefined || customerId === null) {
throw new Error("Missing the required parameter 'customerId' when calling patchCustomer");
}
// verify the required parameter 'patchCustomerRequest' is set
if (patchCustomerRequest === undefined || patchCustomerRequest === null) {
throw new Error("Missing the required parameter 'patchCustomerRequest' when calling patchCustomer");
}
var SdkTracker = require('../utilities/tracking/SdkTracker');
var sdkTracker = new SdkTracker();
postBody = sdkTracker.insertDeveloperIdTracker(postBody, 'module:model/PatchCustomerRequest', this.apiClient.merchantConfig.runEnvironment, this.apiClient.merchantConfig.defaultDeveloperId);
var pathParams = {
'customerId': customerId
};
var queryParams = {
};
var headerParams = {
'profile-id': opts['profileId'],
'if-match': opts['ifMatch']
};
var formParams = {
};
var authNames = [];
var contentTypes = ['application/json;charset=utf-8'];
var accepts = ['application/json;charset=utf-8'];
var returnType = PatchCustomerRequest;
//check isMLE for an api method 'this.patchCustomer'
var inboundMLEStatus = 'false';
var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, inboundMLEStatus, 'patchCustomer');
if (isMLEForApi === true) {
MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => {
return this.apiClient.callApi(
'/tms/v2/customers/{customerId}', 'PATCH',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
});
} else {
return this.apiClient.callApi(
'/tms/v2/customers/{customerId}', 'PATCH',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
}
/**
* Callback function to receive the result of the postCustomer operation.
* @callback module:api/CustomerApi~postCustomerCallback
* @param {String} error Error message, if any.
* @param {module:model/PostCustomerRequest} data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Create a Customer
* | | | | | --- | --- | --- | |**Customers**<br>A Customer represents your tokenized customer information.<br>You should associate the Customer Id with the customer account on your systems.<br>A Customer can have one or more [Payment Instruments](#token-management_customer-payment-instrument_create-a-customer-payment-instrumentl) or [Shipping Addresses](#token-management_customer-shipping-address_create-a-customer-shipping-address) with one allocated as the Customers default.<br><br>**Creating a Customer**<br>It is recommended you [create a Customer via a Payment Authorization](#payments_payments_process-a-payment_samplerequests-dropdown_authorization-with-token-create_authorization-with-customer-token-creation_liveconsole-tab-request-body), this can be for a zero amount.<br>The Customer will be created with a Payment Instrument and Shipping Address.<br>You can also [add additional Payment Instruments to a Customer via a Payment Authorization](#payments_payments_process-a-payment_samplerequests-dropdown_authorization-with-token-create_authorization-create-default-payment-instrument-shipping-address-for-existing-customer_liveconsole-tab-request-body).<br>In Europe: You should perform Payer Authentication alongside the Authorization.| |**Payment Network Tokens**<br>Network tokens perform better than regular card numbers and they are not necessarily invalidated when a cardholder loses their card, or it expires.<br>A Payment Network Token will be automatically created and used in future payments if you are enabled for the service.<br>A Payment Network Token can also be [provisioned for an existing Instrument Identifier](#token-management_instrument-identifier_enroll-an-instrument-identifier-for-payment-network-token).<br>For more information about Payment Network Tokens see the Developer Guide.<br><br>**Payments with Customers**<br>To perform a payment with the Customers default details specify the [Customer Id in the payments request](#payments_payments_process-a-payment_samplerequests-dropdown_authorization-using-tokens_authorization-with-customer-token-id_liveconsole-tab-request-body).<br>To perform a payment with a particular Payment Instrument or Shipping Address <br>specify the [Payment Instrument or Shipping Address Ids in the payments request](#payments_payments_process-a-payment_samplerequests-dropdown_authorization-using-tokens_authorization-with-customer-payment-instrument-and-shipping-address-token-id_liveconsole-tab-request-body). The availability of API features for a merchant may 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/PostCustomerRequest} postCustomerRequest
* @param {Object} opts Optional parameters
* @param {String} opts.profileId The Id of a profile containing user specific TMS configuration.
* @param {module:api/CustomerApi~postCustomerCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link module:model/PostCustomerRequest}
*/
this.postCustomer = function(postCustomerRequest, opts, callback) {
opts = opts || {};
var postBody = postCustomerRequest;
// verify the required parameter 'postCustomerRequest' is set
if (postCustomerRequest === undefined || postCustomerRequest === null) {
throw new Error("Missing the required parameter 'postCustomerRequest' when calling postCustomer");
}
var SdkTracker = require('../utilities/tracking/SdkTracker');
var sdkTracker = new SdkTracker();
postBody = sdkTracker.insertDeveloperIdTracker(postBody, 'module:model/PostCustomerRequest', this.apiClient.merchantConfig.runEnvironment, this.apiClient.merchantConfig.defaultDeveloperId);
var pathParams = {
};
var queryParams = {
};
var headerParams = {
'profile-id': opts['profileId']
};
var formParams = {
};
var authNames = [];
var contentTypes = ['application/json;charset=utf-8'];
var accepts = ['application/json;charset=utf-8'];
var returnType = PostCustomerRequest;
//check isMLE for an api method 'this.postCustomer'
var inboundMLEStatus = 'false';
var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, inboundMLEStatus, 'postCustomer');
if (isMLEForApi === true) {
MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => {
return this.apiClient.callApi(
'/tms/v2/customers', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
});
} else {
return this.apiClient.callApi(
'/tms/v2/customers', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
}
};
return exports;
}));