diff --git a/.gitignore b/.gitignore index e920c16..11afa16 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ node_modules # Optional REPL history .node_repl_history + +# filsystem files +.DS_Store diff --git a/PaymentTransactions/create-an-accept-payment-transaction.js b/AcceptSuite/create-an-accept-payment-transaction.js similarity index 94% rename from PaymentTransactions/create-an-accept-payment-transaction.js rename to AcceptSuite/create-an-accept-payment-transaction.js index d4081a5..9541a95 100644 --- a/PaymentTransactions/create-an-accept-payment-transaction.js +++ b/AcceptSuite/create-an-accept-payment-transaction.js @@ -95,12 +95,12 @@ function createAnAcceptPaymentTransaction(callback) { userFields.setUserField(userFieldList); var transactionSetting1 = new ApiContracts.SettingType(); - transactionSetting1.setSettingName('testRequest'); - transactionSetting1.setSettingValue('s1val'); + transactionSetting1.setSettingName('duplicateWindow'); + transactionSetting1.setSettingValue('120'); var transactionSetting2 = new ApiContracts.SettingType(); - transactionSetting2.setSettingName('testRequest'); - transactionSetting2.setSettingValue('s2val'); + transactionSetting2.setSettingName('recurringBilling'); + transactionSetting2.setSettingValue('false'); var transactionSettingList = []; transactionSettingList.push(transactionSetting1); @@ -138,7 +138,7 @@ function createAnAcceptPaymentTransaction(callback) { var apiResponse = ctrl.getResponse(); - var response = new ApiContracts.CreateTransactionResponse(apiResponse); + if (apiResponse != null) var response = new ApiContracts.CreateTransactionResponse(apiResponse); //pretty print response console.log(JSON.stringify(response, null, 2)); @@ -173,6 +173,8 @@ function createAnAcceptPaymentTransaction(callback) { } } else { + var apiError = ctrl.getError(); + console.log(apiError); console.log('Null Response.'); } diff --git a/CustomerProfiles/get-accept-customer-profile-page.js b/AcceptSuite/get-accept-customer-profile-page.js similarity index 92% rename from CustomerProfiles/get-accept-customer-profile-page.js rename to AcceptSuite/get-accept-customer-profile-page.js index 04c1b66..41b8f93 100644 --- a/CustomerProfiles/get-accept-customer-profile-page.js +++ b/AcceptSuite/get-accept-customer-profile-page.js @@ -33,7 +33,7 @@ function getAcceptCustomerProfilePage(customerProfileId, callback) { var apiResponse = ctrl.getResponse(); - var response = new ApiContracts.GetHostedProfilePageResponse(apiResponse); + if (apiResponse != null) var response = new ApiContracts.GetHostedProfilePageResponse(apiResponse); //pretty print response //console.log(JSON.stringify(response, null, 2)); @@ -54,6 +54,8 @@ function getAcceptCustomerProfilePage(customerProfileId, callback) { } else { + var apiError = ctrl.getError(); + console.log(apiError); console.log('Null response received'); } diff --git a/PaymentTransactions/get-an-accept-payment-page.js b/AcceptSuite/get-an-accept-payment-page.js similarity index 93% rename from PaymentTransactions/get-an-accept-payment-page.js rename to AcceptSuite/get-an-accept-payment-page.js index fd8b884..472d677 100644 --- a/PaymentTransactions/get-an-accept-payment-page.js +++ b/AcceptSuite/get-an-accept-payment-page.js @@ -43,7 +43,7 @@ function getAnAcceptPaymentPage(callback) { var apiResponse = ctrl.getResponse(); - var response = new ApiContracts.GetHostedPaymentPageResponse(apiResponse); + if (apiResponse != null) var response = new ApiContracts.GetHostedPaymentPageResponse(apiResponse); //pretty print response //console.log(JSON.stringify(response, null, 2)); @@ -64,6 +64,8 @@ function getAnAcceptPaymentPage(callback) { } else { + var apiError = ctrl.getError(); + console.log(apiError); console.log('Null response received'); } diff --git a/CustomerProfiles/create-customer-payment-profile.js b/CustomerProfiles/create-customer-payment-profile.js index 79035c0..7232687 100644 --- a/CustomerProfiles/create-customer-payment-profile.js +++ b/CustomerProfiles/create-customer-payment-profile.js @@ -3,6 +3,7 @@ var ApiContracts = require('authorizenet').APIContracts; var ApiControllers = require('authorizenet').APIControllers; var constants = require('../constants.js'); +var randomStreetNumber = Math.round(Math.random() * 1000) function createCustomerPaymentProfile(customerProfileId, callback) { @@ -12,7 +13,7 @@ function createCustomerPaymentProfile(customerProfileId, callback) { var creditCard = new ApiContracts.CreditCardType(); creditCard.setCardNumber('4242424242424242'); - creditCard.setExpirationDate('0822'); + creditCard.setExpirationDate('0842'); var paymentType = new ApiContracts.PaymentType(); paymentType.setCreditCard(creditCard); @@ -20,7 +21,7 @@ function createCustomerPaymentProfile(customerProfileId, callback) { var customerAddress = new ApiContracts.CustomerAddressType(); customerAddress.setFirstName('test'); customerAddress.setLastName('scenario'); - customerAddress.setAddress('123 Main Street'); + customerAddress.setAddress(randomStreetNumber + ' Main Street'); customerAddress.setCity('Bellevue'); customerAddress.setState('WA'); customerAddress.setZip('98004'); @@ -47,7 +48,7 @@ function createCustomerPaymentProfile(customerProfileId, callback) { var apiResponse = ctrl.getResponse(); - var response = new ApiContracts.CreateCustomerPaymentProfileResponse(apiResponse); + if (apiResponse != null) var response = new ApiContracts.CreateCustomerPaymentProfileResponse(apiResponse); //pretty print response //console.log(JSON.stringify(response, null, 2)); @@ -56,7 +57,7 @@ function createCustomerPaymentProfile(customerProfileId, callback) { { if(response.getMessages().getResultCode() == ApiContracts.MessageTypeEnum.OK) { - console.log('Successfully created a customer payment profile with id: ' + response.getCustomerPaymentProfileId()); + console.log('createCustomerPaymentProfile: Successfully created a customer payment profile with id: ' + response.getCustomerPaymentProfileId()); } else { @@ -67,6 +68,8 @@ function createCustomerPaymentProfile(customerProfileId, callback) { } else { + var apiError = ctrl.getError(); + console.log(apiError); console.log('Null response received'); } @@ -75,7 +78,7 @@ function createCustomerPaymentProfile(customerProfileId, callback) { } if (require.main === module) { - createCustomerPaymentProfile('41003872',function(){ + createCustomerPaymentProfile('1929176981',function(){ console.log('createCustomerPaymentProfile call complete.'); }); } diff --git a/CustomerProfiles/create-customer-profile-from-transaction.js b/CustomerProfiles/create-customer-profile-from-transaction.js index f551dce..a659825 100644 --- a/CustomerProfiles/create-customer-profile-from-transaction.js +++ b/CustomerProfiles/create-customer-profile-from-transaction.js @@ -22,7 +22,7 @@ function createCustomerProfileFromTransaction(transactionId, callback) { var apiResponse = ctrl.getResponse(); - var response = new ApiContracts.CreateCustomerProfileResponse(apiResponse); + if (apiResponse != null) var response = new ApiContracts.CreateCustomerProfileResponse(apiResponse); //console.log(JSON.stringify(response.getJSON(), null, 2)); if(response != null) @@ -42,6 +42,8 @@ function createCustomerProfileFromTransaction(transactionId, callback) { } else { + var apiError = ctrl.getError(); + console.log(apiError); console.log('Null response received'); } @@ -51,7 +53,7 @@ function createCustomerProfileFromTransaction(transactionId, callback) { } if (require.main === module) { - createCustomerProfileFromTransaction('2259984863', function(){ + createCustomerProfileFromTransaction('60158389454', function(){ console.log('createCustomerProfileFromTransaction call complete.'); }); } diff --git a/CustomerProfiles/create-customer-profile-with-accept.js b/CustomerProfiles/create-customer-profile-with-accept.js index 2eacfeb..6654192 100644 --- a/CustomerProfiles/create-customer-profile-with-accept.js +++ b/CustomerProfiles/create-customer-profile-with-accept.js @@ -13,7 +13,7 @@ function createCustomerProfile(callback) { //var creditCard = new ApiContracts.CreditCardType(); //creditCard.setCardNumber('4242424242424242'); - //creditCard.setExpirationDate('0822'); + //creditCard.setExpirationDate('0842'); var opaqueData = new ApiContracts.OpaqueDataType(); opaqueData.setDataDescriptor('COMMON.ACCEPT.INAPP.PAYMENT'); @@ -49,7 +49,7 @@ function createCustomerProfile(callback) { var apiResponse = ctrl.getResponse(); - var response = new ApiContracts.CreateCustomerProfileResponse(apiResponse); + if (apiResponse != null) var response = new ApiContracts.CreateCustomerProfileResponse(apiResponse); //pretty print response //console.log(JSON.stringify(response, null, 2)); @@ -69,6 +69,8 @@ function createCustomerProfile(callback) { } else { + var apiError = ctrl.getError(); + console.log(apiError); console.log('Null response received'); } diff --git a/CustomerProfiles/create-customer-profile.js b/CustomerProfiles/create-customer-profile.js index 215feab..0fa37eb 100644 --- a/CustomerProfiles/create-customer-profile.js +++ b/CustomerProfiles/create-customer-profile.js @@ -13,14 +13,25 @@ function createCustomerProfile(callback) { var creditCard = new ApiContracts.CreditCardType(); creditCard.setCardNumber('4242424242424242'); - creditCard.setExpirationDate('0822'); + creditCard.setExpirationDate('0842'); var paymentType = new ApiContracts.PaymentType(); paymentType.setCreditCard(creditCard); + + var customerAddress = new ApiContracts.CustomerAddressType(); + customerAddress.setFirstName('test'); + customerAddress.setLastName('scenario'); + customerAddress.setAddress('123 Main Street'); + customerAddress.setCity('Bellevue'); + customerAddress.setState('WA'); + customerAddress.setZip('98004'); + customerAddress.setCountry('USA'); + customerAddress.setPhoneNumber('000-000-0000'); var customerPaymentProfileType = new ApiContracts.CustomerPaymentProfileType(); customerPaymentProfileType.setCustomerType(ApiContracts.CustomerTypeEnum.INDIVIDUAL); customerPaymentProfileType.setPayment(paymentType); + customerPaymentProfileType.setBillTo(customerAddress); var paymentProfilesList = []; paymentProfilesList.push(customerPaymentProfileType); @@ -39,18 +50,19 @@ function createCustomerProfile(callback) { //pretty print request //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); + var ctrl = new ApiControllers.CreateCustomerProfileController(createRequest.getJSON()); ctrl.execute(function(){ var apiResponse = ctrl.getResponse(); - var response = new ApiContracts.CreateCustomerProfileResponse(apiResponse); + if (apiResponse != null) var response = new ApiContracts.CreateCustomerProfileResponse(apiResponse); //pretty print response //console.log(JSON.stringify(response, null, 2)); - if(response != null) + if(response != null) { if(response.getMessages().getResultCode() == ApiContracts.MessageTypeEnum.OK) { @@ -65,6 +77,8 @@ function createCustomerProfile(callback) { } else { + var apiError = ctrl.getError(); + console.log(apiError); console.log('Null response received'); } @@ -78,4 +92,4 @@ if (require.main === module) { }); } -module.exports.createCustomerProfile = createCustomerProfile; \ No newline at end of file +module.exports.createCustomerProfile = createCustomerProfile; diff --git a/CustomerProfiles/create-customer-shipping-address.js b/CustomerProfiles/create-customer-shipping-address.js index da3338f..466f600 100644 --- a/CustomerProfiles/create-customer-shipping-address.js +++ b/CustomerProfiles/create-customer-shipping-address.js @@ -3,6 +3,7 @@ var ApiContracts = require('authorizenet').APIContracts; var ApiControllers = require('authorizenet').APIControllers; var constants = require('../constants.js'); +var randomStreetNumber = Math.round(Math.random() * 1000) function createCustomerShippingAddress(customerProfileId, callback) { @@ -13,8 +14,8 @@ function createCustomerShippingAddress(customerProfileId, callback) { var customerAddress = new ApiContracts.CustomerAddressType(); customerAddress.setFirstName('test'); customerAddress.setLastName('scenario'); - customerAddress.setAddress('123 Main Street'); - customerAddress.setCity('Bellevue'); + customerAddress.setAddress(randomStreetNumber + ' Main Street'); + customerAddress.setCity('Orchard'); customerAddress.setState('WA'); customerAddress.setZip('98002'); customerAddress.setCountry('USA'); @@ -34,7 +35,7 @@ function createCustomerShippingAddress(customerProfileId, callback) { var apiResponse = ctrl.getResponse(); - var response = new ApiContracts.CreateCustomerShippingAddressResponse(apiResponse); + if (apiResponse != null) var response = new ApiContracts.CreateCustomerShippingAddressResponse(apiResponse); //pretty print response //console.log(JSON.stringify(response, null, 2)); @@ -54,6 +55,8 @@ function createCustomerShippingAddress(customerProfileId, callback) { } else { + var apiError = ctrl.getError(); + console.log(apiError); console.log('Null response received'); } @@ -62,7 +65,7 @@ function createCustomerShippingAddress(customerProfileId, callback) { } if (require.main === module) { - createCustomerShippingAddress('41003872', function(){ + createCustomerShippingAddress('1929176981', function(){ console.log('createCustomerShippingAddress call complete.'); }); } diff --git a/CustomerProfiles/delete-customer-payment-profile.js b/CustomerProfiles/delete-customer-payment-profile.js index 5357722..c0041cb 100644 --- a/CustomerProfiles/delete-customer-payment-profile.js +++ b/CustomerProfiles/delete-customer-payment-profile.js @@ -24,7 +24,7 @@ function deleteCustomerPaymentProfile(customerProfileId, customerPaymentProfileI var apiResponse = ctrl.getResponse(); - var response = new ApiContracts.DeleteCustomerPaymentProfileResponse(apiResponse); + if (apiResponse != null) var response = new ApiContracts.DeleteCustomerPaymentProfileResponse(apiResponse); //pretty print response //console.log(JSON.stringify(response, null, 2)); @@ -44,6 +44,8 @@ function deleteCustomerPaymentProfile(customerProfileId, customerPaymentProfileI } else { + var apiError = ctrl.getError(); + console.log(apiError); console.log('Null response received'); } @@ -52,7 +54,7 @@ function deleteCustomerPaymentProfile(customerProfileId, customerPaymentProfileI } if (require.main === module) { - deleteCustomerPaymentProfile('41003872', '38764361', function(){ + deleteCustomerPaymentProfile('1929176981', '1841409235', function(){ console.log('deleteCustomerPaymentProfile call complete.'); }); } diff --git a/CustomerProfiles/delete-customer-profile.js b/CustomerProfiles/delete-customer-profile.js index 38e8bc0..90acbee 100644 --- a/CustomerProfiles/delete-customer-profile.js +++ b/CustomerProfiles/delete-customer-profile.js @@ -23,7 +23,7 @@ function deleteCustomerProfile(customerProfileId, callback) { var apiResponse = ctrl.getResponse(); - var response = new ApiContracts.DeleteCustomerProfileResponse(apiResponse); + if (apiResponse != null) var response = new ApiContracts.DeleteCustomerProfileResponse(apiResponse); //pretty print response //console.log(JSON.stringify(response, null, 2)); @@ -43,6 +43,8 @@ function deleteCustomerProfile(customerProfileId, callback) { } else { + var apiError = ctrl.getError(); + console.log(apiError); console.log('Null response received'); } @@ -51,7 +53,7 @@ function deleteCustomerProfile(customerProfileId, callback) { } if (require.main === module) { - deleteCustomerProfile('41004277', function(){ + deleteCustomerProfile('1929176986', function(){ console.log('deleteCustomerProfile call complete.'); }); } diff --git a/CustomerProfiles/delete-customer-shipping-address.js b/CustomerProfiles/delete-customer-shipping-address.js index 7ad993e..b082487 100644 --- a/CustomerProfiles/delete-customer-shipping-address.js +++ b/CustomerProfiles/delete-customer-shipping-address.js @@ -24,7 +24,7 @@ function deleteCustomerShippingAddress(customerProfileId, customerAddressId, cal var apiResponse = ctrl.getResponse(); - var response = new ApiContracts.DeleteCustomerShippingAddressResponse(apiResponse); + if (apiResponse != null) var response = new ApiContracts.DeleteCustomerShippingAddressResponse(apiResponse); //pretty print response //console.log(JSON.stringify(response, null, 2)); @@ -44,6 +44,8 @@ function deleteCustomerShippingAddress(customerProfileId, customerAddressId, cal } else { + var apiError = ctrl.getError(); + console.log(apiError); console.log('Null response received'); } @@ -52,7 +54,7 @@ function deleteCustomerShippingAddress(customerProfileId, customerAddressId, cal } if (require.main === module) { - deleteCustomerShippingAddress('12345', '431222', function(){ + deleteCustomerShippingAddress('1929176981', '900520604', function(){ console.log('deleteCustomerShippingAddress call complete.'); }); } diff --git a/CustomerProfiles/get-customer-payment-profile-list.js b/CustomerProfiles/get-customer-payment-profile-list.js new file mode 100644 index 0000000..03de206 --- /dev/null +++ b/CustomerProfiles/get-customer-payment-profile-list.js @@ -0,0 +1,102 @@ +"use strict"; + +var ApiContracts = require("authorizenet").APIContracts; +var ApiControllers = require("authorizenet").APIControllers; +var utils = require("../utils.js"); +var constants = require("../constants.js"); + +function getCustomerPaymentProfileList(callback) { + + // Create a merchantAuthenticationType object with authentication details + // retrieved from the constants file + var merchantAuthenticationType = new ApiContracts.MerchantAuthenticationType(); + merchantAuthenticationType.setName(constants.apiLoginKey); + merchantAuthenticationType.setTransactionKey(constants.transactionKey); + + // Set the transaction"s refId + var refId = utils.getRandomInt(); + + // Set the paging (this particular API call will only return up to 10 results at a time) + var paging = new ApiContracts.Paging(); + paging.setLimit(10); + paging.setOffset(1); + + // Set the sorting + var sorting = new ApiContracts.CustomerPaymentProfileSorting; + sorting.setOrderBy(ApiContracts.CustomerPaymentProfileOrderFieldEnum.ID); + sorting.setOrderDescending(false); + + // Set search parameters + var search = ApiContracts.CustomerPaymentProfileSearchTypeEnum.CARDSEXPIRINGINMONTH; + var month = "2020-12"; + + // Creating the request with the required parameters + var getRequest = new ApiContracts.GetCustomerPaymentProfileListRequest(); + getRequest.setMerchantAuthentication(merchantAuthenticationType); + getRequest.setRefId(refId); + getRequest.setPaging(paging); + getRequest.setSorting(sorting); + getRequest.setSearchType(search); + getRequest.setMonth(month); + + // uncomment to print request + // console.log(JSON.stringify(getRequest.getJSON(), null, 2)); + + var ctrl = new ApiControllers.GetCustomerPaymentProfileListController(getRequest.getJSON()); + + ctrl.execute(function(){ + + var apiResponse = ctrl.getResponse(); + + if (apiResponse != null) var response = new ApiContracts.GetCustomerPaymentProfileListResponse(apiResponse); + + // uncomment to print response + // console.log(JSON.stringify(response, null, 2)); + + if(response != null) + { + if(response.getMessages().getResultCode() == ApiContracts.MessageTypeEnum.OK) + { + console.log("SUCCESS"); + console.log("Total Num in Result Set: " + response.getTotalNumInResultSet()); + var profiles = response.getPaymentProfiles().getPaymentProfile(); + for (var i=0;i -This repository contains working code samples which demonstrate Node.js integration with the Authorize.Net Node.js SDK (https://github.com/AuthorizeNet/sdk-node). -The samples are organized just like our API, which you can also try out directly here: http://developer.authorize.net/api/reference +This repository contains working code samples which demonstrate Node.js integration with the [Authorize.Net Node.js SDK](https://github.com/AuthorizeNet/sdk-node). + +The samples are organized into categories and common usage examples, just like our [API Reference Guide](http://developer.authorize.net/api/reference). Our API Reference Guide is an interactive reference for the Authorize.Net API. It explains the request and response parameters for each API method and has embedded code windows to allow you to send actual requests right within the API Reference Guide. ## Using the Sample Code -The samples are all completely independent and self-contained so you can look at them to get a gist of how the method works, you can use the snippets to try in your own sample project, or you can run each sample from the command line. +The samples are all completely independent and self-contained. You can analyze them to get an understanding of how a particular method works, or you can use the snippets as a starting point for your own project. + +You can also run each sample directly from the command line. -## Running the Samples -### Clone this repository. +## Running the Samples From the Command Line +* Clone this repository: +``` + $ git clone https://github.com/AuthorizeNet/sample-code-node.git ``` - $ git clone https://github.com/AuthorizeNet/sample-code-nodejs.git -``` -### Install the SDK +* Install the [Authorize.Net Node.js SDK](https://www.github.com/AuthorizeNet/sdk-node): ``` $ npm install authorizenet ``` - -### Run Sample Code +* Run the individual samples by name. For example: +``` + $ node PaymentTransactions\[CodeSampleName] +``` +e.g. ``` $ node PaymentTransactions\authorize-credit-card.js ``` + +## For using behind proxy + +1. Create a `config` object as follows: + ```javascript + config = { + 'proxy': { + 'setProxy': true, + 'proxyUrl': 'http://:@:' + } + } + ``` + +2. Pass this `config` object to the controller constructor. + + For example, + + ```javascript + var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON(), config); + ``` \ No newline at end of file diff --git a/RecurringBilling/cancel-subscription.js b/RecurringBilling/cancel-subscription.js index d57d010..601b940 100644 --- a/RecurringBilling/cancel-subscription.js +++ b/RecurringBilling/cancel-subscription.js @@ -21,7 +21,7 @@ function cancelSubscription(subscriptionId, callback) { var apiResponse = ctrl.getResponse(); - var response = new ApiContracts.ARBCancelSubscriptionResponse(apiResponse); + if (apiResponse != null) var response = new ApiContracts.ARBCancelSubscriptionResponse(apiResponse); console.log(JSON.stringify(response, null, 2)); @@ -37,6 +37,8 @@ function cancelSubscription(subscriptionId, callback) { } } else{ + var apiError = ctrl.getError(); + console.log(apiError); console.log('Null Response.'); } diff --git a/RecurringBilling/create-subscription-from-customer-profile.js b/RecurringBilling/create-subscription-from-customer-profile.js index 0a84a01..250b7a9 100644 --- a/RecurringBilling/create-subscription-from-customer-profile.js +++ b/RecurringBilling/create-subscription-from-customer-profile.js @@ -44,7 +44,7 @@ function createSubscriptionFromCustomerProfile(customerProfileId, customerPaymen var apiResponse = ctrl.getResponse(); - var response = new ApiContracts.ARBCreateSubscriptionResponse(apiResponse); + if (apiResponse != null) var response = new ApiContracts.ARBCreateSubscriptionResponse(apiResponse); console.log(JSON.stringify(response, null, 2)); @@ -61,6 +61,8 @@ function createSubscriptionFromCustomerProfile(customerProfileId, customerPaymen } } else{ + var apiError = ctrl.getError(); + console.log(apiError); console.log('Null Response.'); } @@ -69,7 +71,7 @@ function createSubscriptionFromCustomerProfile(customerProfileId, customerPaymen } if (require.main === module) { - createSubscriptionFromCustomerProfile('123123', '123123', '123123', function(){ + createSubscriptionFromCustomerProfile('1929176981', '1841409255', '900520864', function(){ console.log('createSubscriptionFromCustomerProfile call complete.'); }); } diff --git a/RecurringBilling/create-subscription.js b/RecurringBilling/create-subscription.js index 9c44bf6..39caed3 100644 --- a/RecurringBilling/create-subscription.js +++ b/RecurringBilling/create-subscription.js @@ -21,7 +21,7 @@ function createSubscription(callback) { paymentScheduleType.setTrialOccurrences(0); var creditCard = new ApiContracts.CreditCardType(); - creditCard.setExpirationDate('2038-12'); + creditCard.setExpirationDate('2035-12'); creditCard.setCardNumber('4111111111111111'); var payment = new ApiContracts.PaymentType(); @@ -72,7 +72,7 @@ function createSubscription(callback) { var apiResponse = ctrl.getResponse(); - var response = new ApiContracts.ARBCreateSubscriptionResponse(apiResponse); + if (apiResponse != null) var response = new ApiContracts.ARBCreateSubscriptionResponse(apiResponse); console.log(JSON.stringify(response, null, 2)); @@ -89,6 +89,8 @@ function createSubscription(callback) { } } else{ + var apiError = ctrl.getError(); + console.log(apiError); console.log('Null Response.'); } diff --git a/RecurringBilling/get-list-of-subscription.js b/RecurringBilling/get-list-of-subscription.js deleted file mode 100644 index f99b871..0000000 --- a/RecurringBilling/get-list-of-subscription.js +++ /dev/null @@ -1,77 +0,0 @@ -'use strict'; - -var ApiContracts = require('authorizenet').APIContracts; -var ApiControllers = require('authorizenet').APIControllers; -var utils = require('../utils.js'); -var constants = require('../constants.js'); - -function getListOfSubscription(callback) { - var merchantAuthenticationType = new ApiContracts.MerchantAuthenticationType(); - merchantAuthenticationType.setName(constants.apiLoginKey); - merchantAuthenticationType.setTransactionKey(constants.transactionKey); - - var refId = utils.getRandomInt(); - - var sorting = new ApiContracts.ARBGetSubscriptionListSorting(); - sorting.setOrderDescending(true); - sorting.setOrderBy(ApiContracts.ARBGetSubscriptionListOrderFieldEnum.CREATETIMESTAMPUTC); - - var paging = new ApiContracts.Paging(); - paging.setOffset(1); - paging.setLimit(100); - - var listRequest = new ApiContracts.ARBGetSubscriptionListRequest(); - - listRequest.setMerchantAuthentication(merchantAuthenticationType); - - listRequest.setRefId(refId); - listRequest.setSearchType(ApiContracts.ARBGetSubscriptionListSearchTypeEnum.SUBSCRIPTIONACTIVE); - listRequest.setSorting(sorting); - listRequest.setPaging(paging); - - console.log(JSON.stringify(listRequest.getJSON(), null, 2)); - - var ctrl = new ApiControllers.ARBGetSubscriptionListController(listRequest.getJSON()); - - ctrl.execute(function(){ - var apiResponse = ctrl.getResponse(); - - var response = new ApiContracts.ARBGetSubscriptionListResponse(apiResponse); - - console.log(JSON.stringify(response, null, 2)); - - if(response != null){ - if(response.getMessages().getResultCode() == ApiContracts.MessageTypeEnum.OK){ - console.log('Total Results : ' + response.getTotalNumInResultSet()); - console.log('List of Subscription Ids : '); - var subscriptions = response.getSubscriptionDetails().getSubscriptionDetail(); - for (var i=0;i:@:' + } +} \ No newline at end of file diff --git a/list_of_sample_codes.txt b/list_of_sample_codes.txt index 2d961c9..a1f8472 100644 --- a/list_of_sample_codes.txt +++ b/list_of_sample_codes.txt @@ -13,7 +13,7 @@ chargeTokenizedCreditCard,1 cancelSubscription,1 createSubscriptionFromCustomerProfile,1 createSubscription,1 -getListOfSubscription,1 +getListOfSubscriptions,1 getSubscriptionStatus,1 getSubscription,1 updateSubscription,1 @@ -23,9 +23,9 @@ getTransactionDetails,1 getTransactionList,1 getTransactionListForCustomer,1 getUnsettledTransactionList,1 -createVisaCheckoutTransaction,0 -decryptVisaCheckoutData,1 -authorizationAndCaptureContinue,1 +createVisaSrcTransaction,0 +decryptVisaSrcData,1 +authorizationAndCaptureContinued,1 authorizationAndCapture,1 authorizationOnlyContinued,1 authorizationOnly,1 @@ -41,7 +41,8 @@ deleteCustomerPaymentProfile,1 deleteCustomerProfile,1 deleteCustomerShippingAddress,1 getCustomerPaymentProfile,1 -getCustomerProfileIds,1 +getCustomerPaymentProfileList,1 +getCustomerProfileIds,0 getCustomerProfile,1 getCustomerShippingAddress,1 updateCustomerPaymentProfile,1 diff --git a/package.json b/package.json index 1559765..1fa2413 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,10 @@ "description": "Sample code for nodejs sdk", "main": "constants.js", "dependencies": { - "authorizenet": "^1.0.1", "chai": "^3.5.0", - "eslint": "^2.12.0" + "eslint": "^4.18.2", + "yarn": "^1.22.10" }, - "devDependencies": {}, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, diff --git a/test-runner.js b/test-runner.js index 2a19ce0..69b81cf 100644 --- a/test-runner.js +++ b/test-runner.js @@ -7,344 +7,357 @@ var PaymentTransactionsModule = require('./PaymentTransactions'); var RecurringBillingModule = require('./RecurringBilling'); var TransactionReportingModule = require('./TransactionReporting'); var VisaCheckoutModule = require('./VisaCheckout'); -var PaypalExpressCheckoutModule = require('./PaypalExpressCheckout'); -var ApplePayTransactionsModule = require('./ApplePayTransactions'); +var PayPalExpressCheckoutModule = require('./PayPalExpressCheckout'); +//var ApplePayTransactionsModule = require('./ApplePayTransactions'); var CustomerProfilesModule = require('./CustomerProfiles'); +var filterTestMethod = process.argv[2] class TestRunner { - validateResponse(response){ - if(response == null){ - return false; - } - - if(response.getMessages().getResultCode() != ApiContracts.MessageTypeEnum.OK){ - return false; - } - - return true; - } - - authorizeCreditCard(validateFunctionCallback){ - PaymentTransactionsModule.authorizeCreditCard(validateFunctionCallback); - } - - chargeCreditCard(validateFunctionCallback){ - PaymentTransactionsModule.chargeCreditCard(validateFunctionCallback); - } - - capturePreviouslyAuthorizedAmount(validateFunctionCallback){ - PaymentTransactionsModule.authorizeCreditCard(function(response){ - PaymentTransactionsModule.capturePreviouslyAuthorizedAmount(response.getTransactionResponse().getTransId(), - validateFunctionCallback); - }); - } - - captureFundsAuthorizedThroughAnotherChannel(validateFunctionCallback){ - PaymentTransactionsModule.captureFundsAuthorizedThroughAnotherChannel(validateFunctionCallback); - } - - refundTransaction(validateFunctionCallback){ - PaymentTransactionsModule.authorizeCreditCard(function(response){ - PaymentTransactionsModule.capturePreviouslyAuthorizedAmount(response.getTransactionResponse().getTransId(), - function(captureResponse){ - PaymentTransactionsModule.refundTransaction(captureResponse.getTransactionResponse().getTransId(), validateFunctionCallback); - }); - }); - } - - voidTransaction(validateFunctionCallback){ - PaymentTransactionsModule.authorizeCreditCard(function(response){ - PaymentTransactionsModule.voidTransaction(response.getTransactionResponse().getTransId(), validateFunctionCallback); - }); - } - - updateSplitTenderGroup(validateFunctionCallback){ - PaymentTransactionsModule.updateSplitTenderGroup(validateFunctionCallback); - } - - debitBankAccount(validateFunctionCallback){ - PaymentTransactionsModule.debitBankAccount(validateFunctionCallback); - } - - creditBankAccount(validateFunctionCallback){ - PaymentTransactionsModule.debitBankAccount(function(response){ - PaymentTransactionsModule.creditBankAccount(response.getTransactionResponse().getTransId(), validateFunctionCallback); - }); - } - - chargeCustomerProfile(validateFunctionCallback){ - CustomerProfilesModule.createCustomerProfile(function(response){ - CustomerProfilesModule.createCustomerPaymentProfile(response.getCustomerProfileId(), function(paymentProfileResponse){ - PaymentTransactionsModule.chargeCustomerProfile(response.getCustomerProfileId(), paymentProfileResponse.getCustomerPaymentProfileId(), validateFunctionCallback); - }); - }); - } - - chargeTokenizedCreditCard(validateFunctionCallback){ - PaymentTransactionsModule.chargeTokenizedCreditCard(validateFunctionCallback); - } - - cancelSubscription(validateFunctionCallback){ - RecurringBillingModule.createSubscription(function(response){ - RecurringBillingModule.cancelSubscription(response.getSubscriptionId(), validateFunctionCallback); - }); - } - - createSubscriptionFromCustomerProfile(validateFunctionCallback){ - CustomerProfilesModule.createCustomerProfile(function(response){ - CustomerProfilesModule.createCustomerPaymentProfile(response.getCustomerProfileId(), function(paymentProfileResponse){ - CustomerProfilesModule.createCustomerShippingAddress(response.getCustomerProfileId(), function(shippingResponse){ - RecurringBillingModule.createSubscriptionFromCustomerProfile(response.getCustomerProfileId(), paymentProfileResponse.getCustomerPaymentProfileId(), shippingResponse.getCustomerAddressId(), validateFunctionCallback); - }); - }); - }); - } - - createSubscription(validateFunctionCallback){ - RecurringBillingModule.createSubscription(validateFunctionCallback); - } - - getListOfSubscription(validateFunctionCallback){ - RecurringBillingModule.getListOfSubscription(validateFunctionCallback); - } - - getSubscriptionStatus(validateFunctionCallback){ - RecurringBillingModule.createSubscription(function(response){ - RecurringBillingModule.getSubscriptionStatus(response.getSubscriptionId(), validateFunctionCallback); - }); - } - - getSubscription(validateFunctionCallback){ - RecurringBillingModule.createSubscription(function(response){ - RecurringBillingModule.getSubscription(response.getSubscriptionId(), validateFunctionCallback); - }); - } - - updateSubscription(validateFunctionCallback){ - RecurringBillingModule.createSubscription(function(response){ - RecurringBillingModule.updateSubscription(response.getSubscriptionId(), validateFunctionCallback); - }); - } - - getBatchStatistics(validateFunctionCallback){ - TransactionReportingModule.getBatchStatistics('4594221', validateFunctionCallback); - } - - getSettledBatchList(validateFunctionCallback){ - TransactionReportingModule.getSettledBatchList(validateFunctionCallback); - } - - getTransactionDetails(validateFunctionCallback){ - PaymentTransactionsModule.authorizeCreditCard(function(response){ - TransactionReportingModule.getTransactionDetails(response.getTransactionResponse().getTransId(), validateFunctionCallback); - }); - } - - getTransactionList(validateFunctionCallback){ - TransactionReportingModule.getTransactionList('4594221', validateFunctionCallback); - } - - getTransactionListForCustomer(validateFunctionCallback){ - TransactionReportingModule.getTransactionListForCustomer('1811474252', validateFunctionCallback); - - } - - getUnsettledTransactionList(validateFunctionCallback){ - TransactionReportingModule.getUnsettledTransactionList(validateFunctionCallback); - } - - createVisaCheckoutTransaction(validateFunctionCallback){ - VisaCheckoutModule.createVisaCheckoutTransaction(validateFunctionCallback); - } - - decryptVisaCheckoutData(validateFunctionCallback){ - VisaCheckoutModule.decryptVisaCheckoutData(validateFunctionCallback); - } - - authorizationOnly(validateFunctionCallback){ - PaypalExpressCheckoutModule.authorizationOnly(validateFunctionCallback); - } - - authorizationAndCapture(validateFunctionCallback){ - PaypalExpressCheckoutModule.authorizationAndCapture(validateFunctionCallback); - } - - authorizationOnlyContinued(validateFunctionCallback){ - PaypalExpressCheckoutModule.authorizationOnly(function(response){ - PaypalExpressCheckoutModule.authorizationOnlyContinued(response.getTransactionResponse().getTransId(), validateFunctionCallback); - }); - } - - authorizationAndCaptureContinue(validateFunctionCallback){ - PaypalExpressCheckoutModule.authorizationAndCapture(function(response){ - PaypalExpressCheckoutModule.authorizationAndCaptureContinue(response.getTransactionResponse().getTransId(), validateFunctionCallback); - }); - } - - priorAuthorizationCapture(validateFunctionCallback){ - PaypalExpressCheckoutModule.authorizationAndCapture(function(response){ - PaypalExpressCheckoutModule.priorAuthorizationCapture(response.getTransactionResponse().getTransId(), validateFunctionCallback); - }); - } - - paypalVoid(validateFunctionCallback){ - PaypalExpressCheckoutModule.authorizationAndCapture(function(response){ - PaypalExpressCheckoutModule.paypalVoid(response.getTransactionResponse().getTransId(), validateFunctionCallback); - }); - } - - getDetails(validateFunctionCallback){ - PaypalExpressCheckoutModule.authorizationAndCapture(function(response){ - PaypalExpressCheckoutModule.getDetails(response.getTransactionResponse().getTransId(), validateFunctionCallback); - }); - } - - credit(validateFunctionCallback){ - PaypalExpressCheckoutModule.authorizationAndCapture(function(response){ - PaypalExpressCheckoutModule.credit(response.getTransactionResponse().getTransId(), validateFunctionCallback); - }); - } - - createApplePayTransaction(validateFunctionCallback){ - ApplePayTransactionsModule.createApplePayTransaction(validateFunctionCallback); - } - - createCustomerProfile(validateFunctionCallback){ - CustomerProfilesModule.createCustomerProfile(validateFunctionCallback); - } - - createCustomerPaymentProfile(validateFunctionCallback){ - CustomerProfilesModule.createCustomerProfile(function(response){ - CustomerProfilesModule.createCustomerPaymentProfile(response.getCustomerProfileId(), validateFunctionCallback); - }); - } - - createCustomerProfileFromTransaction(validateFunctionCallback){ - PaymentTransactionsModule.authorizeCreditCard(function(response){ - CustomerProfilesModule.createCustomerProfileFromTransaction(response.getTransactionResponse().getTransId(), validateFunctionCallback); - }); - } - - getCustomerProfile(validateFunctionCallback){ - CustomerProfilesModule.createCustomerProfile(function(response){ - CustomerProfilesModule.getCustomerProfile(response.getCustomerProfileId(), validateFunctionCallback); - }); - } - - getCustomerPaymentProfile(validateFunctionCallback){ - CustomerProfilesModule.createCustomerProfile(function(response){ - CustomerProfilesModule.createCustomerPaymentProfile(response.getCustomerProfileId(), function(paymentProfileResponse){ - CustomerProfilesModule.getCustomerPaymentProfile(response.getCustomerProfileId(), paymentProfileResponse.getCustomerPaymentProfileId(), validateFunctionCallback); - }); - }); - } - - createCustomerShippingAddress(validateFunctionCallback){ - CustomerProfilesModule.createCustomerProfile(function(response){ - CustomerProfilesModule.createCustomerShippingAddress(response.getCustomerProfileId(), validateFunctionCallback); - }); - } - - deleteCustomerPaymentProfile(validateFunctionCallback){ - CustomerProfilesModule.createCustomerProfile(function(response){ - CustomerProfilesModule.createCustomerPaymentProfile(response.getCustomerProfileId(), function(paymentProfileResponse){ - CustomerProfilesModule.deleteCustomerPaymentProfile(response.getCustomerProfileId(), paymentProfileResponse.getCustomerPaymentProfileId(), validateFunctionCallback); - }); - }); - } - - deleteCustomerProfile(validateFunctionCallback){ - CustomerProfilesModule.createCustomerProfile(function(response){ - CustomerProfilesModule.deleteCustomerProfile(response.getCustomerProfileId(), validateFunctionCallback); - }); - } - - deleteCustomerShippingAddress(validateFunctionCallback){ - CustomerProfilesModule.createCustomerProfile(function(response){ - CustomerProfilesModule.createCustomerShippingAddress(response.getCustomerProfileId(), function(shippingResponse){ - CustomerProfilesModule.deleteCustomerShippingAddress(response.getCustomerProfileId(), shippingResponse.getCustomerAddressId(), validateFunctionCallback); - }); - }); - } - - getCustomerProfileIds(validateFunctionCallback){ - CustomerProfilesModule.getCustomerProfileIds(validateFunctionCallback); - } - - getCustomerShippingAddress(validateFunctionCallback){ - CustomerProfilesModule.createCustomerProfile(function(response){ - CustomerProfilesModule.createCustomerShippingAddress(response.getCustomerProfileId(), function(shippingResponse){ - CustomerProfilesModule.getCustomerShippingAddress(response.getCustomerProfileId(), shippingResponse.getCustomerAddressId(), validateFunctionCallback); - }); - }); - } - - getHostedProfilePage(validateFunctionCallback){ - CustomerProfilesModule.createCustomerProfile(function(response){ - CustomerProfilesModule.getHostedProfilePage(response.getCustomerProfileId(), validateFunctionCallback); - }); - } - - updateCustomerPaymentProfile(validateFunctionCallback){ - CustomerProfilesModule.createCustomerProfile(function(response){ - CustomerProfilesModule.createCustomerPaymentProfile(response.getCustomerProfileId(), function(paymentProfileResponse){ - CustomerProfilesModule.updateCustomerPaymentProfile(response.getCustomerProfileId(), paymentProfileResponse.getCustomerPaymentProfileId(), validateFunctionCallback); - }); - }); - } - - updateCustomerProfile(validateFunctionCallback){ - CustomerProfilesModule.createCustomerProfile(function(response){ - CustomerProfilesModule.updateCustomerProfile(response.getCustomerProfileId(), validateFunctionCallback); - }); - } - - updateCustomerShippingAddress(validateFunctionCallback){ - CustomerProfilesModule.createCustomerProfile(function(response){ - CustomerProfilesModule.createCustomerShippingAddress(response.getCustomerProfileId(), function(shippingResponse){ - CustomerProfilesModule.updateCustomerShippingAddress(response.getCustomerProfileId(), shippingResponse.getCustomerAddressId(), validateFunctionCallback); - }); - }); - } - - validateCustomerPaymentProfile(validateFunctionCallback){ - CustomerProfilesModule.createCustomerProfile(function(response){ - CustomerProfilesModule.createCustomerPaymentProfile(response.getCustomerProfileId(), function(paymentProfileResponse){ - CustomerProfilesModule.validateCustomerPaymentProfile(response.getCustomerProfileId(), paymentProfileResponse.getCustomerPaymentProfileId(), validateFunctionCallback); - }); - }); - } - - callTestMethod(testMethodName, validateFunctionCallback){ - return this[testMethodName](validateFunctionCallback); - } - - testAllSamples(){ - var lineReader = require('readline').createInterface({ - input: require('fs').createReadStream('./list_of_sample_codes.txt') - }); - - var testRunnerObject = this; - - lineReader.on('line', function (line) { - var sample = line.split(','); - var apiName = sample[0]; - var shouldApiRun = sample[1].trim()[0]; - - if(shouldApiRun == '1'){ - console.log('Running : ' + apiName); - testRunnerObject.callTestMethod(apiName, function(response) { - assert.isTrue(testRunnerObject.validateResponse(response)); - /* - if(!testRunnerObject.validateResponse(response)){ - console.log('Error in running ' + apiName + '. Stopped test runner.'); - return; - } - */ - }); - } - }); - } + validateResponse(response) { + if(response == null) { + return false; + } + + if(response.getMessages().getResultCode() != ApiContracts.MessageTypeEnum.OK) { + return false; + } + + return true; + } + + authorizeCreditCard(validateFunctionCallback) { + PaymentTransactionsModule.authorizeCreditCard(validateFunctionCallback); + } + + chargeCreditCard(validateFunctionCallback) { + PaymentTransactionsModule.chargeCreditCard(validateFunctionCallback); + } + + capturePreviouslyAuthorizedAmount(validateFunctionCallback) { + PaymentTransactionsModule.authorizeCreditCard(function(response) { + PaymentTransactionsModule.capturePreviouslyAuthorizedAmount(response.getTransactionResponse().getTransId(), validateFunctionCallback); + }); + } + + captureFundsAuthorizedThroughAnotherChannel(validateFunctionCallback) { + PaymentTransactionsModule.captureFundsAuthorizedThroughAnotherChannel(validateFunctionCallback); + } + + refundTransaction(validateFunctionCallback) { + PaymentTransactionsModule.authorizeCreditCard(function(response) { + PaymentTransactionsModule.capturePreviouslyAuthorizedAmount(response.getTransactionResponse().getTransId(), + function(captureResponse) { + PaymentTransactionsModule.refundTransaction(captureResponse.getTransactionResponse().getTransId(), validateFunctionCallback); + }); + }); + } + + voidTransaction(validateFunctionCallback) { + PaymentTransactionsModule.authorizeCreditCard(function(response) { + PaymentTransactionsModule.voidTransaction(response.getTransactionResponse().getTransId(), validateFunctionCallback); + }); + } + + updateSplitTenderGroup(validateFunctionCallback) { + PaymentTransactionsModule.updateSplitTenderGroup(validateFunctionCallback); + } + + debitBankAccount(validateFunctionCallback) { + PaymentTransactionsModule.debitBankAccount(validateFunctionCallback); + } + + creditBankAccount(validateFunctionCallback) { + PaymentTransactionsModule.debitBankAccount(function(response) { + PaymentTransactionsModule.creditBankAccount(response.getTransactionResponse().getTransId(), validateFunctionCallback); + }); + } + + chargeCustomerProfile(validateFunctionCallback) { + CustomerProfilesModule.createCustomerProfile(function(response) { + CustomerProfilesModule.createCustomerPaymentProfile(response.getCustomerProfileId(), function(paymentProfileResponse) { + PaymentTransactionsModule.chargeCustomerProfile(response.getCustomerProfileId(), paymentProfileResponse.getCustomerPaymentProfileId(), validateFunctionCallback); + }); + }); + } + + chargeTokenizedCreditCard(validateFunctionCallback) { + PaymentTransactionsModule.chargeTokenizedCreditCard(validateFunctionCallback); + } + + cancelSubscription(validateFunctionCallback) { + RecurringBillingModule.createSubscription(function(response) { + RecurringBillingModule.cancelSubscription(response.getSubscriptionId(), validateFunctionCallback); + }); + } + + createSubscriptionFromCustomerProfile(validateFunctionCallback) { + /* CustomerProfilesModule.createCustomerProfile(function(response) { + CustomerProfilesModule.createCustomerPaymentProfile(response.getCustomerProfileId(), function(paymentProfileResponse) { + CustomerProfilesModule.createCustomerShippingAddress(response.getCustomerProfileId(), function(shippingResponse) { + RecurringBillingModule.createSubscriptionFromCustomerProfile(response.getCustomerProfileId(), paymentProfileResponse.getCustomerPaymentProfileId(), shippingResponse.getCustomerAddressId(), validateFunctionCallback); + }); + }); + }); */ + + CustomerProfilesModule.getCustomerProfile("1929176981", function(profileResponse) { + RecurringBillingModule.createSubscriptionFromCustomerProfile(profileResponse.profile.customerProfileId, profileResponse.profile.paymentProfiles[0].customerPaymentProfileId, profileResponse.profile.shipToList[0].customerAddressId, validateFunctionCallback); + }); + + } + + createSubscription(validateFunctionCallback) { + RecurringBillingModule.createSubscription(validateFunctionCallback); + } + + getListOfSubscriptions(validateFunctionCallback) { + RecurringBillingModule.getListOfSubscriptions(validateFunctionCallback); + } + + getSubscriptionStatus(validateFunctionCallback) { + RecurringBillingModule.createSubscription(function(response) { + RecurringBillingModule.getSubscriptionStatus(response.getSubscriptionId(), validateFunctionCallback); + }); + } + + getSubscription(validateFunctionCallback) { + RecurringBillingModule.createSubscription(function(response) { + RecurringBillingModule.getSubscription(response.getSubscriptionId(), validateFunctionCallback); + }); + } + + updateSubscription(validateFunctionCallback) { + RecurringBillingModule.createSubscription(function(response) { + RecurringBillingModule.updateSubscription(response.getSubscriptionId(), validateFunctionCallback); + }); + } + + getBatchStatistics(validateFunctionCallback) { + TransactionReportingModule.getBatchStatistics('4594221', validateFunctionCallback); + } + + getSettledBatchList(validateFunctionCallback) { + TransactionReportingModule.getSettledBatchList(validateFunctionCallback); + } + + getTransactionDetails(validateFunctionCallback) { + PaymentTransactionsModule.authorizeCreditCard(function(response) { + TransactionReportingModule.getTransactionDetails(response.getTransactionResponse().getTransId(), validateFunctionCallback); + }); + } + + getTransactionList(validateFunctionCallback) { + TransactionReportingModule.getTransactionList('4594221', validateFunctionCallback); + } + + getTransactionListForCustomer(validateFunctionCallback) { + TransactionReportingModule.getTransactionListForCustomer('1811474252', validateFunctionCallback); + + } + + getUnsettledTransactionList(validateFunctionCallback) { + TransactionReportingModule.getUnsettledTransactionList(validateFunctionCallback); + } + + createVisaSrcTransaction(validateFunctionCallback) { + VisaCheckoutModule.createVisaSrcTransaction(validateFunctionCallback); + } + + decryptVisaSrcData(validateFunctionCallback) { + VisaCheckoutModule.decryptVisaSrcData(validateFunctionCallback); + } + + authorizationOnly(validateFunctionCallback) { + PayPalExpressCheckoutModule.authorizationOnly(validateFunctionCallback); + } + + authorizationAndCapture(validateFunctionCallback) { + PayPalExpressCheckoutModule.authorizationAndCapture(validateFunctionCallback); + } + + authorizationOnlyContinued(validateFunctionCallback) { + PayPalExpressCheckoutModule.authorizationOnly(function(response) { + PayPalExpressCheckoutModule.authorizationOnlyContinued(response.getTransactionResponse().getTransId(), validateFunctionCallback); + }); + } + + authorizationAndCaptureContinued(validateFunctionCallback) { + PayPalExpressCheckoutModule.authorizationAndCapture(function(response) { + PayPalExpressCheckoutModule.authorizationAndCaptureContinued(response.getTransactionResponse().getTransId(), validateFunctionCallback); + }); + } + + priorAuthorizationCapture(validateFunctionCallback) { + PayPalExpressCheckoutModule.authorizationAndCapture(function(response) { + PayPalExpressCheckoutModule.priorAuthorizationCapture(response.getTransactionResponse().getTransId(), validateFunctionCallback); + }); + } + + paypalVoid(validateFunctionCallback) { + PayPalExpressCheckoutModule.authorizationAndCapture(function(response) { + PayPalExpressCheckoutModule.paypalVoid(response.getTransactionResponse().getTransId(), validateFunctionCallback); + }); + } + + getDetails(validateFunctionCallback) { + PayPalExpressCheckoutModule.authorizationAndCapture(function(response) { + PayPalExpressCheckoutModule.getDetails(response.getTransactionResponse().getTransId(), validateFunctionCallback); + }); + } + + credit(validateFunctionCallback) { + PayPalExpressCheckoutModule.authorizationAndCapture(function(response) { + PayPalExpressCheckoutModule.credit(response.getTransactionResponse().getTransId(), validateFunctionCallback); + }); + } + + createApplePayTransaction(validateFunctionCallback) { + ApplePayTransactionsModule.createApplePayTransaction(validateFunctionCallback); + } + + createCustomerProfile(validateFunctionCallback) { + CustomerProfilesModule.createCustomerProfile(validateFunctionCallback); + } + + createCustomerPaymentProfile(validateFunctionCallback) { + CustomerProfilesModule.createCustomerProfile(function(response) { + CustomerProfilesModule.createCustomerPaymentProfile(response.getCustomerProfileId(), validateFunctionCallback); + }); + } + + createCustomerProfileFromTransaction(validateFunctionCallback) { + PaymentTransactionsModule.authorizeCreditCard(function(response) { + CustomerProfilesModule.createCustomerProfileFromTransaction(response.getTransactionResponse().getTransId(), validateFunctionCallback); + }); + } + + getCustomerProfile(validateFunctionCallback) { + CustomerProfilesModule.createCustomerProfile(function(response) { + CustomerProfilesModule.getCustomerProfile(response.getCustomerProfileId(), validateFunctionCallback); + }); + } + + getCustomerPaymentProfile(validateFunctionCallback) { + CustomerProfilesModule.createCustomerProfile(function(response) { + CustomerProfilesModule.createCustomerPaymentProfile(response.getCustomerProfileId(), function(paymentProfileResponse) { + CustomerProfilesModule.getCustomerPaymentProfile(response.getCustomerProfileId(), paymentProfileResponse.getCustomerPaymentProfileId(), validateFunctionCallback); + }); + }); + } + + getCustomerPaymentProfileList(validateFunctionCallback) { + CustomerProfilesModule.getCustomerPaymentProfileList(validateFunctionCallback); + } + + createCustomerShippingAddress(validateFunctionCallback) { + CustomerProfilesModule.createCustomerProfile(function(response) { + CustomerProfilesModule.createCustomerShippingAddress(response.getCustomerProfileId(), validateFunctionCallback); + }); + } + + deleteCustomerPaymentProfile(validateFunctionCallback) { + CustomerProfilesModule.createCustomerProfile(function(response) { + CustomerProfilesModule.createCustomerPaymentProfile(response.getCustomerProfileId(), function(paymentProfileResponse) { + CustomerProfilesModule.deleteCustomerPaymentProfile(response.getCustomerProfileId(), paymentProfileResponse.getCustomerPaymentProfileId(), validateFunctionCallback); + }); + }); + } + + deleteCustomerProfile(validateFunctionCallback) { + CustomerProfilesModule.createCustomerProfile(function(response) { + CustomerProfilesModule.deleteCustomerProfile(response.getCustomerProfileId(), validateFunctionCallback); + }); + } + + deleteCustomerShippingAddress(validateFunctionCallback) { + CustomerProfilesModule.createCustomerProfile(function(response) { + CustomerProfilesModule.createCustomerShippingAddress(response.getCustomerProfileId(), function(shippingResponse) { + CustomerProfilesModule.deleteCustomerShippingAddress(response.getCustomerProfileId(), shippingResponse.getCustomerAddressId(), validateFunctionCallback); + }); + }); + } + + getCustomerProfileIds(validateFunctionCallback) { + CustomerProfilesModule.getCustomerProfileIds(validateFunctionCallback); + } + + getCustomerShippingAddress(validateFunctionCallback) { + CustomerProfilesModule.createCustomerProfile(function(response) { + CustomerProfilesModule.createCustomerShippingAddress(response.getCustomerProfileId(), function(shippingResponse) { + CustomerProfilesModule.getCustomerShippingAddress(response.getCustomerProfileId(), shippingResponse.getCustomerAddressId(), validateFunctionCallback); + }); + }); + } + + getHostedProfilePage(validateFunctionCallback) { + CustomerProfilesModule.createCustomerProfile(function(response) { + CustomerProfilesModule.getHostedProfilePage(response.getCustomerProfileId(), validateFunctionCallback); + }); + } + + updateCustomerPaymentProfile(validateFunctionCallback) { + CustomerProfilesModule.createCustomerProfile(function(response) { + CustomerProfilesModule.createCustomerPaymentProfile(response.getCustomerProfileId(), function(paymentProfileResponse) { + CustomerProfilesModule.updateCustomerPaymentProfile(response.getCustomerProfileId(), paymentProfileResponse.getCustomerPaymentProfileId(), validateFunctionCallback); + }); + }); + } + + updateCustomerProfile(validateFunctionCallback) { + CustomerProfilesModule.createCustomerProfile(function(response) { + CustomerProfilesModule.updateCustomerProfile(response.getCustomerProfileId(), validateFunctionCallback); + }); + } + + updateCustomerShippingAddress(validateFunctionCallback) { + CustomerProfilesModule.createCustomerProfile(function(response) { + CustomerProfilesModule.createCustomerShippingAddress(response.getCustomerProfileId(), function(shippingResponse) { + CustomerProfilesModule.updateCustomerShippingAddress(response.getCustomerProfileId(), shippingResponse.getCustomerAddressId(), validateFunctionCallback); + }); + }); + } + + validateCustomerPaymentProfile(validateFunctionCallback) { + CustomerProfilesModule.createCustomerProfile(function(response) { + CustomerProfilesModule.createCustomerPaymentProfile(response.getCustomerProfileId(), function(paymentProfileResponse) { + CustomerProfilesModule.validateCustomerPaymentProfile(response.getCustomerProfileId(), paymentProfileResponse.getCustomerPaymentProfileId(), validateFunctionCallback); + }); + }); + } + + callTestMethod(testMethodName, validateFunctionCallback) { + return this[testMethodName](validateFunctionCallback); + } + + testAllSamples() { + var lineReader = require('readline').createInterface({ + input: require('fs').createReadStream('./list_of_sample_codes.txt') + }); + + var testRunnerObject = this; + + lineReader.on('line', function (line) { + var sample = line.split(','); + var apiName = sample[0]; + var shouldApiRun = sample[1].trim()[0]; + + if(shouldApiRun == '1') { + if (filterTestMethod && apiName !== filterTestMethod) return + console.log('\n************************ Running : ' + apiName + ' ************************\n'); + testRunnerObject.callTestMethod(apiName, function(response) { + console.log('\n************************ Testing : ' + apiName + ' ************************\n'); + assert.isTrue(testRunnerObject.validateResponse(response), "Error detected."); + /* + if(!testRunnerObject.validateResponse(response)) { + console.log('Error in running ' + apiName + '. Stopped test runner.'); + return; + } + */ + }); + + console.log('\n************************ Ending : ' + apiName + ' ************************\n'); + } + }); + } } var testRunner = new TestRunner();