Class: TigerPayment::Gateway
- Inherits:
-
Object
- Object
- TigerPayment::Gateway
- 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.(
: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.
Defined Under Namespace
Classes: Config
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
- #add_recurring(params) ⇒ Object
- #add_recurring_and_charge(params) ⇒ Object
- #authorize(params) ⇒ Object
- #delete_recurring(transaction_id) ⇒ Object
- #get_customers(customer_vault_id = nil) ⇒ Object
- #get_specified_transactions(ids) ⇒ Object
- #get_transactions(params = {}) ⇒ Object
-
#get_transactions_for_date(date) ⇒ Object
Request methods for retrieving transactions and customer info.
-
#initialize(params = {}) ⇒ Gateway
constructor
A new instance of Gateway.
- #params_config(params) ⇒ Object
- #remove_customer_from_vault(vault_id) ⇒ Object
- #update_customer_vault(params, vault_id) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Gateway
Returns a new instance of Gateway.
105 106 107 108 109 |
# 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 |
Instance Method Details
#add_recurring(params) ⇒ Object
127 128 129 130 |
# 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) ⇒ Object
132 133 134 135 |
# File 'lib/tiger-payment/gateway.rb', line 132 def add_recurring_and_charge(params) params.merge! :type => 'sale' make_transaction(params) end |
#authorize(params) ⇒ Object
122 123 124 125 |
# File 'lib/tiger-payment/gateway.rb', line 122 def (params) params.merge! :type => "auth" make_transaction(params) end |
#delete_recurring(transaction_id) ⇒ Object
137 138 139 140 |
# 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) ⇒ Object
173 174 175 176 177 |
# 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) ⇒ Object
164 165 166 167 |
# 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 = {}) ⇒ Object
169 170 171 |
# File 'lib/tiger-payment/gateway.rb', line 169 def get_transactions(params={}) make_request(params) end |
#get_transactions_for_date(date) ⇒ Object
Request methods for retrieving transactions and customer info
159 160 161 162 |
# 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) ⇒ Object
111 112 113 |
# 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) ⇒ Object
142 143 144 145 146 147 148 |
# 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) ⇒ Object
150 151 152 153 154 155 156 |
# 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 |