cybersource-rest-client
Version:
Node.js SDK for the CyberSource REST API
440 lines (376 loc) • 28 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/PatchCustomerPaymentInstrumentRequest', 'model/PaymentInstrumentList', 'model/PostCustomerPaymentInstrumentRequest'], 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/PatchCustomerPaymentInstrumentRequest'), require('../model/PaymentInstrumentList'), require('../model/PostCustomerPaymentInstrumentRequest'));
} else {
// Browser globals (root is window)
if (!root.CyberSource) {
root.CyberSource = {};
}
root.CyberSource.CustomerPaymentInstrumentApi = 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.PatchCustomerPaymentInstrumentRequest, root.CyberSource.PaymentInstrumentList, root.CyberSource.PostCustomerPaymentInstrumentRequest);
}
}(this, function(MLEUtility, ApiClient, InlineResponse400, InlineResponse403, InlineResponse409, InlineResponse410, InlineResponse412, InlineResponse424, InlineResponse500, PatchCustomerPaymentInstrumentRequest, PaymentInstrumentList, PostCustomerPaymentInstrumentRequest) {
'use strict';
/**
* CustomerPaymentInstrument service.
* @module api/CustomerPaymentInstrumentApi
* @version 0.0.1
*/
/**
* Constructs a new CustomerPaymentInstrumentApi.
* @alias module:api/CustomerPaymentInstrumentApi
* @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 deleteCustomerPaymentInstrument operation.
* @callback module:api/CustomerPaymentInstrumentApi~deleteCustomerPaymentInstrumentCallback
* @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 Payment Instrument
* | | | | | --- | --- | --- | |**Customer Payment Instrument**<br>A Customer Payment Instrument represents tokenized customer payment information such as expiration date, billing address & card type.<br>A [Customer](#token-management_customer_create-a-customer) can have [one or more Payment Instruments](#token-management_customer-payment-instrument_retrieve-a-customer-payment-instrument), with one allocated as the Customers default for use in payments.<br>A Payment Instrument token does not store the card number. A Payment Instrument is associated with an [Instrument Identifier](#token-management_instrument-identifier_create-an-instrument-identifier) that represents either a payment card number, or in the case of an ACH bank account, the routing and account number.<br>| |**Deleting a Customers Payment Instrument**<br>Your system can use this API to delete an existing Payment Instrument for a Customer.<br>Any Instrument Identifiers representing the card number will also be deleted if they are not associated with any other Payment Instruments.<br>If a customer has more than one Payment Instrument then the default Payment Instrument cannot be deleted without first selecting a [new default Payment Instrument](#token-management_customer-payment-instrument_update-a-customer-payment-instrument_samplerequests-dropdown_make-customer-payment-instrument-the-default_liveconsole-tab-request-body).
* @param {String} customerId The Id of a Customer.
* @param {String} paymentInstrumentId The Id of a payment instrument.
* @param {Object} opts Optional parameters
* @param {String} opts.profileId The Id of a profile containing user specific TMS configuration.
* @param {module:api/CustomerPaymentInstrumentApi~deleteCustomerPaymentInstrumentCallback} callback The callback function, accepting three arguments: error, data, response
*/
this.deleteCustomerPaymentInstrument = function(customerId, paymentInstrumentId, 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 deleteCustomerPaymentInstrument");
}
// verify the required parameter 'paymentInstrumentId' is set
if (paymentInstrumentId === undefined || paymentInstrumentId === null) {
throw new Error("Missing the required parameter 'paymentInstrumentId' when calling deleteCustomerPaymentInstrument");
}
var pathParams = {
'customerId': customerId,
'paymentInstrumentId': paymentInstrumentId
};
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.deleteCustomerPaymentInstrument'
var isMLESupportedByCybsForApi = false;
var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, isMLESupportedByCybsForApi, 'deleteCustomerPaymentInstrument');
if (isMLEForApi === true) {
MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => {
return this.apiClient.callApi(
'/tms/v2/customers/{customerId}/payment-instruments/{paymentInstrumentId}', 'DELETE',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
});
} else {
return this.apiClient.callApi(
'/tms/v2/customers/{customerId}/payment-instruments/{paymentInstrumentId}', 'DELETE',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
}
/**
* Callback function to receive the result of the getCustomerPaymentInstrument operation.
* @callback module:api/CustomerPaymentInstrumentApi~getCustomerPaymentInstrumentCallback
* @param {String} error Error message, if any.
* @param {module:model/PostCustomerPaymentInstrumentRequest} data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Retrieve a Customer Payment Instrument
* | | | | | --- | --- | --- | |**Customer Payment Instrument**<br>A Customer Payment Instrument represents tokenized customer payment information such as expiration date, billing address & card type.<br>A [Customer](#token-management_customer_create-a-customer) can have [one or more Payment Instruments](#token-management_customer-payment-instrument_retrieve-a-customer-payment-instrument), with one allocated as the Customers default for use in payments.<br>A Payment Instrument token does not store the card number. A Payment Instrument is associated with an [Instrument Identifier](#token-management_instrument-identifier_create-an-instrument-identifier) that represents either a payment card number, or in the case of an ACH bank account, the routing and account number.<br>| |**Retrieving a Customer Payment Instrument**<br>Your system can use this API to retrieve an existing Payment Instrument for a Customer.<br>To perform a payment with a particular Payment Instrument simply specify the [Payment Instrument Id 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 {String} paymentInstrumentId The Id of a payment instrument.
* @param {Object} opts Optional parameters
* @param {String} opts.profileId The Id of a profile containing user specific TMS configuration.
* @param {module:api/CustomerPaymentInstrumentApi~getCustomerPaymentInstrumentCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link module:model/PostCustomerPaymentInstrumentRequest}
*/
this.getCustomerPaymentInstrument = function(customerId, paymentInstrumentId, 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 getCustomerPaymentInstrument");
}
// verify the required parameter 'paymentInstrumentId' is set
if (paymentInstrumentId === undefined || paymentInstrumentId === null) {
throw new Error("Missing the required parameter 'paymentInstrumentId' when calling getCustomerPaymentInstrument");
}
var pathParams = {
'customerId': customerId,
'paymentInstrumentId': paymentInstrumentId
};
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 = PostCustomerPaymentInstrumentRequest;
//check isMLE for an api method 'this.getCustomerPaymentInstrument'
var isMLESupportedByCybsForApi = false;
var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, isMLESupportedByCybsForApi, 'getCustomerPaymentInstrument');
if (isMLEForApi === true) {
MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => {
return this.apiClient.callApi(
'/tms/v2/customers/{customerId}/payment-instruments/{paymentInstrumentId}', 'GET',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
});
} else {
return this.apiClient.callApi(
'/tms/v2/customers/{customerId}/payment-instruments/{paymentInstrumentId}', 'GET',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
}
/**
* Callback function to receive the result of the getCustomerPaymentInstrumentsList operation.
* @callback module:api/CustomerPaymentInstrumentApi~getCustomerPaymentInstrumentsListCallback
* @param {String} error Error message, if any.
* @param {module:model/PaymentInstrumentList} data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* List Payment Instruments for a Customer
* | | | | | --- | --- | --- | |**Customer Payment Instrument**<br>A Customer Payment Instrument represents tokenized customer payment information such as expiration date, billing address & card type.<br>A [Customer](#token-management_customer_create-a-customer) can have [one or more Payment Instruments](#token-management_customer-payment-instrument_retrieve-a-customer-payment-instrument), with one allocated as the Customers default for use in payments.<br>A Payment Instrument token does not store the card number. A Payment Instrument is associated with an [Instrument Identifier](#token-management_instrument-identifier_create-an-instrument-identifier) that represents either a payment card number, or in the case of an ACH bank account, the routing and account number.<br>| |**Retrieving all Customer Payment Instruments**<br>Your system can use this API to retrieve all existing Payment Instruments for a Customer.
* @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 {Number} opts.offset Starting record in zero-based dataset that should be returned as the first object in the array. Default is 0. (default to 0)
* @param {Number} opts.limit The maximum number that can be returned in the array starting from the offset record in zero-based dataset. Default is 20, maximum is 100. (default to 20)
* @param {module:api/CustomerPaymentInstrumentApi~getCustomerPaymentInstrumentsListCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link module:model/PaymentInstrumentList}
*/
this.getCustomerPaymentInstrumentsList = 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 getCustomerPaymentInstrumentsList");
}
var pathParams = {
'customerId': customerId
};
var queryParams = {
'offset': opts['offset'],
'limit': opts['limit']
};
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 = PaymentInstrumentList;
//check isMLE for an api method 'this.getCustomerPaymentInstrumentsList'
var isMLESupportedByCybsForApi = false;
var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, isMLESupportedByCybsForApi, 'getCustomerPaymentInstrumentsList');
if (isMLEForApi === true) {
MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => {
return this.apiClient.callApi(
'/tms/v2/customers/{customerId}/payment-instruments', 'GET',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
});
} else {
return this.apiClient.callApi(
'/tms/v2/customers/{customerId}/payment-instruments', 'GET',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
}
/**
* Callback function to receive the result of the patchCustomersPaymentInstrument operation.
* @callback module:api/CustomerPaymentInstrumentApi~patchCustomersPaymentInstrumentCallback
* @param {String} error Error message, if any.
* @param {module:model/PatchCustomerPaymentInstrumentRequest} data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Update a Customer Payment Instrument
* | | | | | --- | --- | --- | |**Customer Payment Instrument**<br>A Customer Payment Instrument represents tokenized customer payment information such as expiration date, billing address & card type.<br>A [Customer](#token-management_customer_create-a-customer) can have [one or more Payment Instruments](#token-management_customer-payment-instrument_retrieve-a-customer-payment-instrument), with one allocated as the Customers default for use in payments.<br>A Payment Instrument token does not store the card number. A Payment Instrument is associated with an [Instrument Identifier](#token-management_instrument-identifier_create-an-instrument-identifier) that represents either a payment card number, or in the case of an ACH bank account, the routing and account number.<br>| |**Updating a Customers Payment Instrument**<br>Your system can use this API to update an existing Payment Instrument for a Customer, including selecting a [default Payment Instrument](#token-management_customer-payment-instrument_update-a-customer-payment-instrument_samplerequests-dropdown_make-customer-payment-instrument-the-default_liveconsole-tab-request-body) for use in payments.
* @param {String} customerId The Id of a Customer.
* @param {String} paymentInstrumentId The Id of a payment instrument.
* @param {module:model/PatchCustomerPaymentInstrumentRequest} patchCustomerPaymentInstrumentRequest
* @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/CustomerPaymentInstrumentApi~patchCustomersPaymentInstrumentCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link module:model/PatchCustomerPaymentInstrumentRequest}
*/
this.patchCustomersPaymentInstrument = function(customerId, paymentInstrumentId, patchCustomerPaymentInstrumentRequest, opts, callback) {
opts = opts || {};
var postBody = patchCustomerPaymentInstrumentRequest;
// verify the required parameter 'customerId' is set
if (customerId === undefined || customerId === null) {
throw new Error("Missing the required parameter 'customerId' when calling patchCustomersPaymentInstrument");
}
// verify the required parameter 'paymentInstrumentId' is set
if (paymentInstrumentId === undefined || paymentInstrumentId === null) {
throw new Error("Missing the required parameter 'paymentInstrumentId' when calling patchCustomersPaymentInstrument");
}
// verify the required parameter 'patchCustomerPaymentInstrumentRequest' is set
if (patchCustomerPaymentInstrumentRequest === undefined || patchCustomerPaymentInstrumentRequest === null) {
throw new Error("Missing the required parameter 'patchCustomerPaymentInstrumentRequest' when calling patchCustomersPaymentInstrument");
}
var SdkTracker = require('../utilities/tracking/SdkTracker');
var sdkTracker = new SdkTracker();
postBody = sdkTracker.insertDeveloperIdTracker(postBody, 'module:model/PatchCustomerPaymentInstrumentRequest', this.apiClient.merchantConfig.runEnvironment, this.apiClient.merchantConfig.defaultDeveloperId);
var pathParams = {
'customerId': customerId,
'paymentInstrumentId': paymentInstrumentId
};
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 = PatchCustomerPaymentInstrumentRequest;
//check isMLE for an api method 'this.patchCustomersPaymentInstrument'
var isMLESupportedByCybsForApi = false;
var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, isMLESupportedByCybsForApi, 'patchCustomersPaymentInstrument');
if (isMLEForApi === true) {
MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => {
return this.apiClient.callApi(
'/tms/v2/customers/{customerId}/payment-instruments/{paymentInstrumentId}', 'PATCH',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
});
} else {
return this.apiClient.callApi(
'/tms/v2/customers/{customerId}/payment-instruments/{paymentInstrumentId}', 'PATCH',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
}
/**
* Callback function to receive the result of the postCustomerPaymentInstrument operation.
* @callback module:api/CustomerPaymentInstrumentApi~postCustomerPaymentInstrumentCallback
* @param {String} error Error message, if any.
* @param {module:model/PostCustomerPaymentInstrumentRequest} data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Create a Customer Payment Instrument
* | | | | | --- | --- | --- | |**Customer Payment Instrument**<br>A Customer Payment Instrument represents tokenized customer payment information such as expiration date, billing address & card type.<br>A [Customer](#token-management_customer_create-a-customer) can have [one or more Payment Instruments](#token-management_customer-payment-instrument_retrieve-a-customer-payment-instrument), with one allocated as the Customers default for use in payments.<br>A Payment Instrument token does not store the card number. A Payment Instrument is associated with an [Instrument Identifier](#token-management_instrument-identifier_create-an-instrument-identifier) that represents either a payment card number, or in the case of an ACH bank account, the routing and account number.<br><br>**Creating a Customer Payment Instrument**<br>It is recommended you [create a Customer Payment Instrument 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), this can be for a zero amount.<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 Payment Instrument**<br>To perform a payment with a particular Payment Instrument or Shipping Address specify the [Payment Instrument in the payment 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 {module:model/PostCustomerPaymentInstrumentRequest} postCustomerPaymentInstrumentRequest
* @param {Object} opts Optional parameters
* @param {String} opts.profileId The Id of a profile containing user specific TMS configuration.
* @param {module:api/CustomerPaymentInstrumentApi~postCustomerPaymentInstrumentCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link module:model/PostCustomerPaymentInstrumentRequest}
*/
this.postCustomerPaymentInstrument = function(customerId, postCustomerPaymentInstrumentRequest, opts, callback) {
opts = opts || {};
var postBody = postCustomerPaymentInstrumentRequest;
// verify the required parameter 'customerId' is set
if (customerId === undefined || customerId === null) {
throw new Error("Missing the required parameter 'customerId' when calling postCustomerPaymentInstrument");
}
// verify the required parameter 'postCustomerPaymentInstrumentRequest' is set
if (postCustomerPaymentInstrumentRequest === undefined || postCustomerPaymentInstrumentRequest === null) {
throw new Error("Missing the required parameter 'postCustomerPaymentInstrumentRequest' when calling postCustomerPaymentInstrument");
}
var SdkTracker = require('../utilities/tracking/SdkTracker');
var sdkTracker = new SdkTracker();
postBody = sdkTracker.insertDeveloperIdTracker(postBody, 'module:model/PostCustomerPaymentInstrumentRequest', this.apiClient.merchantConfig.runEnvironment, this.apiClient.merchantConfig.defaultDeveloperId);
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 = PostCustomerPaymentInstrumentRequest;
//check isMLE for an api method 'this.postCustomerPaymentInstrument'
var isMLESupportedByCybsForApi = false;
var isMLEForApi = MLEUtility.checkIsMLEForAPI(this.apiClient.merchantConfig, isMLESupportedByCybsForApi, 'postCustomerPaymentInstrument');
if (isMLEForApi === true) {
MLEUtility.encryptRequestPayload(this.apiClient.merchantConfig, postBody).then(postBody => {
return this.apiClient.callApi(
'/tms/v2/customers/{customerId}/payment-instruments', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
});
} else {
return this.apiClient.callApi(
'/tms/v2/customers/{customerId}/payment-instruments', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
}
};
return exports;
}));