1+ 'use strict' ;
2+
3+ var ApiContracts = require ( 'authorizenet' ) . APIContracts ;
4+ var ApiControllers = require ( 'authorizenet' ) . APIControllers ;
5+ var constants = require ( '../constants.js' ) ;
6+
7+ function getTransactionListForCustomer ( customerProfileId , callback ) {
8+ var merchantAuthenticationType = new ApiContracts . MerchantAuthenticationType ( ) ;
9+ merchantAuthenticationType . setName ( constants . apiLoginKey ) ;
10+ merchantAuthenticationType . setTransactionKey ( constants . transactionKey ) ;
11+
12+ var paging = new ApiContracts . Paging ( ) ;
13+ paging . setLimit ( 10 ) ;
14+ paging . setOffset ( 1 ) ;
15+
16+ var sorting = new ApiContracts . TransactionListSorting ( ) ;
17+ sorting . setOrderBy ( ApiContracts . TransactionListOrderFieldEnum . ID ) ;
18+ sorting . setOrderDescending ( true ) ;
19+
20+ var getRequest = new ApiContracts . GetTransactionListForCustomerRequest ( ) ;
21+ getRequest . setMerchantAuthentication ( merchantAuthenticationType ) ;
22+ getRequest . setCustomerProfileId ( customerProfileId ) ;
23+ getRequest . setPaging ( paging ) ;
24+ getRequest . setSorting ( sorting ) ;
25+
26+
27+ console . log ( JSON . stringify ( getRequest . getJSON ( ) , null , 2 ) ) ;
28+
29+ var ctrl = new ApiControllers . GetTransactionListForCustomerController ( getRequest . getJSON ( ) ) ;
30+
31+ ctrl . execute ( function ( ) {
32+
33+ var apiResponse = ctrl . getResponse ( ) ;
34+
35+ var response = new ApiContracts . GetTransactionListResponse ( apiResponse ) ;
36+
37+ console . log ( JSON . stringify ( response , null , 2 ) ) ;
38+
39+ if ( response != null ) {
40+ if ( response . getMessages ( ) . getResultCode ( ) == ApiContracts . MessageTypeEnum . OK ) {
41+ console . log ( 'Message Code : ' + response . getMessages ( ) . getMessage ( ) [ 0 ] . getCode ( ) ) ;
42+ console . log ( 'Message Text : ' + response . getMessages ( ) . getMessage ( ) [ 0 ] . getText ( ) ) ;
43+ if ( response . getTransactions ( ) != null ) {
44+ var transactions = response . getTransactions ( ) . getTransaction ( ) ;
45+ for ( var i = 0 ; i < transactions . length ; i ++ )
46+ {
47+ console . log ( 'Transaction Id : ' + transactions [ i ] . getTransId ( ) ) ;
48+ console . log ( 'Transaction Status : ' + transactions [ i ] . getTransactionStatus ( ) ) ;
49+ console . log ( 'Amount Type : ' + transactions [ i ] . getAccountType ( ) ) ;
50+ console . log ( 'Settle Amount : ' + transactions [ i ] . getSettleAmount ( ) ) ;
51+ }
52+ }
53+ }
54+ else {
55+ console . log ( 'Result Code: ' + response . getMessages ( ) . getResultCode ( ) ) ;
56+ console . log ( 'Error Code: ' + response . getMessages ( ) . getMessage ( ) [ 0 ] . getCode ( ) ) ;
57+ console . log ( 'Error message: ' + response . getMessages ( ) . getMessage ( ) [ 0 ] . getText ( ) ) ;
58+ }
59+ }
60+ else {
61+ console . log ( 'Null Response.' ) ;
62+ }
63+
64+ callback ( response ) ;
65+ } ) ;
66+ }
67+
68+ if ( require . main === module ) {
69+ getTransactionListForCustomer ( '1811474252' , function ( ) {
70+ console . log ( 'getTransactionListForCustomer call complete.' ) ;
71+ } ) ;
72+ }
73+
74+ module . exports . getTransactionListForCustomer = getTransactionListForCustomer ;
0 commit comments