Class: TigerPayment::Gateway

Inherits:
Object
  • Object
show all
Defined in:
lib/tiger-payment/gateway.rb

Overview

Overview

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

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

config/tiger-payment/#{RAILS_ENV}.yml

Creating a Gateway

First we instantiate a gateway in a rails application:

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

# create a gateway in any ruby application
gateway = TigerPayment::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_URLS =
{
  :transaction => "https://secure.tigergateway.net/api/transact.php",
  :query => "https://secure.networkmerchants.com/api/query.php"
}

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Gateway

Returns a new instance of Gateway.



104
105
106
107
108
# File 'lib/tiger-payment/gateway.rb', line 104

def initialize(params = {})
  config = TigerPayment::Configuration.new
  @username = config.username
  @password = config.password
end

Instance Method Details

#add_recurring(params) ⇒ Object



122
123
124
125
# File 'lib/tiger-payment/gateway.rb', line 122

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

#add_recurring_and_charge(params) ⇒ Object



127
128
129
130
# File 'lib/tiger-payment/gateway.rb', line 127

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

#authorize(params) ⇒ Object



117
118
119
120
# File 'lib/tiger-payment/gateway.rb', line 117

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

#delete_recurring(transaction_id) ⇒ Object



132
133
134
135
# File 'lib/tiger-payment/gateway.rb', line 132

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

#get_customers(customer_vault_id = nil) ⇒ Object



168
169
170
171
172
# File 'lib/tiger-payment/gateway.rb', line 168

def get_customers(customer_vault_id=nil)
  params = {:report_type => 'customer_vault'}
  params.merge!(:customer_vault_id => customer_vault_id) if customer_vault_id
  make_request(params, 'customer')
end

#get_specified_transactions(ids) ⇒ Object



159
160
161
162
# File 'lib/tiger-payment/gateway.rb', line 159

def get_specified_transactions(ids)
  params = {:transaction_id => Array(ids).join(',')}
  make_request(params)
end

#get_transactions(params) ⇒ Object



164
165
166
# File 'lib/tiger-payment/gateway.rb', line 164

def get_transactions(params)
  make_request(params)
end

#get_transactions_for_date(date) ⇒ Object

Request methods for retrieving transactions and customer info



154
155
156
157
# File 'lib/tiger-payment/gateway.rb', line 154

def get_transactions_for_date(date)
  params = {:start_date => date}
  make_request(params)
end

#remove_customer_from_vault(vault_id) ⇒ Object



137
138
139
140
141
142
143
# File 'lib/tiger-payment/gateway.rb', line 137

def remove_customer_from_vault(vault_id)
  params = {
    customer_vault: 'delete_customer',
    customer_vault_id: vault_id
  }
  make_transaction(params)
end

#update_customer_vault(params, vault_id) ⇒ Object



145
146
147
148
149
150
151
# File 'lib/tiger-payment/gateway.rb', line 145

def update_customer_vault(params, vault_id)
  params.merge!({
    customer_vault: 'update_customer',
    customer_vault_id: vault_id
  })
  make_transaction(params)
end