ba_spree_loyalty_points 1.0.1 → 1.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f6866802e9e83952b7ad7d6ca8b211afd04057198f122674790922e63a7e368
4
- data.tar.gz: 6ecd351413370fc2c6e9fc00680bc683c854be9f8bdf31838bee0aa217f0e064
3
+ metadata.gz: 965b20980d2644cd0cb51ca7f3bf26c204e2bc3aaa94bf97902b6baa0ac5652f
4
+ data.tar.gz: 5c320797901114e822084ecd2bdd96ca2f2e7f5206bd56710e3977fdf62158d7
5
5
  SHA512:
6
- metadata.gz: 59da86cdce5a6c27cdab6cdbfa30304c7d43f714ecb70e00921e7ecfe9ffcc9a5274906fd603b8163cb9994d018567dab54b01e53d8cfeb682b12d09ad589990
7
- data.tar.gz: 13c74e5a58e0666f6be833259797be0cb3775a67494353ac081b607b769ccca1571f1177341b42e15ddcb66f2490318b14b4f4fc08f5254ab8f8dc990581e728
6
+ metadata.gz: e3e40af8824dee3c35a6c47b8f4de8b14eae28895a08b6551059eed64659e454a0b0cdc055d802a185b3f1fac9ba5cc3aeb689d9cdbd31b3db7d381f977500ee
7
+ data.tar.gz: a1889bcdb99bcd0ade33fc40bf455e577630246e1de1cd4df473ede3c699eb5758eadb16c386c9519a716960b693da85ed28e460290a38d6f4807972cd302f49
@@ -1,3 +1,3 @@
1
1
  module SpreeLoyaltyPoints
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ba_spree_loyalty_points
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - be agile Co., Ltd.
@@ -278,7 +278,6 @@ files:
278
278
  - app/controllers/spree/admin/loyalty_points_transactions_controller.rb
279
279
  - app/controllers/spree/admin/resource_controller_decorator.rb
280
280
  - app/controllers/spree/admin/return_authorizations_controller_decorator.rb
281
- - app/controllers/spree/checkout_controller_decorator.rb
282
281
  - app/controllers/spree/loyalty_points_controller.rb
283
282
  - app/controllers/spree_loyalty_points/checkout_controller_decorator.rb
284
283
  - app/models/concerns/spree/loyalty_points.rb
@@ -288,18 +287,12 @@ files:
288
287
  - app/models/spree/loyalty_points_credit_transaction.rb
289
288
  - app/models/spree/loyalty_points_debit_transaction.rb
290
289
  - app/models/spree/loyalty_points_transaction.rb
291
- - app/models/spree/order_decorator.rb
292
- - app/models/spree/payment_decorator.rb
293
290
  - app/models/spree/payment_method/loyalty_points.rb
294
- - app/models/spree/payment_method_decorator.rb
295
291
  - app/models/spree/return_authorization_decorator.rb
296
- - app/models/spree/store_decorator.rb
297
292
  - app/models/spree_loyalty_points/order_decorator.rb
298
293
  - app/models/spree_loyalty_points/payment_decorator.rb
299
294
  - app/models/spree_loyalty_points/payment_method_decorator.rb
300
295
  - app/models/spree_loyalty_points/store_decorator.rb
301
- - app/overrides/add_condition_to_amount_on_return_authorization_page.rb
302
- - app/overrides/add_loyalty_points_balance_to_account_page.rb
303
296
  - app/overrides/add_loyalty_points_debiting_to_return_authorization_page.rb
304
297
  - app/overrides/add_loyalty_points_to_account_nav.rb
305
298
  - app/overrides/add_loyalty_points_to_admin_user_show_page.rb
@@ -338,7 +331,6 @@ files:
338
331
  - lib/ba_spree_loyalty_points.rb
339
332
  - lib/generators/spree_loyalty_points/install/install_generator.rb
340
333
  - lib/spree_loyalty_points/engine.rb
341
- - lib/spree_loyalty_points/factories.rb
342
334
  - lib/spree_loyalty_points/version.rb
343
335
  - lib/tasks/loyalty_points/award.rake
344
336
  homepage: https://github.com/be-agile/ba_spree_loyalty_points
@@ -1,21 +0,0 @@
1
- module Spree
2
- module CheckoutControllerDecorator
3
- def self.prepended(base)
4
- base.before_action :sufficient_loyalty_points, only: [:update], if: -> { params[:state] == 'payment' }
5
- end
6
-
7
- private
8
-
9
- def sufficient_loyalty_points
10
- payment_method_ids = params[:order][:payments_attributes].collect do |payment|
11
- payment["payment_method_id"]
12
- end
13
- if Spree::PaymentMethod.loyalty_points_id_included?(payment_method_ids) && !@order.user.has_sufficient_loyalty_points?(@order)
14
- flash[:error] = Spree.t(:insufficient_loyalty_points)
15
- redirect_to spree.checkout_state_path(@order.state)
16
- end
17
- end
18
- end
19
- end
20
-
21
- Spree::CheckoutController.prepend Spree::CheckoutControllerDecorator if Spree::CheckoutController.included_modules.exclude?(Spree::CheckoutControllerDecorator)
@@ -1,33 +0,0 @@
1
- module Spree
2
- module OrderDecorator
3
- def self.prepended(base)
4
- base.include Spree::LoyaltyPoints
5
- base.include Spree::Order::LoyaltyPoints
6
-
7
- base.has_many :loyalty_points_transactions, as: :source
8
- base.has_many :loyalty_points_credit_transactions, as: :source
9
- base.has_many :loyalty_points_debit_transactions, as: :source
10
-
11
- base.scope :loyalty_points_not_awarded, -> {
12
- includes(:loyalty_points_credit_transactions).where(spree_loyalty_points_transactions: { source_id: nil })
13
- }
14
-
15
- base.scope :with_hours_since_payment, ->(num) {
16
- where('`spree_orders`.`paid_at` < ? ', num.hours.ago)
17
- }
18
-
19
- base.scope :with_uncredited_loyalty_points, ->(num) {
20
- with_hours_since_payment(num).loyalty_points_not_awarded
21
- }
22
-
23
- # FSM transitions
24
- base.state_machines[:state].after_transition(
25
- from: base.state_machines[:state].states.map(&:name) - [:complete],
26
- to: [:complete],
27
- do: :complete_loyalty_points_payments
28
- )
29
- end
30
- end
31
- end
32
-
33
- Spree::Order.prepend(Spree::OrderDecorator)
@@ -1,38 +0,0 @@
1
- module Spree
2
- module PaymentDecorator
3
- def self.prepended(base)
4
- base.include Spree::LoyaltyPoints
5
- base.include Spree::Payment::LoyaltyPoints
6
-
7
- base.validates :amount, numericality: { greater_than: 0 }, if: :by_loyalty_points?
8
- base.validate :redeemable_user_balance, if: :by_loyalty_points?
9
- base.scope :state_not, ->(s) { where('state != ?', s) }
10
-
11
- fsm = base.state_machines[:state]
12
- fsm.after_transition from: fsm.states.map(&:name) - [:completed], to: [:completed], do: :notify_paid_order
13
- fsm.after_transition from: fsm.states.map(&:name) - [:completed], to: [:completed], do: :redeem_loyalty_points, if: :by_loyalty_points?
14
- fsm.after_transition from: [:completed], to: fsm.states.map(&:name) - [:completed], do: :return_loyalty_points, if: :by_loyalty_points?
15
- end
16
-
17
- private
18
-
19
- def invalidate_old_payments
20
- return if store_credit? || by_loyalty_points?
21
- order.payments.with_state('checkout').where("id != ?", self.id).each do |payment|
22
- payment.invalidate! unless payment.store_credit?
23
- end
24
- end
25
-
26
- def notify_paid_order
27
- if all_payments_completed?
28
- order.touch :paid_at
29
- end
30
- end
31
-
32
- def all_payments_completed?
33
- order.payments.state_not('invalid').all? { |payment| payment.completed? }
34
- end
35
- end
36
- end
37
-
38
- Spree::Payment.prepend Spree::PaymentDecorator if Spree::Payment.included_modules.exclude?(Spree::PaymentDecorator)
@@ -1,16 +0,0 @@
1
- module Spree
2
- module PaymentMethodDecorator
3
- def self.prepended(base)
4
- base.scope :loyalty_points_type, -> { where(type: 'Spree::PaymentMethod::LoyaltyPoints') }
5
- base.extend ClassMethods
6
- end
7
-
8
- module ClassMethods
9
- def loyalty_points_id_included?(method_ids)
10
- loyalty_points_type.where(id: method_ids).size != 0
11
- end
12
- end
13
- end
14
- end
15
-
16
- Spree::PaymentMethod.prepend(Spree::PaymentMethodDecorator)
@@ -1,23 +0,0 @@
1
- module Spree
2
- module StoreDecorator
3
- def self.prepended(base)
4
- existing_settings = base.typed_stores[:settings]&.fields || {}
5
- base.typed_store :settings, coder: ActiveRecord::TypedStore::IdentityCoder do |s|
6
- existing_settings.each do |name, field|
7
- s.send(field.type_sym, name, **field.instance_variables.each_with_object({}) { |var, hash|
8
- hash[var.to_s.delete("@").to_sym] = field.instance_variable_get(var) unless var == :@type
9
- })
10
- end
11
- unless existing_settings.key?(:loyalty_points_awarding_unit)
12
- s.decimal :loyalty_points_awarding_unit, default: 0.01, null: false
13
- s.decimal :loyalty_points_redeeming_balance, default: 0.0, null: false
14
- s.decimal :loyalty_points_conversion_rate, default: 1.0, null: false
15
- s.integer :loyalty_points_award_period, default: 12, null: false
16
- s.decimal :min_amount_required_to_get_loyalty_points, default: 0.0, null: false
17
- end
18
- end
19
- end
20
- end
21
- end
22
-
23
- Spree::Store.prepend Spree::StoreDecorator
@@ -1,8 +0,0 @@
1
- Deface::Override.new(virtual_path: 'spree/admin/return_authorizations/_form',
2
- name: 'surround_amount_with_condition_in_return_authorization_form',
3
- surround: "erb[loud]:contains('field_container :amount')",
4
- text: "
5
- <% if !@return_authorization.order.loyalty_points_used? %>
6
- <%= render_original %>
7
- <% end %>
8
- ")
@@ -1,9 +0,0 @@
1
- Deface::Override.new(virtual_path: 'spree/users/show',
2
- name: 'add_loyalty_points_balance_to_account_page',
3
- insert_after: ".account-page-user-info-item-store-credits",
4
- text: "
5
- <dl id='loyalty-points-info'>
6
- <dt><%= Spree.t(:loyalty_points_balance) %></dt>
7
- <dd><%= @user.loyalty_points_balance %> (<%= link_to Spree.t(:details), spree.loyalty_points_path %>)</dd>
8
- </dl>
9
- ")
@@ -1,84 +0,0 @@
1
- FactoryGirl.define do
2
- # Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them.
3
- #
4
- # Example adding this to your spec_helper will load these Factories for use:
5
- # require 'spree_loyalty_points/factories'
6
-
7
- factory :loyalty_points_transaction, class: Spree::LoyaltyPointsTransaction do
8
- loyalty_points { (10..99).to_a.sample }
9
- balance { (100..999).to_a.sample }
10
- comment { FFaker::Lorem.words(3).join(' ') }
11
- type "Spree::LoyaltyPointsCreditTransaction"
12
-
13
- association :user, factory: :user_with_loyalty_points
14
-
15
- factory :loyalty_points_credit_transaction, class: Spree::LoyaltyPointsCreditTransaction do
16
- type "Spree::LoyaltyPointsCreditTransaction"
17
- end
18
-
19
- factory :loyalty_points_debit_transaction, class: Spree::LoyaltyPointsDebitTransaction do
20
- type "Spree::LoyaltyPointsDebitTransaction"
21
- end
22
-
23
- end
24
-
25
- factory :user_with_loyalty_points, parent: :user do
26
- loyalty_points_balance { (100..999).to_a.sample }
27
-
28
- transient do
29
- transactions_count 5
30
- end
31
-
32
- after(:create) do |user, evaluator|
33
- create_list(:loyalty_points_transaction, evaluator.transactions_count, user: user)
34
- end
35
- end
36
-
37
- factory :order_with_loyalty_points, parent: :order do
38
-
39
- association :user, factory: :user_with_loyalty_points
40
-
41
- transient do
42
- transactions_count 5
43
- end
44
-
45
- after(:create) do |order, evaluator|
46
- create_list(:loyalty_points_transaction, evaluator.transactions_count, source: order)
47
- end
48
-
49
- factory :shipped_order_with_loyalty_points, parent: :shipped_order do
50
- transient do
51
- shipments_count 5
52
- end
53
-
54
- after(:create) do |order, evaluator|
55
- create_list(:shipment, evaluator.shipments_count, order: order, state: "shipped")
56
- end
57
- end
58
-
59
- end
60
-
61
- factory :payment_with_loyalty_points, parent: :payment do
62
-
63
- association :order, factory: :order_with_loyalty_points
64
-
65
- end
66
-
67
- factory :return_authorization_with_loyalty_points, parent: :return_authorization do
68
- loyalty_points { (50..99).to_a.sample }
69
- loyalty_points_transaction_type "Debit"
70
-
71
- association :order, factory: :shipped_order_with_loyalty_points
72
-
73
- end
74
-
75
- end
76
-
77
- FactoryGirl.modify do
78
-
79
- factory :return_authorization, class: Spree::ReturnAuthorization do
80
- loyalty_points { (50..99).to_a.sample }
81
- loyalty_points_transaction_type "Debit"
82
- end
83
-
84
- end