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:
1 2 3 4 |
initializer "spree.gateway.payment_methods", :after => "spree.register.payment_methods" do |app| app.config.spree.payment_methods << Spree::Gateway::AnotherGateway end |
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:
1 2 3 4 |
Spree::Gateway::Engine.config.after_initialize do Your::Application.config.spree.payment_methods << Spree::Gateway::YourGateway end |