class TigerPayment::Gateway

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.

Constants

Config
TIGER_URLS

Public Class Methods

new(params = {}) click to toggle source
# File lib/tiger-payment/gateway.rb, line 105
def initialize(params = {})
  config = TigerPayment::Configuration.new rescue params_config(params)
  @username = config.username
  @password = config.password
end

Public Instance Methods

add_recurring(params) click to toggle source
# File lib/tiger-payment/gateway.rb, line 127
def add_recurring(params)
  params.merge! :type => 'add_recurring'
  make_transaction(params)
end
add_recurring_and_charge(params) click to toggle source
# File lib/tiger-payment/gateway.rb, line 132
def add_recurring_and_charge(params)
  params.merge! :type => 'sale'
  make_transaction(params)
end
authorize(params) click to toggle source
# File lib/tiger-payment/gateway.rb, line 122
def authorize(params)
  params.merge! :type => "auth"
  make_transaction(params)
end
delete_recurring(transaction_id) click to toggle source
# File lib/tiger-payment/gateway.rb, line 137
def delete_recurring(transaction_id)
  params = {delete_recurring: transaction_id}
  make_transaction(params)
end
get_customers(customer_vault_id=nil) click to toggle source
# File lib/tiger-payment/gateway.rb, line 173
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) click to toggle source
# File lib/tiger-payment/gateway.rb, line 164
def get_specified_transactions(ids)
  params = {:transaction_id => Array(ids).join(',')}
  make_request(params)
end
get_transactions(params={}) click to toggle source
# File lib/tiger-payment/gateway.rb, line 169
def get_transactions(params={})
  make_request(params)
end
get_transactions_for_date(date) click to toggle source

Request methods for retrieving transactions and customer info

# File lib/tiger-payment/gateway.rb, line 159
def get_transactions_for_date(date)
  params = {:start_date => date}
  make_request(params)
end
params_config(params) click to toggle source
# File lib/tiger-payment/gateway.rb, line 111
def params_config(params)
  Config.new(params.fetch(:username), params.fetch(:password))
end
remove_customer_from_vault(vault_id) click to toggle source
# File lib/tiger-payment/gateway.rb, line 142
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) click to toggle source
# File lib/tiger-payment/gateway.rb, line 150
def update_customer_vault(params, vault_id)
  params.merge!({
    customer_vault: 'update_customer',
    customer_vault_id: vault_id
  })
  make_transaction(params)
end

Private Instance Methods

make_request(params, report_type=nil) click to toggle source
# File lib/tiger-payment/gateway.rb, line 187
def make_request(params, report_type=nil)
  params.merge! :username => @username, :password => @password
  response_string = tiger_query_gateway.post(params).to_s
  if report_type == 'customer'
    TigerPayment::Response.build_customers_from_xml(response_string)
  else
    TigerPayment::Response.build_transactions_from_xml(response_string)
  end
end
make_transaction(params) click to toggle source
# File lib/tiger-payment/gateway.rb, line 181
def make_transaction(params)
  params.merge! :username => @username, :password => @password
  response_string = tiger_transaction_gateway.post(params)
  TigerPayment::Response.build_from_string(response_string)
end
tiger_query_gateway() click to toggle source
# File lib/tiger-payment/gateway.rb, line 201
def tiger_query_gateway
  @tiger_gateway ||= RestClient::Resource.new(TIGER_URLS[:query], ssl_version: :TLSv1_2)
end
tiger_transaction_gateway() click to toggle source
# File lib/tiger-payment/gateway.rb, line 197
def tiger_transaction_gateway
  @tiger_gateway ||= RestClient::Resource.new(TIGER_URLS[:transaction], ssl_version: :TLSv1_2)
end