Giter Club home page Giter Club logo

node-authorize-net-arb's Introduction

authorize-net-arb

Build Status Coverage Status

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.

Usage

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();

Methods

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.

Create Subscription

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"
}

Update Subscription

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"
}

Get Subscription Status

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"
}

Cancel Subscription

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"
}

Errors

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.

node-authorize-net-arb's People

Contributors

reywood avatar

Watchers

macinnir avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.