spree_wallet 2.1.1 → 2.2.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.
data/README.md CHANGED
@@ -7,13 +7,19 @@ Installation
7
7
  Add spree_wallet to your Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'spree_wallet', '2.1.1'
10
+ gem 'spree_wallet'
11
11
  ```
12
12
 
13
- But if you are using 2.0.x version of spree
13
+ But if you are using older version of spree
14
14
 
15
15
  ```ruby
16
- gem 'spree_wallet', '2.0.9'
16
+ # Spree 2.1.x
17
+ gem 'spree_wallet', '2.1.0'
18
+ ```
19
+
20
+ ```ruby
21
+ # Spree 2.0.x
22
+ gem 'spree_wallet', '2.0.6'
17
23
  ```
18
24
 
19
25
  Bundle your dependencies and run the installation generator:
@@ -36,28 +42,13 @@ Testing
36
42
 
37
43
  You need to do a quick one-time creation of a test application and then you can use it to run the tests.
38
44
 
39
- ```
40
- bundle exec rake test_app
41
- ```
45
+ bundle exec rake test_app
42
46
 
43
47
  Then run the rspec tests with mysql.
44
48
 
45
- ```
46
- bundle exec rspec .
47
- ```
48
-
49
+ bundle exec rspec .
49
50
 
50
51
 
51
- Contributing
52
- ------------
53
-
54
- 1. Fork the repo.
55
- 2. Clone your repo.
56
- 3. Run `bundle install`.
57
- 4. Run `bundle exec rake test_app` to create the test application in `spec/test_app`.
58
- 5. Make your changes.
59
- 6. Ensure specs pass by running `bundle exec rspec spec`.
60
- 7. Submit your pull request.
61
52
 
62
53
  Credits
63
54
  -------
@@ -1,32 +1,7 @@
1
1
  Spree::CheckoutController.class_eval do
2
2
  before_filter :validate_payments, :only => :update, :if => lambda { @order && @order.has_checkout_step?("payment") && @order.payment? && @order.available_wallet_payment_method }
3
-
3
+
4
4
  private
5
- def object_params
6
- if @order.has_checkout_step?("payment") && @order.payment?
7
- if params[:payment_source].present?
8
- source_params = params.delete(:payment_source)[non_wallet_payment_method]
9
-
10
- if source_params
11
- non_wallet_payment_attributes(params[:order][:payments_attributes]).first[:source_attributes] = source_params
12
- end
13
- end
14
-
15
- if (params[:order][:payments_attributes])
16
- # This method is overrided because spree add all order total in first payment, now after wallet we can have multiple payments.
17
- if spree_current_user && @order.available_wallet_payment_method
18
- wallet_payments = wallet_payment_attributes(params[:order][:payments_attributes])
19
- wallet_payments.first[:amount] = [@order.remaining_total, spree_current_user.store_credits_total].min if wallet_payments.present?
20
- params[:order][:payments_attributes] = wallet_payments if remaining_order_total_after_wallet(@order, wallet_payments) <= 0
21
- non_wallet_payment_attributes(params[:order][:payments_attributes]).first[:amount] = remaining_order_total_after_wallet(@order, wallet_payments) if non_wallet_payment_attributes(params[:order][:payments_attributes]).present?
22
- else
23
- params[:order][:payments_attributes].first[:amount] = @order.remaining_total
24
- end
25
- end
26
- end
27
- params[:order]
28
- end
29
-
30
5
  def validate_payments
31
6
  payments_attributes = params[:order][:payments_attributes]
32
7
  wallet_payment = wallet_payment_attributes(payments_attributes)
@@ -46,6 +46,70 @@ Spree::Order.class_eval do
46
46
  Spree::Money.new(remaining_total_after_wallet)
47
47
  end
48
48
 
49
+ def process_payments!
50
+ if pending_payments.empty? && wallet_payments.empty?
51
+ raise Spree::Core::GatewayError.new Spree.t(:no_pending_payments)
52
+ else
53
+ [pending_payments, wallet_payments].flatten.each do |payment|
54
+ break if payment_total >= total
55
+
56
+ payment.process!
57
+
58
+ if payment.completed?
59
+ self.payment_total += payment.amount
60
+ end
61
+ end
62
+ end
63
+ rescue Spree::Core::GatewayError => e
64
+ result = !!Spree::Config[:allow_checkout_on_gateway_error]
65
+ errors.add(:base, e.message) and return result
66
+ end
67
+
68
+
69
+ ### This methods are extensions of spree/order/checkout.rb
70
+
71
+ def update_params_payment_source
72
+ if has_checkout_step?("payment") && self.payment?
73
+ if @updating_params[:payment_source].present?
74
+ source_params = @updating_params.delete(:payment_source)[non_wallet_payment_method]
75
+
76
+ if source_params
77
+ non_wallet_payment_attributes(@updating_params[:order][:payments_attributes]).first[:source_attributes] = source_params
78
+ end
79
+ end
80
+
81
+ if (@updating_params[:order][:payments_attributes])
82
+ user = user_or_by_email
83
+ # This method is overrided because spree add all order total in first payment, now after wallet we can have multiple payments.
84
+ if user && available_wallet_payment_method
85
+ wallet_payments = wallet_payment_attributes(@updating_params[:order][:payments_attributes])
86
+ wallet_payments.first[:amount] = [remaining_total, user.store_credits_total].min if wallet_payments.present?
87
+ @updating_params[:order][:payments_attributes] = wallet_payments if remaining_order_total_after_wallet(wallet_payments) <= 0
88
+ non_wallet_payment_attributes(@updating_params[:order][:payments_attributes]).first[:amount] = remaining_order_total_after_wallet(wallet_payments) if non_wallet_payment_attributes(@updating_params[:order][:payments_attributes]).present?
89
+ else
90
+ @updating_params[:order][:payments_attributes].first[:amount] = remaining_total
91
+ end
92
+ end
93
+ end
94
+ @updating_params[:order]
95
+ end
96
+
97
+ def non_wallet_payment_method
98
+ non_wallet_payment_attributes(@updating_params[:order][:payments_attributes]).first[:payment_method_id] if non_wallet_payment_attributes(@updating_params[:order][:payments_attributes]).first
99
+ end
100
+
101
+ def remaining_order_total_after_wallet(wallet_payments)
102
+ wallet_payments.present? ? remaining_total - wallet_payments.first[:amount] : remaining_total
103
+ end
104
+
105
+ def wallet_payment_attributes(payment_attributes)
106
+ payment_attributes.select { |payment| payment["payment_method_id"] == Spree::PaymentMethod::Wallet.first.id.to_s }
107
+ end
108
+
109
+ def non_wallet_payment_attributes(payment_attributes)
110
+ @non_wallet_payment ||= payment_attributes - wallet_payment_attributes(payment_attributes)
111
+ end
112
+
49
113
  private
50
114
  def wallet_payments
51
115
  payments.where(:payment_method_id => Spree::PaymentMethod::Wallet.pluck(:id))
@@ -9,17 +9,17 @@
9
9
 
10
10
  <%= form_for [:admin, @user, @store_credit], :as => :store_credit do |f| %>
11
11
  <%= f.field_container :amount do %>
12
- <%= f.label :amount %><br />
12
+ <%= f.label :amount %>*<br />
13
13
  <%= f.text_field :amount, :id => "debit_credit_amount" %>
14
14
  <% end %>
15
15
 
16
16
  <%= f.field_container :payment_mode do %>
17
- <%= f.label :payment_mode, 'Payment Mode' %><br />
17
+ <%= f.label :payment_mode, 'Payment Mode' %>*<br />
18
18
  <%= f.select :payment_mode, store_credit_class::PAYMENT_MODE.select { |key, value| value >= 0 }, { :prompt => 'Select' } %>
19
19
  <% end %>
20
20
 
21
21
  <%= f.field_container :reason do %>
22
- <%= f.label :reason %><br />
22
+ <%= f.label :reason %>*<br />
23
23
  <%= f.text_field :reason %>
24
24
  <% end %>
25
25
 
@@ -1,16 +1,51 @@
1
1
  <fieldset id="payment" data-hook>
2
2
  <legend align="center"><%= Spree.t(:payment_information) %></legend>
3
3
  <div data-hook="checkout_payment_step">
4
+
5
+ <% if @payment_sources.present? %>
6
+ <div class="card_options">
7
+ <%= radio_button_tag 'use_existing_card', 'yes', true %>
8
+ <label for="use_existing_card_yes">Use an existing card on file</label>
9
+ <br/>
10
+ <%= radio_button_tag 'use_existing_card', 'no' %>
11
+ <label for="use_existing_card_no">Use a new card / payment method</label>
12
+ </div>
13
+
14
+ <div id="existing_cards">
15
+ <p class="field" data-hook="existing_cards">
16
+ <table class="existing-credit-card-list">
17
+ <tbody>
18
+ <% @payment_sources.each do |card| %>
19
+ <tr id="<%= dom_id(card,'spree')%>" class="<%= cycle('even', 'odd') %>">
20
+ <td><%= card.name %></td>
21
+ <td><%= card.display_number %></td>
22
+ <td><%= card.month %></td>
23
+ <td><%= card.year %></td>
24
+ <td>
25
+ <%= radio_button_tag "existing_card", card.id, (card == @payment_sources.first), { class: "existing-cc-radio" } %>
26
+ </td>
27
+ </tr>
28
+ <% end %>
29
+ </tbody>
30
+ </table>
31
+ </p>
32
+ </div>
33
+ <% end %>
34
+
4
35
  <div id="payment-method-fields" data-hook>
5
36
  <% if spree_current_user && @order.available_wallet_payment_method && !spree_current_user.store_credits_total.to_f.zero? %>
37
+ <p>
38
+ <label>
6
39
  <%= check_box_tag "order[payments_attributes][][payment_method_id]", @order.available_wallet_payment_method.id %>
7
- <%= Spree.t(@order.available_wallet_payment_method.name, :scope => :payment_methods, :default => @order.available_wallet_payment_method.name) %>( <%= spree_current_user.store_credits_total %> )
40
+ <%= Spree.t(@order.available_wallet_payment_method.name, :scope => :payment_methods, :default => @order.available_wallet_payment_method.name) %>( <%= number_to_currency spree_current_user.store_credits_total %> )
41
+ </label>
42
+ </p>
8
43
  <% end %>
9
-
44
+
10
45
  <% @order.available_payment_methods_without_wallet.each do |method| %>
11
46
  <p>
12
47
  <label>
13
- <%= radio_button_tag "order[payments_attributes][][payment_method_id]", method.id %>
48
+ <%= radio_button_tag "order[payments_attributes][][payment_method_id]", method.id, method == @order.available_payment_methods_without_wallet.first %>
14
49
  <%= Spree.t(method.name, :scope => :payment_methods, :default => method.name) %>
15
50
  </label>
16
51
  </p>
@@ -19,8 +54,7 @@
19
54
 
20
55
  <ul id="payment-methods" data-hook>
21
56
  <% @order.available_payment_methods_without_wallet.each do |method| %>
22
- <!-- hidden class is added to hide the partial initially -->
23
- <li id="payment_method_<%= method.id %>" class="hidden <%= 'last' if method == @order.available_payment_methods_without_wallet.last %>" data-hook>
57
+ <li id="payment_method_<%= method.id %>" class="<%= 'last' if method == @order.available_payment_methods_without_wallet.last %>" data-hook>
24
58
  <fieldset>
25
59
  <%= render :partial => "spree/checkout/payment/#{method.method_type}", :locals => { :payment_method => method } %>
26
60
  </fieldset>
@@ -28,12 +62,10 @@
28
62
  <% end %>
29
63
  </ul>
30
64
  <br style="clear:both;" />
31
- <% if Spree::Promotion.with_code.count > 0 %>
32
- <p class='field' data-hook='coupon_code'>
33
- <%= form.label :coupon_code %><br />
34
- <%= form.text_field :coupon_code %>
35
- </p>
36
- <% end %>
65
+ <p class='field' data-hook='coupon_code'>
66
+ <%= form.label :coupon_code %><br />
67
+ <%= form.text_field :coupon_code %>
68
+ </p>
37
69
  </div>
38
70
  </fieldset>
39
71
 
@@ -1,6 +1,6 @@
1
1
  class AddLockVersionToSpreeUsers < ActiveRecord::Migration
2
2
  def change
3
- unless Spree::User.column_names.include? "lock_version"
3
+ if Spree::User.column_names.include? "lock_version"
4
4
  add_column :spree_users, :lock_version, :integer, :default => 0
5
5
  end
6
6
  end
@@ -5,7 +5,7 @@ module SpreeWallet
5
5
  class_option :auto_run_migrations, :type => :boolean, :default => false
6
6
 
7
7
  def add_stylesheets
8
- inject_into_file 'app/assets/stylesheets/store/all.css', " *= require store/spree_wallet\n", :before => /\*\//, :verbose => true
8
+ inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require store/spree_wallet\n", :before => /\*\//, :verbose => true
9
9
  end
10
10
 
11
11
  def add_migrations
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_wallet
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
- - 1
9
- - 1
10
- version: 2.1.1
8
+ - 2
9
+ - 0
10
+ version: 2.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nishant 'CyRo' Tuteja
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2014-03-27 00:00:00 Z
18
+ date: 2014-05-23 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: spree_core
@@ -25,12 +25,12 @@ dependencies:
25
25
  requirements:
26
26
  - - ~>
27
27
  - !ruby/object:Gem::Version
28
- hash: 11
28
+ hash: 7
29
29
  segments:
30
30
  - 2
31
- - 1
31
+ - 2
32
32
  - 0
33
- version: 2.1.0
33
+ version: 2.2.0
34
34
  type: :runtime
35
35
  version_requirements: *id001
36
36
  description: Add wallet payment method functionality to spree