Class: ActiveTiger::Gateway

Inherits:
Object
  • Object
show all
Defined in:
lib/activetiger/gateway.rb

Overview

Overview

The Gateway class alows you to interact with Tiger Payment Processing.

First, we instantiate a gateway. If you’re using ActiveTiger in a rails application, there’s no need to provide username/password credentials on instantiation. ActiveTiger will look for a configuration file at:

config/activetiger/#{RAILS_ENV}.yml

Creating a Gateway

First we instantiate a gateway in a rails application:

# create a gateway from a rails app
gateway = ActiveTiger::Gateway.new

# create a gateway in any ruby application
gateway = ActiveTiger::Gateway.new(:username => "demo", :password => "password")

Gateway Actions

Once a Gateway is created, we can take many actions. Let’s look at each of these.

Sale

Charge a card immediately. You must provide a ccnumber, ccexp and amount as a minimum.

response = gateway.sale(
 :ccnumber => "4111111111111111", 
 :ccexp => "1010", 
 :amount => "1.00"
)

puts "Success!" if response.approved?

Authorize

Authorize the card to be captured in the future. Again, provide a ccnumber, ccexp and amount at a minumum. Store the resulting transaction_id to capture at a later time.

response = gateway.authorize(
 :ccnumber => "4111111111111111", 
 :ccexp => "1010", 
 :amount => "1.00"
)

# store transaction_id for capture later
transaction_id = response.transaction_id

Capture

Capture a previously authorized transaction. All you need is the transactionid.

response = gateway.capture(:transactionid => my_transaction_id)
puts "Success!" if response.approved?

Credit

Credit the card with some amount. Provide the ccnumber, ccexp and amount.

response = gateway.credit(
 :ccnumber => "4111111111111111", 
 :ccexp => "1010", 
 :amount => "1.00"
)

puts "you just gave them a buck" if response.approved?

Void

Void an uncaptured transaction. Just provide the transactionid.

response = gateway.void(:transactionid => my_transaction_id)
puts "voided ftw" if response.approved?

Refund

Refund a transaction that has already been sold or captured. Just give it that transactionid.

response = gateway.refund(:transactionid => my_transaction_id)
puts "refund-city" if response.approved?

Update

Update an uncaptured transaction. Just provide the transactionid.

response = gateway.update(:transactionid => my_transaction_id)
puts "updated" if response.approved?

Responses

For more info on how to deal with responses from the Gateway, check out the Response class.

Constant Summary collapse

TIGER_GATEWAY_URL =
"https://secure.tigergateway.net/api/transact.php"

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Gateway

Returns a new instance of Gateway.



101
102
103
104
105
106
107
108
109
110
# File 'lib/activetiger/gateway.rb', line 101

def initialize(params = {})
  if defined?(RAILS_ENV) && defined?(RAILS_ROOT)
    config = ActiveTiger::Configuration.new
    @username = config.username
    @password = config.password
  else
    @username = params[:username]
    @password = params[:password]
  end
end

Instance Method Details

#add_recurring(params) ⇒ Object



124
125
126
127
# File 'lib/activetiger/gateway.rb', line 124

def add_recurring(params)
  params.merge! :type => 'add_recurring'
  make_request(params)
end

#add_recurring_and_charge(params) ⇒ Object



129
130
131
132
# File 'lib/activetiger/gateway.rb', line 129

def add_recurring_and_charge(params)
  params.merge! :type => 'sale'
  make_request(params)
end

#authorize(params) ⇒ Object



119
120
121
122
# File 'lib/activetiger/gateway.rb', line 119

def authorize(params)
  params.merge! :type => "auth"
  make_request(params)
end

#delete_recurring(transaction_id) ⇒ Object



134
135
136
137
# File 'lib/activetiger/gateway.rb', line 134

def delete_recurring(transaction_id)
  params = {delete_recurring: transaction_id}
  make_request(params)
end