Ruby SOAP Guide

Downloads

You can download the files below or create them by running the command:

wsdl2ruby.rb --wsdl https://www.usaepay.com/soap/gate/*********/usaepay.wsdl --type client

for Sandbox Server use Sandbox wsdl link. You can generate a link in the Developer's Center.

File Version Release Date Description
Download usaepay_ruby_live.zip 1.0.0 3/21/11 Library for Live/Production
Download usaepay_ruby_sandbox.zip 1.0.0 3/21/11 Library for Sandbox

Usage

Step 1: Import Classes

In classes that are going to use the USAePay SOAP methods or object, you need to include the appropriate classes. The following will import all usaepay objects at once:

    require 'usaepayDriver'

If you place files in another directory, you should specify the correct path to usaepayDriver.rb

Step 2: Instantiate client Object

All calls to the USAePay SOAP servers are handled by a "client" object of type "UeSoapServerPortType". To instantiate a client:

    # Instantiate client
    @client=UeSoapServerPortType.new

Step 3: Generate Security Token

A "token" object (of type UeSecurityToken) is required by all SOAP methods in the USAePay API. It is used to identify the merchant.

    # Create security token
    require 'digest'

    def getToken(key,pin)
        token=UeSecurityToken.new
        token.clientIP = "123.123.123.123"
        hash=UeHash.new
        t=Time.now
        seed = "#{t.year}#{t.month}#{t.day}#{t.hour}#{rand(1000)}"
        prehash = "#{key}#{seed}#{pin.to_s.strip}"
        hash.seed=seed
        hash.type="sha1"
        hash.hashValue=Digest::SHA1.hexdigest(prehash).to_s
        token.pinHash = hash
        token.sourceKey=key
        return token
    end

    token=getToken("YOUR_SOURCE KEY","1234")

Step 4: Calling a SOAP Method

SOAP methods are called using the client object. Below is an example for calling the runTransaction method. For further examples see the SOAP API documentation.

    request=TransactionRequestObject.new
    request.accountHolder="TesterJones"
    request.command="sale"

    details=TransactionDetail.new
    details.amount="1.00"
    details.description="example sale"
    request.details=details

    creditcard=CreditCardData.new
    creditcard.avsStreet="123 main st."
    creditcard.avsZip="90010"
    creditcard.cardNumber="4444555566667779"
    creditcard.cardExpiration="1212"
    request.creditCardData=creditcard

    @client=UeSoapServerPortType.new
    response=@client.runTransaction(token,request)
    p "RefNum:#{response.refNum}"

Additional Documentation

For additional documentation please see the main Soap API v1.6 Documentation. It includes a description of all methods and their parameters as well as examples.

Troubleshooting

uninitialized constant SOAP::Mapping::EncodedRegistry

Make sure that you have soap4r installed or install it by running :

gem install soap4r --include-dependencies

and add the following to /config/environment.rb:

require 'rubygems'
gem 'soap4r'

For questions please email devsupport@usaepay.com