### Complete SDK Configuration Example Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/configuration.md A comprehensive example demonstrating the setup of merchant authentication, transaction details, payment information, and SDK configuration including timeout, logger, and proxy settings for a sandbox environment. ```javascript var ApiContracts = require('authorizenet').APIContracts; var ApiControllers = require('authorizenet').APIControllers; var Constants = require('authorizenet').Constants; var merchant = new ApiContracts.MerchantAuthenticationType(); merchant.setName('API_LOGIN_ID'); merchant.setTransactionKey('TRANSACTION_KEY'); var config = { timeout: 45000, logger: { enabled: true, level: 'info', location: './logs' }, proxy: { setProxy: false } }; var transactionRequest = new ApiContracts.TransactionRequestType(); transactionRequest.setTransactionType(ApiContracts.TransactionTypeEnum.AUTHCAPTURETRANSACTION); var card = new ApiContracts.CreditCardType(); card.setCardNumber('4242424242424242'); card.setExpirationDate('0825'); var payment = new ApiContracts.PaymentType(); payment.setCreditCard(card); transactionRequest.setPayment(payment); transactionRequest.setAmount('25.00'); var request = new ApiContracts.CreateTransactionRequest(); request.setMerchantAuthentication(merchant); request.setTransactionRequest(transactionRequest); var ctrl = new ApiControllers.CreateTransactionController(request.getJSON(), config); ctrl.setEnvironment(Constants.endpoint.sandbox); ctrl.execute(function() { var apiResponse = ctrl.getResponse(); var response = new ApiContracts.CreateTransactionResponse(apiResponse); console.log('Result: ' + response.getMessages().getResultCode()); }); ``` -------------------------------- ### Install Authorize.Net SDK Source: https://github.com/authorizenet/sdk-node/blob/master/README.md Use npm to install the Authorize.Net SDK. Ensure your Node.js version is 14.x.x or higher. ```bash npm install authorizenet ``` -------------------------------- ### Execute AuthenticateTestController Example Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Provides a complete example of how to use the AuthenticateTestController. It demonstrates setting merchant authentication, executing the controller, and checking the response to verify credentials. ```javascript var request = new ApiContracts.AuthenticateTestRequest(); request.setMerchantAuthentication(merchant); var ctrl = new ApiControllers.AuthenticateTestController(request.getJSON()); ctrl.execute(function() { var response = new ApiContracts.AuthenticateTestResponse(ctrl.getResponse()); if (response.getMessages().getResultCode() === ApiContracts.MessageTypeEnum.OK) { console.log('Credentials are valid'); } }); ``` -------------------------------- ### Execute API Request with Proxy Configuration Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/configuration.md Example of setting up and executing an API request controller with proxy configuration. ```javascript var config = { proxy: { setProxy: true, proxyUrl: 'http://corp-proxy:3128' } }; var request = new ApiContracts.CreateTransactionRequest(); // ... set request fields ... var ctrl = new ApiControllers.CreateTransactionController( request.getJSON(), config ); ctrl.execute(function() { // Handle response }); ``` -------------------------------- ### Setup Merchant Credentials Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/quick-reference.md Set up your merchant authentication with API Login ID and Transaction Key. ```javascript var merchant = new ApiContracts.MerchantAuthenticationType(); merchant.setName('YOUR_API_LOGIN_ID'); merchant.setTransactionKey('YOUR_TRANSACTION_KEY'); ``` -------------------------------- ### Initialize Paging Parameters Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/advanced-types.md Sets up pagination for API requests. You can specify the number of results per page and the starting offset. ```javascript new ApiContracts.Paging({ limit?: string, offset?: string }) ``` -------------------------------- ### Enable and Configure Logging Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/configuration.md Enable SDK logging and specify the log level and output directory. This example enables logging and sets the level to 'debug'. ```javascript var config = { logger: { enabled: true, location: './logs', level: 'debug' } }; ``` -------------------------------- ### Usage of PaymentScheduleType and Interval Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/advanced-types.md Example of configuring a payment schedule with a specific interval, start date, and occurrence counts for a subscription. ```javascript var interval = new ApiContracts.PaymentScheduleType.Interval(); interval.setLength('1'); interval.setUnit(ApiContracts.ARBSubscriptionUnitEnum.MONTHS); var schedule = new ApiContracts.PaymentScheduleType(); schedule.setInterval(interval); schedule.setStartDate('2025-02-01'); schedule.setTotalOccurrences('12'); schedule.setTrialOccurrences('1'); // One free trial subscription.setPaymentSchedule(schedule); ``` -------------------------------- ### Perform Basic Authorization and Capture Transaction Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/quick-reference.md This example demonstrates how to create and execute a basic authorization and capture transaction using the SDK. Ensure you have set up your merchant credentials and imported the necessary modules. ```javascript // Create credit card var card = new ApiContracts.CreditCardType(); card.setCardNumber('4242424242424242'); card.setExpirationDate('0825'); // Create payment var payment = new ApiContracts.PaymentType(); payment.setCreditCard(card); // Create transaction request var transactionRequest = new ApiContracts.TransactionRequestType(); transactionRequest.setTransactionType(ApiContracts.TransactionTypeEnum.AUTHCAPTURETRANSACTION); transactionRequest.setPayment(payment); transactionRequest.setAmount('25.00'); // Create and execute transaction var request = new ApiContracts.CreateTransactionRequest(); request.setMerchantAuthentication(merchant); request.setTransactionRequest(transactionRequest); var ctrl = new ApiControllers.CreateTransactionController(request.getJSON()); ctrl.setEnvironment(Constants.endpoint.sandbox); ctrl.execute(function() { var apiResponse = ctrl.getResponse(); var response = new ApiContracts.CreateTransactionResponse(apiResponse); if (response.getMessages().getResultCode() === 'Ok') { console.log('Transaction successful: ' + response.getTransactionResponse().getTransId()); } else { console.error('Transaction failed'); } }); ``` -------------------------------- ### Set Credit Card Details and Payment Type Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/types-core.md Example of setting credit card details and associating them with a PaymentType object. ```javascript var card = new ApiContracts.CreditCardType(); card.setCardNumber('4242424242424242'); card.setExpirationDate('0825'); card.setCardCode('123'); var payment = new ApiContracts.PaymentType(); payment.setCreditCard(card); ``` -------------------------------- ### Usage of OrderType Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/advanced-types.md Example of creating an OrderType object and setting its properties before associating it with a transaction request. ```javascript var order = new ApiContracts.OrderType(); order.setInvoiceNumber('INV-2025-001'); order.setDescription('Monthly subscription payment'); order.setPurchaseOrderNumber('PO-98765'); transactionRequest.setOrder(order); ``` -------------------------------- ### Get Settled Batch List Controller Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Instantiate this controller to retrieve a list of settled batches. Requires request data and external configuration. ```javascript new GetSettledBatchListController(requestJSON, externalConfig) ``` -------------------------------- ### Get Merchant Details Controller Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/specialized-operations.md Instantiate the controller for retrieving merchant account configuration and settings. Requires request JSON and external configuration. ```javascript new ApiControllers.GetMerchantDetailsController(requestJSON, externalConfig) ``` -------------------------------- ### Handling Specific Network/HTTP Errors Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/error-handling.md This example shows how to identify and handle specific network or HTTP error codes returned by `ctrl.getError()`, such as timeouts or DNS failures. ```javascript ctrl.execute(function() { var error = ctrl.getError(); if (error) { if (error.code === 'ECONNABORTED') { console.error('Request timeout'); } else if (error.code === 'ENOTFOUND') { console.error('DNS resolution failed'); } else if (error.code === 'ECONNREFUSED') { console.error('Connection refused'); } else { console.error('HTTP error: ' + error.message); } } }); ``` -------------------------------- ### Usage: Create Customer Profile From Transaction Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/specialized-operations.md Demonstrates how to set up and execute the creation of a customer profile from a transaction. This involves setting merchant authentication, transaction ID, and then processing the response to get customer and payment profile IDs. ```javascript var request = new ApiContracts.CreateCustomerProfileFromTransactionRequest(); request.setMerchantAuthentication(merchant); request.setTransId(transactionId); var ctrl = new ApiControllers.CreateCustomerProfileFromTransactionController(request.getJSON()); ctrl.execute(function() { var response = new ApiContracts.CreateCustomerProfileFromTransactionResponse(ctrl.getResponse()); var customerId = response.getCustomerProfileId(); var paymentProfileId = response.getCustomerPaymentProfileIdList()[0]; }); ``` -------------------------------- ### Get Batch Statistics Controller Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Instantiate this controller to retrieve statistics for a specific batch. Requires request data and external configuration. ```javascript new GetBatchStatisticsController(requestJSON, externalConfig) ``` -------------------------------- ### Get Transaction List for Customer Controller Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Instantiate this controller to retrieve a list of transactions for a specific customer. Requires request data and external configuration. ```javascript new GetTransactionListForCustomerController(requestJSON, externalConfig) ``` -------------------------------- ### Sensitive Field Masking Example Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/configuration.md Demonstrates how sensitive fields like cardNumber and expirationDate are masked with 'X' characters in log output. ```json [2025-01-15T10:30:45.123Z] [DEBUG] [ApiOperationBase]: { "cardNumber": "XXXXXXXXXXXXXXXX", "expirationDate": "XXXX", "cardCode": "XXX", "transactionKey": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" } ``` -------------------------------- ### Create a New Recurring Billing Subscription Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Use ARBCreateSubscriptionController to create a new recurring billing subscription. This example demonstrates setting up subscription details, payment schedule, and payment information. ```javascript var subscription = new ApiContracts.ARBSubscriptionType(); subscription.setName('Monthly Subscription'); var paymentSchedule = new ApiContracts.PaymentScheduleType(); paymentSchedule.setInterval(new ApiContracts.PaymentScheduleType.Interval()); paymentSchedule.getInterval().setLength(1); paymentSchedule.getInterval().setUnit(ApiContracts.ARBSubscriptionUnitEnum.MONTHS); paymentSchedule.setStartDate(new Date()); paymentSchedule.setTotalOccurrences(12); subscription.setPaymentSchedule(paymentSchedule); subscription.setAmount('99.99'); var payment = new ApiContracts.PaymentType(); var creditCard = new ApiContracts.CreditCardType(); creditCard.setCardNumber('4242424242424242'); creditCard.setExpirationDate('0825'); payment.setCreditCard(creditCard); subscription.setPayment(payment); var createRequest = new ApiContracts.ARBCreateSubscriptionRequest(); createRequest.setMerchantAuthentication(merchant); createRequest.setSubscription(subscription); var ctrl = new ApiControllers.ARBCreateSubscriptionController(createRequest.getJSON()); ctrl.execute(function() { var response = new ApiContracts.ARBCreateSubscriptionResponse(ctrl.getResponse()); var subscriptionId = response.getSubscriptionId(); }); ``` -------------------------------- ### Set HTTP Request Timeout Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/configuration.md Configure the HTTP request timeout duration in milliseconds. This example sets the timeout to 60 seconds. ```javascript var config = { timeout: 60000 // 60 seconds }; var ctrl = new ApiControllers.CreateTransactionController(requestJSON, config); ``` -------------------------------- ### Google Pay Payment Type Setup Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/specialized-operations.md Configure the payment type for Google Pay transactions. Requires an encrypted payment token obtained from the Google Pay framework. ```javascript var opaqueData = new ApiContracts.OpaqueData(); opaqueData.setDataDescriptor('COMMON.GOOGLE.INAPP.PAYMENT'); opaqueData.setDataValue(encryptedPaymentToken); var payment = new ApiContracts.PaymentType(); payment.setGooglePaymentToken(opaqueData); transactionRequest.setPayment(payment); ``` -------------------------------- ### Chase Pay Transaction Setup Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/specialized-operations.md Set up a transaction for Chase Pay, a tokenized payment method. Note that Chase Pay uses the Apple Payment Token field for its opaque data. ```javascript transactionRequest.setTransactionType(ApiContracts.TransactionTypeEnum.AUTHCAPTURETRANSACTION); var payment = new ApiContracts.PaymentType(); var opaqueData = new ApiContracts.OpaqueData(); opaqueData.setDataDescriptor('COMMON.CHASE.INAPP.PAYMENT'); opaqueData.setDataValue(chasePaymentToken); payment.setApplePaymentToken(opaqueData); // Using Apple field for Chase transactionRequest.setPayment(payment); ``` -------------------------------- ### Production Configuration with Short Timeout Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/configuration.md Configure the SDK for production with a reduced timeout of 30 seconds. ```javascript var config = { timeout: 30000 // 30 seconds }; var ctrl = new ApiControllers.CreateTransactionController(requestJSON, config); ctrl.setEnvironment(Constants.endpoint.production); ctrl.execute(callback); ``` -------------------------------- ### PaymentScheduleType Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/advanced-types.md Defines the payment schedule for recurring billing, including interval, start date, and total/trial occurrences. ```APIDOC ## PaymentScheduleType ### Description Defines the payment schedule for recurring billing. ### Properties - **interval** (Interval) - Optional - Payment interval (length and unit) - **startDate** (string) - Optional - Start date (YYYY-MM-DD) - **totalOccurrences** (string) - Optional - Total number of payments - **trialOccurrences** (string) - Optional - Number of trial period payments ### Methods - `setInterval(p_interval)` / `getInterval()` - `setStartDate(p_startDate)` / `getStartDate()` - `setTotalOccurrences(p_totalOccurrences)` / `getTotalOccurrences()` - `setTrialOccurrences(p_trialOccurrences)` / `getTrialOccurrences()` ``` -------------------------------- ### Configure Proxy Settings for SDK Source: https://github.com/authorizenet/sdk-node/blob/master/README.md Set up proxy configuration for SDK requests. Ensure the proxy URL includes username, password, host, and port. ```javascript config = { 'proxy': { 'setProxy': true, 'proxyUrl': 'http://:@:' } } ``` -------------------------------- ### Get AU Job Summary Controller Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/specialized-operations.md Instantiate the GetAUJobSummaryController to retrieve a summary of Account Updater jobs. ```javascript new ApiControllers.GetAUJobSummaryController(requestJSON, externalConfig) ``` -------------------------------- ### Get AU Job Details Controller Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/specialized-operations.md Instantiate the GetAUJobDetailsController to retrieve details for an Account Updater job. ```javascript new ApiControllers.GetAUJobDetailsController(requestJSON, externalConfig) ``` -------------------------------- ### Initialize and Execute CreateTransactionRequest Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/README.md Demonstrates how to initialize merchant authentication, build a CreateTransactionRequest, and execute it using the CreateTransactionController. This pattern is useful for processing various transaction types. ```javascript // Initialization var merchant = new ApiContracts.MerchantAuthenticationType(); merchant.setName('API_LOGIN_ID'); merchant.setTransactionKey('TRANSACTION_KEY'); // Building request var request = new ApiContracts.CreateTransactionRequest(); request.setMerchantAuthentication(merchant); // Executing operation var ctrl = new ApiControllers.CreateTransactionController(request.getJSON()); ctrl.execute(function() { var response = new ApiContracts.CreateTransactionResponse(ctrl.getResponse()); }); ``` -------------------------------- ### Paging Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/advanced-types.md Specifies pagination parameters for retrieving data, allowing control over the number of results per page and the starting offset. ```APIDOC ## Paging ### Description Pagination parameters. ### Fields - **limit** (string) - Optional - Results per page (1-1000). Defaults to 1000. - **offset** (string) - Optional - Starting offset. Defaults to 0. ### Usage ```javascript var paging = new ApiContracts.Paging(); paging.setLimit('100'); paging.setOffset('200'); // Skip first 200 results request.setPaging(paging); ``` ``` -------------------------------- ### Development Configuration with Detailed Logging Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/configuration.md Configure the SDK for development with detailed logging enabled and set to 'debug' level, logging to the './logs' directory. ```javascript var config = { timeout: 120000, logger: { enabled: true, level: 'debug', location: './logs' } }; var ctrl = new ApiControllers.CreateTransactionController(requestJSON, config); ctrl.execute(callback); ``` -------------------------------- ### IsAliveController Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Tests basic API connectivity. This controller checks if the API is responsive. ```APIDOC ## IsAliveController ### Description Tests basic API connectivity. ### Method Not specified (instantiated with `new`) ### Endpoint Not specified ### Parameters - `requestJSON` (object) - Required - The request payload for the alive check. - `externalConfig` (object) - Required - External configuration for the controller. ### Request Example ```javascript new IsAliveController(requestJSON, externalConfig) ``` ### Response - `IsAliveResponse` (object) - The response object indicating the API's status. ``` -------------------------------- ### Get Message Object Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Retrieves the message object from the API response, which contains details about the result code and any associated messages. ```javascript var message = controller.getMessagetype(); ``` -------------------------------- ### Corporate Proxy Environment Configuration Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/configuration.md Configure the SDK to use a corporate proxy with specific authentication, a 60-second timeout, and info-level logging to '/var/log/payments'. ```javascript var config = { timeout: 60000, proxy: { setProxy: true, proxyUrl: 'http://proxy-user:password@proxy.corp.local:3128' }, logger: { enabled: true, level: 'info', location: '/var/log/payments' } }; var ctrl = new ApiControllers.CreateTransactionController(requestJSON, config); ``` -------------------------------- ### Configure API Client Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/quick-reference.md Set up configuration options for the API client, such as timeout and logging. ```javascript var config = { timeout: 30000, // 30 seconds logger: { enabled: true, level: 'info', location: './logs' }, proxy: { setProxy: false } }; var ctrl = new ApiControllers.CreateTransactionController(requestJSON, config); ``` -------------------------------- ### Get API Error Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Retrieves any error object encountered during the API request execution. Returns null if the request was successful. ```javascript var error = controller.getError(); ``` -------------------------------- ### Configure API Controller with Options Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Pass a configuration object to the controller constructor to set timeouts, proxy settings, and logging preferences. ```javascript var config = { timeout: 60000, proxy: { setProxy: true, proxyUrl: 'http://proxy.example.com:8080' }, logger: { enabled: true, level: 'debug', location: '/var/log' } }; var ctrl = new ApiControllers.CreateTransactionController(requestJSON, config); ``` -------------------------------- ### Configure Proxy for Transaction Controller Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/quick-reference.md Set up proxy configuration by defining the proxy object with `setProxy` and `proxyUrl`. This configuration is then passed to the `CreateTransactionController`. ```javascript var config = { proxy: { setProxy: true, proxyUrl: 'http://proxy.example.com:8080' } }; var ctrl = new ApiControllers.CreateTransactionController(requestJSON, config); ctrl.execute(callback); ``` -------------------------------- ### Switch to Production Environment Source: https://github.com/authorizenet/sdk-node/blob/master/README.md To use the production environment instead of the default sandbox, call `setEnvironment` on the controller variable with `SDKConstants.endpoint.production`. ```javascript // For PRODUCTION use ctrl.setEnvironment(SDKConstants.endpoint.production); ``` -------------------------------- ### Get API Response Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Retrieves the parsed API response object after the request has been executed. Returns null if the request has not yet completed. ```javascript var response = controller.getResponse(); ``` -------------------------------- ### Instantiate GetHostedProfilePageController Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/specialized-operations.md Instantiates the GetHostedProfilePageController with request JSON and external configuration. ```javascript new ApiControllers.GetHostedProfilePageController(requestJSON, externalConfig) ``` -------------------------------- ### Instantiate PaymentScheduleType Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/advanced-types.md Defines the payment schedule for recurring billing. Use this to set the interval, start date, total occurrences, and trial occurrences. ```javascript new ApiContracts.PaymentScheduleType({ interval?: PaymentScheduleType.Interval, startDate?: string, totalOccurrences?: string, trialOccurrences?: string }) ``` -------------------------------- ### Instantiate IsAliveController Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Instantiates the controller for testing basic API connectivity. This is a simple check to ensure the Authorize.Net API is reachable and responsive. ```javascript new IsAliveController(requestJSON, externalConfig) ``` -------------------------------- ### Instantiate Controller with Proxy Configuration Source: https://github.com/authorizenet/sdk-node/blob/master/README.md Pass the configuration object, including proxy settings, to the ApiControllers constructor when creating a transaction. ```javascript var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON(), config); ``` -------------------------------- ### Create Customer Profile Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/quick-reference.md Create a new customer profile with individual details and email. ```javascript var customer = new ApiContracts.CustomerType(); customer.setType(ApiContracts.CustomerTypeEnum.INDIVIDUAL); customer.setEmail('customer@example.com'); var request = new ApiContracts.CreateCustomerProfileRequest(); request.setMerchantAuthentication(merchant); request.setProfile(customer); var ctrl = new ApiControllers.CreateCustomerProfileController(request.getJSON()); ctrl.execute(function() { var response = new ApiContracts.CreateCustomerProfileResponse(ctrl.getResponse()); var customerId = response.getCustomerProfileId(); }); ``` -------------------------------- ### Set Paging Options Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/advanced-types.md Demonstrates how to instantiate and configure Paging parameters, then apply them to a request object. The limit defaults to 1000 and offset to 0 if not specified. ```javascript var paging = new ApiContracts.Paging(); paging.setLimit('100'); paging.setOffset('200'); // Skip first 200 results request.setPaging(paging); ``` -------------------------------- ### Main Entry Point Export Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/overview.md This code snippet shows the main components exported from the SDK's entry point file, lib/authorizenet.js. It includes the APIContracts, APIControllers, and Constants modules. ```javascript module.exports = { APIContracts: require('./apicontracts.js'), APIControllers: require('./apicontrollers.js'), Constants: require('./constants.js').constants }; ``` -------------------------------- ### Get Customer Shipping Address Controller Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Instantiate this controller to retrieve an existing shipping address for a customer. Requires request data and external configuration. ```javascript new GetCustomerShippingAddressController(requestJSON, externalConfig) ``` -------------------------------- ### Get Transaction Details Request and Response Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/request-response-types.md Retrieve details for a previously submitted transaction using its ID. Requires merchant authentication and the transaction ID. ```javascript var request = new ApiContracts.GetTransactionDetailsRequest(); request.setMerchantAuthentication(merchant); request.setTransId('TRANS_ID_123'); var ctrl = new ApiControllers.GetTransactionDetailsController(request.getJSON()); ctrl.execute(function() { var response = new ApiContracts.GetTransactionDetailsResponse(ctrl.getResponse()); var transaction = response.getTransaction(); console.log('Amount: ' + transaction.getAmount()); console.log('Status: ' + transaction.getTransactionStatus()); }); ``` -------------------------------- ### Initialize GetHostedPaymentPageController Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/specialized-operations.md Initializes the GetHostedPaymentPageController to generate a secure hosted payment page token and URL. Requires a request JSON and external configuration. ```javascript new ApiControllers.GetHostedPaymentPageController(requestJSON, externalConfig) ``` -------------------------------- ### Retrieve AVS and CVV Result Codes Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/error-handling.md Get the AVS and CVV result codes from the transaction response object. These codes are crucial for fraud detection. ```javascript var transactionResponse = response.getTransactionResponse(); var avsCode = transactionResponse.getAvsResultCode(); var cvvCode = transactionResponse.getCvvResultCode(); // Process AVS and CVV responses ``` -------------------------------- ### Enable Detailed Logging Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/quick-reference.md Configure the SDK to enable detailed logging. Logs are saved to a file in the specified location and sensitive fields are automatically masked. ```javascript var config = { logger: { enabled: true, level: 'debug', location: './logs' } }; // Logs go to: ./logs/sdk-node-YYYY-MM-DD.log // Sensitive fields are masked automatically ``` -------------------------------- ### Accessing Transaction-Level Errors Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/error-handling.md This example shows how to access and log specific error details from the `TransactionResponse` object for transaction-related requests, including the error code and text. ```javascript var response = new ApiContracts.CreateTransactionResponse(ctrl.getResponse()); var transactionResponse = response.getTransactionResponse(); if (transactionResponse) { var responseCode = transactionResponse.getResponseCode(); var errors = transactionResponse.getErrors(); if (errors) { errors.forEach(function(error) { console.error('Error Code: ' + error.getErrorCode()); console.error('Error Text: ' + error.getErrorText()); }); } } ``` -------------------------------- ### Instantiate SecurePaymentContainerController Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/specialized-operations.md Instantiates the SecurePaymentContainerController with request JSON and external configuration for initiating a secure payment container. ```javascript new ApiControllers.SecurePaymentContainerController(requestJSON, externalConfig) ``` -------------------------------- ### CreateCustomerShippingAddressController Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Creates a shipping address for a customer. It takes a request JSON and external configuration as input. ```APIDOC ## CreateCustomerShippingAddressController ### Description Creates a shipping address for a customer. ### Usage ```javascript new CreateCustomerShippingAddressController(requestJSON, externalConfig) ``` ### Request Type `CreateCustomerShippingAddressRequest` ### Response Type `CreateCustomerShippingAddressResponse` ``` -------------------------------- ### Run Specific SDK Tests Source: https://github.com/authorizenet/sdk-node/blob/master/README.md Execute a particular test file within the SDK's test suite. ```bash mocha test/ ``` -------------------------------- ### Get Customer Payment Profile List Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Instantiates the controller for retrieving a list of all payment profiles associated with a customer. Use this to view all stored payment methods. ```javascript new GetCustomerPaymentProfileListController(requestJSON, externalConfig) ``` -------------------------------- ### Get Customer Payment Profile Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Instantiates the controller for retrieving a specific payment profile. Use this to fetch details of a stored credit card or bank account. ```javascript new GetCustomerPaymentProfileController(requestJSON, externalConfig) ``` -------------------------------- ### CreateCustomerProfileController Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Creates a new customer profile. This controller takes a CreateCustomerProfileRequest and returns a CreateCustomerProfileResponse. ```APIDOC ## CreateCustomerProfileController ### Description Creates a new customer profile. ### Method Not applicable (SDK method) ### Endpoint Not applicable (SDK method) ### Parameters This controller accepts a `requestJSON` object of type `CreateCustomerProfileRequest` and an optional `externalConfig` object. ### Request Example ```javascript var customer = new ApiContracts.CustomerType(); customer.setType(ApiContracts.CustomerTypeEnum.INDIVIDUAL); customer.setId('CUSTOMER_ID'); customer.setEmail('customer@example.com'); var createRequest = new ApiContracts.CreateCustomerProfileRequest(); createRequest.setMerchantAuthentication(merchant); createRequest.setProfile(customer); var ctrl = new ApiControllers.CreateCustomerProfileController(createRequest.getJSON()); ctrl.execute(function() { var response = new ApiContracts.CreateCustomerProfileResponse(ctrl.getResponse()); var customerId = response.getCustomerProfileId(); }); ``` ### Response #### Success Response Returns a `CreateCustomerProfileResponse` object containing the new customer profile ID. ``` -------------------------------- ### Apple Pay Payment Type Setup Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/specialized-operations.md Configure the payment type for Apple Pay transactions. Requires an encrypted payment token obtained from the Apple Pay framework. ```javascript var opaqueData = new ApiContracts.OpaqueData(); opaqueData.setDataDescriptor('COMMON.APPLE.INAPP.PAYMENT'); opaqueData.setDataValue(encryptedPaymentToken); var payment = new ApiContracts.PaymentType(); payment.setApplePaymentToken(opaqueData); transactionRequest.setPayment(payment); ``` -------------------------------- ### Create Customer Profile From Transaction Controller Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/specialized-operations.md Instantiate the controller for automatically creating a customer profile from a transaction. Requires request JSON and external configuration. ```javascript new ApiControllers.CreateCustomerProfileFromTransactionController(requestJSON, externalConfig) ``` -------------------------------- ### Get Result Code Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Retrieves the result code from the API response. This indicates the overall status of the transaction (e.g., 'Ok', 'Error'). Returns null if no response is available. ```javascript var resultCode = controller.getResultcode(); ``` -------------------------------- ### Proxy Configuration with Authentication Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/configuration.md Configure HTTPS proxy settings with username and password authentication for API requests. ```javascript var config = { proxy: { setProxy: true, proxyUrl: 'http://user:password@proxy.example.com:8080' } }; ``` -------------------------------- ### Instantiate GetHostedProfilePageController Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Instantiates the controller for generating a Hosted Customer Profile Page URL. Use this to allow customers to manage their profiles on a secure, hosted page. ```javascript new GetHostedProfilePageController(requestJSON, externalConfig) ``` -------------------------------- ### Get Customer Payment Profile Nonce Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Instantiates the controller for retrieving a secure nonce for a payment profile. This nonce can be used for subsequent transactions without exposing sensitive payment details. ```javascript new GetCustomerPaymentProfileNonceController(requestJSON, externalConfig) ``` -------------------------------- ### Global Configuration Defaults Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/configuration.md The default SDK configuration is defined in `lib/config.js`. While direct editing is possible, it's not recommended for production environments. For persistent changes, consider modifying this file or consistently providing custom configurations to controllers. ```javascript // lib/config.js var config = { 'timeout': 120000, 'clientId': 'sdk-node-1.0.10', 'logger': { 'enabled': false, 'location': './', 'level': 'debug' }, 'proxy': { 'setProxy': false, 'proxyUrl': 'http://proxy.yourcompany.com:80' } }; ``` -------------------------------- ### Authenticate Test Request and Controller Usage Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/request-response-types.md Demonstrates how to create an AuthenticateTestRequest, set merchant authentication, and use the AuthenticateTestController to execute the request and process the response. Use this to verify merchant credentials. ```javascript var request = new ApiContracts.AuthenticateTestRequest(); request.setMerchantAuthentication(merchant); var ctrl = new ApiControllers.AuthenticateTestController(request.getJSON()); ctrl.execute(function() { var response = new ApiContracts.AuthenticateTestResponse(ctrl.getResponse()); if (response.getMessages().getResultCode() === 'Ok') { console.log('Credentials are valid'); } }); ``` -------------------------------- ### Implement Retry Logic for Timeouts in Node.js Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/error-handling.md Configure a timeout and implement a retry mechanism with exponential backoff for requests that time out. This example retries up to a maximum of 3 times with a 1-second delay between retries. ```javascript var config = { timeout: 30000 // 30 seconds }; var retryCount = 0; var maxRetries = 3; function executeWithRetry() { var ctrl = new ApiControllers.CreateTransactionController(requestJSON, config); ctrl.execute(function() { var error = ctrl.getError(); if (error && error.code === 'ECONNABORTED' && retryCount < maxRetries) { retryCount++; console.log('Request timed out, retrying (' + retryCount + '/' + maxRetries + ')'); setTimeout(executeWithRetry, 1000 * retryCount); // Exponential backoff } else { handleResponse(ctrl); } }); } executeWithRetry(); ``` -------------------------------- ### Run SDK Tests with Mocha Source: https://github.com/authorizenet/sdk-node/blob/master/README.md Execute all tests for the SDK using the mocha test runner. ```bash mocha ``` -------------------------------- ### Create SettingType Object Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/advanced-types.md Instantiate a SettingType object to configure merchant account settings. Properties are optional. ```javascript new ApiContracts.SettingType({ settingName?: string, settingValue?: string }) ``` -------------------------------- ### Instantiate LineItemType Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/advanced-types.md Represents a single line item in an order. Use this to define item details such as ID, name, description, quantity, unit price, and taxability. ```javascript new ApiContracts.LineItemType({ itemId?: string, name?: string, description?: string, quantity?: string, unitPrice?: string, taxable?: boolean }) ``` -------------------------------- ### Import SDK Modules Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/quick-reference.md Import necessary modules from the Authorize.Net Node.js SDK for use in your application. ```javascript var AuthorizeNet = require('authorizenet'); var ApiContracts = AuthorizeNet.APIContracts; var ApiControllers = AuthorizeNet.APIControllers; var Constants = AuthorizeNet.Constants; ``` -------------------------------- ### ARBGetSubscriptionController Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Retrieves details for a specific subscription. It takes a request object and an optional external configuration. ```APIDOC ## ARBGetSubscriptionController ### Description Retrieves details for a specific subscription. ### Method ```javascript new ARBGetSubscriptionController(requestJSON, externalConfig) ``` ### Request Type `ARBGetSubscriptionRequest` ### Response Type `ARBGetSubscriptionResponse` ``` -------------------------------- ### Instantiate GetMerchantDetailsController Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Instantiates the controller to retrieve merchant account settings. This is useful for auditing or displaying current merchant configurations. ```javascript new GetMerchantDetailsController(requestJSON, externalConfig) ``` -------------------------------- ### Configure Logging Level and Location Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/configuration.md Set the logging level to 'info' and specify a custom log file location. This configuration is only effective when logger.enabled is true. ```javascript var config = { logger: { enabled: true, level: 'info', location: '/var/log/myapp' } }; ``` -------------------------------- ### Basic Proxy Configuration Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/configuration.md Configure basic HTTPS proxy settings for API requests. ```javascript var config = { proxy: { setProxy: true, proxyUrl: 'http://proxy.example.com:8080' } }; ``` -------------------------------- ### ARBCreateSubscriptionController Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Creates a new recurring billing subscription. It takes a request object and an optional external configuration. ```APIDOC ## ARBCreateSubscriptionController ### Description Creates a new recurring billing subscription. ### Method ```javascript new ARBCreateSubscriptionController(requestJSON, externalConfig) ``` ### Request Type `ARBCreateSubscriptionRequest` ### Response Type `ARBCreateSubscriptionResponse` ### Example ```javascript var subscription = new ApiContracts.ARBSubscriptionType(); subscription.setName('Monthly Subscription'); var paymentSchedule = new ApiContracts.PaymentScheduleType(); paymentSchedule.setInterval(new ApiContracts.PaymentScheduleType.Interval()); paymentSchedule.getInterval().setLength(1); paymentSchedule.getInterval().setUnit(ApiContracts.ARBSubscriptionUnitEnum.MONTHS); paymentSchedule.setStartDate(new Date()); paymentSchedule.setTotalOccurrences(12); subscription.setPaymentSchedule(paymentSchedule); subscription.setAmount('99.99'); var payment = new ApiContracts.PaymentType(); var creditCard = new ApiContracts.CreditCardType(); creditCard.setCardNumber('4242424242424242'); creditCard.setExpirationDate('0825'); payment.setCreditCard(creditCard); subscription.setPayment(payment); var createRequest = new ApiContracts.ARBCreateSubscriptionRequest(); createRequest.setMerchantAuthentication(merchant); createRequest.setSubscription(subscription); var ctrl = new ApiControllers.ARBCreateSubscriptionController(createRequest.getJSON()); ctrl.execute(function() { var response = new ApiContracts.ARBCreateSubscriptionResponse(ctrl.getResponse()); var subscriptionId = response.getSubscriptionId(); }); ``` ``` -------------------------------- ### Create Customer Shipping Address Controller Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Instantiate this controller to create a new shipping address for a customer. Requires request data and external configuration. ```javascript new CreateCustomerShippingAddressController(requestJSON, externalConfig) ``` -------------------------------- ### Authorize.Net API Endpoints Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/quick-reference.md Reference for Authorize.Net API endpoints. Use Constants.endpoint.sandbox for testing and Constants.endpoint.production for live transactions. ```javascript // Sandbox (default) Constants.endpoint.sandbox // https://apitest.authorize.net/xml/v1/request.api // Production Constants.endpoint.production // https://api2.authorize.net/xml/v1/request.api ``` -------------------------------- ### Create ANetApiRequest Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/types-core.md Instantiate the base request object. Merchant authentication is required. ```javascript new ApiContracts.ANetApiRequest({ merchantAuthentication?: MerchantAuthenticationType, clientId?: string, refId?: string }) ``` -------------------------------- ### Initialize BatchDetailsType Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/advanced-types.md Represents the details of a settled batch. Includes batch ID, settlement times, state, payment method, and associated statistics. ```javascript new ApiContracts.BatchDetailsType({ batchId?: string, settlementTimeUTC?: string, settlementTimeLocal?: string, settlementState?: string, paymentMethod?: string, statistics?: Array }) ``` -------------------------------- ### Switch API Environment Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/quick-reference.md Change the active API environment for the controller. Use Constants.endpoint.production for live API calls. ```javascript ctrl.setEnvironment(Constants.endpoint.production); ``` -------------------------------- ### CustomerType Constructor Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/types-core.md Represents a customer. Use this to create a customer object with various optional fields. ```javascript new ApiContracts.CustomerType({ type?: string, id?: string, email?: string, phoneNumber?: string, faxNumber?: string, driversLicenseNum?: string, driversLicenseStateNum?: string, taxId?: string }) ``` -------------------------------- ### Create Customer Profile Transaction Controller Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/specialized-operations.md Instantiate the controller for creating a transaction from a customer profile. Requires request JSON and external configuration. ```javascript new ApiControllers.CreateCustomerProfileTransactionController(requestJSON, externalConfig) ``` -------------------------------- ### ARBGetSubscriptionListController Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Retrieves a list of subscriptions. It takes a request object and an optional external configuration. ```APIDOC ## ARBGetSubscriptionListController ### Description Retrieves a list of subscriptions. ### Method ```javascript new ARBGetSubscriptionListController(requestJSON, externalConfig) ``` ### Request Type `ARBGetSubscriptionListRequest` ### Response Type `ARBGetSubscriptionListResponse` ``` -------------------------------- ### Instantiate UpdateMerchantDetailsController Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Instantiates the controller for updating merchant account settings. Use this to modify configurations such as contact information or business details. ```javascript new UpdateMerchantDetailsController(requestJSON, externalConfig) ``` -------------------------------- ### Instantiate AuthenticateTestController Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/api-controllers.md Instantiates the controller to test merchant authentication credentials. This is a crucial step to ensure your API keys and login IDs are correctly configured. ```javascript new AuthenticateTestController(requestJSON, externalConfig) ``` -------------------------------- ### Instantiate OrderType Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/advanced-types.md Represents order-level information. Use this to set invoice number, description, and purchase order number. ```javascript new ApiContracts.OrderType({ invoiceNumber?: string, description?: string, purchaseOrderNumber?: string }) ``` -------------------------------- ### NameAndAddressType Constructor Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/types-core.md Represents a name and address. Use this to create an address object with optional fields for personal or company details. ```javascript new ApiContracts.NameAndAddressType({ firstName?: string, lastName?: string, company?: string, address?: string, city?: string, state?: string, zip?: string, country?: string }) ``` -------------------------------- ### Mobile Device Registration Controller Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/specialized-operations.md Instantiate the MobileDeviceRegistrationController to register a mobile device for authentication. ```javascript new ApiControllers.MobileDeviceRegistrationController(requestJSON, externalConfig) ``` -------------------------------- ### CreateCustomerProfileRequest / CreateCustomerProfileResponse Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/request-response-types.md Handles the creation of a new customer profile. Includes fields for merchant authentication, customer details, and validation mode. ```APIDOC ## CreateCustomerProfileRequest / CreateCustomerProfileResponse ### Description Request to create a new customer profile. ### Request Body - **merchantAuthentication** (MerchantAuthenticationType) - Required - Merchant authentication - **profile** (CustomerType) - Required - Customer information - **validationMode** (string) - Optional - Validation mode - **profileType** (string) - Optional - 'guest' or 'regular' ### Response #### Success Response (200) - **messages** (MessagesType) - Result code and messages - **customerProfileId** (string) - New customer profile ID - **customerPaymentProfileIdList** (Array) - Payment profile IDs - **customerShippingAddressIdList** (Array) - Shipping address IDs - **validationDirectResponseList** (Array) - Validation responses ### Usage Example ```javascript var customer = new ApiContracts.CustomerType(); customer.setType(ApiContracts.CustomerTypeEnum.INDIVIDUAL); customer.setId('CUST123'); customer.setEmail('customer@example.com'); customer.setPhoneNumber('1234567890'); var request = new ApiContracts.CreateCustomerProfileRequest(); request.setMerchantAuthentication(merchant); request.setProfile(customer); var ctrl = new ApiControllers.CreateCustomerProfileController(request.getJSON()); ctrl.execute(function() { var response = new ApiContracts.CreateCustomerProfileResponse(ctrl.getResponse()); var customerId = response.getCustomerProfileId(); }); ``` ``` -------------------------------- ### Create Customer Profile Request Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/request-response-types.md Use this snippet to create a new customer profile. It requires merchant authentication and customer details. ```javascript var customer = new ApiContracts.CustomerType(); customer.setType(ApiContracts.CustomerTypeEnum.INDIVIDUAL); customer.setId('CUST123'); customer.setEmail('customer@example.com'); customer.setPhoneNumber('1234567890'); var request = new ApiContracts.CreateCustomerProfileRequest(); request.setMerchantAuthentication(merchant); request.setProfile(customer); var ctrl = new ApiControllers.CreateCustomerProfileController(request.getJSON()); ctrl.execute(function() { var response = new ApiContracts.CreateCustomerProfileResponse(ctrl.getResponse()); var customerId = response.getCustomerProfileId(); }); ``` -------------------------------- ### Per-Controller Configuration Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/configuration.md Override default SDK settings for a specific request by passing a custom configuration object to the controller constructor. This allows for fine-grained control over timeouts, logging, and proxy settings on a per-request basis. ```javascript var customConfig = { timeout: 30000, logger: { enabled: true, level: 'info', location: './logs' }, proxy: { setProxy: true, proxyUrl: 'http://proxy.corp.com:8080' } }; var ctrl = new ApiControllers.CreateTransactionController( requestJSON, customConfig ); ``` -------------------------------- ### TransactionSummaryType Constructor Source: https://github.com/authorizenet/sdk-node/blob/master/_autodocs/advanced-types.md Provides summary information for a transaction within a list. Includes essential details like transaction ID, status, timestamps, amount, and authorization code. ```javascript new ApiContracts.TransactionSummaryType({ transId?: string, transactionStatus?: string, submitTime?: string, submitTimeUTC?: string, amount?: string, settleAmount?: string, description?: string, authCode?: string, accountNumber?: string, accountType?: string, refTransID?: string, splitTenderId?: string, ... }) ```