Skip to content

Commit b0abf65

Browse files
committed
add sample for getCustomerPaymentProfileList
1 parent ccecc65 commit b0abf65

File tree

5 files changed

+107
-1
lines changed

5 files changed

+107
-1
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
"use strict";
2+
3+
var ApiContracts = require("authorizenet").APIContracts;
4+
var ApiControllers = require("authorizenet").APIControllers;
5+
var utils = require("../utils.js");
6+
var constants = require("../constants.js");
7+
8+
function getCustomerPaymentProfileList(callback) {
9+
10+
// Create a merchantAuthenticationType object with authentication details
11+
// retrieved from the constants file
12+
var merchantAuthenticationType = new ApiContracts.MerchantAuthenticationType();
13+
merchantAuthenticationType.setName(constants.apiLoginKey);
14+
merchantAuthenticationType.setTransactionKey(constants.transactionKey);
15+
16+
// Set the transaction"s refId
17+
var refId = utils.getRandomInt();
18+
19+
// Set the paging (this particular API call will only return up to 10 results at a time)
20+
var paging = new ApiContracts.Paging();
21+
paging.setLimit(10);
22+
paging.setOffset(1);
23+
24+
// Set the sorting
25+
var sorting = new ApiContracts.CustomerPaymentProfileSorting;
26+
sorting.setOrderBy(ApiContracts.CustomerPaymentProfileOrderFieldEnum.ID);
27+
sorting.setOrderDescending(false);
28+
29+
// Set search parameters
30+
var search = ApiContracts.CustomerPaymentProfileSearchTypeEnum.CARDSEXPIRINGINMONTH;
31+
var month = "2020-12";
32+
33+
// Creating the request with the required parameters
34+
var getRequest = new ApiContracts.GetCustomerPaymentProfileListRequest();
35+
getRequest.setMerchantAuthentication(merchantAuthenticationType);
36+
getRequest.setRefId(refId);
37+
getRequest.setPaging(paging);
38+
getRequest.setSorting(sorting);
39+
getRequest.setSearchType(search);
40+
getRequest.setMonth(month);
41+
42+
// uncomment to print request
43+
// console.log(JSON.stringify(getRequest.getJSON(), null, 2));
44+
45+
var ctrl = new ApiControllers.GetCustomerPaymentProfileListController(getRequest.getJSON());
46+
47+
ctrl.execute(function(){
48+
49+
var apiResponse = ctrl.getResponse();
50+
51+
var response = new ApiContracts.GetCustomerPaymentProfileListResponse(apiResponse);
52+
53+
// uncomment to print response
54+
// console.log(JSON.stringify(response, null, 2));
55+
56+
if(response != null)
57+
{
58+
if(response.getMessages().getResultCode() == ApiContracts.MessageTypeEnum.OK)
59+
{
60+
console.log("SUCCESS");
61+
console.log("Total Num in Result Set: " + response.getTotalNumInResultSet());
62+
var profiles = response.getPaymentProfiles().getPaymentProfile();
63+
for (var i=0;i<profiles.length;i++)
64+
{
65+
console.log("Profile ID: " + profiles[i].getCustomerProfileId());
66+
console.log("Payment Profile ID: " + profiles[i].getCustomerPaymentProfileId());
67+
if(profiles[i].payment.creditCard)
68+
{
69+
console.log("Card: " + profiles[i].payment.creditCard.cardNumber);
70+
}
71+
else if(profiles[i].payment.bankAccount)
72+
{
73+
console.log("Bank Account: " + profiles[i].payment.bankAccount.accountNumber);
74+
}
75+
console.log("");
76+
}
77+
}
78+
else
79+
{
80+
console.log("Result Code: " + response.getMessages().getResultCode());
81+
console.log("Error Code: " + response.getMessages().getMessage()[0].getCode());
82+
console.log("Error Message: " + response.getMessages().getMessage()[0].getText());
83+
}
84+
}
85+
else
86+
{
87+
console.log("Null response received");
88+
}
89+
90+
callback(response);
91+
});
92+
}
93+
94+
if (require.main === module) {
95+
getCustomerPaymentProfileList(function(){
96+
console.log("getCustomerPaymentProfileList call complete.");
97+
});
98+
}
99+
100+
module.exports.getCustomerPaymentProfileList = getCustomerPaymentProfileList;

CustomerProfiles/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = {
88
deleteCustomerProfile: require('./delete-customer-profile.js').deleteCustomerProfile,
99
deleteCustomerShippingAddress: require('./delete-customer-shipping-address.js').deleteCustomerShippingAddress,
1010
getCustomerPaymentProfile: require('./get-customer-payment-profile.js').getCustomerPaymentProfile,
11+
getCustomerPaymentProfileList: require('./get-customer-payment-profile-list.js').getCustomerPaymentProfileList,
1112
getCustomerProfileIds: require('./get-customer-profile-ids.js').getCustomerProfileIds,
1213
getCustomerProfile: require('./get-customer-profile.js').getCustomerProfile,
1314
getCustomerShippingAddress: require('./get-customer-shipping-address.js').getCustomerShippingAddress,

list_of_sample_codes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ deleteCustomerPaymentProfile,1
4141
deleteCustomerProfile,1
4242
deleteCustomerShippingAddress,1
4343
getCustomerPaymentProfile,1
44+
getCustomerPaymentProfileList,1
4445
getCustomerProfileIds,1
4546
getCustomerProfile,1
4647
getCustomerShippingAddress,1

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Sample code for nodejs sdk",
55
"main": "constants.js",
66
"dependencies": {
7-
"authorizenet": "^1.0.1",
7+
"authorizenet": "^1.0.3",
88
"chai": "^3.5.0",
99
"eslint": "^2.12.0"
1010
},

test-runner.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ class TestRunner {
239239
});
240240
}
241241

242+
getCustomerPaymentProfileList(validateFunctionCallback){
243+
CustomerProfilesModule.getCustomerPaymentProfileList(validateFunctionCallback);
244+
}
245+
242246
createCustomerShippingAddress(validateFunctionCallback){
243247
CustomerProfilesModule.createCustomerProfile(function(response){
244248
CustomerProfilesModule.createCustomerShippingAddress(response.getCustomerProfileId(), validateFunctionCallback);

0 commit comments

Comments
 (0)