Created
July 8, 2009 09:29
-
-
Save janx/142714 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#-------------------------------------------------- | |
# ActiveMerchant Options | |
# | |
# :order_id - The order number. | |
# :ip - The IP address of the customer making the purchase. | |
# :customer - The name, customer number, or other information that identifies the customer. | |
# :invoice - The invoice number. | |
# :merchant - The name or description of the merchant offering the product. | |
# :description - A description of the transaction. | |
# :email - The email address of the customer. | |
# :currency - The currency of the transaction. Only important when you are using a currency that is not the default with a gateway supports multiple currencies. | |
# :billing_address - A hash containing the billing address of the customer. | |
# :shipping_address - A hash containing the shipping address of the customer. | |
# | |
# The :billing_address and :shipping_address hashes can have the following keys: | |
# | |
# :name - The full name of the customer. | |
# :company - The company name of the customer. | |
# :address1 - The primary street address of the customer. | |
# :address2 - Additional line of address information. | |
# :city - The city of the customer. | |
# :state - The state of the customer. The 2 digit code for US and Canadian addresses. The full name of the state or province for foreign addresses. | |
# :country - The ISO 3166-1-alpha-2 code (http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm) for the customer. | |
# :zip - The zip or postal code of the customer. | |
# :phone - The phone number of the customer. | |
# | |
# You must pass in the :address1 and :zip keys in the billing address hash if you want to use AVS. | |
#-------------------------------------------------- | |
def self.purchase | |
ActiveMerchant::Billing::Base.mode = :test | |
gateway = ActiveMerchant::Billing::BraintreeGateway.new({ | |
:login => 'demo', | |
:password => 'password' | |
}) | |
creditcard = ActiveMerchant::Billing::CreditCard.new({ | |
:first_name => 'Cody', | |
:last_name => 'Fauser', | |
:number => '4111111111111111', | |
:month => '10', | |
:year => (Time.now.year+1).to_s, | |
:verification_value => '999' | |
}) | |
options = { | |
:billing_address => { | |
:name => 'Cody Fauser', | |
:address1 => '1234 foo', | |
:address2 => 'Apartment 2', | |
:city => 'Ottawa', | |
:state => 'ON', | |
:country => 'CA', | |
:zip => 'K3P5N5', | |
:phone => '555-555-5555' | |
}, | |
:description => 'show me the money' | |
} | |
if creditcard.valid? | |
response = gateway.purchase(100, creditcard, options) | |
print "(TEST)" if response.test? | |
if response.success? | |
puts "success. the authorization is #{response.authorization}" | |
else | |
puts "failed because #{response.message}" | |
end | |
else | |
puts "invalid credit card" | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment