Authorize.net Automated Recurring Billing (ARB) support for nodejs. Check out Authorize.net's ARB page for more info about their service. You will need to be familiar with the ARB XML API (PDF) in order to know what fields are appropriate to use and when to use them.
First off, you will need to create an ARB client object with your API login ID and transaction key.
var arb = require("authorize-net-arb");
var arbClient = arb.client("my-api-login-id", "my-transaction-key");
You can also use ARB in sandbox mode. All requests will go to Authorize.net's sandbox server after this mode is enabled.
var arb = require("authorize-net-arb");
arb.useSandbox();
All methods take two parameters. The first is an object whose properties closely mirror the nodes of the "request" XML documents of each API call described in Authorize.net's documentation. The second is a callback that receives two parameters: an error object and a response object. If the operation was successful, the error parameter will have a value of undefined
. The response parameter will contain any non-error related info returned by the API call.
This library makes no effort to make sure the values you specify in your request are well formed before sending it. You must adhere to the rules outlined in Authorize.net's documentation.
var arb = require("authorize-net-arb");
var arbClient = arb.client("my-api-login-id", "my-transaction-key");
var request = {
refId: "my-ref",
subscription: {
name: "my-subscription",
order: {
invoiceNumber: "inv-0001",
description: "My Subscription"
},
paymentSchedule: {
interval: {
length: 1,
unit: "months"
},
startDate: "2015-01-31",
totalOccurrences: 9999,
trialOccurrences: 1
},
amount: 19.99,
trialAmount: 0,
payment: {
creditCard: {
cardNumber: "4111111111111111",
expirationDate: "2020-01",
cardCode: "111"
}
},
customer: {
id: "abc123",
email: "[email protected]",
phoneNumber: "555-555-5555",
faxNumber: "555-555-5555"
},
billTo: {
firstName: "Jane",
lastName: "Doe",
address: "123 Main St",
city: "Anytown",
state: "CA",
zip: "11111",
country: "US"
},
shipTo: {
firstName: "Jane",
lastName: "Doe",
address: "123 Main St",
city: "Anytown",
state: "CA",
zip: "11111",
country: "US"
}
}
};
arbClient.createSubscription(request, function(error, response) {
if (error) {
// handle error response
} else {
// handle success
}
});
If the call succeeds, the response
object will have the format:
{
refId: "my-ref",
subscriptionId: "1234567890"
}
var arb = require("authorize-net-arb");
var arbClient = arb.client("my-api-login-id", "my-transaction-key");
var request = {
refId: "my-ref",
subscriptionId: "1234567890",
subscription: {
name: "my-subscription",
paymentSchedule: {
startDate: "2015-01-31",
totalOccurrences: 9999,
trialOccurrences: 1
},
amount: 19.99,
trialAmount: 0,
payment: {
creditCard: {
cardNumber: "4111111111111111",
expirationDate: "2020-01",
cardCode: "111"
}
},
customer: {
id: "abc123"
},
billTo: {
firstName: "Jane",
lastName: "Doe",
address: "123 Main St"
},
shipTo: {
firstName: "Jane",
lastName: "Doe",
address: "123 Main St"
}
}
};
arbClient.updateSubscription(request, function(error, response) {
if (error) {
// handle error response
} else {
// handle success
}
});
If the call succeeds, the response
object will have the format:
{
refId: "my-ref"
}
var arb = require("authorize-net-arb");
var arbClient = arb.client("my-api-login-id", "my-transaction-key");
var request = {
refId: "my-ref",
subscriptionId: "1234567890"
};
arbClient.getSubscriptionStatus(request, function(error, response) {
if (error) {
// handle error response
} else {
// handle success
}
});
If the call succeeds, the response
object will have the format:
{
refId: "my-ref",
status: "active|expired|suspended|canceled|terminated"
}
var arb = require("authorize-net-arb");
var arbClient = arb.client("my-api-login-id", "my-transaction-key");
var request = {
refId: "my-ref",
subscriptionId: "1234567890"
};
arbClient.cancelSubscription(request, function(error, response) {
if (error) {
// handle error response
} else {
// handle success
}
});
If the call succeeds, the response
object will have the format:
{
refId: "my-ref"
}
Error objects returned by method calls will generally have source
, refId
, and message
properties. If the error was returned by Authorize.net, it will usually have a code
property as well. If an unexpected response was received from the API server, a response
property with the entire response text should be present.