rocketgate-ruby

Build Status Coverage Status Code Climate

RocketGate's Payment Gateway, minus the painful integration.

Installation

Add this line to your application's Gemfile:

gem 'rocketgate-ruby'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rocketgate-ruby

Usage

Configuration

Before you can jump in, you need to configure the gem with your RocketGate credentials:

RocketGate.configure do |config|
  config.merchant_id        = 'rocketgate_merchant_id'
  config.merchant_password  = 'rocketgate_merchant_password'
end

You can also supply other configuration settings:

RocketGate.configure do |config|
  config.merchant_id        = 'rocketgate_merchant_id'
  config.merchant_password  = 'rocketgate_merchant_password'
  config.currency           = 'USD'
  config.request_host       = 'special-gateway.rocketgate.com'
  config.request_path       = '/specialServlet'
  config.request_port       = 8080
  config.request_timeout    = 5
  config.request_version    = 'R2.0'
  config.require_avs        = false
  config.require_cvv        = false
  config.require_scrub      = false
  config.require_ssl        = false
end

And if you want to test something against the sandbox gateway:

RocketGate.configuration.testing!

Making an Authorization Request

In order to get an authorization, you'll need to send a request to the gateway.

  1. Build a Customer and CreditCard so we know who and how to charge:
  customer    = RocketGate::Customer.new('John', 'Doe', '123 Main St', 'Beverly Hills', 'CA', '90210')  
  credit_card = RocketGate::CreditCard.new('4111-1111-1111-1111', '08', '2042', '012')
  1. Build a Transaction
  transaction     = RocketGate::Transaction.new(9.99, customer, credit_card)
  1. Set the transaction type
  transaction.type = RocketGate::Transaction::TYPE[:purchase]
  1. Optionally, add an identifier that ties the transaction and customer to something relevant for you, like a User or Invoice. (A UUID will be generated if not.)
  credit_card.id = User.id
  transaction.id = Invoice.id
  1. Build a Request
  request = RocketGate::Request.new(transaction)
  1. Send the request to the gateway
  response = RocketGate.send_request!(request)
  1. Check the Response
  response.authorized?            # => true (authorization OK)
  response.success?               # => true (authorization + gateway response OK)
  1. Confirm receipt of the transaction response (Note: RocketGate will cancel your transaction if you don't confirm it!)
  response.confirm! # => returns a Response like the original request

Authorizations

In the section above you created and sent a request, then looked at the response. The response's Authorization has lots of great information, too.

authorization = response.authorization

authorization.avs_ok?           # => AVS check OK or disabled
authorization.cvv_ok?           # => CVV check OK or disabled
authorization.success?          # => AVS check + CVV check + reason code OK
authorization.declined?         # => opposite of success?
authorization.auth_code         # => authorization code from gateway, may be blank
authorization.reason_code       # => descriptive(ish) reason for the response
authorization.approved_amount   # => dollar amount of authorization (should match transaction)
authorization.approved_currency # => currency the authorization settled in (should match transaction)
authorization.card_hash         # => unique hash of the card data which can be used later
authorization.card_expiration   # => 4-digit representation of the card expiration
authorization.card_last_four    # => the last four digits of the card charged
authorization.reference_id      # => unique reference ID used to confirm, void or reverse the request

Not Yet Implemented (Future Plans)

  • Rebill functionality

Compatibility

This library supports Ruby >= 1.9.3 on a variety of platforms.

Travis CI builds every commit under these environments:

  • MRI 1.9.3, 2.0.0, 2.1.1 and HEAD
  • JRuby 1.7.11 (1.9 mode) and HEAD
  • Rubinius 2.2.1

Other interpreters and earlier versions of MRI, JRuby and RBX are not supported.

Contributing

  1. Fork it ( https://github.com/ccashwell/rocketgate-ruby/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request