Richard Hart

Head of Something @ Somewhere
Kent, UK

My Music
My Photos


Adding a custom Spree payment Gateway outside a Rails Engine

Adding a new Payment Gateway to Spree through a Rails Engine is pretty straight forward as you can hook in your new gateway after the initial payment gateway array has been created. This is how the spree_gateway gem does it:

initializer "spree.gateway.payment_methods", :after => "spree.register.payment_methods" do |app|
    app.config.spree.payment_methods << Spree::Gateway::AnotherGateway

If you want to do the same thing for your own project contained gateway it's a little different. If you try to just directly edit the payment_methods array in an initializer it will get wiped out when the Spree core engine sets the initial bogus and simple methods. I got around the problem by hooking my gateway in using the after_initialize method. Here I'm hooking in after SpreeGateway:

Spree::Gateway::Engine.config.after_initialize do
  Your::Application.config.spree.payment_methods << Spree::Gateway::YourGateway