Skip to content

Instantly share code, notes, and snippets.

@teeparham
Created April 28, 2010 03:19
Show Gist options
  • Save teeparham/381679 to your computer and use it in GitHub Desktop.
Save teeparham/381679 to your computer and use it in GitHub Desktop.
Rake task to configure Spree Authorize.net gateway
# rake yoursite:setup_gateway
namespace :yoursite
desc "Set up gateway"
task :setup_gateway => :environment do
Gateway.transaction do
auth_net = "Authorize.net"
gateway = Gateway.find_by_name_and_environment(auth_net, RAILS_ENV)
gateway.destroy unless gateway.nil?
gateway = Gateway::AuthorizeNet.create(
:name => auth_net,
:environment => RAILS_ENV,
:description => auth_net,
:test_mode => "false",
:active => "true",
:server => (RAILS_ENV == "production") ? "live" : "test"
)
if RAILS_ENV == "production"
gateway.set_preference(:login, "-- your production key --")
gateway.set_preference(:password, "-- your production password --")
else
gateway.set_preference(:login, "-- your test key --")
gateway.set_preference(:password, "-- your test password --")
end
gateway.save!
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment