Skip to content

Commit

Permalink
update for spree 4.1.x, based on pull vinsol-spree-contrib#39 of vins…
Browse files Browse the repository at this point in the history
…ol-spree-contrib's spree_bank_transfer
  • Loading branch information
spencerwp committed Feb 22, 2021
1 parent 2a38cf1 commit 26bf68e
Show file tree
Hide file tree
Showing 21 changed files with 152 additions and 114 deletions.
19 changes: 10 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
source 'https://rubygems.org'

# Provides basic authentication functionality for testing parts of your engine
version = '3-1-stable'
gem 'spree', github: 'spree/spree', branch: version
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: version
spree_version = 'master'
gem 'spree', github: 'spree/spree', branch: spree_version
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: spree_version

gem 'coffee-rails', ' ~> 4.0.1'
gem 'sass-rails', '~> 5.0.1'
gem 'coffee-rails', ' ~> 5.0.0'
gem 'sass-rails', '~> 6.0.0'

group :test do
gem 'minitest'
gem 'rspec-rails', '~> 3.4.0'
gem 'shoulda-matchers', '~> 3.1.1'
gem 'rspec-activemodel-mocks', '~> 1.0.3'
gem 'rspec-rails', '~> 4.0.0'
gem 'shoulda-matchers', '~> 4.3.0'
gem 'rspec-activemodel-mocks', '~> 1.1.0'
gem 'simplecov', require: false
gem 'database_cleaner'
end
gemspec

gemspec
1 change: 1 addition & 0 deletions Versionfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'4.1.x' => { branch: '4-1-stable' }
'3.0.x' => { branch: '3-0-stable' }
'2.4.x' => { branch: '2-4-stable' }
'2.3.x' => { branch: '2-3-stable' }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//= require jquery-ui/datepicker
//= require jquery-ui/widgets/datepicker
$(document).ready(function() {
$('#banktransfer_instructions').on("click", function(event) {
newwindow = window.open($(this).attr('href'), 'bank transfer', 'left=20,top=20,width=650,height=750,toolbar=0,resizable=0,scrollbars=1');
Expand Down
4 changes: 0 additions & 4 deletions app/assets/stylesheets/spree/frontend/spree_bank_transfer.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,4 @@
width: 18em; /* fix calendar width */
padding: .2em .2em 0;
}
.bt_payment_form { margin-left: -10px; }
.bt_payment_form table { border-collapse: inherit; }
.bt_payment_form [type="submit"] { margin-left: 10px; }
.bt_payment_form input[type="text"], .bt_payment_form input[type="date"] { width: 138px; }
.hidden { display: none; }
3 changes: 1 addition & 2 deletions app/controllers/spree/content_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Spree::ContentController.class_eval do
def bank_transfer
render layout: false
end
end
end
8 changes: 4 additions & 4 deletions app/controllers/spree/payments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Spree
class PaymentsController < Spree::StoreController
before_filter :authenticate_spree_user!
before_filter :find_payment
#before_action :authenticate_spree_user!
before_action :find_payment

def update
payment_details = PaymentDetails.new(@payment, payment_params)
Expand All @@ -17,13 +17,13 @@ def find_payment
@payment = spree_current_user.payments.find_by(number: params[:id])
unless @payment
flash[:error] = Spree.t(:payment_not_found)
redirect_to :back
redirect_back(fallback_location: root_path)
end
end

private
def payment_params
params.require(:payment).permit(:deposited_on, :bank_name, :account_no, :transaction_reference_no)
params.require(:payment).permit(:deposited_on, :bank_name, :account_no, :transaction_reference_no, :receipt)
end
end
end
22 changes: 19 additions & 3 deletions app/models/spree/payment_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
Spree::Payment.class_eval do
attr_accessor :validate_bank_details
validates :bank_name, :account_no, :transaction_reference_no, :deposited_on, presence: true, if: :validate_bank_details

has_one_attached :receipt
belongs_to :order
validates :bank_name, :deposited_on, :receipt, presence: true, if: :validate_bank_details

before_save :update_source_type, if: :validate_bank_details
after_save :update_order_state, if: :validate_bank_details

scope :from_bank_transfer, -> { joins(:payment_method).where(spree_payment_methods: { type: 'Spree::PaymentMethod::BankTransfer' }) }

self.whitelisted_ransackable_attributes = %w( transaction_reference_no state )
self.whitelisted_ransackable_attributes = %w( bank_name state )

def details_submitted?
transaction_reference_no?
bank_name?
end

private

def update_source_type
self.source_type = "Spree::PaymentMethod::BankTransfer"
end

def update_order_state
order.update(payment_state: :paid)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
insert_after: "#payment-method-fields",
text: %q{
<% if @order.available_payment_methods.any? { |pm| pm.type == 'Spree::PaymentMethod::BankTransfer' } %>
<p><%= link_to t(:how_bank_transfer_works), bank_transfer_instructions_path, id: 'banktransfer_instructions', target: "_blank" %></p>
<p><%= link_to Spree.t(:how_bank_transfer_works), bank_transfer_instructions_path, id: 'banktransfer_instructions', target: "_blank" %></p>
<% end %>
}
)
15 changes: 8 additions & 7 deletions app/overrides/add_payment_reference_details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@
<% if bank_transfer_payment = @order.payments.from_bank_transfer.first %>
<fieldset class="no-border-bottom" >
<legend align="center"><%= Spree.t(:payment_reference_details) %></legend>
<table class="index">
<table class="index table">
<thead>
<tr data-hook="payments_header">
<tr data-hook="payments_header" class="table-active">
<th><%= Spree.t(:deposited_on) %></th>
<th><%= Spree.t(:bank_name) %></th>
<th><%= Spree.t(:account_no) %></th>
<th><%= Spree.t(:transaction_reference_no) %></th>
<th class="actions"></th>
<th><%= Spree.t(:receipt) %></th>
</tr>
</thead>
<tbody>
<tr>
<td class='align-center'><%= bank_transfer_payment.deposited_on %></td>
<td class='align-center'><%= bank_transfer_payment.bank_name %></td>
<td class='align-center'><%= bank_transfer_payment.account_no %></td>
<td class='align-center'><%= bank_transfer_payment.transaction_reference_no %></td>
<td class='align-center' width="450px">
<% if bank_transfer_payment.receipt.attached? %>
<%= image_tag main_app.url_for(bank_transfer_payment.receipt), class: "w-100" %>
<% end %>
</td>
</tr>
</tbody>
</table>
Expand Down
15 changes: 4 additions & 11 deletions app/overrides/filter_results_by_transaction_reference_no.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,11 @@
text: %q{
<div class="row">
<div class="col-md-4">
<div class="field checkbox">
<label>
<%= f.check_box :payments_transaction_reference_no_not_null %>
<%= Spree.t(:only_show_orders_with_bank_transfer_payment_reference_number) %>
</label>
</div>
</div>
<div class="col-md-4">
<div class="field">
<div class="form-group">
<%= label_tag nil, Spree.t(:payment_state) %>
<%= f.select :payments_state_eq, Spree::Payment.state_machines[:state].states.collect {|s| [s.name, s.value]}, {include_blank: true}, class: 'select2' %>
<%= f.select :payments_state_eq, Spree::Payment.state_machines[:state].states.collect {|s| [s.name, s.value]},
{include_blank: true},
{class: 'select2 form-control'} %>
</div>
</div>
</div>
Expand Down
74 changes: 40 additions & 34 deletions app/views/spree/content/bank_transfer.html.erb
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
<h4>HOW BANK TRANSFER WORKS</h4>
<b>Steps:</b>
<ol>
<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.
<% if (banks = Spree::Bank.active).any? %>
<div style="padding:20px 0">
<table border="1" align='center' width="80%">
<tr>
<th><%= Spree.t(:bank_name) %></th>
<th><%= Spree.t(:account_no) %></th>
<th><%= Spree.t(:additional_details) %></th>
</tr>
<% banks.each do |bank| %>
<tr>
<td><center><%= bank.name %></center></td>
<td><center><%= bank.account_no %></center></td>
<td><center><%= bank.additional_details %></center></td>
</tr>
<% end %>
</table>
</div>
<% end %>
</li>
<li>Enter this payment reference number on Order Details page by following steps:
<ol style="padding:10px 0 0 20px" type='a'>
<li>Go to "My Account" page.</li>
<li>Select Order for which you want to provide details.</li>
<li>Click on "Add Details" link visible in "Payment Information" column.</li>
<li>Provide payment details and Submit.</li>
<br><br>
<%= image_tag 'payment_details.png' %>
</ol>
</li>
</ol>
<div class="container mt-4 pb-3">
<h4>HOW BANK TRANSFER WORKS</h4>
<b>Steps:</b>
<ol>
<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.
<% if (banks = Spree::Bank.active).any? %>
<div class="w-75">
<table class="table table-bordered">
<tr class="table-active">
<th><%= Spree.t(:bank_name) %></th>
<th><%= Spree.t(:account_no) %></th>
<th><%= Spree.t(:additional_details) %></th>
</tr>
<% banks.each do |bank| %>
<tr>
<td><center><%= bank.name %></center></td>
<td><center><%= bank.account_no %></center></td>
<td><center><%= bank.additional_details %></center></td>
</tr>
<% end %>
</table>
</div>
<% end %>
</li>
<li>Enter this payment reference number on Order Details page by following steps:
<ol style="padding:10px 0 0 20px" type='a'>
<li>Go to "My Account" page.</li>
<li>Select Order for which you want to provide details.</li>
<li>Click on "Add Details" link visible in "Payment Information" column.</li>
<li>Provide payment details and Submit.</li>
<br><br>
<%= image_tag 'payment_details.png' %>
</ol>
</li>
</ol>

<div class="w-100">
<%= image_tag 'payment_details.png', class: "w-75 img-thumbnail" %>
</div>
</div>
59 changes: 34 additions & 25 deletions app/views/spree/orders/_bank_transfer_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
<% if bank_transfer_payment = @order.payments.from_bank_transfer.first %>
<% bank_transfer_payment = @order.payments.from_bank_transfer.first %>
<% if bank_transfer_payment.present? %>
<% unless bank_transfer_payment.details_submitted? %>
<br>
<%= link_to Spree.t(:add_details), "javascript:void(0);", class: 'button add_bt_details' %>
<% end %>
<%= form_for bank_transfer_payment, html: { class: "bt_payment_form", style: "#{bank_transfer_payment.details_submitted? ? '' : 'display:none;'}" } do |f| %>
<table>
<tr>
<td><%= Spree.t(:deposited_on) %></td><td><%= f.text_field :deposited_on, disabled: bank_transfer_payment.details_submitted?, class: 'required_field', 'field-name' => 'Deposited on' %></td>
</tr>
<tr>
<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>
</tr>
<tr>
<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>
</tr>
<tr>
<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>
</tr>
</table>
<br>
<% unless bank_transfer_payment.details_submitted? %>
<%= f.submit "Submit", confirm: Spree.t(:confirm_details_submit) %>
<%= form_for bank_transfer_payment, html: { class: "bt_payment_form", style: "#{bank_transfer_payment.details_submitted? ? '' : 'display:none;'}" } do |f| %>
<div class="row mx-0 my-3">
<div class="form-group col-12 px-0">
<%= f.label Spree.t(:deposited_on), class: 'mb-0' %>
<%= f.text_field :deposited_on, disabled: bank_transfer_payment.details_submitted?, class: 'required_field form-control form-control-sm' %>
</div>
<br>
<div class="form-group col-12 px-0">
<%= f.label Spree.t(:bank_name), class: 'mb-0' %>
<%= f.select :bank_name, options_for_select(Spree::Bank.pluck(:name)), {}, {disabled: bank_transfer_payment.details_submitted?, class: 'required_field form-control form-control-sm'} %>
</div>
<br>
<div class="form-group col-12 px-0">
<%= f.label Spree.t(:receipt), class: 'mb-0' %>
<%= f.file_field :receipt, disabled: bank_transfer_payment.details_submitted?, class: 'required_field form-control-file' %>
</div>
<br>
<div class="col-12 px-0">
<% unless bank_transfer_payment.details_submitted? %>
<%= f.submit "Submit", confirm: Spree.t(:confirm_details_submit), class: "btn btn-success btn-block btn-sm" %>
<% end %>
</div>
</div>
<% end %>
<% else %>
<div class="my-3">
<p class="text-success font-weight-bold mb-0">
<i class="fas fa-check-circle"></i> <%= Spree.t(:bank_transfer_completed) %>
</p>
<p class="mb-0"><%= Spree.t(:deposited_on) %>: <%= bank_transfer_payment.deposited_on.strftime("%d/%m/%Y") %></p>
<p class="mb-0"><%= Spree.t(:bank_name) %>: <%= bank_transfer_payment.bank_name %></p>
<a href="<%= main_app.url_for(bank_transfer_payment.receipt) %>" target="_blank"><%= Spree.t(:view_receipt) %></a>
</div>
<% end %>
<% end %>
<% if I18n.locale != :en %>
<%= javascript_include_tag "jquery-ui/datepicker-#{I18n.locale}" %>
<% end %>
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ en:
payment_successfully_updated: Payment successfully updated
payment_reference_details: Bank Transfer Payment Reference Details
transaction_reference_no: Transaction Reference No
receipt: Receipt
activerecord:
models:
spree/bank:
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20130717071443_create_table_bank.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateTableBank < ActiveRecord::Migration
class CreateTableBank < SpreeExtension::Migration[4.2]
def change
create_table :spree_banks do |t|
t.string :name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddIndexOnActiveOnSpreeBank < ActiveRecord::Migration
class AddIndexOnActiveOnSpreeBank < SpreeExtension::Migration[4.2]
def change
add_index :spree_banks, :active
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddBankNameAccountNumberAndTransactionReferenceNumberToPayments < ActiveRecord::Migration
class AddBankNameAccountNumberAndTransactionReferenceNumberToPayments < SpreeExtension::Migration[4.2]
def change
add_column :spree_payments, :bank_name, :string
add_column :spree_payments, :account_no, :string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddColumnDepositedOnToSpreePayments < ActiveRecord::Migration
class AddColumnDepositedOnToSpreePayments < SpreeExtension::Migration[4.2]
def change
add_column :spree_payments, :deposited_on, :date
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddColAdditionalDetailsToBanks < ActiveRecord::Migration
class AddColAdditionalDetailsToBanks < SpreeExtension::Migration[4.2]
def change
add_column :spree_banks, :additional_details, :text
end
Expand Down
4 changes: 4 additions & 0 deletions lib/spree_bank_transfer.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
require 'spree_core'
require 'rails/generators'
require 'spree_bank_transfer/engine'
require 'spree_bank_transfer/version'
require 'spree_extension'
require 'deface'
6 changes: 3 additions & 3 deletions lib/spree_bank_transfer/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def self.activate
end
end

initializer "spree.register.payment_methods" do |app|
config.to_prepare &method(:activate).to_proc

initializer "spree.spree_bank_transfer.payment_methods", after: "spree.register.payment_methods" do |app|
app.config.spree.payment_methods << Spree::PaymentMethod::BankTransfer
end

config.to_prepare &method(:activate).to_proc
end
end
Loading

0 comments on commit 26bf68e

Please sign in to comment.