spree_ebsin 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. data/.gitignore +14 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +19 -0
  4. data/Gemfile +8 -0
  5. data/LICENSE +26 -0
  6. data/README.md +60 -0
  7. data/Rakefile +15 -0
  8. data/Versionfile +11 -0
  9. data/app/assets/javascripts/admin/spree_ebsin.js +1 -0
  10. data/app/assets/javascripts/store/spree_ebsin.js +1 -0
  11. data/app/assets/stylesheets/admin/spree_ebsin.css +3 -0
  12. data/app/assets/stylesheets/store/spree_ebsin.css +3 -0
  13. data/app/controllers/spree/checkout_controller_decorator.rb +17 -0
  14. data/app/controllers/spree/gateway/ebsin_controller.rb +80 -0
  15. data/app/models/spree/ebsinfo.rb +35 -0
  16. data/app/models/spree/order_decorator.rb +5 -0
  17. data/app/models/spree/payment_decorator.rb +5 -0
  18. data/app/models/spree/payment_method/ebsin.rb +16 -0
  19. data/app/models/spree.rb +5 -0
  20. data/app/views/admin/payments/_list.html.erb +23 -0
  21. data/app/views/spree/checkout/payment/_ebsin.html.erb +2 -0
  22. data/app/views/spree/gateway/ebsin/show.html.erb +45 -0
  23. data/config/locales/en.yml +26 -0
  24. data/config/routes.rb +6 -0
  25. data/db/migrate/20130702115540_create_ebsinfos.rb +14 -0
  26. data/lib/generators/spree_ebsin/install/install_generator.rb +31 -0
  27. data/lib/spree_ebsin/engine.rb +26 -0
  28. data/lib/spree_ebsin/factories.rb +17 -0
  29. data/lib/spree_ebsin/rc4.rb +44 -0
  30. data/lib/spree_ebsin.rb +2 -0
  31. data/script/rails +7 -0
  32. data/spec/features/admin_payment_method_spec.rb +37 -0
  33. data/spec/features/order_spec.rb +89 -0
  34. data/spec/models/ebsinfo_spec.rb +5 -0
  35. data/spec/spec_helper.rb +95 -0
  36. data/spree_ebsin.gemspec +31 -0
  37. metadata +258 -0
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ .idea
6
+ .project
7
+ .sass-cache
8
+ coverage
9
+ Gemfile.lock
10
+ tmp
11
+ nbproject
12
+ pkg
13
+ *.swp
14
+ spec/dummy
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,19 @@
1
+ language: ruby
2
+ before_script:
3
+ - "sh -e /etc/init.d/xvfb start"
4
+ - "bundle exec rake test_app"
5
+ script:
6
+ - "export DISPLAY=:99.0"
7
+ - "bundle exec rspec spec"
8
+ rvm:
9
+ - 1.9.3
10
+ - 2.0.0
11
+ - ruby-head
12
+ gemfile:
13
+ - Gemfile
14
+ matrix:
15
+ allow_failures:
16
+ - rvm: ruby-head
17
+ notifications:
18
+ email:
19
+ - raj.surya19@gmail.com
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Provides basic authentication functionality for testing parts of your engine
4
+ gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-0-stable'
5
+
6
+ gem 'coveralls', require: false
7
+
8
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2013 Surya Tripathi
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Spree nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ [![Code Climate](https://codeclimate.com/github/suryart/spree_ebsin.png)](https://codeclimate.com/github/suryart/spree_ebsin)
2
+ [![Build Status](https://travis-ci.org/suryart/spree_ebsin.png?branch=master)](https://travis-ci.org/suryart/spree_ebsin)
3
+ [![Coverage Status](https://coveralls.io/repos/suryart/spree_ebsin/badge.png)](https://coveralls.io/r/suryart/spree_ebsin)
4
+
5
+ # Welcome to Spree Ebsin
6
+
7
+ This is [EBS](http://www.ebs.in) Payment Gateway Extension for Spree. It has been extended to support Spree's Billing Integrations which allows users to configure the Ebs Payment gateway via the Admin UI.
8
+
9
+ Installation
10
+ ------------
11
+
12
+ Add spree_ebsin to your Gemfile:
13
+
14
+ ```ruby
15
+ gem 'spree_ebsin'
16
+ ```
17
+
18
+ Bundle your dependencies and run the installation generator:
19
+
20
+ ```shell
21
+ bundle
22
+ bundle exec rails g spree_ebsin:install
23
+ ```
24
+
25
+ ## TODOs
26
+
27
+ * Enhance the admin interface for refund and capture options.
28
+
29
+ ## Testing
30
+
31
+ Be sure to bundle your dependencies and then create a dummy test app for the specs to run against.
32
+
33
+ ```shell
34
+ bundle
35
+ bundle exec rake test_app
36
+ bundle exec rspec spec
37
+ ```
38
+
39
+ When testing your applications integration with this extension you may use it's factories.
40
+ Simply add this require statement to your spec_helper:
41
+
42
+ ```ruby
43
+ require 'spree_ebsin/factories'
44
+ ```
45
+
46
+ Also, here is the link to: [Credit Card Payment Credentials for Testing](https://support.ebs.in/app/index.php?/default_import/Knowledgebase/Article/View/339/0/what-is-the-test-credentials-for-testing-the-credit-payment-option)
47
+
48
+
49
+ ## Contributing
50
+
51
+ 1. [Fork](https://help.github.com/articles/fork-a-repo) the project
52
+ 2. Make one or more well commented and clean commits to the repository. You can make a new branch here if you are modifying more than one part or feature.
53
+ 3. Add tests for it. This is important so I don’t break it in a future version unintentionally.
54
+ 4. Perform a [pull request](https://help.github.com/articles/using-pull-requests) in github's web interface.
55
+
56
+ ## NOTE
57
+
58
+ The current version supports Spree 2.0.0 or above. Older versions of Spree are unlikely to work, so attempt at your own risk.
59
+
60
+ Copyright (c) 2013 Surya Tripathi, released under the New BSD License
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ require 'spree/testing_support/extension_rake'
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task :default => [:spec]
10
+
11
+ desc 'Generates a dummy app for testing'
12
+ task :test_app do
13
+ ENV['LIB_NAME'] = 'spree_ebsin'
14
+ Rake::Task['extension:test_app'].invoke
15
+ end
data/Versionfile ADDED
@@ -0,0 +1,11 @@
1
+ # This file is used to designate compatibilty with different versions of Spree
2
+ # Please see http://spreecommerce.com/documentation/extensions.html#versionfile for details
3
+
4
+ # Examples
5
+ #
6
+ # '1.2.x' => { :branch => 'master' }
7
+ # '1.1.x' => { :branch => '1-1-stable' }
8
+ # '1.0.x' => { :branch => '1-0-stable' }
9
+ # '0.70.x' => { :branch => '0-70-stable' }
10
+ # '0.40.x' => { :tag => 'v1.0.0', :version => '1.0.0' }
11
+
@@ -0,0 +1 @@
1
+ //= require admin/spree_backend
@@ -0,0 +1 @@
1
+ //= require store/spree_frontend
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require admin/spree_backend
3
+ */
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require store/spree_frontend
3
+ */
@@ -0,0 +1,17 @@
1
+ module Spree
2
+ CheckoutController.class_eval do
3
+
4
+ before_filter :redirect_to_ebsin, :only => :update
5
+
6
+ private
7
+
8
+ def redirect_to_ebsin
9
+ return unless params[:state] == "payment"
10
+ @payment_method = Spree::PaymentMethod.find(params[:order][:payments_attributes].first[:payment_method_id])
11
+ if @payment_method && @payment_method.kind_of?(Spree::PaymentMethod::Ebsin)
12
+ @order.update_attributes(object_params)
13
+ redirect_to gateway_ebsin_path(:gateway_id => @payment_method.id, :id => @order.number)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,80 @@
1
+ require 'base64'
2
+ require 'digest/md5'
3
+ require 'spree_ebsin/rc4'
4
+
5
+ module Spree
6
+ class Gateway::EbsinController < Spree::StoreController
7
+ helper 'spree/orders'
8
+ skip_before_filter :verify_authenticity_token, :only => [:comeback]
9
+
10
+ # Show form EBS for payment
11
+ def show
12
+ load_order
13
+ @order.payments.destroy_all
14
+ @hash = Digest::MD5.hexdigest([@gateway.preferred_secret_key, @gateway.preferred_account_id, @order.total.to_s, @order.number, [gateway_ebsin_comeback_url(@order),'DR={DR}'].join('?'), @gateway.preferred_mode].join('|'))
15
+ payment = @order.payments.create!(:amount => 0, :payment_method_id => @gateway.id)
16
+
17
+ if @order.blank? || @gateway.blank?
18
+ flash[:error] = Spree.t(:invalid_arguments)
19
+ redirect_to :back
20
+ else
21
+ @bill_address, @ship_address = @order.bill_address, (@order.ship_address || @order.bill_address)
22
+ render :action => :show
23
+ end
24
+ end
25
+
26
+ # Comback from EBS
27
+ def comeback
28
+ load_order
29
+ @data = ebsin_decode(params[:DR], @gateway.preferred_secret_key)
30
+ if (@data) &&
31
+ (@data["ResponseMessage"] == "Transaction Successful") &&
32
+ (@data["ResponseCode"] == "0") &&
33
+ (@data["MerchantRefNo"] == @order.number.to_s) &&
34
+ (@data["Amount"].to_f == @order.outstanding_balance.to_f)
35
+
36
+ ebsin_payment_success
37
+
38
+ redirect_to order_url(@order, {:checkout_complete => true, :token => @order.token}), :notice => Spree.t(:payment_success)
39
+ else
40
+ flash[:error] = Spree.t(:ebsin_payment_response_error, {:error_message => @data["ResponseMessage"]})
41
+ redirect_to (@order.blank? ? root_url : edit_order_url(@order, {:token => @order.token}))
42
+ end
43
+
44
+ end
45
+
46
+ private
47
+ def load_order
48
+ @order = current_order || Spree::Order.find_by_number(params[:id])
49
+ @gateway = params[:gateway_id].blank? ? @order.payments.last.payment_method : @order.available_payment_methods.find{|x| x.id == params[:gateway_id].to_i }
50
+ end
51
+
52
+ # processing geteway's comback data
53
+ def ebsin_decode(data, key)
54
+ rc4 = SpreeEbsin::RC4.new(key)
55
+ (Hash[rc4.encrypt(Base64.decode64(data.gsub(/ /,'+'))).split('&').map{ |x| x.split("=") }]).slice(* Spree::Ebsinfo::NECESSARY )
56
+ end
57
+
58
+ # save the payment record and complete the order
59
+ def ebsin_payment_success
60
+ source = Spree::Ebsinfo.create(:first_name => @order.bill_address.firstname, :last_name => @order.bill_address.lastname, :transaction_id => @data["TransactionID"], :payment_id => @data["PaymentID"], :amount => @data["Amount"], :order_id => @order.id)
61
+
62
+ ebs_payment_method = Spree::PaymentMethod::Ebsin.last
63
+ payment = @order.payments.where(:payment_method_id => ebs_payment_method.id).first
64
+ payment = @order.payments.create!(:amount => 0, :payment_method_id => ebs_payment_method.id) if payment.blank?
65
+ payment.source = source
66
+ payment.amount = source.amount
67
+ payment.save
68
+ payment.complete!
69
+
70
+ @order.reload
71
+ @order.next
72
+ @order.state = 'complete'
73
+ @order.save
74
+
75
+ session[:order_id] = nil
76
+
77
+ @order.finalize!
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,35 @@
1
+ module Spree
2
+ class Ebsinfo < ActiveRecord::Base
3
+ attr_accessible :first_name, :last_name, :transaction_id, :payment_id, :amount, :order_id
4
+
5
+ belongs_to :order, :class_name => 'Spree::Order'
6
+
7
+ NECESSARY = %w(Mode PaymentID DateCreated MerchantRefNo Amount TransactionID ResponseCode ResponseMessage).freeze
8
+
9
+ def actions
10
+ %w(mark_as_captured void)
11
+ end
12
+
13
+ # Indicates whether it's possible to capture the payment
14
+ def can_mark_as_captured?(payment)
15
+ ['checkout', 'pending'].include?(payment.state)
16
+ end
17
+
18
+ # Indicates whether it's possible to void the payment.
19
+ def can_void?(payment)
20
+ payment.state != 'void'
21
+ end
22
+
23
+ def mark_as_captured(payment)
24
+ payment.update_attribute(:state, 'pending') if payment.state == 'checkout'
25
+ payment.complete
26
+ true
27
+ end
28
+
29
+ def void(payment)
30
+ payment.update_attribute(:state, 'pending') if payment.state == 'checkout'
31
+ payment.void
32
+ true
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ module Spree
2
+ Order.class_eval do
3
+ has_one :ebsinfo, :class_name => 'Spree::Ebsinfo'
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Spree
2
+ Payment.class_eval do
3
+ attr_accessible :source, :source_attributes
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ module Spree
2
+ class PaymentMethod::Ebsin < PaymentMethod
3
+
4
+ preference :account_id, :string
5
+ preference :url, :string, :default => "https://secure.ebs.in/pg/ma/sale/pay/"
6
+ preference :secret_key, :string
7
+ preference :mode, :string
8
+ preference :currency_code, :string
9
+
10
+ attr_accessible :preferred_account_id, :preferred_url, :preferred_secret_key, :preferred_mode, :preferred_currency_code
11
+
12
+ def payment_profiles_supported?
13
+ false
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module Spree
2
+ def self.table_name_prefix
3
+ 'spree_'
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ <table class="index">
2
+ <tr>
3
+ <th><%= "#{Spree.t('spree.date')}/#{Spree.t('spree.time')}" %></th>
4
+ <th><%= Spree.t("amount") %></th>
5
+ <th><%= Spree.t("payment_method") %></th>
6
+ <th></th>
7
+ </tr>
8
+ <% payments.each do |payment| %>
9
+ <tr>
10
+ <td><%= payment.created_at.to_s(:date_time24) %></td>
11
+ <td><%= number_to_currency(payment.amount) %></td>
12
+ <td><%= payment_method_name payment %></td>
13
+ <td>
14
+ <% unless payment_method_name(payment) == 'Ebsin' %>
15
+ <%= link_to Spree.t('show'), admin_order_payment_path(@order, payment) %>
16
+ <% payment.actions.each do |action| %>
17
+ <%= link_to Spree.t(action), fire_admin_order_payment_path(@order, payment, :e => action), :method => :put, :confirm => Spree.t('are_you_sure') %>
18
+ <% end %>
19
+ <% end %>
20
+ </td>
21
+ </tr>
22
+ <% end %>
23
+ </table>
@@ -0,0 +1,2 @@
1
+ <%= Spree.t('ebsin_pay_instructions') %>
2
+
@@ -0,0 +1,45 @@
1
+ <h3 class="heading"> <%= image_tag "spinner.gif"%> <%= Spree.t(:redirecting_for_payment) %></h3>
2
+
3
+ <fieldset id="order_details" class="pg-redirect-od">
4
+ <div class="clear"></div>
5
+ <p style='text-transform:uppercase;font-weight:bold; margin:0px 0px 10px 10px;'>
6
+ <%= Spree.t(:order_number) %>
7
+ <%= @order.number %>
8
+ (<%= link_to "&larr; #{Spree.t(:back_to_payment_options)}".html_safe, checkout_state_path(:payment) %>)</p>
9
+ <%= render :partial => 'spree/shared/order_details', :locals => {:order => @order} -%>
10
+ </fieldset>
11
+
12
+ <%= form_tag @gateway.preferred_url, :id => 'ebs_form' do -%>
13
+ <%= hidden_field_tag 'account_id', @gateway.preferred_account_id %>
14
+ <%= hidden_field_tag 'reference_no', @order.number %>
15
+ <%= hidden_field_tag 'amount', @order.total.to_s %>
16
+ <%= hidden_field_tag 'return_url', [gateway_ebsin_comeback_url(@order),'DR={DR}'].join('?') %>
17
+ <%= hidden_field_tag 'secure_hash', @hash %>
18
+ <%= hidden_field_tag 'name', @bill_address.firstname %>
19
+ <%= hidden_field_tag 'address', @bill_address.address1 %>
20
+ <%= hidden_field_tag 'city', @bill_address.city %>
21
+ <%= hidden_field_tag 'postal_code', @bill_address.zipcode %>
22
+ <%= hidden_field_tag 'country', @bill_address.country.iso3 %>
23
+ <%= hidden_field_tag 'description', "#{Spree::Config[:site_name]} Order: #{@order.number}" %>
24
+ <%= hidden_field_tag 'email', @order.email || @order.user.try(:email) %>
25
+
26
+ <%= hidden_field_tag 'mode', @gateway.preferred_mode %>
27
+ <%= hidden_field_tag 'phone', @bill_address.phone %>
28
+ <%= hidden_field_tag 'state', @bill_address.state.try(:name) || @bill_address.state_name %>
29
+
30
+ <%= hidden_field_tag 'ship_address', @ship_address.address1 %>
31
+ <%= hidden_field_tag 'ship_city', @ship_address.city %>
32
+ <%= hidden_field_tag 'ship_country', @ship_address.country.iso3 %>
33
+ <%= hidden_field_tag 'ship_name', @ship_address.full_name %>
34
+ <%= hidden_field_tag 'ship_phone', @ship_address.phone %>
35
+ <%= hidden_field_tag 'ship_postal_code',@ship_address.zipcode %>
36
+ <%= hidden_field_tag 'ship_state', @ship_address.state.try(:name) || @ship_address.state_name %>
37
+ <% end %>
38
+
39
+ <script type="text/javascript">
40
+ $(document).ready(function() {
41
+ setTimeout(function(){
42
+ document.getElementById("ebs_form").submit();
43
+ }, 5000)
44
+ });
45
+ </script>
@@ -0,0 +1,26 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ spree:
6
+ account_id: "Account Id"
7
+ back_to_payment_options: "Back to payment options"
8
+ confirm_your_order: "Confirm your order"
9
+ currency_code: "Currency"
10
+ ebsin: "Payment"
11
+ ebsin_pay_instructions: "Pay using credit or debit card from EBS (you'll be redirected to EBS secure server)"
12
+ ebsin_payment: "Pay by credit card"
13
+ ebsin_payment_failure: "Something went wrong. Please try again."
14
+ ebsin_payment_response_error: "%{error_message}. Payment was not successful."
15
+ ebsin_payment_success: "Your payment has been accepted."
16
+ ebsin_submit: "Pay and place order"
17
+ language: "Language"
18
+ mode: "Work mode"
19
+ order_number: "Order number:"
20
+ pay_now: "Pay Now"
21
+ payment_success: "Payment Success"
22
+ redirecting_for_payment: "Redirecting for payment ..."
23
+ redirect_success: "Success Redirect URL"
24
+ redirect_fail: "Failure Redirect URL"
25
+ secret_key: "Secret Key"
26
+ url: "URL"
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ Spree::Core::Engine.routes.draw do
2
+ namespace :gateway do
3
+ match '/:gateway_id/ebsin/:id' => 'ebsin#show', :as => :ebsin
4
+ match '/ebsin/:id/comeback' => 'ebsin#comeback', :as => :ebsin_comeback
5
+ end
6
+ end
@@ -0,0 +1,14 @@
1
+ class CreateEbsinfos < ActiveRecord::Migration
2
+ def change
3
+ create_table :spree_ebsinfos do |t|
4
+ t.string :first_name
5
+ t.string :last_name
6
+ t.string :transaction_id
7
+ t.string :payment_id
8
+ t.decimal :amount
9
+ t.integer :order_id
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,31 @@
1
+ module SpreeEbsin
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+
5
+ class_option :auto_run_migrations, :type => :boolean, :default => false
6
+
7
+ def add_javascripts
8
+ append_file 'app/assets/javascripts/store/all.js', "//= require store/spree_ebsin\n"
9
+ append_file 'app/assets/javascripts/admin/all.js', "//= require admin/spree_ebsin\n"
10
+ end
11
+
12
+ def add_stylesheets
13
+ inject_into_file 'app/assets/stylesheets/store/all.css', " *= require store/spree_ebsin\n", :before => /\*\//, :verbose => true
14
+ inject_into_file 'app/assets/stylesheets/admin/all.css', " *= require admin/spree_ebsin\n", :before => /\*\//, :verbose => true
15
+ end
16
+
17
+ def add_migrations
18
+ run 'bundle exec rake railties:install:migrations FROM=spree_ebsin'
19
+ end
20
+
21
+ def run_migrations
22
+ run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask 'Would you like to run the migrations now? [Y/n]')
23
+ if run_migrations
24
+ run 'bundle exec rake db:migrate'
25
+ else
26
+ puts 'Skipping rake db:migrate, don\'t forget to run it!'
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ module SpreeEbsin
2
+ class Engine < Rails::Engine
3
+ require 'spree/core'
4
+ isolate_namespace Spree
5
+ engine_name 'spree_ebsin'
6
+
7
+ config.autoload_paths += %W(#{config.root}/lib)
8
+
9
+ # use rspec for tests
10
+ config.generators do |g|
11
+ g.test_framework :rspec
12
+ end
13
+
14
+ def self.activate
15
+ Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
16
+ Rails.configuration.cache_classes ? require(c) : load(c)
17
+ end
18
+ end
19
+
20
+ initializer "spree.register.payment_methods" do |app|
21
+ app.config.spree.payment_methods += [Spree::PaymentMethod::Ebsin]
22
+ end
23
+
24
+ config.to_prepare &method(:activate).to_proc
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ FactoryGirl.define do
2
+ # Example adding this to your spec_helper will load these Factories for use:
3
+ # require 'spree_ebsin/factories'
4
+
5
+ factory :ebs_payment_method, :class => Spree::PaymentMethod::Ebsin do
6
+ name 'Credit Card / Debit Card / Net Banking'
7
+ environment 'test'
8
+
9
+ after(:create) do |payment_method|
10
+ payment_method.preferred_currency_code = "INR"
11
+ payment_method.preferred_secret_key = "ebskey"
12
+ payment_method.preferred_url = "https://secure.ebs.in/pg/ma/sale/pay/"
13
+ payment_method.preferred_account_id = "5880"
14
+ payment_method.preferred_mode = "TEST"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,44 @@
1
+ module SpreeEbsin
2
+ class RC4
3
+
4
+ def initialize(str)
5
+ begin
6
+ raise SyntaxError, "RC4: Key supplied is blank" if str.eql?('')
7
+
8
+ @q1, @q2 = 0, 0
9
+ @key = []
10
+ str.each_byte {|elem| @key << elem} while @key.size < 256
11
+ @key.slice!(256..@key.size-1) if @key.size >= 256
12
+ @s = (0..255).to_a
13
+ j = 0
14
+ 0.upto(255) do |i|
15
+ j = (j + @s[i] + @key[i] )%256
16
+ @s[i], @s[j] = @s[j], @s[i]
17
+ end
18
+ end
19
+ end
20
+
21
+ def encrypt!(text)
22
+ process text
23
+ end
24
+
25
+ def encrypt(text)
26
+ process text.dup
27
+ end
28
+
29
+ alias_method :decrypt, :encrypt
30
+
31
+ private
32
+
33
+ def process(text)
34
+ text.unpack("C*").map { |c| c ^ round }.pack("C*")
35
+ end
36
+
37
+ def round
38
+ @q1 = (@q1 + 1)%256
39
+ @q2 = (@q2 + @s[@q1])%256
40
+ @s[@q1], @s[@q2] = @s[@q2], @s[@q1]
41
+ @s[(@s[@q1]+@s[@q2])%256]
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,2 @@
1
+ require 'spree_core'
2
+ require 'spree_ebsin/engine'
data/script/rails ADDED
@@ -0,0 +1,7 @@
1
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
2
+
3
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
4
+ ENGINE_PATH = File.expand_path('../../lib/spree_ebsin/engine', __FILE__)
5
+
6
+ require 'rails/all'
7
+ require 'rails/engine/commands'
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Orders' do
4
+ stub_authorization!
5
+
6
+ context "admin creating and update a new payment method" do
7
+ it 'should be able to create a new payment method for Ebs and update preferences' do
8
+ visit spree.admin_path
9
+ click_link "Configuration"
10
+
11
+ click_link "Payment Methods"
12
+ click_link "admin_new_payment_methods_link"
13
+
14
+ fill_in "payment_method_name", :with => "Credit Card / Debit Card / Net Banking"
15
+ fill_in "payment_method_description", :with => "Testing Credit Card / Debit Card / Net Banking Payment using EBS"
16
+
17
+ select "PaymentMethod::Ebsin", :from => "gtwy-type"
18
+ select Rails.env.to_s.humanize, :from => "gtwy-env"
19
+
20
+ click_button "Create"
21
+ page.should have_content("successfully created!")
22
+
23
+ expect(find_field('payment_method_ebsin_preferred_url').value).to eq("https://secure.ebs.in/pg/ma/sale/pay/")
24
+
25
+ fill_in 'payment_method_ebsin_preferred_account_id', :with => "5880"
26
+ fill_in 'payment_method_ebsin_preferred_secret_key', :with => "ebskey"
27
+ fill_in 'payment_method_ebsin_preferred_mode', :with => "TEST"
28
+ fill_in 'payment_method_ebsin_preferred_currency_code', :with => "INR"
29
+ select 'Both', :from => "payment_method_display_on"
30
+
31
+ click_button "Update"
32
+ page.should have_content("successfully updated!")
33
+
34
+ find_field("payment_method_name").value.should == "Credit Card / Debit Card / Net Banking"
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Orders' do
4
+ let!(:product) { create(:product, :available_on => 1.day.ago) }
5
+ let!(:zone) { Spree::Zone.find_by_name("GlobalZone") || create(:global_zone) }
6
+ let!(:shipping_method) { create(:shipping_method, :zones => [zone]) }
7
+
8
+ # let(:order) { OrderWalkthrough.up_to(:payment) }
9
+ # let(:user) { create(:user) }
10
+
11
+ # before do
12
+ # order.stub(:available_payment_methods => [create(:ebs_payment_method, :environment => 'test') ])
13
+ # order.update_attribute(:user_id, user.id)
14
+ # Spree::OrdersController.any_instance.stub(:try_spree_current_user => user)
15
+ # end
16
+
17
+ # stub_authorization!
18
+
19
+ context 'User makes a payment using ebs' do
20
+ before(:each) do
21
+ create(:ebs_payment_method)
22
+
23
+ @user = create(:user, :email => "email@person.com", :password => "secret", :password_confirmation => "secret")
24
+
25
+ visit spree.root_path
26
+
27
+ click_link product.name
28
+ click_button 'Add To Cart'
29
+ click_button 'Checkout'
30
+
31
+ fill_in 'spree_user_email', :with => @user.email
32
+ fill_in 'spree_user_password', :with => @user.password
33
+
34
+ click_button "Login"
35
+
36
+ fill_in 'order_bill_address_attributes_firstname', :with => 'Test'
37
+ fill_in 'order_bill_address_attributes_lastname', :with => 'User'
38
+ fill_in 'order_bill_address_attributes_address1', :with => 'Testing Address1'
39
+ fill_in 'order_bill_address_attributes_address2', :with => 'Testing Street Address2'
40
+ fill_in 'order_bill_address_attributes_city', :with => 'Test City'
41
+ select 'Alabama', :from => 'order_bill_address_attributes_state_id'
42
+
43
+ fill_in 'order_bill_address_attributes_zipcode', :with => '35004'
44
+ fill_in 'order_bill_address_attributes_phone', :with => '8888888888'
45
+
46
+ click_button 'Save and Continue'
47
+ click_button 'Save and Continue'
48
+ click_button 'Save and Continue'
49
+
50
+ sleep(20)
51
+
52
+ fill_in 'frm_name_on_card', :with => 'Test User'
53
+ end
54
+
55
+ it "should be able to make an order with complete state", :js => true do
56
+ fill_in 'number_1', :with => '4111'
57
+ fill_in 'number_2', :with => '1111'
58
+ fill_in 'number_3', :with => '1111'
59
+ fill_in 'number_4', :with => '1111'
60
+ select "07 (Jul)", :from => 'frm_exp_month'
61
+ select "2016", :from => 'frm_exp_year'
62
+ fill_in 'frm_cvv', :with => '123'
63
+
64
+ click_button "Pay"
65
+
66
+ sleep(10)
67
+
68
+ page.should have_content(Spree.t(:payment_success))
69
+ expect(@user.orders.complete.last.state).to eq("complete")
70
+ end
71
+
72
+ it "should be able to fail an order with payment state", :js => true do
73
+ fill_in 'number_1', :with => '4111'
74
+ fill_in 'number_2', :with => '1111'
75
+ fill_in 'number_3', :with => '1111'
76
+ fill_in 'number_4', :with => '1111'
77
+ select "07 (Jul)", :from => 'frm_exp_month'
78
+ select "2017", :from => 'frm_exp_year'
79
+ fill_in 'frm_cvv', :with => '123'
80
+
81
+ click_button "Pay"
82
+ click_link "Merchant Website"
83
+
84
+ page.should have_content("Transaction Failed. Payment was not successful.")
85
+ expect(@user.orders.last.state).to eq("payment")
86
+ end
87
+ end
88
+
89
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Ebsinfo do
4
+
5
+ end
@@ -0,0 +1,95 @@
1
+ # Run Coverage report
2
+ require 'coveralls'
3
+ Coveralls.wear!
4
+
5
+ require 'simplecov'
6
+ SimpleCov.start do
7
+ add_group 'Controllers', 'app/controllers'
8
+ add_group 'Helpers', 'app/helpers'
9
+ add_group 'Mailers', 'app/mailers'
10
+ add_group 'Models', 'app/models'
11
+ add_group 'Views', 'app/views'
12
+ add_group 'Libraries', 'lib'
13
+ end
14
+
15
+ # Configure Rails Environment
16
+ ENV['RAILS_ENV'] = 'test'
17
+
18
+ require File.expand_path('../dummy/config/environment.rb', __FILE__)
19
+
20
+ require 'rspec/rails'
21
+ require 'database_cleaner'
22
+ require 'ffaker'
23
+ require 'factory_girl'
24
+ FactoryGirl.find_definitions
25
+
26
+ # Requires supporting ruby files with custom matchers and macros, etc,
27
+ # in spec/support/ and its subdirectories.
28
+ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
29
+
30
+ # Requires factories defined in spree_core
31
+ require 'spree/testing_support/factories'
32
+ require 'spree_ebsin/factories'
33
+ require 'spree/testing_support/controller_requests'
34
+ require 'spree/testing_support/authorization_helpers'
35
+ require 'spree/testing_support/url_helpers'
36
+ require 'spree/testing_support/order_walkthrough'
37
+
38
+ # Requires factories defined in lib/spree_ebsin/factories.rb
39
+ require 'spree_ebsin/factories'
40
+
41
+ RSpec.configure do |config|
42
+ config.include FactoryGirl::Syntax::Methods
43
+
44
+ # == URL Helpers
45
+ #
46
+ # Allows access to Spree's routes in specs:
47
+ #
48
+ # visit spree.admin_path
49
+ # current_path.should eql(spree.products_path)
50
+ # config.include Spree::TestingSupport::UrlHelpers
51
+ config.include Spree::TestingSupport::AuthorizationHelpers
52
+ config.include Spree::TestingSupport::UrlHelpers
53
+ config.include Spree::TestingSupport::ControllerRequests
54
+ config.include Spree::TestingSupport::Preferences
55
+ config.include Spree::TestingSupport::Flash
56
+ config.include Capybara::DSL
57
+
58
+ # == Mock Framework
59
+ #
60
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
61
+ #
62
+ # config.mock_with :mocha
63
+ # config.mock_with :flexmock
64
+ # config.mock_with :rr
65
+ config.mock_with :rspec
66
+ config.color = true
67
+
68
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
69
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
70
+
71
+ # Capybara javascript drivers require transactional fixtures set to false, and we use DatabaseCleaner
72
+ # to cleanup after each test instead. Without transactional fixtures set to false the records created
73
+ # to setup a test will be unavailable to the browser, which runs under a seperate server instance.
74
+ config.use_transactional_fixtures = false
75
+
76
+ # Ensure Suite is set to use transactions for speed.
77
+ config.before :suite do
78
+ DatabaseCleaner.strategy = :transaction
79
+ DatabaseCleaner.clean_with :truncation
80
+ end
81
+
82
+ # Before each spec check if it is a Javascript test and switch between using database transactions or not where necessary.
83
+ config.before :each do
84
+ DatabaseCleaner.strategy = example.metadata[:js] ? :truncation : :transaction
85
+ DatabaseCleaner.start
86
+ reset_spree_preferences
87
+ end
88
+
89
+ # After each spec clean the database.
90
+ config.after :each do
91
+ DatabaseCleaner.clean
92
+ end
93
+
94
+ config.fail_fast = ENV['FAIL_FAST'] || false
95
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: UTF-8
2
+ Gem::Specification.new do |s|
3
+ s.platform = Gem::Platform::RUBY
4
+ s.name = 'spree_ebsin'
5
+ s.version = '2.0.0'
6
+ s.summary = 'Adds Ebsin as a Payment Method to Spree store'
7
+ s.description = 'Adds Ebsin Payment Method option in admin, which can be enabled for payments using Ebsin(http://www.ebs.in/) on your Spree store.'
8
+ s.required_ruby_version = '>= 1.9.3'
9
+
10
+ s.author = 'Surya Tripathi'
11
+ s.email = 'raj.surya19@gmail.com'
12
+ s.homepage = 'https://github.com/suryart/spree_ebsin'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.require_path = 'lib'
17
+ s.requirements << 'none'
18
+
19
+ s.add_dependency 'spree_core', '~> 2.0.0'
20
+
21
+ s.add_development_dependency 'capybara', '~> 2.1'
22
+ s.add_development_dependency 'coffee-rails'
23
+ s.add_development_dependency 'database_cleaner', '1.0.1'
24
+ s.add_development_dependency 'factory_girl', '~> 4.2'
25
+ s.add_development_dependency 'ffaker'
26
+ s.add_development_dependency 'rspec-rails', '~> 2.13'
27
+ s.add_development_dependency 'sass-rails'
28
+ s.add_development_dependency 'selenium-webdriver'
29
+ s.add_development_dependency 'simplecov'
30
+ s.add_development_dependency 'sqlite3'
31
+ end
metadata ADDED
@@ -0,0 +1,258 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_ebsin
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Surya Tripathi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: spree_core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: capybara
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '2.1'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.1'
46
+ - !ruby/object:Gem::Dependency
47
+ name: coffee-rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: database_cleaner
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 1.0.1
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 1.0.1
78
+ - !ruby/object:Gem::Dependency
79
+ name: factory_girl
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '4.2'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '4.2'
94
+ - !ruby/object:Gem::Dependency
95
+ name: ffaker
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rspec-rails
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '2.13'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '2.13'
126
+ - !ruby/object:Gem::Dependency
127
+ name: sass-rails
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: selenium-webdriver
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: simplecov
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ - !ruby/object:Gem::Dependency
175
+ name: sqlite3
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ description: Adds Ebsin Payment Method option in admin, which can be enabled for payments
191
+ using Ebsin(http://www.ebs.in/) on your Spree store.
192
+ email: raj.surya19@gmail.com
193
+ executables: []
194
+ extensions: []
195
+ extra_rdoc_files: []
196
+ files:
197
+ - .gitignore
198
+ - .rspec
199
+ - .travis.yml
200
+ - Gemfile
201
+ - LICENSE
202
+ - README.md
203
+ - Rakefile
204
+ - Versionfile
205
+ - app/assets/javascripts/admin/spree_ebsin.js
206
+ - app/assets/javascripts/store/spree_ebsin.js
207
+ - app/assets/stylesheets/admin/spree_ebsin.css
208
+ - app/assets/stylesheets/store/spree_ebsin.css
209
+ - app/controllers/spree/checkout_controller_decorator.rb
210
+ - app/controllers/spree/gateway/ebsin_controller.rb
211
+ - app/models/spree.rb
212
+ - app/models/spree/ebsinfo.rb
213
+ - app/models/spree/order_decorator.rb
214
+ - app/models/spree/payment_decorator.rb
215
+ - app/models/spree/payment_method/ebsin.rb
216
+ - app/views/admin/payments/_list.html.erb
217
+ - app/views/spree/checkout/payment/_ebsin.html.erb
218
+ - app/views/spree/gateway/ebsin/show.html.erb
219
+ - config/locales/en.yml
220
+ - config/routes.rb
221
+ - db/migrate/20130702115540_create_ebsinfos.rb
222
+ - lib/generators/spree_ebsin/install/install_generator.rb
223
+ - lib/spree_ebsin.rb
224
+ - lib/spree_ebsin/engine.rb
225
+ - lib/spree_ebsin/factories.rb
226
+ - lib/spree_ebsin/rc4.rb
227
+ - script/rails
228
+ - spec/features/admin_payment_method_spec.rb
229
+ - spec/features/order_spec.rb
230
+ - spec/models/ebsinfo_spec.rb
231
+ - spec/spec_helper.rb
232
+ - spree_ebsin.gemspec
233
+ homepage: https://github.com/suryart/spree_ebsin
234
+ licenses: []
235
+ post_install_message:
236
+ rdoc_options: []
237
+ require_paths:
238
+ - lib
239
+ required_ruby_version: !ruby/object:Gem::Requirement
240
+ none: false
241
+ requirements:
242
+ - - ! '>='
243
+ - !ruby/object:Gem::Version
244
+ version: 1.9.3
245
+ required_rubygems_version: !ruby/object:Gem::Requirement
246
+ none: false
247
+ requirements:
248
+ - - ! '>='
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ requirements:
252
+ - none
253
+ rubyforge_project:
254
+ rubygems_version: 1.8.24
255
+ signing_key:
256
+ specification_version: 3
257
+ summary: Adds Ebsin as a Payment Method to Spree store
258
+ test_files: []