spree-bank-transfer 2.2.4 → 2.2.5

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.
@@ -0,0 +1,30 @@
1
+ //= require jquery.ui.datepicker
2
+ $(document).ready(function() {
3
+ $('#banktransfer_instructions').click(function(event) {
4
+ newwindow = window.open($(this).attr('href'), 'bank transfer', 'left=20,top=20,width=650,height=750,toolbar=0,resizable=0,scrollbars=1');
5
+ if (window.focus) {
6
+ newwindow.focus();
7
+ }
8
+ return false;
9
+ });
10
+
11
+ $('[name="payment[deposited_on]"]').datepicker({dateFormat: '<%= Spree.t(:js_format, :scope => "date_picker", :default => "yy/mm/dd") %>'});
12
+
13
+ $('.add_bt_details').click(function() {
14
+ $(this).hide();
15
+ $('.bt_payment_form').show();
16
+ });
17
+
18
+ $('.bt_payment_form input[type="submit"]').click(function(event) {
19
+ var empty_fields = $('.required_field').filter(function() { return !$(this).val().trim().length }), empty_fields_names = []
20
+ if ($(empty_fields).length) {
21
+ $(empty_fields).each(function() {
22
+ empty_fields_names.push($(this).attr('field-name'));
23
+ });
24
+
25
+ alert(empty_fields_names.join(', ') + " can't be blank");
26
+ event.preventDefault();
27
+ return false;
28
+ }
29
+ });
30
+ });
@@ -1 +1,9 @@
1
- .bt_payment_form { margin-left: 10px;}
1
+ /*
2
+ *= require jquery.ui.datepicker
3
+ */
4
+
5
+ .bt_payment_form { margin-left: -10px; }
6
+ .bt_payment_form table { border-collapse: inherit; }
7
+ .bt_payment_form [type="submit"] { margin-left: 10px; }
8
+ .bt_payment_form input[type="text"], .bt_payment_form input[type="date"] { width: 138px; }
9
+ .hidden { display: none; }
@@ -4,11 +4,11 @@ module Spree
4
4
  before_filter :find_payment
5
5
 
6
6
  def update
7
- @payment.validate_bank_details = true
8
- if @payment.update_attributes(payment_params)
7
+ payment_details = PaymentDetails.new(@payment, payment_params)
8
+ if payment_details.save
9
9
  flash[:notice] = Spree.t(:payment_successfully_updated)
10
10
  else
11
- flash[:error] = @payment.errors.full_messages.to_sentence
11
+ flash[:error] = payment_details.errors.to_sentence
12
12
  end
13
13
  redirect_to :back
14
14
  end
@@ -23,7 +23,7 @@ module Spree
23
23
 
24
24
  private
25
25
  def payment_params
26
- params.require(:payment).permit(:bank_name, :account_no, :transaction_reference_no)
26
+ params.require(:payment).permit(:deposited_on, :bank_name, :account_no, :transaction_reference_no)
27
27
  end
28
28
  end
29
29
  end
@@ -1,6 +1,10 @@
1
1
  Spree::Payment.class_eval do
2
2
  attr_accessor :validate_bank_details
3
- validates :bank_name, :account_no, :transaction_reference_no, :presence => true, :if => :validate_bank_details
3
+ validates :bank_name, :account_no, :transaction_reference_no, :deposited_on, :presence => true, :if => :validate_bank_details
4
4
 
5
5
  scope :from_bank_transfer, -> { joins(:payment_method).where(:spree_payment_methods => { :type => 'Spree::PaymentMethod::BankTransfer' }) }
6
+
7
+ def details_submitted?
8
+ transaction_reference_no?
9
+ end
6
10
  end
@@ -1,23 +1,32 @@
1
1
  Deface::Override.new(
2
- :virtual_path => 'spree/orders/show',
2
+ :virtual_path => 'spree/shared/_order_details',
3
3
  :name => 'add_bank_details_form_to_order_show',
4
- :insert_before => "[data-hook='links']",
4
+ :insert_bottom => ".payment-info",
5
5
  :text => %q{
6
6
  <% if bank_transfer_payment = @order.payments.from_bank_transfer.first %>
7
- <%= form_for bank_transfer_payment, :html => { :class => "bt_payment_form" } do |f| %>
7
+ <% unless bank_transfer_payment.details_submitted? %>
8
+ <br>
9
+ <%= link_to Spree.t(:add_details), "javascript:void(0);", :class => 'button add_bt_details' %>
10
+ <% end %>
11
+ <%= form_for bank_transfer_payment, :html => { :class => "bt_payment_form #{bank_transfer_payment.details_submitted? ? '' : 'hidden'}" } do |f| %>
8
12
  <table>
9
13
  <tr>
10
- <td><%= Spree.t(:bank_name) %></td><td><%= f.text_field :bank_name %></td>
14
+ <td><%= Spree.t(:deposited_on) %></td><td><%= f.date_field :deposited_on, :disabled => bank_transfer_payment.details_submitted?, :class => 'required_field', 'field-name' => 'Deposited on' %></td>
15
+ </tr>
16
+ <tr>
17
+ <td><%= Spree.t(:bank_name) %></td><td><%= f.text_field :bank_name, :disabled => bank_transfer_payment.details_submitted?, :class => 'required_field', 'field-name' => 'Bank name' %></td>
11
18
  </tr>
12
19
  <tr>
13
- <td><%= Spree.t(:account_no) %></td><td><%= f.text_field :account_no %></td>
20
+ <td><%= Spree.t(:account_no) %></td><td><%= f.text_field :account_no, :disabled => bank_transfer_payment.details_submitted?, :class => 'required_field', 'field-name' => 'Account No.' %></td>
14
21
  </tr>
15
22
  <tr>
16
- <td><%= Spree.t(:transaction_reference_no) %></td><td><%= f.text_field :transaction_reference_no %></td>
23
+ <td><%= Spree.t(:transaction_reference_no) %></td><td><%= f.text_field :transaction_reference_no, :disabled => bank_transfer_payment.details_submitted?, :class => 'required_field', 'field-name' => 'Transaction Reference No.' %></td>
17
24
  </tr>
18
25
  </table>
19
26
  <br>
20
- <%= f.submit "Submit" %>
27
+ <% unless bank_transfer_payment.details_submitted? %>
28
+ <%= f.submit "Submit", :confirm => "Are you sure you want to Submit these details? You will not be able to Edit these details once Submitted. Press 'OK' to confirm." %>
29
+ <% end %>
21
30
  <% end %>
22
31
  <% end %>
23
32
  }
@@ -0,0 +1,9 @@
1
+ Deface::Override.new(
2
+ :virtual_path => 'spree/checkout/_payment',
3
+ :name => 'add_bank_transfer_instructions_link_to_payment',
4
+ :insert_after => "#payment-method-fields",
5
+ :text => %q{
6
+ <p><%= link_to "How Bank Transfer works?", bank_transfer_instructions_path, :id => 'banktransfer_instructions', :target => "_blank" %></p>
7
+ }
8
+ )
9
+
@@ -5,10 +5,11 @@ Deface::Override.new(
5
5
  :text => %q{
6
6
  <% if bank_transfer_payment = @order.payments.from_bank_transfer.first %>
7
7
  <fieldset class="no-border-bottom" >
8
- <legend align="center"><%= Spree.t(:payment_reference_details) %></legend>
8
+ <legend align="center"><%= Spree.t(:bank_transfer_payment_reference_details) %></legend>
9
9
  <table class="index">
10
10
  <thead>
11
11
  <tr data-hook="payments_header">
12
+ <th><%= Spree.t(:deposited_on) %></th>
12
13
  <th><%= Spree.t(:bank_name) %></th>
13
14
  <th><%= Spree.t(:account_no) %></th>
14
15
  <th><%= Spree.t(:transaction_reference_no) %></th>
@@ -17,6 +18,7 @@ Deface::Override.new(
17
18
  </thead>
18
19
  <tbody>
19
20
  <tr>
21
+ <td class='align-center'><%= bank_transfer_payment.deposited_on %></td>
20
22
  <td class='align-center'><%= bank_transfer_payment.bank_name %></td>
21
23
  <td class='align-center'><%= bank_transfer_payment.account_no %></td>
22
24
  <td class='align-center'><%= bank_transfer_payment.transaction_reference_no %></td>
@@ -8,7 +8,7 @@ Deface::Override.new(
8
8
  <div class="field checkbox">
9
9
  <label>
10
10
  <%= f.check_box :payments_transaction_reference_no_not_null %>
11
- <%= Spree.t(:only_show_orders_with_payment_reference_number) %>
11
+ <%= Spree.t(:only_show_orders_with_bank_transfer_payment_reference_number) %>
12
12
  </label>
13
13
  </div>
14
14
 
@@ -1,5 +1,3 @@
1
- <%= link_to "How it works?", bank_transfer_instructions_path, :id => 'banktransfer_instructions', :target => "_blank" %>
2
- <br><br>
3
1
  <% if (banks = Spree::Bank.active).any? %>
4
2
  <table>
5
3
  <tr>
@@ -1,23 +1,32 @@
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>
1
+ <h4>HOW BANK TRANSFER WORKS</h4>
2
+ <b>Steps:</b>
3
+ <ol>
4
+ <li>Deposit order total in one of the below mentioned bank accounts. After this payment a payment reference number will be provided by the bank.
5
+ <% if (banks = Spree::Bank.active).any? %>
6
+ <div style="padding:20px 0">
7
+ <table border="1" align='center' width="60%">
8
+ <tr>
9
+ <th><center>Name</center></th>
10
+ <th><center>Account No</center></th>
11
+ </tr>
12
+ <% banks.each do |bank| %>
13
+ <tr>
14
+ <td><center><%= bank.name %></center></td>
15
+ <td><center><%= bank.account_no %></center></td>
16
+ </tr>
17
+ <% end %>
18
+ </table>
19
+ </div>
21
20
  <% end %>
22
- </table>
23
- <% end %>
21
+ </li>
22
+ <li>Enter this payment reference number on Order Details page by following steps:
23
+ <ol style="padding:10px 0 0 20px" type='a'>
24
+ <li>Go to "My Account" page.</li>
25
+ <li>Select Order for which you want to provide details.</li>
26
+ <li>Click on "Add Details" link visible in "Payment Information" column.</li>
27
+ <li>Provide payment details and Submit.</li>
28
+ <br><br>
29
+ <%= image_tag 'payment_details.png' %>
30
+ </ol>
31
+ </li>
32
+ </ol>
@@ -0,0 +1,5 @@
1
+ class AddColumnDepositedOnToSpreePayments < ActiveRecord::Migration
2
+ def change
3
+ add_column :spree_payments, :deposited_on, :date
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ class PaymentDetails
2
+ attr_accessor :payment, :errors, :params
3
+
4
+ def initialize(payment, params)
5
+ self.payment = payment
6
+ self.params = params
7
+ self.errors = []
8
+ end
9
+
10
+ def save
11
+ if payment.details_submitted?
12
+ errors << "Payment Details can be submitted only once."
13
+ else
14
+ payment.validate_bank_details = true
15
+ unless payment.update_attributes(params)
16
+ errors << payment.errors.full_messages.to_sentence
17
+ end
18
+ end
19
+ errors.empty?
20
+ end
21
+ end
@@ -43,8 +43,8 @@ describe Spree::PaymentsController do
43
43
 
44
44
  describe "PATCH update" do
45
45
  before do
46
- @payment.stub(:validate_bank_details=)
47
- @payment.stub(:update_attributes)
46
+ @payment_details = double('payment_details', :save => true)
47
+ PaymentDetails.stub(:new).and_return(@payment_details)
48
48
  end
49
49
 
50
50
  def send_request
@@ -53,34 +53,31 @@ describe Spree::PaymentsController do
53
53
 
54
54
  it_behaves_like "request which finds payment"
55
55
 
56
- it "sets validate_bank_details to true" do
57
- @payment.should_receive(:validate_bank_details=).with(true)
56
+
57
+ it "creates new payment details" do
58
+ PaymentDetails.should_receive(:new).with(@payment, { 'bank_name' => 'bank_name', 'account_no' => "account_no", 'transaction_reference_no' => "transaction_reference_no" })
58
59
  send_request
59
60
  end
60
61
 
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")
62
+ it "saves payment_details" do
63
+ @payment_details.should_receive(:save)
63
64
  send_request
64
65
  end
65
66
 
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
67
+ context 'when payment details saved successfully' do
68
+ it 'sets flash message' do
72
69
  send_request
73
70
  flash[:notice].should eq("Payment successfully updated")
74
71
  end
75
72
  end
76
73
 
77
- context 'when payment not updated' do
74
+ context 'when payment details not saved' do
78
75
  before do
79
- @payment.stub(:update_attributes).and_return(false)
80
- @payment.stub_chain(:errors, :full_messages).and_return(["some error occurred"])
76
+ @payment_details.stub(:save).and_return(false)
77
+ @payment_details.stub(:errors).and_return(["some error occurred"])
81
78
  end
82
79
 
83
- it "sets flash error" do
80
+ it 'sets flash error' do
84
81
  send_request
85
82
  flash[:error].should eq("some error occurred")
86
83
  end
@@ -93,9 +90,9 @@ describe Spree::PaymentsController do
93
90
  end
94
91
 
95
92
  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" })
93
+ it "permits only bank_name, account_no, transaction_reference_no, deposited_on" do
94
+ controller.params = { :payment => { :bank_name => 'Bank Name', :account_no => 'Account number', :transaction_reference_no => "transaction reference number", :order_id => 'order_id', :deposited_on => 'deposited_on' } }
95
+ controller.send(:payment_params).should eq({ "bank_name" => "Bank Name", "account_no" => "Account number", "transaction_reference_no" => "transaction reference number", 'deposited_on' => 'deposited_on' })
99
96
  end
100
97
  end
101
98
  end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+
3
+ describe PaymentDetails do
4
+ before do
5
+ @payment = mock_model(Spree::Payment, :update_attributes => true, :validate_bank_details= => nil)
6
+ @params = { 'bank_name' => 'bank_name', 'account_no' => "account_no", 'transaction_reference_no' => "transaction_reference_no" }
7
+ @payment_details = PaymentDetails.new(@payment, @params)
8
+ end
9
+
10
+ describe "#initialize" do
11
+ it "sets payment" do
12
+ @payment_details.payment.should eq(@payment)
13
+ end
14
+
15
+ it "sets params" do
16
+ @payment_details.params.should eq(@params)
17
+ end
18
+
19
+ it "initializes errors" do
20
+ @payment_details.errors.should eq([])
21
+ end
22
+ end
23
+
24
+ describe "#save" do
25
+ context 'when payment details submitted' do
26
+ before do
27
+ @payment.stub(:details_submitted?).and_return(true)
28
+ end
29
+
30
+ it "sets errors" do
31
+ @payment_details.save
32
+ @payment_details.errors.should eq(["Payment Details can be submitted only once."])
33
+ end
34
+
35
+ it "does not update payment" do
36
+ @payment.should_not_receive(:update_attributes)
37
+ @payment_details.save
38
+ end
39
+
40
+ it "returns false" do
41
+ @payment_details.save.should be_false
42
+ end
43
+
44
+ end
45
+
46
+ context 'when payment details not submitted' do
47
+ before do
48
+ @payment.stub(:details_submitted?).and_return(false)
49
+ end
50
+
51
+ it 'sets validates_bank_details to true' do
52
+ @payment.should_receive(:validate_bank_details=).with(true)
53
+ @payment_details.save
54
+ end
55
+
56
+ it "updates payment attributes" do
57
+ @payment.should_receive(:update_attributes)
58
+ @payment_details.save
59
+ end
60
+
61
+ context 'when payment attributes not updated successfully' do
62
+ before do
63
+ @payment.stub(:update_attributes).and_return(false)
64
+ @payment.stub_chain(:errors, :full_messages).and_return(["some error occurred"])
65
+ end
66
+
67
+ it 'sets errors' do
68
+ @payment_details.save
69
+ @payment_details.errors.should eq(["some error occurred"])
70
+ end
71
+
72
+ it 'returns false' do
73
+ @payment_details.save.should be_false
74
+ end
75
+ end
76
+
77
+ context 'when payment attributes updated successfully' do
78
+ it 'returns true' do
79
+ @payment_details.save.should be_true
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -9,6 +9,7 @@ describe Spree::Payment do
9
9
  it { should validate_presence_of(:bank_name) }
10
10
  it { should validate_presence_of(:account_no) }
11
11
  it { should validate_presence_of(:transaction_reference_no) }
12
+ it { should validate_presence_of(:deposited_on) }
12
13
  end
13
14
 
14
15
  context 'when validate_bank_details not true' do
@@ -55,4 +56,26 @@ describe Spree::Payment do
55
56
  Spree::Payment.from_bank_transfer.should =~ [@bank_transfer_payment1, @bank_transfer_payment2]
56
57
  end
57
58
  end
59
+
60
+ describe "#details_submitted?" do
61
+ before do
62
+ @payment = Spree::Payment.new
63
+ end
64
+
65
+ context 'when transaction_reference_no present' do
66
+ before do
67
+ @payment.transaction_reference_no = 'transaction_reference_no'
68
+ end
69
+
70
+ it 'is true' do
71
+ @payment.details_submitted?.should be_true
72
+ end
73
+ end
74
+
75
+ context 'when transaction_reference_no not present' do
76
+ it 'is false' do
77
+ @payment.details_submitted?.should be_false
78
+ end
79
+ end
80
+ end
58
81
  end
@@ -2,7 +2,7 @@
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.4'
5
+ s.version = '2.2.5'
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'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree-bank-transfer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 2
9
- - 4
10
- version: 2.2.4
9
+ - 5
10
+ version: 2.2.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mohit Bansal
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2014-05-23 00:00:00 Z
18
+ date: 2014-06-09 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: spree_core
@@ -50,8 +50,9 @@ files:
50
50
  - README.md
51
51
  - Rakefile
52
52
  - Versionfile
53
+ - app/assets/images/payment_details.png
53
54
  - app/assets/javascripts/admin/spree_bank_transfer.js
54
- - app/assets/javascripts/store/spree_bank_transfer.js
55
+ - app/assets/javascripts/store/spree_bank_transfer.js.erb
55
56
  - app/assets/stylesheets/admin/spree_bank_transfer.css
56
57
  - app/assets/stylesheets/store/spree_bank_transfer.css
57
58
  - app/controllers/spree/admin/banks_controller.rb
@@ -67,6 +68,7 @@ files:
67
68
  - app/models/spree/payment_method/bank_transfer.rb
68
69
  - app/models/spree/user_decorator.rb
69
70
  - app/overrides/add_bank_details_form_to_order_show.rb
71
+ - app/overrides/add_bank_transfer_instructions_link_to_payment.rb
70
72
  - app/overrides/add_banks_to_admin_configuration_sidebar.rb
71
73
  - app/overrides/add_payment_reference_details.rb
72
74
  - app/overrides/filter_results_by_transaction_reference_no.rb
@@ -86,8 +88,10 @@ files:
86
88
  - db/migrate/20130717071443_create_table_bank.rb
87
89
  - db/migrate/20130717125312_add_index_on_active_on_spree_bank.rb
88
90
  - db/migrate/20140519125402_add_bank_name_account_number_and_transaction_reference_number_to_payments.rb
91
+ - db/migrate/20140530055151_add_column_deposited_on_to_spree_payments.rb
89
92
  - lib/generators/spree_bank_transfer/.DS_Store
90
93
  - lib/generators/spree_bank_transfer/install/install_generator.rb
94
+ - lib/payment_details.rb
91
95
  - lib/spree_bank_transfer.rb
92
96
  - lib/spree_bank_transfer/engine.rb
93
97
  - lib/spree_bank_transfer/factories.rb
@@ -95,6 +99,7 @@ files:
95
99
  - spec/controllers/spree/admin/banks_controller_spec.rb
96
100
  - spec/controllers/spree/content_controller_spec.rb
97
101
  - spec/controllers/spree/payments_controller_spec.rb
102
+ - spec/lib/payment_details_spec.rb
98
103
  - spec/models/spree/bank_spec.rb
99
104
  - spec/models/spree/payment_method/bank_transfer_spec.rb
100
105
  - spec/models/spree/payment_spec.rb
@@ -1,9 +0,0 @@
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
- });