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 ;
0 commit comments