spree-bank-transfer 2.2.2 → 2.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Spree Bank Transfer [![Code Climate](https://codeclimate.com/github/vinsol/spree_bank_transfer.png)](https://codeclimate.com/github/vinsol/spree_bank_transfer) [![Build Status](https://travis-ci.org/vinsol/spree_bank_transfer.png?branch=master)](https://travis-ci.org/vinsol/spree_bank_transfer)
2
2
  =================
3
3
 
4
- This Spree extension allows admin to provide bank transfer payment method to its users for.
4
+ Spree Bank Transfer extension creates a new payment method in Spree. This payment method allows customers to pay by transferring money directly into merchant’s bank account. It also allows admin to provide their Bank account's (Merchant Bank Account) details which will be displayed to customers while checkout, and they can use this information to make payment for their orders. This extension also facilitate admin to Activate/Deactivate Bank accounts.
5
5
 
6
6
 
7
7
  Installation
@@ -30,13 +30,54 @@ bundle
30
30
  bundle exec rails g spree_bank_transfer:install
31
31
  ```
32
32
 
33
- Use
33
+ How it works:
34
34
  ---
35
- Login as Admin and create a new payment method with Spree::PaymentMethod::BankTransfer as provider class.
36
35
 
37
- Create bank details under configuration/banks.
36
+ * To add Bank Transfer feature, Admin needs to add “Bank Transfer” payment method:
38
37
 
39
- Checkout and select bank transfer payment method. Here, user can see the list of bank details.
38
+ Configuration -> Payment Methods -> New payment Method
39
+
40
+ You need to select “Spree::PaymentMethod::BankTransfer” as the Provider
41
+
42
+ * Add bank account information from “Banks” link on “Configuration” page.
43
+
44
+ - Provide Name of the bank
45
+ - Provide Account number
46
+ - Select “Status” check box
47
+
48
+ ![Listing Banks](http://vinsol.com/gems_screenshots/spree-bank-transfer/list%20banks.png)
49
+
50
+ **Bank Account will be visible on Checkout Page only if it is Active.**
51
+ * After adding the payment method and bank details (as stated above), this payment method will be visible on Checkout page while making payment against an order.
52
+
53
+ * Active merchant **accounts number** will also be visible on Checkout page under this method.
54
+
55
+ ![Checkout](http://vinsol.com/gems_screenshots/spree-bank-transfer/checkout%20page.png)
56
+
57
+ * Customer will be able to order by completing the order with this method and can transfer money equal to total order value directly into any one of the merchant’s bank account.
58
+
59
+ * After receiving amount into his account, admin can update order by following the steps:
60
+
61
+ - On ‘Orders’ tab, click on order number to go to the order’s details page..
62
+ - Select “Payments” link.
63
+ - Mark the payment “Capture”
64
+ ![Order Page](http://vinsol.com/gems_screenshots/spree-bank-transfer/order%20page.png)
65
+
66
+ * The order will not be marked Completed until admin captures the payment as mentioned in step above.
67
+
68
+
69
+
70
+
71
+ Contributing
72
+ ------------
73
+
74
+ 1. Fork the repo.
75
+ 2. Clone your repo.
76
+ 3. Run `bundle install`.
77
+ 4. Run `bundle exec rake test_app` to create the test application in `spec/test_app`.
78
+ 5. Make your changes.
79
+ 6. Ensure specs pass by running `bundle exec rspec spec`.
80
+ 7. Submit your pull request.
40
81
 
41
82
  Testing
42
83
  -------
@@ -56,17 +97,6 @@ Simply add this require statement to your spec_helper:
56
97
  require 'spree_bank_transfer/factories'
57
98
  ```
58
99
 
59
- Contributing
60
- ------------
61
-
62
- 1. Fork the repo.
63
- 2. Clone your repo.
64
- 3. Run `bundle install`.
65
- 4. Run `bundle exec rake test_app` to create the test application in `spec/test_app`.
66
- 5. Make your changes.
67
- 6. Ensure specs pass by running `bundle exec rspec spec`.
68
- 7. Submit your pull request.
69
-
70
100
 
71
101
  Credits
72
102
  -------
@@ -0,0 +1,9 @@
1
+ $(document).ready(function() {
2
+ $('#banktransfer_instructions').click(function(event) {
3
+ newwindow = window.open($(this).attr('href'), 'bank transfer', 'left=20,top=20,width=500,height=500,toolbar=0,resizable=0,scrollbars=1');
4
+ if (window.focus) {
5
+ newwindow.focus();
6
+ }
7
+ return false;
8
+ });
9
+ });
@@ -0,0 +1 @@
1
+ .bt_payment_form { margin-left: 10px;}
@@ -0,0 +1,5 @@
1
+ Spree::ContentController.class_eval do
2
+ def bank_transfer
3
+ render :layout => false
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ module Spree
2
+ class PaymentsController < Spree::StoreController
3
+ before_filter :authenticate_spree_user!
4
+ before_filter :find_payment
5
+
6
+ def update
7
+ @payment.validate_bank_details = true
8
+ if @payment.update_attributes(payment_params)
9
+ flash[:notice] = Spree.t(:payment_successfully_updated)
10
+ else
11
+ flash[:error] = @payment.errors.full_messages.to_sentence
12
+ end
13
+ redirect_to :back
14
+ end
15
+
16
+ def find_payment
17
+ @payment = spree_current_user.payments.where(:id => params[:id]).first
18
+ unless @payment
19
+ flash[:error] = Spree.t(:payment_not_found)
20
+ redirect_to :back
21
+ end
22
+ end
23
+
24
+ private
25
+ def payment_params
26
+ params.require(:payment).permit(:bank_name, :account_no, :transaction_reference_no)
27
+ end
28
+ end
29
+ end
@@ -3,6 +3,6 @@ module Spree
3
3
  validates :name, :account_no , :presence => true
4
4
  validates_uniqueness_of :account_no , :scope => :name
5
5
 
6
- scope :active, where(:active => true)
6
+ scope :active, -> { where(:active => true) }
7
7
  end
8
8
  end
@@ -0,0 +1,6 @@
1
+ Spree::Payment.class_eval do
2
+ attr_accessor :validate_bank_details
3
+ validates :bank_name, :account_no, :transaction_reference_no, :presence => true, :if => :validate_bank_details
4
+
5
+ scope :from_bank_transfer, -> { joins(:payment_method).where(:spree_payment_methods => { :type => 'Spree::PaymentMethod::BankTransfer' }) }
6
+ end
@@ -0,0 +1,3 @@
1
+ Spree::User.class_eval do
2
+ has_many :payments, :through => :orders
3
+ end
@@ -0,0 +1,24 @@
1
+ Deface::Override.new(
2
+ :virtual_path => 'spree/orders/show',
3
+ :name => 'add_bank_details_form_to_order_show',
4
+ :insert_before => "[data-hook='links']",
5
+ :text => %q{
6
+ <% if bank_transfer_payment = @order.payments.from_bank_transfer.first %>
7
+ <%= form_for bank_transfer_payment, :html => { :class => "bt_payment_form" } do |f| %>
8
+ <table>
9
+ <tr>
10
+ <td><%= Spree.t(:bank_name) %></td><td><%= f.text_field :bank_name %></td>
11
+ </tr>
12
+ <tr>
13
+ <td><%= Spree.t(:account_no) %></td><td><%= f.text_field :account_no %></td>
14
+ </tr>
15
+ <tr>
16
+ <td><%= Spree.t(:transaction_reference_no) %></td><td><%= f.text_field :transaction_reference_no %></td>
17
+ </tr>
18
+ </table>
19
+ <br>
20
+ <%= f.submit "Submit" %>
21
+ <% end %>
22
+ <% end %>
23
+ }
24
+ )
@@ -0,0 +1,33 @@
1
+ Deface::Override.new(
2
+ :virtual_path => 'spree/admin/payments/_list',
3
+ :name => 'add_payment_reference_details',
4
+ :insert_after => "table.index",
5
+ :text => %q{
6
+ <% if bank_transfer_payment = @order.payments.from_bank_transfer.first %>
7
+ <fieldset class="no-border-bottom" >
8
+ <legend align="center"><%= Spree.t(:payment_reference_details) %></legend>
9
+ <table class="index">
10
+ <thead>
11
+ <tr data-hook="payments_header">
12
+ <th><%= Spree.t(:bank_name) %></th>
13
+ <th><%= Spree.t(:account_no) %></th>
14
+ <th><%= Spree.t(:transaction_reference_no) %></th>
15
+ <th class="actions"></th>
16
+ </tr>
17
+ </thead>
18
+ <tbody>
19
+ <tr>
20
+ <td class='align-center'><%= bank_transfer_payment.bank_name %></td>
21
+ <td class='align-center'><%= bank_transfer_payment.account_no %></td>
22
+ <td class='align-center'><%= bank_transfer_payment.transaction_reference_no %></td>
23
+ </tr>
24
+ </tbody>
25
+ </table>
26
+ </fieldset>
27
+ <% end %>
28
+ }
29
+ )
30
+
31
+
32
+
33
+
@@ -0,0 +1,29 @@
1
+ Deface::Override.new(
2
+ :virtual_path => 'spree/admin/orders/index',
3
+ :name => 'filter_results_by_transaction_reference_no',
4
+ :insert_after => "div.omega.four.columns",
5
+ :text => %q{
6
+ <div class="clearfix"></div>
7
+ <div class="field-block alpha four columns">
8
+ <div class="field checkbox">
9
+ <label>
10
+ <%= f.check_box :payments_transaction_reference_no_not_null %>
11
+ <%= Spree.t(:only_show_orders_with_payment_reference_number) %>
12
+ </label>
13
+ </div>
14
+
15
+ <div class="field">
16
+ <%= label_tag nil, Spree.t(:payment_state) %>
17
+ <%= f.select :payments_state_eq, Spree::Payment.state_machines[:state].states.collect {|s| [s.name, s.value]}, {:include_blank => true}, :class => 'select2' %>
18
+ </div>
19
+ </div>
20
+ }
21
+ )
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
@@ -1,3 +1,5 @@
1
+ <%= link_to "How it works?", bank_transfer_instructions_path, :id => 'banktransfer_instructions', :target => "_blank" %>
2
+ <br><br>
1
3
  <% if (banks = Spree::Bank.active).any? %>
2
4
  <table>
3
5
  <tr>
@@ -0,0 +1,23 @@
1
+ <p>Deposit order amount in one of the below mentioned Bank Accounts.</p>
2
+ <p>Note: A payment reference number will be generated by the bank.</p>
3
+ Enter this payment reference number on Order's page by following steps:<br><br>
4
+ a) Select "My Account" from top right corner. <br>
5
+ b) Select "Order" link from drop down. <br>
6
+ c) Click on the Order number. <br>
7
+ d) Provide payment details and Submit.
8
+ <br><br>
9
+
10
+ <% if (banks = Spree::Bank.active).any? %>
11
+ <table border="1">
12
+ <tr>
13
+ <th>Name</th>
14
+ <th>Account No</th>
15
+ </tr>
16
+ <% banks.each do |bank| %>
17
+ <tr>
18
+ <td><%= bank.name %></td>
19
+ <td><%= bank.account_no %></td>
20
+ </tr>
21
+ <% end %>
22
+ </table>
23
+ <% end %>
@@ -3,3 +3,10 @@
3
3
 
4
4
  en:
5
5
  hello: "Hello world"
6
+ spree:
7
+ payment_not_found: "Payment not found"
8
+ payment_successfully_updated: "Payment successfully updated"
9
+ payment_reference_details: "Payment Reference Details"
10
+ bank_name: "Bank Name"
11
+ account_no: 'Account No'
12
+ transaction_reference_no: 'Transaction Reference No'
data/config/routes.rb CHANGED
@@ -5,4 +5,6 @@ Spree::Core::Engine.routes.draw do
5
5
  put :toggle_activation, :on => :member
6
6
  end
7
7
  end
8
+ resources :payments, :only => :update
9
+ get '/content/bank_transfer', :to => 'content#bank_transfer', :as => :bank_transfer_instructions
8
10
  end
@@ -0,0 +1,7 @@
1
+ class AddBankNameAccountNumberAndTransactionReferenceNumberToPayments < ActiveRecord::Migration
2
+ def change
3
+ add_column :spree_payments, :bank_name, :string
4
+ add_column :spree_payments, :account_no, :string
5
+ add_column :spree_payments, :transaction_reference_no, :string
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::ContentController do
4
+ before do
5
+ controller.stub(:authenticate_spree_user!).and_return(true)
6
+ @user = mock_model(Spree::User, :generate_spree_api_key! => false, :last_incomplete_spree_order => nil)
7
+ controller.stub(:spree_current_user).and_return(@user)
8
+ end
9
+
10
+ describe "GET bank_transfer" do
11
+ it "renders bank_transfer" do
12
+ get :bank_transfer, :use_route => 'spree'
13
+ response.should render_template("bank_transfer")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::PaymentsController do
4
+ before do
5
+ controller.stub(:authenticate_spree_user!).and_return(true)
6
+ @user = mock_model(Spree::User, :generate_spree_api_key! => false, :last_incomplete_spree_order => nil)
7
+ controller.stub(:spree_current_user).and_return(@user)
8
+
9
+ @payment = mock_model(Spree::Payment)
10
+ @current_user_payments = double("current_user_payments", :where => [@payment])
11
+ @user.stub(:payments).and_return(@current_user_payments)
12
+ request.env["HTTP_REFERER"] = "http://localhost"
13
+ end
14
+
15
+ shared_examples_for "request which finds payment" do
16
+
17
+ it "finds payment" do
18
+ @current_user_payments.should_receive(:where).with(:id => 'payment_id')
19
+ send_request
20
+ end
21
+
22
+ it "assigns @payment" do
23
+ send_request
24
+ assigns(:payment).should eq(@payment)
25
+ end
26
+
27
+ context 'when payment not found' do
28
+ before do
29
+ @current_user_payments.stub(:where).and_return([])
30
+ end
31
+
32
+ it "sets flash message" do
33
+ send_request
34
+ flash[:error].should eq("Payment not found")
35
+ end
36
+
37
+ it "redirects to back" do
38
+ send_request
39
+ response.should redirect_to(:back)
40
+ end
41
+ end
42
+ end
43
+
44
+ describe "PATCH update" do
45
+ before do
46
+ @payment.stub(:validate_bank_details=)
47
+ @payment.stub(:update_attributes)
48
+ end
49
+
50
+ def send_request
51
+ patch :update, :id => 'payment_id', :payment => { :bank_name => 'bank_name', :account_no => "account_no", :transaction_reference_no => "transaction_reference_no" }, :use_route => 'spree'
52
+ end
53
+
54
+ it_behaves_like "request which finds payment"
55
+
56
+ it "sets validate_bank_details to true" do
57
+ @payment.should_receive(:validate_bank_details=).with(true)
58
+ send_request
59
+ end
60
+
61
+ it "update_attributes" do
62
+ @payment.should_receive(:update_attributes).with("bank_name" => 'bank_name', "account_no" => "account_no", "transaction_reference_no" => "transaction_reference_no")
63
+ send_request
64
+ end
65
+
66
+ context 'when payment updated' do
67
+ before do
68
+ @payment.stub(:update_attributes).and_return(true)
69
+ end
70
+
71
+ it "sets flash message" do
72
+ send_request
73
+ flash[:notice].should eq("Payment successfully updated")
74
+ end
75
+ end
76
+
77
+ context 'when payment not updated' do
78
+ before do
79
+ @payment.stub(:update_attributes).and_return(false)
80
+ @payment.stub_chain(:errors, :full_messages).and_return(["some error occurred"])
81
+ end
82
+
83
+ it "sets flash error" do
84
+ send_request
85
+ flash[:error].should eq("some error occurred")
86
+ end
87
+ end
88
+
89
+ it "redirects to back" do
90
+ send_request
91
+ response.should redirect_to(:back)
92
+ end
93
+ end
94
+
95
+ describe "#payment_params" do
96
+ it "permits only bank_name, account_no, transaction_reference_no" do
97
+ controller.params = { :payment => { :bank_name => 'Bank Name', :account_no => 'Account number', :transaction_reference_no => "transaction reference number", :order_id => 'order_id' } }
98
+ controller.send(:payment_params).should eq({ "bank_name" => "Bank Name", "account_no" => "Account number", "transaction_reference_no" => "transaction reference number" })
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Payment do
4
+ context 'when validate_bank_details' do
5
+ before do
6
+ subject.validate_bank_details = true
7
+ end
8
+
9
+ it { should validate_presence_of(:bank_name) }
10
+ it { should validate_presence_of(:account_no) }
11
+ it { should validate_presence_of(:transaction_reference_no) }
12
+ end
13
+
14
+ context 'when validate_bank_details not true' do
15
+ it { should_not validate_presence_of(:bank_name) }
16
+ it { should_not validate_presence_of(:account_no) }
17
+ it { should_not validate_presence_of(:transaction_reference_no) }
18
+ end
19
+
20
+ describe ".from_bank_transfer" do
21
+ before do
22
+ check_payment_method = Spree::PaymentMethod::Check.new
23
+ check_payment_method.name = "Check Payment Method"
24
+ check_payment_method.save!
25
+
26
+ bank_transfer_payment_method = Spree::PaymentMethod::BankTransfer.new
27
+ bank_transfer_payment_method.name = "Bank Transfer"
28
+ bank_transfer_payment_method.save!
29
+
30
+ @order = Spree::Order.new
31
+ @order.save!
32
+
33
+ @payment1 = Spree::Payment.new
34
+ @payment1.order_id = @order.id
35
+ @payment1.payment_method_id = check_payment_method.id
36
+ @payment1.save!
37
+
38
+ @payment2 = Spree::Payment.new
39
+ @payment2.order_id = @order.id
40
+ @payment2.payment_method_id = check_payment_method.id
41
+ @payment2.save!
42
+
43
+ @bank_transfer_payment1 = Spree::Payment.new
44
+ @bank_transfer_payment1.order_id = @order.id
45
+ @bank_transfer_payment1.payment_method_id = bank_transfer_payment_method.id
46
+ @bank_transfer_payment1.save!
47
+
48
+ @bank_transfer_payment2 = Spree::Payment.new
49
+ @bank_transfer_payment2.order_id = @order.id
50
+ @bank_transfer_payment2.payment_method_id = bank_transfer_payment_method.id
51
+ @bank_transfer_payment2.save!
52
+ end
53
+
54
+ it "returns payments with payment method as bank_transfer" do
55
+ Spree::Payment.from_bank_transfer.should =~ [@bank_transfer_payment1, @bank_transfer_payment2]
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::User do
4
+ it { should have_many(:payments).through(:orders) }
5
+ end
@@ -2,12 +2,12 @@
2
2
  Gem::Specification.new do |s|
3
3
  s.platform = Gem::Platform::RUBY
4
4
  s.name = 'spree-bank-transfer'
5
- s.version = '2.2.2'
5
+ s.version = '2.2.4'
6
6
  s.summary = 'Spree extension to create bank transfer payment method.'
7
7
  s.description = 'This Spree extension allows admin to provide bank transfer payment method to its users.'
8
8
  s.required_ruby_version = '>= 1.9.3'
9
9
 
10
- s.authors = ['Mohit Bansal', 'Vishal Zambre']
10
+ s.author = 'Mohit Bansal'
11
11
  s.email = 'info@vinsol.com'
12
12
  s.homepage = 'http://vinsol.com'
13
13
  s.license = "MIT"
metadata CHANGED
@@ -1,22 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree-bank-transfer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 2
9
- - 2
10
- version: 2.2.2
9
+ - 4
10
+ version: 2.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mohit Bansal
14
- - Vishal Zambre
15
14
  autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2014-05-12 00:00:00 Z
18
+ date: 2014-05-23 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: spree_core
@@ -56,14 +55,21 @@ files:
56
55
  - app/assets/stylesheets/admin/spree_bank_transfer.css
57
56
  - app/assets/stylesheets/store/spree_bank_transfer.css
58
57
  - app/controllers/spree/admin/banks_controller.rb
58
+ - app/controllers/spree/content_controller_decorator.rb
59
+ - app/controllers/spree/payments_controller.rb
59
60
  - app/helpers/.DS_Store
60
61
  - app/helpers/spree/.DS_Store
61
62
  - app/helpers/spree/admin/banks_helper.rb
62
63
  - app/models/.DS_Store
63
64
  - app/models/spree/.DS_Store
64
65
  - app/models/spree/bank.rb
66
+ - app/models/spree/payment_decorator.rb
65
67
  - app/models/spree/payment_method/bank_transfer.rb
68
+ - app/models/spree/user_decorator.rb
69
+ - app/overrides/add_bank_details_form_to_order_show.rb
66
70
  - app/overrides/add_banks_to_admin_configuration_sidebar.rb
71
+ - app/overrides/add_payment_reference_details.rb
72
+ - app/overrides/filter_results_by_transaction_reference_no.rb
67
73
  - app/views/.DS_Store
68
74
  - app/views/spree/admin/banks/_form.html.erb
69
75
  - app/views/spree/admin/banks/edit.html.erb
@@ -74,10 +80,12 @@ files:
74
80
  - app/views/spree/admin/payments/source_views/_banktransfer.html.erb
75
81
  - app/views/spree/checkout/.DS_Store
76
82
  - app/views/spree/checkout/payment/_banktransfer.html.erb
83
+ - app/views/spree/content/bank_transfer.html.erb
77
84
  - config/locales/en.yml
78
85
  - config/routes.rb
79
86
  - db/migrate/20130717071443_create_table_bank.rb
80
87
  - db/migrate/20130717125312_add_index_on_active_on_spree_bank.rb
88
+ - db/migrate/20140519125402_add_bank_name_account_number_and_transaction_reference_number_to_payments.rb
81
89
  - lib/generators/spree_bank_transfer/.DS_Store
82
90
  - lib/generators/spree_bank_transfer/install/install_generator.rb
83
91
  - lib/spree_bank_transfer.rb
@@ -85,8 +93,12 @@ files:
85
93
  - lib/spree_bank_transfer/factories.rb
86
94
  - script/rails
87
95
  - spec/controllers/spree/admin/banks_controller_spec.rb
96
+ - spec/controllers/spree/content_controller_spec.rb
97
+ - spec/controllers/spree/payments_controller_spec.rb
88
98
  - spec/models/spree/bank_spec.rb
89
99
  - spec/models/spree/payment_method/bank_transfer_spec.rb
100
+ - spec/models/spree/payment_spec.rb
101
+ - spec/models/spree/user_spec.rb
90
102
  - spec/spec_helper.rb
91
103
  - spree_bank_transfer.gemspec
92
104
  homepage: http://vinsol.com