Topic: Spree Commerce Cybersource Gateway Integration with version 0.70.2 and

Spree Commerce is Open source eCommerce Project, to know more about the same please visit http://guides.spreecommerce.com/

Recently we came across with the requirement for integrating Cybersource Gateway Integration with Open Source eCommerce. There are many existing plugins/extensions available. But those are not for the latest versions of Spree.

Following are the steps for generating extensions till its integration.

spree extension spree-cybersource-gateway

or

bundle exec spree extension cybersource_gateway

The output should be

    create spree_cybersource_gateway
    create spree_cybersource_gateway/app
    create spree_cybersource_gateway/app/assets/javascripts/admin/spree_cybersource_gateway.js
    create spree_cybersource_gateway/app/assets/javascripts/store/spree_cybersource_gateway.js
    create spree_cybersource_gateway/app/assets/stylesheets/admin/spree_cybersource_gateway.css
    create spree_cybersource_gateway/app/assets/stylesheets/store/spree_cybersource_gateway.css
    create spree_cybersource_gateway/app/controllers
    create spree_cybersource_gateway/app/helpers
    create spree_cybersource_gateway/app/models
    create spree_cybersource_gateway/app/views
    create spree_cybersource_gateway/app/overrides
    create spree_cybersource_gateway/config
    create spree_cybersource_gateway/db
    create spree_cybersource_gateway/lib
    create spree_cybersource_gateway/lib/spree_cybersource_gateway.rb
    create spree_cybersource_gateway/lib/spree_cybersource_gateway/engine.rb
    create spree_cybersource_gateway/lib/generators/spree_cybersource_gateway/install/install_generator.rb
    create spree_cybersource_gateway/script
    create spree_cybersource_gateway/script/rails
    create spree_cybersource_gateway/spec
    create spree_cybersource_gateway/LICENSE
    create spree_cybersource_gateway/Rakefile
    create spree_cybersource_gateway/README.md
    create spree_cybersource_gateway/.gitignore
    create spree_cybersource_gateway/spree_cybersource_gateway.gemspec
    create spree_cybersource_gateway/Versionfile
    create spree_cybersource_gateway/config/routes.rb
    create spree_cybersource_gateway/spec/spec_helper.rb
    create spree_cybersource_gateway/.rspec
    append Gemfile 

Open file spree_cybersource_gateway/lib/spree_cybersource_gateway/engine.rb
Add at the top,

require 'spree_core'

and inside def self.activate add

require 'active_merchant'
ActiveMerchant::Billing::CyberSourceGateway

After the method add,

config.after_initialize do |app|
app.config.spree.payment_methods += [
Gateway::CyberSource
]

Your file should look like

    require ‘spree_core’
    module SpreeCybersourceGateway
    class Engine < Rails::Engine
    engine_name 'spree_cybersource_gateway'

    config.autoload_paths += %W(#{config.root}/lib)

    # use rspec for tests
    config.generators do |g|
    g.test_framework :rspec
    end

    def self.activate
    require 'active_merchant'
    ActiveMerchant::Billing::CyberSourceGateway
    Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
    Rails.application.config.cache_classes ? require(c) : load(c)
    end

    Dir.glob(File.join(File.dirname(__FILE__), "../../app/overrides/*.rb")) do |c|
    Rails.application.config.cache_classes ? require(c) : load(c)
    end
    end
    config.after_initialize do |app|
    app.config.spree.payment_methods += [
    Gateway::CyberSource
    ]
    config.to_prepare &method(:activate).to_proc
    end
    end 

Create folder in app > models as gateway
Create file insider gateway > cyber_source.rb
Add following code

class Gateway::CyberSource < Gateway
preference :login, :string
preference :password, :string

def provider_class
ActiveMerchant::Billing::CyberSourceGateway
end
end

Now execute command

bundle

And we are ready with the Cybersource gateway.. But we are not done yet.
Register or login with test account https://ebctest.cybersource.com/
Navigate to Account Management > Transaction Security Keys > Security Keys for the SOAP Toolkit API
Click on Generate Key and copy that into wordpad.
Now login to spree as admin and navigate to admin > Configuration > Payment Methods > New payment method
You should see Gateway::CyberSource within dropdown for provider.
Select the same, it shall now ask for username and password. Enter username which is used for the cybersource.
The key generated is the password

Last edited by rortechie (2012-02-21 05:42:23)