Ruby Psigate Library

Psigate (http://www.psigate.com) is a Canadian company which specializes in payment transactions over the internet. They support real time transactions and recurring billing options with a stored credit card accounts.

The purpose of this library to allow Ruby applications to interact with Psigate's API.

Why not use Active Merchant instead?

Active Merchant is a library that supports many different gateways. If you were to, say, build an online shopping cart, and must support 10-20 gateways because the store owner may be partnered with any one of those companies, then Active Merchant is the appropriate choice. However, if you were building a service based web application, and you happened to use Psigate, then Active Merchant's features do not necessarily fulfill what you need. Specifically, if you wished to create billing profiles (eg. for recurring billings), Active Merchant's API does not currently support that option.

I am sure there are many edge cases that require more specific features of Psigate's API, and so this library attempts to satisfy those needs.

Underneath the hood, Ruby Psigate differs from Active Merchant in that it uses XML to communicate with Psigate's servers rather than through posted parameters.

Disclaimer: Parts of this library were based on Active Merchant's design

Installation

In your terminal, just type: gem install ruby-psigate

Then, in your application: require 'ruby_psigate'

Usage

1) First initialize your gateway instance object

@gateway = RubyPsigate::Gateway.new( :cid => "1000001", :login => "teststore", :password => "test1234" )

The library defaults to TEST environment. When you are ready to use it in production environment, simply:

RubyPsigate::Gateway.test = false

2) You can treat this object as the "params container" you want to send to psigate to process. But first you must specify whether you want to send it to Psigate's xml transaction server (for pre auth/post auth/sale/void/refund type of transactions) or to Psigate's account manager server (for creating recurring accounts, viewing existing accounts, changing charges for recurring accounts)

@gateway.mode = :transaction

or

@gateway.mode = :account_manager

4) Say we are using the transaction server (@gateway = :transaction), and we want to create a "SALE" transaction. The RubyPsigate library contains several other classes beside the RubyPsigate::Gateway class, in order to help you organize the data you will be sending to Psigate.

First, there is the RubyPsigate::Address class. This class simply allows you to create an instance to hold together address information. The purpose of separating this out to its own class is so that if you wanted to specify a shipping and billing address, you can simply by referring it to the same instance object.

@address = RubyPsigate::Address.new( :email => "[email protected]", :firstname => "Bob", :lastname => "John", :company => "Bob John's Company", :line1 => "1234 Alley Street", :line2 => nil, :city => "Los Caltown", :state => "California", :zipcode => "12345", :country => "USA", :telephone => "416-123-1232", :fax => nil )

@gateway.billing = @address @gateway.shipping = @address

4) Next, there is the RubyPsigate::CreditCard class. This class does some basic validations that the credit card you've provided is a valid one. Since Psigate only accepts Visa/Mastercard/Amex, if you try to enter something other than these three, an error will be raised.

@credit_card = RubyPsigate::CreditCard.new( :number => "4111111111111111", :month => "9", :year => "2010", :name => "Bob John" )

@gateway.cc = @credit_card

5) Specify the amount you will be charging. This is done via the instance object #amount:

@gateway.amount = "10.00"

6) Finally, tell the object what you want it to do. Depending on the action you want the object to take, you may or may not have provided enough details and an error may be raised. However, for this example, we have enough information for the object to post a "SALE" to Psigate.

@gateway.sale!

7) There are a lot of different functionalities to the RubyPsigate library, such as adding items and option details to the order. Please look at the source documentation for details!

Authors

Ruby Psigate is created by Simon Chiu.

Parts of this software is based on Active Merchant. Active Merchant is written by Tobias Luetke, Cody Fauser, and contributors.