├── MobileInAppTransactions ├── index.js ├── create-an-accept-transaction.js ├── create-google-pay-transaction.js ├── create-an-apple-pay-transaction.js └── create-an-android-pay-transaction.js ├── VisaCheckout ├── index.js ├── decrypt-visa-src-data.js └── create-visa-src-transaction.js ├── .eslintrc.yml ├── constants.js ├── utils.js ├── TransactionReporting ├── index.js ├── get-transaction-details.js ├── get-merchant-details.js ├── get-settled-batch-list.js ├── get-batch-statistics.js ├── get-transaction-list.js ├── get-unsettled-transaction-list.js └── get-customer-profile-transaction-list.js ├── RecurringBilling ├── index.js ├── cancel-subscription.js ├── get-subscription.js ├── get-subscription-status.js ├── update-subscription.js ├── get-list-of-subscriptions.js ├── create-subscription-from-customer-profile.js └── create-subscription.js ├── .gitignore ├── PayPalExpressCheckout ├── index.js ├── get-details.js ├── void.js ├── prior-authorization-capture.js ├── credit.js ├── authorization-only.js ├── authorization-and-capture.js ├── authorization-only-continued.js └── authorization-and-capture-continued.js ├── package.json ├── Sha512 └── compute_trans_hashSHA2.js ├── PaymentTransactions ├── index.js ├── update-split-tender-group.js ├── void-transaction.js ├── capture-previously-authorized-amount.js ├── refund-transaction.js ├── capture-funds-authorized-through-another-channel.js ├── credit-bank-account.js ├── charge-customer-profile.js ├── debit-bank-account.js └── authorize-credit-card.js ├── LICENSE ├── list_of_sample_codes.txt ├── CustomerProfiles ├── index.js ├── delete-customer-profile.js ├── get-customer-profile-ids.js ├── get-customer-profile.js ├── delete-customer-shipping-address.js ├── create-customer-profile-from-transaction.js ├── delete-customer-payment-profile.js ├── update-customer-profile.js ├── validate-customer-payment-profile.js ├── get-customer-payment-profile.js ├── get-customer-shipping-address.js ├── create-customer-shipping-address.js ├── update-customer-shipping-address.js ├── create-customer-payment-profile.js ├── create-customer-profile-with-accept.js ├── update-customer-payment-profile.js ├── create-customer-profile.js └── get-customer-payment-profile-list.js ├── README.md ├── AcceptSuite ├── get-accept-customer-profile-page.js └── get-an-accept-payment-page.js └── FraudManagement ├── get-held-transaction-list.js └── approve-or-decline-held-transaction.js /MobileInAppTransactions/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | createApplePayTransaction: require('./create-an-apple-pay-transaction.js').createApplePayTransaction 5 | }; 6 | -------------------------------------------------------------------------------- /VisaCheckout/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | createVisaSrcTransaction: require('./create-visa-src-transaction.js').createVisaSrcTransaction, 5 | decryptVisaSrcData: require('./decrypt-visa-src-data.js').decryptVisaSrcData 6 | }; -------------------------------------------------------------------------------- /.eslintrc.yml: -------------------------------------------------------------------------------- 1 | env: 2 | node: true 3 | mocha: true 4 | es6: true 5 | extends: 'eslint:recommended' 6 | parserOptions: 7 | sourceType: module 8 | rules: 9 | indent: 10 | - error 11 | - tab 12 | quotes: 13 | - error 14 | - single 15 | semi: 16 | - error 17 | - always 18 | -------------------------------------------------------------------------------- /constants.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports.apiLoginKey = '5KP3u95bQpv'; 4 | module.exports.transactionKey = '346HZ32z3fP4hTG2'; 5 | module.exports.config = { 6 | 'logger': { 7 | 'enabled': false, 8 | 'location': '', 9 | //logging levels - { error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5 10 | 'level': 'silly' 11 | }, 12 | 'proxy': { 13 | 'setProxy': false, 14 | 'proxyUrl': 'http://:@:' 15 | } 16 | } -------------------------------------------------------------------------------- /utils.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | function getRandomString(text){ 4 | return text + Math.floor((Math.random() * 100000) + 1); 5 | } 6 | 7 | function getRandomInt(){ 8 | return Math.floor((Math.random() * 100000) + 1); 9 | } 10 | 11 | function getRandomAmount(){ 12 | return ((Math.random() * 100) + 1).toFixed(2); 13 | } 14 | 15 | function getDate(){ 16 | return (new Date()).toISOString().substring(0, 10) ; 17 | } 18 | 19 | 20 | module.exports.getRandomString = getRandomString; 21 | module.exports.getRandomInt = getRandomInt; 22 | module.exports.getRandomAmount = getRandomAmount; 23 | module.exports.getDate = getDate; -------------------------------------------------------------------------------- /TransactionReporting/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | getBatchStatistics: require('./get-batch-statistics.js').getBatchStatistics, 5 | getSettledBatchList: require('./get-settled-batch-list.js').getSettledBatchList, 6 | getTransactionDetails: require('./get-transaction-details.js').getTransactionDetails, 7 | getTransactionList: require('./get-transaction-list.js').getTransactionList, 8 | getTransactionListForCustomer: require('./get-customer-profile-transaction-list.js').getTransactionListForCustomer, 9 | getUnsettledTransactionList: require('./get-unsettled-transaction-list.js').getUnsettledTransactionList 10 | }; -------------------------------------------------------------------------------- /RecurringBilling/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | cancelSubscription: require('./cancel-subscription.js').cancelSubscription, 5 | createSubscriptionFromCustomerProfile: require('./create-subscription-from-customer-profile.js').createSubscriptionFromCustomerProfile, 6 | createSubscription: require('./create-subscription.js').createSubscription, 7 | getListOfSubscriptions: require('./get-list-of-subscriptions.js').getListOfSubscriptions, 8 | getSubscriptionStatus: require('./get-subscription-status.js').getSubscriptionStatus, 9 | getSubscription: require('./get-subscription.js').getSubscription, 10 | updateSubscription: require('./update-subscription.js').updateSubscription 11 | }; 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # Optional REPL history 33 | .node_repl_history 34 | 35 | # filsystem files 36 | .DS_Store 37 | -------------------------------------------------------------------------------- /PayPalExpressCheckout/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | authorizationAndCaptureContinued: require('./authorization-and-capture-continued.js').authorizationAndCaptureContinued, 5 | authorizationAndCapture: require('./authorization-and-capture.js').authorizationAndCapture, 6 | authorizationOnlyContinued: require('./authorization-only-continued.js').authorizationOnlyContinued, 7 | authorizationOnly: require('./authorization-only.js').authorizationOnly, 8 | credit: require('./credit.js').credit, 9 | getDetails: require('./get-details.js').getDetails, 10 | priorAuthorizationCapture: require('./prior-authorization-capture.js').priorAuthorizationCapture, 11 | paypalVoid: require('./void.js').paypalVoid 12 | }; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sample-code-node", 3 | "version": "1.0.0", 4 | "description": "Sample code for nodejs sdk", 5 | "main": "constants.js", 6 | "dependencies": { 7 | "chai": "^3.5.0", 8 | "eslint": "^4.18.2", 9 | "yarn": "^1.22.10" 10 | }, 11 | "scripts": { 12 | "test": "echo \"Error: no test specified\" && exit 1" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git+https://github.com/AuthorizeNet/sample-code-node.git" 17 | }, 18 | "keywords": [ 19 | "AuthorizeNet", 20 | "sample", 21 | "codes" 22 | ], 23 | "author": "", 24 | "license": "ISC", 25 | "bugs": { 26 | "url": "https://github.com/AuthorizeNet/sample-code-node/issues" 27 | }, 28 | "homepage": "https://github.com/AuthorizeNet/sample-code-node#readme" 29 | } 30 | -------------------------------------------------------------------------------- /Sha512/compute_trans_hashSHA2.js: -------------------------------------------------------------------------------- 1 | var sha512 = require('js-sha512'); 2 | var apiLogin ="2Kfn5S7x7D"; 3 | var transId ="60115585081"; 4 | var amount ='12.00'; 5 | var signatureKey = '56E529FE6C63D60E545F84686096E6AA01D5E18A119F18A130F7CFB3983104216979E95D84C91BDD382AA0875264A63940A2D0AA5548F6023B4C78A9D52C18DA'; 6 | var textToHash = "^" + apiLogin + "^" + transId + "^" + amount + "^"; 7 | 8 | function generateSHA512(textToHash, signatureKey) 9 | { 10 | if (textToHash != null && signatureKey != null) { 11 | var sig = sha512.hmac(Buffer.from(signatureKey, 'hex'), textToHash).toUpperCase(); 12 | console.log("Computed SHA512 Hash: " + sig + "\n"); 13 | } else { 14 | console.log("Either Signature key or the text to hash is empty \n"); 15 | } 16 | } 17 | 18 | generateSHa512(textToHash, signatureKey); 19 | -------------------------------------------------------------------------------- /PaymentTransactions/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | authorizeCreditCard: require('./authorize-credit-card.js').authorizeCreditCard, 5 | chargeCreditCard: require('./charge-credit-card.js').chargeCreditCard, 6 | capturePreviouslyAuthorizedAmount: require('./capture-previously-authorized-amount.js').capturePreviouslyAuthorizedAmount, 7 | captureFundsAuthorizedThroughAnotherChannel: require('./capture-funds-authorized-through-another-channel.js').captureFundsAuthorizedThroughAnotherChannel, 8 | refundTransaction: require('./refund-transaction.js').refundTransaction, 9 | voidTransaction: require('./void-transaction.js').voidTransaction, 10 | updateSplitTenderGroup: require('./update-split-tender-group.js').updateSplitTenderGroup, 11 | debitBankAccount: require('./debit-bank-account.js').debitBankAccount, 12 | creditBankAccount: require('./credit-bank-account.js').creditBankAccount, 13 | chargeCustomerProfile: require('./charge-customer-profile.js').chargeCustomerProfile, 14 | chargeTokenizedCreditCard: require('./charge-tokenized-credit-card.js').chargeTokenizedCreditCard 15 | }; 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Authorize.Net 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /list_of_sample_codes.txt: -------------------------------------------------------------------------------- 1 | SampleCode,RunApi 2 | authorizeCreditCard,1 3 | chargeCreditCard,1 4 | capturePreviouslyAuthorizedAmount,1 5 | captureFundsAuthorizedThroughAnotherChannel,1 6 | refundTransaction,0 7 | voidTransaction,1 8 | updateSplitTenderGroup,1 9 | debitBankAccount,1 10 | creditBankAccount,0 11 | chargeCustomerProfile,1 12 | chargeTokenizedCreditCard,1 13 | cancelSubscription,1 14 | createSubscriptionFromCustomerProfile,1 15 | createSubscription,1 16 | getListOfSubscriptions,1 17 | getSubscriptionStatus,1 18 | getSubscription,1 19 | updateSubscription,1 20 | getBatchStatistics,1 21 | getSettledBatchList,1 22 | getTransactionDetails,1 23 | getTransactionList,1 24 | getTransactionListForCustomer,1 25 | getUnsettledTransactionList,1 26 | createVisaSrcTransaction,0 27 | decryptVisaSrcData,1 28 | authorizationAndCaptureContinued,1 29 | authorizationAndCapture,1 30 | authorizationOnlyContinued,1 31 | authorizationOnly,1 32 | credit,0 33 | getDetails,1 34 | priorAuthorizationCapture,0 35 | paypalVoid,0 36 | createApplePayTransaction,0 37 | createCustomerPaymentProfile,1 38 | createCustomerProfile,1 39 | createCustomerShippingAddress,1 40 | deleteCustomerPaymentProfile,1 41 | deleteCustomerProfile,1 42 | deleteCustomerShippingAddress,1 43 | getCustomerPaymentProfile,1 44 | getCustomerPaymentProfileList,1 45 | getCustomerProfileIds,0 46 | getCustomerProfile,1 47 | getCustomerShippingAddress,1 48 | updateCustomerPaymentProfile,1 49 | updateCustomerProfile,1 50 | updateCustomerShippingAddress,1 51 | validateCustomerPaymentProfile,1 52 | createCustomerProfileFromTransaction,1 -------------------------------------------------------------------------------- /CustomerProfiles/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | createCustomerPaymentProfile: require('./create-customer-payment-profile.js').createCustomerPaymentProfile, 5 | createCustomerProfile: require('./create-customer-profile.js').createCustomerProfile, 6 | createCustomerShippingAddress: require('./create-customer-shipping-address.js').createCustomerShippingAddress, 7 | deleteCustomerPaymentProfile: require('./delete-customer-payment-profile.js').deleteCustomerPaymentProfile, 8 | deleteCustomerProfile: require('./delete-customer-profile.js').deleteCustomerProfile, 9 | deleteCustomerShippingAddress: require('./delete-customer-shipping-address.js').deleteCustomerShippingAddress, 10 | getCustomerPaymentProfile: require('./get-customer-payment-profile.js').getCustomerPaymentProfile, 11 | getCustomerPaymentProfileList: require('./get-customer-payment-profile-list.js').getCustomerPaymentProfileList, 12 | getCustomerProfileIds: require('./get-customer-profile-ids.js').getCustomerProfileIds, 13 | getCustomerProfile: require('./get-customer-profile.js').getCustomerProfile, 14 | getCustomerShippingAddress: require('./get-customer-shipping-address.js').getCustomerShippingAddress, 15 | updateCustomerPaymentProfile: require('./update-customer-payment-profile.js').updateCustomerPaymentProfile, 16 | updateCustomerProfile: require('./update-customer-profile.js').updateCustomerProfile, 17 | updateCustomerShippingAddress: require('./update-customer-shipping-address.js').updateCustomerShippingAddress, 18 | validateCustomerPaymentProfile: require('./validate-customer-payment-profile.js').validateCustomerPaymentProfile, 19 | createCustomerProfileFromTransaction: require('./create-customer-profile-from-transaction.js').createCustomerProfileFromTransaction 20 | }; -------------------------------------------------------------------------------- /RecurringBilling/cancel-subscription.js: -------------------------------------------------------------------------------- 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 cancelSubscription(subscriptionId, callback) { 8 | var merchantAuthenticationType = new ApiContracts.MerchantAuthenticationType(); 9 | merchantAuthenticationType.setName(constants.apiLoginKey); 10 | merchantAuthenticationType.setTransactionKey(constants.transactionKey); 11 | 12 | var cancelRequest = new ApiContracts.ARBCancelSubscriptionRequest(); 13 | cancelRequest.setMerchantAuthentication(merchantAuthenticationType); 14 | cancelRequest.setSubscriptionId(subscriptionId); 15 | 16 | console.log(JSON.stringify(cancelRequest.getJSON(), null, 2)); 17 | 18 | var ctrl = new ApiControllers.ARBCancelSubscriptionController(cancelRequest.getJSON()); 19 | 20 | ctrl.execute(function(){ 21 | 22 | var apiResponse = ctrl.getResponse(); 23 | 24 | if (apiResponse != null) var response = new ApiContracts.ARBCancelSubscriptionResponse(apiResponse); 25 | 26 | console.log(JSON.stringify(response, null, 2)); 27 | 28 | if(response != null){ 29 | if(response.getMessages().getResultCode() == ApiContracts.MessageTypeEnum.OK){ 30 | console.log('Message Code : ' + response.getMessages().getMessage()[0].getCode()); 31 | console.log('Message Text : ' + response.getMessages().getMessage()[0].getText()); 32 | } 33 | else{ 34 | console.log('Result Code: ' + response.getMessages().getResultCode()); 35 | console.log('Error Code: ' + response.getMessages().getMessage()[0].getCode()); 36 | console.log('Error message: ' + response.getMessages().getMessage()[0].getText()); 37 | } 38 | } 39 | else{ 40 | var apiError = ctrl.getError(); 41 | console.log(apiError); 42 | console.log('Null Response.'); 43 | } 44 | 45 | callback(response); 46 | }); 47 | } 48 | 49 | if (require.main === module) { 50 | cancelSubscription('4058648', function(){ 51 | console.log('cancelSubscription call complete.'); 52 | }); 53 | } 54 | 55 | module.exports.cancelSubscription = cancelSubscription; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Node.js Sample Code for the Authorize.Net SDK 2 | 3 | 4 | This repository contains working code samples which demonstrate Node.js integration with the [Authorize.Net Node.js SDK](https://github.com/AuthorizeNet/sdk-node). 5 | 6 | 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. 7 | 8 | 9 | ## Using the Sample Code 10 | 11 | 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. 12 | 13 | You can also run each sample directly from the command line. 14 | 15 | ## Running the Samples From the Command Line 16 | * Clone this repository: 17 | ``` 18 | $ git clone https://github.com/AuthorizeNet/sample-code-node.git 19 | ``` 20 | * Install the [Authorize.Net Node.js SDK](https://www.github.com/AuthorizeNet/sdk-node): 21 | ``` 22 | $ npm install authorizenet 23 | ``` 24 | * Run the individual samples by name. For example: 25 | ``` 26 | $ node PaymentTransactions\[CodeSampleName] 27 | ``` 28 | e.g. 29 | ``` 30 | $ node PaymentTransactions\authorize-credit-card.js 31 | ``` 32 | 33 | ## For using behind proxy 34 | 35 | 1. Create a `config` object as follows: 36 | ```javascript 37 | config = { 38 | 'proxy': { 39 | 'setProxy': true, 40 | 'proxyUrl': 'http://:@:' 41 | } 42 | } 43 | ``` 44 | 45 | 2. Pass this `config` object to the controller constructor. 46 | 47 | For example, 48 | 49 | ```javascript 50 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON(), config); 51 | ``` -------------------------------------------------------------------------------- /RecurringBilling/get-subscription.js: -------------------------------------------------------------------------------- 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 getSubscription(subscriptionId, callback) { 8 | var merchantAuthenticationType = new ApiContracts.MerchantAuthenticationType(); 9 | merchantAuthenticationType.setName(constants.apiLoginKey); 10 | merchantAuthenticationType.setTransactionKey(constants.transactionKey); 11 | 12 | var getRequest = new ApiContracts.ARBGetSubscriptionRequest(); 13 | getRequest.setMerchantAuthentication(merchantAuthenticationType); 14 | getRequest.setSubscriptionId(subscriptionId); 15 | 16 | console.log(JSON.stringify(getRequest.getJSON(), null, 2)); 17 | 18 | var ctrl = new ApiControllers.ARBGetSubscriptionController(getRequest.getJSON()); 19 | 20 | ctrl.execute(function(){ 21 | var apiResponse = ctrl.getResponse(); 22 | 23 | if (apiResponse != null) var response = new ApiContracts.ARBGetSubscriptionResponse(apiResponse); 24 | 25 | console.log(JSON.stringify(response, null, 2)); 26 | 27 | if(response != null){ 28 | if(response.getMessages().getResultCode() == ApiContracts.MessageTypeEnum.OK){ 29 | console.log('Subscription Name : ' + response.getSubscription().getName()); 30 | console.log('Message Code : ' + response.getMessages().getMessage()[0].getCode()); 31 | console.log('Message Text : ' + response.getMessages().getMessage()[0].getText()); 32 | } 33 | else{ 34 | console.log('Result Code: ' + response.getMessages().getResultCode()); 35 | console.log('Error Code: ' + response.getMessages().getMessage()[0].getCode()); 36 | console.log('Error message: ' + response.getMessages().getMessage()[0].getText()); 37 | } 38 | } 39 | else{ 40 | var apiError = ctrl.getError(); 41 | console.log(apiError); 42 | console.log('Null Response.'); 43 | } 44 | 45 | 46 | callback(response); 47 | }); 48 | } 49 | 50 | if (require.main === module) { 51 | getSubscription('4058648', function(){ 52 | console.log('getSubscription call complete.'); 53 | }); 54 | } 55 | 56 | module.exports.getSubscription = getSubscription; -------------------------------------------------------------------------------- /CustomerProfiles/delete-customer-profile.js: -------------------------------------------------------------------------------- 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 deleteCustomerProfile(customerProfileId, callback) { 8 | 9 | var merchantAuthenticationType = new ApiContracts.MerchantAuthenticationType(); 10 | merchantAuthenticationType.setName(constants.apiLoginKey); 11 | merchantAuthenticationType.setTransactionKey(constants.transactionKey); 12 | 13 | var deleteRequest = new ApiContracts.DeleteCustomerProfileRequest(); 14 | deleteRequest.setMerchantAuthentication(merchantAuthenticationType); 15 | deleteRequest.setCustomerProfileId(customerProfileId); 16 | 17 | //pretty print request 18 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 19 | 20 | var ctrl = new ApiControllers.DeleteCustomerProfileController(deleteRequest.getJSON()); 21 | 22 | ctrl.execute(function(){ 23 | 24 | var apiResponse = ctrl.getResponse(); 25 | 26 | if (apiResponse != null) var response = new ApiContracts.DeleteCustomerProfileResponse(apiResponse); 27 | 28 | //pretty print response 29 | //console.log(JSON.stringify(response, null, 2)); 30 | 31 | if(response != null) 32 | { 33 | if(response.getMessages().getResultCode() == ApiContracts.MessageTypeEnum.OK) 34 | { 35 | console.log('Successfully deleted a customer profile with id: ' + customerProfileId); 36 | } 37 | else 38 | { 39 | //console.log('Result Code: ' + response.getMessages().getResultCode()); 40 | console.log('Error Code: ' + response.getMessages().getMessage()[0].getCode()); 41 | console.log('Error message: ' + response.getMessages().getMessage()[0].getText()); 42 | } 43 | } 44 | else 45 | { 46 | var apiError = ctrl.getError(); 47 | console.log(apiError); 48 | console.log('Null response received'); 49 | } 50 | 51 | callback(response); 52 | }); 53 | } 54 | 55 | if (require.main === module) { 56 | deleteCustomerProfile('1929176986', function(){ 57 | console.log('deleteCustomerProfile call complete.'); 58 | }); 59 | } 60 | 61 | module.exports.deleteCustomerProfile = deleteCustomerProfile; -------------------------------------------------------------------------------- /PaymentTransactions/update-split-tender-group.js: -------------------------------------------------------------------------------- 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 updateSplitTenderGroup(callback) { 8 | var merchantAuthenticationType = new ApiContracts.MerchantAuthenticationType(); 9 | merchantAuthenticationType.setName(constants.apiLoginKey); 10 | merchantAuthenticationType.setTransactionKey(constants.transactionKey); 11 | 12 | var updateRequest = new ApiContracts.UpdateSplitTenderGroupRequest(); 13 | updateRequest.setMerchantAuthentication(merchantAuthenticationType); 14 | updateRequest.setSplitTenderId('115901'); 15 | updateRequest.setSplitTenderStatus(ApiContracts.SplitTenderStatusEnum.VOIDED); 16 | 17 | //pretty print request 18 | console.log(JSON.stringify(updateRequest.getJSON(), null, 2)); 19 | 20 | var ctrl = new ApiControllers.UpdateSplitTenderGroupController(updateRequest.getJSON()); 21 | 22 | ctrl.execute(function(){ 23 | 24 | var apiResponse = ctrl.getResponse(); 25 | 26 | if (apiResponse != null) var response = new ApiContracts.UpdateSplitTenderGroupResponse(apiResponse); 27 | 28 | //pretty print response 29 | console.log(JSON.stringify(response, null, 2)); 30 | 31 | if(response != null){ 32 | if(response.getMessages().getResultCode() == ApiContracts.MessageTypeEnum.OK){ 33 | console.log('Text: ' + response.getMessages().getMessage()[0].getText()); 34 | } 35 | else{ 36 | console.log('Result Code: ' + response.getMessages().getResultCode()); 37 | console.log('Error Code: ' + response.getMessages().getMessage()[0].getCode()); 38 | console.log('Error message: ' + response.getMessages().getMessage()[0].getText()); 39 | } 40 | } 41 | else{ 42 | var apiError = ctrl.getError(); 43 | console.log(apiError); 44 | console.log('Null Response.'); 45 | } 46 | 47 | 48 | 49 | callback(response); 50 | }); 51 | } 52 | 53 | if (require.main === module) { 54 | updateSplitTenderGroup(function(){ 55 | console.log('updatedSplitTenderGroup call complete.'); 56 | }); 57 | } 58 | 59 | module.exports.updateSplitTenderGroup = updateSplitTenderGroup; -------------------------------------------------------------------------------- /RecurringBilling/get-subscription-status.js: -------------------------------------------------------------------------------- 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 getSubscriptionStatus(subscriptionId, callback) { 8 | var merchantAuthenticationType = new ApiContracts.MerchantAuthenticationType(); 9 | merchantAuthenticationType.setName(constants.apiLoginKey); 10 | merchantAuthenticationType.setTransactionKey(constants.transactionKey); 11 | 12 | var getRequest = new ApiContracts.ARBGetSubscriptionStatusRequest(); 13 | getRequest.setMerchantAuthentication(merchantAuthenticationType); 14 | getRequest.setSubscriptionId(subscriptionId); 15 | 16 | console.log(JSON.stringify(getRequest.getJSON(), null, 2)); 17 | 18 | var ctrl = new ApiControllers.ARBGetSubscriptionStatusController(getRequest.getJSON()); 19 | 20 | ctrl.execute(function(){ 21 | var apiResponse = ctrl.getResponse(); 22 | 23 | if (apiResponse != null) var response = new ApiContracts.ARBGetSubscriptionStatusResponse(apiResponse); 24 | 25 | console.log(JSON.stringify(response, null, 2)); 26 | 27 | if(response != null){ 28 | if(response.getMessages().getResultCode() == ApiContracts.MessageTypeEnum.OK){ 29 | console.log('Status : ' + response.getStatus()); 30 | console.log('Message Code : ' + response.getMessages().getMessage()[0].getCode()); 31 | console.log('Message Text : ' + response.getMessages().getMessage()[0].getText()); 32 | } 33 | else{ 34 | console.log('Result Code: ' + response.getMessages().getResultCode()); 35 | console.log('Error Code: ' + response.getMessages().getMessage()[0].getCode()); 36 | console.log('Error message: ' + response.getMessages().getMessage()[0].getText()); 37 | } 38 | } 39 | else{ 40 | var apiError = ctrl.getError(); 41 | console.log(apiError); 42 | console.log('Null Response.'); 43 | } 44 | 45 | callback(response); 46 | }); 47 | } 48 | 49 | if (require.main === module) { 50 | getSubscriptionStatus('4058648', function(){ 51 | console.log('getSubscriptionStatus call complete.'); 52 | }); 53 | } 54 | 55 | module.exports.getSubscriptionStatus = getSubscriptionStatus; -------------------------------------------------------------------------------- /CustomerProfiles/get-customer-profile-ids.js: -------------------------------------------------------------------------------- 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 getCustomerProfileIds(callback) { 8 | 9 | var merchantAuthenticationType = new ApiContracts.MerchantAuthenticationType(); 10 | merchantAuthenticationType.setName(constants.apiLoginKey); 11 | merchantAuthenticationType.setTransactionKey(constants.transactionKey); 12 | 13 | var getRequest = new ApiContracts.GetCustomerProfileIdsRequest(); 14 | getRequest.setMerchantAuthentication(merchantAuthenticationType); 15 | 16 | //pretty print request 17 | //console.log(JSON.stringify(getRequest.getJSON(), null, 2)); 18 | 19 | var ctrl = new ApiControllers.GetCustomerProfileIdsController(getRequest.getJSON()); 20 | 21 | ctrl.execute(function(){ 22 | 23 | var apiResponse = ctrl.getResponse(); 24 | 25 | if (apiResponse != null) var response = new ApiContracts.GetCustomerProfileIdsResponse(apiResponse); 26 | 27 | //pretty print response 28 | //console.log(JSON.stringify(response, null, 2)); 29 | 30 | if(response != null) 31 | { 32 | if(response.getMessages().getResultCode() == ApiContracts.MessageTypeEnum.OK) 33 | { 34 | console.log('List of Customer profile Ids : '); 35 | var profileIds = response.getIds().getNumericString(); 36 | for (var i=0;i