Created
August 15, 2012 08:17
-
-
Save amasses/3357572 to your computer and use it in GitHub Desktop.
Ruby Library Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gemfile | |
gem "fat_zebra" | |
# In your code | |
require 'fat_zebra' | |
gw = FatZebra::Gateway.new("TEST", "TEST") | |
card = { | |
:number => "5123456789012346", | |
:expiry => "05/2013", | |
:cvv => "123", | |
:card_holder => "Jim Simpson" | |
} | |
ip = "1.2.3.4" # If using Rails or a similar rack based system you should be able to use request.remote_address | |
response = gw.purchase(10000, card, "PURCH-123", ip) | |
if response.successful && response.result.successful | |
# Handle the successful response | |
else | |
if response.successful | |
# Likely the card declined or something similar | |
puts "Failed: #{response.result.message}" | |
else | |
# Handle the failure of the entire request (e.g. maybe bad credentials or bad data?) | |
puts "Error: #{response.errors.inspect}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment