Authorize.net

  • Tags: ecommerce
  • Latest: 0.12
  • Last Updated: 28 June 2010
  • Grails version: 1.2.2 > *
  • Authors: null
0 vote
Dependency:
compile ":authorize-net:0.12"

 Documentation

Summary

Installation

grails install-plugin authorize-net

Description

The Authorize.net plugin allows you to do authorize/capture, void, and refunds through Authorize.net.

Author: Bob Pawlowski (bobp at webcleats dot com)

Sign up for an Authorize.Net developer's account (if you don't already have one)

In addition to installing the plugin, you need to have an authorize.net account. If you do not have one, you can get a developer test account here:

http://developer.authorize.net/testaccount/

Right now this plugin only uses the AIM connection method so make sure it is checked when signing up for your Authorize.net developer's account. Future plans for this plugin include the CIM connection method, so you'll want to include this also. CIM allows you to store and retrieve sensitive information, e.g., credit card information, in a PCI compliant way to Authorize.net.

Edit AuthorizeNetConfig.groovy

Next, edit the AuthorizeNetConfig.groovy in the grails-app/conf directory to add your Authorize.net login and transactionKey.

authorizeNet {
    testMode = false
    duplicateWindow = '120'  //Default is 120 (2 minutes)
    delimiter = ';'
}

environments { development { authorizeNet { login = '<--PUT LOGIN ID HERE-->' transactionKey = '<--PUT TRANSACTION KEY HERE-->' urlString = 'https://test.authorize.net/gateway/transact.dll' } } }

Add import statement to files that will use the plugin

import com.vinomis.authnet.AuthorizeNet

Examples

Authorize and Capture (charge credit card) with minimal information

def s = new AuthorizeNet()
    s.authorizeAndCapture {
        amount '100.00'
        ccNumber '370000000000002'
        cvv '122'
        ccExpDate '012011'
        email 'john@acme.com'
        invoiceId '123'        
    }

def anr = s.submit() println anr

Authorize and Capture (charge credit card) with full information

def s = new AuthorizeNet()

//NOTE: If you need to override the login and transaction keys from the configuration, you can do it here: // s.login = 'XXXXX' // s.transactionKey = 'XXXXX'

s.authorizeAndCapture { custId '20' description 'orderDescription' firstName 'John' lastName 'Doe' address '100 Main St.' city 'Cranberry Twp.' state 'PA' amount '180.00' zip '16066' phone '7241112222' country 'USA' company 'Acme Inc.' ccNumber '370000000000002' cvv '122' ccExpDate '012011' email 'john@acme.com' invoiceId '123' shipToLastName 'Doe' shipToFirstName 'John' shipToAddress 'Main St.' shipToCity 'Cranberry Twp.' shipToState 'PA' shipToZip '16066' shipToPhone '7241112222' shipToCountry 'USA' shipToCompany 'Acme Inc.' item (id:'12', name:'widget', description:'Super Widgets', price:'25.0', quantity:'4', taxable:'NO') item (id:'13', name:'widget2', description:'Normal Widgets', price:'10.0', quantity:'8', taxable:'NO') } def anr = s.submit() println anr

Authorize and Capture for bank accounts. Note that all you need is a valid bankAbaCode (routing number) for testing. Everything else can be fake.

def s = new AuthorizeNet()
    s.echeck {
        amount '0.20'
        bankAbaCode '123456789' //TODO: Replace this with any valid bank routing number'
        bankAcctNum '1234567890'
        bankAcctType 'CHECKING'   //Can be CHECKING, SAVINGS, BUSINESSCHECKING
        bankName 'Foo Bank'
        bankAcctName 'John Smith'
        echeckType 'WEB'
        recurringBilling 'NO'
        email 'john@acme.com'
        invoiceId '123'        
    }
   def anr = s.submit()
   println "$anr.responseReasonCode: $anr.responseReasonText"

Authorize Only

def s = new AuthorizeNet()
    s.authorizeOnly {
        amount '100.00'
        ccNumber '370000000000002'
        cvv '122'
        ccExpDate '012011'
        email 'john@acme.com'
        invoiceId '123'        
    }

def anr = s.submit() println anr

Capture Previous Authorization

def s = new AuthorizeNet()
    s.capturePriorAuthorization {
        amount '100.00'  // Only needed if this amount is less than the original authorization. It cannot be more.
        txid '2151828130'  //TODO: Replace this txId
    }

def anr = s.submit() println anr

Void an unsettled credit card transaction

def s = new AuthorizeNet()
 s.void {
     txid '2151828130'  //TODO: Replace this txId
 }

def anr = s.submit() println anr

Void unsettled echeck (bank account) transaction

def s = new AuthorizeNet()
 s.echeckVoid {
     txid '2152324019'  //TODO: Replace this txId
     amount '.10'
     email 'john@acme.com'
 }
    def anr = s.submit()
   println anr
   println "$anr.responseReasonCode: $anr.responseReasonText"
}

Credit a settled transaction (won't work unless Transaction has been settled.)

def s = new AuthorizeNet()
 s.credit {
     txid '2151828130'  //TODO: Replace this txId
     amount '3.00'
     ccNumber '0002'  //Just last 4 digits of credit card are needed
     email 'bobp@webcleats.com'
 }
    def anr = s.submit()
   println anr

Credit a settled echeck transaction

def s = new AuthorizeNet()
 s.echeckCredit {
     txid '2152324019'  //TODO: Replace this txId
     amount '.10'
     email 'bob@vinomis.com'
     bankAbaCode '6789'  //TODO: enter last 3 digits of bank routing number
     bankAcctNum '7890' //TODO: enter last 4 digits of bank account number
 }
    def anr = s.submit()
   println anr
   println "$anr.responseReasonCode: $anr.responseReasonText"

Additional Notes

  • For a full list of input parameters, see the AIM Developer's guide: http://www.authorize.net/support/AIM_guide.pdf. Each paramter can be specified in three different ways:
    • x_card_num
    • card_num
    • cardNum
    • NOTE: The plugin also adds additional names to certain parameters. For example, you can reference x_card_num by ccNumber.
  • For information on the Authorize.net echeck api: http://developer.authorize.net/guides/echeck.pdf
  • Each call returns an AuthorizeNetResponse object. the fields are as follows:
static def paramNames = [
     'responseCode', 'responseSubCode','responseReasonCode','responseReasonText','authorizationCode',
     'avsResponse', 'transactionId', 'invoiceNumber', 'description', 'amount',
     'method', 'type', 'customerId', 'billingFirstName','billingLastName',
     'billingCompany', 'billingAddress','billingCity','billingState','billingZipCode',
     'billingCountry','billingPhone','billingFax','email','shippingFirstName',
     'shippingLastName','shippingCompany','shippingAddress','shippingCity', 'shippingState',
     'shippingZipCode', 'shippingCountry', 'tax', 'duty','freight',
     'taxExempt','purchaseOrderNumber','md5Hash','cardCodeResponse','cardholderAuthenticationVerificationResponse'
 ]

Release History

DateVersionDetails
2010-01-25.1Initial release: authorize and capture, credit, void
2010-02-24.11echeck support
2010-06-29.12Add support for authorization only

Roadmap

  • Support for the Authrorize.net CIM API. This allows for Credit Cards and Bank Accounts to be saved in a PCI compliant way.