effective_orders 4.6.1 → 4.6.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 +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +86 -11
- data/app/controllers/admin/customers_controller.rb +16 -5
- data/app/controllers/admin/order_items_controller.rb +9 -6
- data/app/controllers/admin/orders_controller.rb +81 -17
- data/app/controllers/effective/carts_controller.rb +6 -10
- data/app/controllers/effective/customers_controller.rb +2 -4
- data/app/controllers/effective/orders_controller.rb +23 -27
- data/app/controllers/effective/providers/cheque.rb +1 -3
- data/app/controllers/effective/providers/free.rb +1 -3
- data/app/controllers/effective/providers/mark_as_paid.rb +2 -4
- data/app/controllers/effective/providers/moneris.rb +1 -3
- data/app/controllers/effective/providers/paypal.rb +2 -3
- data/app/controllers/effective/providers/phone.rb +1 -3
- data/app/controllers/effective/providers/pretend.rb +1 -3
- data/app/controllers/effective/providers/refund.rb +1 -3
- data/app/controllers/effective/providers/stripe.rb +1 -3
- data/app/controllers/effective/subscripter_controller.rb +2 -4
- data/app/controllers/effective/webhooks_controller.rb +3 -12
- data/app/datatables/admin/effective_customers_datatable.rb +3 -7
- data/app/datatables/admin/effective_orders_datatable.rb +2 -2
- data/app/datatables/effective_orders_datatable.rb +1 -1
- data/app/mailers/effective/orders_mailer.rb +96 -131
- data/app/models/concerns/acts_as_purchasable.rb +11 -0
- data/app/models/concerns/acts_as_subscribable.rb +6 -0
- data/app/models/effective/access_denied.rb +17 -0
- data/app/models/effective/cart.rb +5 -7
- data/app/models/effective/cart_item.rb +4 -7
- data/app/models/effective/customer.rb +6 -7
- data/app/models/effective/order.rb +42 -51
- data/app/models/effective/order_item.rb +8 -10
- data/app/models/effective/product.rb +6 -9
- data/app/models/effective/subscription.rb +12 -13
- data/app/views/admin/orders/_form.html.haml +9 -5
- data/app/views/admin/orders/_order_item_fields.html.haml +12 -8
- data/app/views/effective/orders/_checkout_step2.html.haml +2 -1
- data/app/views/effective/orders/_order_actions.html.haml +1 -1
- data/config/effective_orders.rb +32 -8
- data/config/routes.rb +17 -16
- data/db/migrate/01_create_effective_orders.rb.erb +0 -4
- data/lib/effective_orders.rb +76 -34
- data/lib/effective_orders/engine.rb +7 -0
- data/lib/effective_orders/version.rb +1 -1
- data/lib/generators/templates/effective_orders_mailer_preview.rb +13 -13
- data/lib/tasks/effective_orders_tasks.rake +2 -2
- metadata +2 -1
data/config/routes.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
EffectiveOrders::Engine.routes.draw do
|
2
|
-
scope module
|
2
|
+
scope :module => 'effective' do
|
3
3
|
resources :orders, except: [:destroy] do
|
4
4
|
member do
|
5
5
|
get :purchased
|
@@ -7,32 +7,33 @@ EffectiveOrders::Engine.routes.draw do
|
|
7
7
|
get :declined
|
8
8
|
get :send_buyer_receipt
|
9
9
|
|
10
|
-
post :free
|
11
|
-
post :mark_as_paid
|
12
|
-
post :cheque
|
13
|
-
post :phone
|
14
|
-
post :pretend
|
15
|
-
post :refund
|
16
|
-
post :stripe
|
10
|
+
post :free if EffectiveOrders.free?
|
11
|
+
post :mark_as_paid if EffectiveOrders.mark_as_paid?
|
12
|
+
post :cheque if EffectiveOrders.cheque?
|
13
|
+
post :phone if EffectiveOrders.phone?
|
14
|
+
post :pretend if EffectiveOrders.pretend?
|
15
|
+
post :refund if EffectiveOrders.refund?
|
16
|
+
post :stripe if EffectiveOrders.stripe?
|
17
17
|
end
|
18
18
|
|
19
19
|
collection do
|
20
20
|
post :bulk_send_buyer_receipt
|
21
21
|
|
22
|
-
post :moneris_postback
|
23
|
-
post :paypal_postback
|
22
|
+
post :moneris_postback if EffectiveOrders.moneris?
|
23
|
+
post :paypal_postback if EffectiveOrders.paypal?
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
post 'orders/:id', to: 'orders#update'
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
if EffectiveOrders.subscriptions?
|
30
|
+
match 'subscribe', to: 'subscripter#update', via: :post, as: :subscripter
|
31
|
+
|
32
|
+
match 'customer/settings', to: 'customers#edit', as: :customer_settings, via: [:get]
|
33
|
+
match 'customer/settings', to: 'customers#update', via: [:patch, :put, :post]
|
34
|
+
match 'webhooks/stripe', to: 'webhooks#stripe', via: [:get, :post, :put]
|
35
|
+
end
|
34
36
|
|
35
|
-
# Carts
|
36
37
|
match 'cart', to: 'carts#show', as: 'cart', via: :get
|
37
38
|
match 'cart', to: 'carts#destroy', via: :delete
|
38
39
|
|
@@ -2,7 +2,6 @@ class CreateEffectiveOrders < ActiveRecord::Migration[4.2]
|
|
2
2
|
def self.up
|
3
3
|
create_table <%= @orders_table_name %> do |t|
|
4
4
|
t.integer :user_id
|
5
|
-
t.string :user_type
|
6
5
|
|
7
6
|
t.integer :parent_id
|
8
7
|
t.string :parent_type
|
@@ -54,8 +53,6 @@ class CreateEffectiveOrders < ActiveRecord::Migration[4.2]
|
|
54
53
|
|
55
54
|
create_table <%= @carts_table_name %> do |t|
|
56
55
|
t.integer :user_id
|
57
|
-
t.string :user_type
|
58
|
-
|
59
56
|
t.integer :cart_items_count, :default => 0
|
60
57
|
t.timestamps
|
61
58
|
end
|
@@ -79,7 +76,6 @@ class CreateEffectiveOrders < ActiveRecord::Migration[4.2]
|
|
79
76
|
|
80
77
|
create_table <%= @customers_table_name %> do |t|
|
81
78
|
t.integer :user_id
|
82
|
-
t.string :user_type
|
83
79
|
|
84
80
|
t.string :stripe_customer_id
|
85
81
|
t.string :payment_method_id
|
data/lib/effective_orders.rb
CHANGED
@@ -1,47 +1,94 @@
|
|
1
1
|
require 'effective_addresses'
|
2
|
-
require 'effective_resources'
|
3
2
|
require 'effective_orders/engine'
|
4
3
|
require 'effective_orders/version'
|
5
4
|
|
6
5
|
module EffectiveOrders
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
PENDING = 'pending'.freeze # New orders are created in a pending state
|
7
|
+
CONFIRMED = 'confirmed'.freeze # Once the order has passed checkout step 1
|
8
|
+
DEFERRED = 'deferred'.freeze # Deferred providers. Cheque or Phone was selected.
|
9
|
+
PURCHASED = 'purchased'.freeze # Purchased by provider
|
10
|
+
DECLINED = 'declined'.freeze # Declined by provider
|
11
|
+
|
13
12
|
STATES = { PENDING => PENDING, CONFIRMED => CONFIRMED, DEFERRED => DEFERRED, PURCHASED => PURCHASED, DECLINED => DECLINED }
|
14
13
|
|
15
14
|
# Subscription statuses (as per stripe)
|
16
|
-
ACTIVE = 'active'
|
17
|
-
PAST_DUE = 'past_due'
|
18
|
-
TRIALING = 'trialing'
|
19
|
-
CANCELED = 'canceled'
|
15
|
+
ACTIVE = 'active'.freeze
|
16
|
+
PAST_DUE = 'past_due'.freeze
|
17
|
+
TRIALING = 'trialing'.freeze
|
18
|
+
CANCELED = 'canceled'.freeze
|
20
19
|
|
21
20
|
STATUSES = { ACTIVE => ACTIVE, PAST_DUE => PAST_DUE, CANCELED => CANCELED, TRIALING => TRIALING }
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
22
|
+
# The following are all valid config keys
|
23
|
+
mattr_accessor :orders_table_name
|
24
|
+
mattr_accessor :order_items_table_name
|
25
|
+
mattr_accessor :carts_table_name
|
26
|
+
mattr_accessor :cart_items_table_name
|
27
|
+
mattr_accessor :customers_table_name
|
28
|
+
mattr_accessor :subscriptions_table_name
|
29
|
+
mattr_accessor :products_table_name
|
30
|
+
|
31
|
+
mattr_accessor :authorization_method
|
32
|
+
|
33
|
+
mattr_accessor :layout
|
34
|
+
mattr_accessor :mailer
|
35
|
+
|
36
|
+
mattr_accessor :orders_collection_scope
|
37
|
+
mattr_accessor :order_tax_rate_method
|
38
|
+
|
39
|
+
mattr_accessor :obfuscate_order_ids
|
40
|
+
mattr_accessor :billing_address
|
41
|
+
mattr_accessor :shipping_address
|
42
|
+
mattr_accessor :use_address_full_name
|
43
|
+
|
44
|
+
mattr_accessor :collect_note
|
45
|
+
mattr_accessor :collect_note_required
|
46
|
+
mattr_accessor :collect_note_message
|
47
|
+
|
48
|
+
mattr_accessor :terms_and_conditions
|
49
|
+
mattr_accessor :terms_and_conditions_label
|
50
|
+
|
51
|
+
mattr_accessor :minimum_charge
|
52
|
+
|
53
|
+
# Features
|
54
|
+
mattr_accessor :free_enabled
|
55
|
+
mattr_accessor :mark_as_paid_enabled
|
56
|
+
mattr_accessor :pretend_enabled
|
57
|
+
mattr_accessor :pretend_message
|
58
|
+
|
59
|
+
# Payment processors. false or Hash
|
60
|
+
mattr_accessor :cheque
|
61
|
+
mattr_accessor :moneris
|
62
|
+
mattr_accessor :paypal
|
63
|
+
mattr_accessor :phone
|
64
|
+
mattr_accessor :refund
|
65
|
+
mattr_accessor :stripe
|
66
|
+
mattr_accessor :subscriptions # Stripe subscriptions
|
67
|
+
mattr_accessor :trial # Trial mode
|
68
|
+
|
69
|
+
def self.setup
|
70
|
+
yield self
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.authorized?(controller, action, resource)
|
74
|
+
@_exceptions ||= [Effective::AccessDenied, (CanCan::AccessDenied if defined?(CanCan)), (Pundit::NotAuthorizedError if defined?(Pundit))].compact
|
75
|
+
|
76
|
+
return !!authorization_method unless authorization_method.respond_to?(:call)
|
77
|
+
controller = controller.controller if controller.respond_to?(:controller)
|
78
|
+
|
79
|
+
begin
|
80
|
+
!!(controller || self).instance_exec((controller || self), action, resource, &authorization_method)
|
81
|
+
rescue *@_exceptions
|
82
|
+
false
|
83
|
+
end
|
39
84
|
end
|
40
85
|
|
41
|
-
|
86
|
+
def self.authorize!(controller, action, resource)
|
87
|
+
raise Effective::AccessDenied.new('Access Denied', action, resource) unless authorized?(controller, action, resource)
|
88
|
+
end
|
42
89
|
|
43
90
|
def self.permitted_params
|
44
|
-
|
91
|
+
[
|
45
92
|
:cc, :note, :terms_and_conditions, :confirmed_checkout,
|
46
93
|
billing_address: EffectiveAddresses.permitted_params,
|
47
94
|
shipping_address: EffectiveAddresses.permitted_params,
|
@@ -122,11 +169,6 @@ module EffectiveOrders
|
|
122
169
|
[('cheque' if cheque?), ('phone' if phone?)].compact
|
123
170
|
end
|
124
171
|
|
125
|
-
def self.mailer_klass
|
126
|
-
name = mailer_class_name.presence || 'Effective::OrdersMailer'
|
127
|
-
name.safe_constantize || raise("unable to constantize mailer class. check config.mailer_class_name")
|
128
|
-
end
|
129
|
-
|
130
172
|
def self.can_skip_checkout_step1?
|
131
173
|
return false if require_billing_address
|
132
174
|
return false if require_shipping_address
|
@@ -16,6 +16,13 @@ module EffectiveOrders
|
|
16
16
|
eval File.read("#{config.root}/config/effective_orders.rb")
|
17
17
|
end
|
18
18
|
|
19
|
+
# Set up mail delivering config option
|
20
|
+
initializer 'effective_orders.mailer', after: :load_config_initializers do |app|
|
21
|
+
EffectiveOrders.mailer[:deliver_method] ||= (
|
22
|
+
(Rails.application.config.respond_to?(:active_job) && Rails.application.config.active_job.queue_adapter) ? :deliver_later : :deliver_now
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
19
26
|
initializer "effective_orders.append_precompiled_assets" do |app|
|
20
27
|
Rails.application.config.assets.precompile += ['effective_orders/*']
|
21
28
|
end
|
@@ -4,55 +4,55 @@
|
|
4
4
|
|
5
5
|
class EffectiveOrdersMailerPreview < ActionMailer::Preview
|
6
6
|
def order_receipt_to_admin
|
7
|
-
|
7
|
+
Effective::OrdersMailer.order_receipt_to_admin(build_preview_order)
|
8
8
|
end
|
9
9
|
|
10
10
|
def order_receipt_to_buyer
|
11
|
-
|
11
|
+
Effective::OrdersMailer.order_receipt_to_buyer(build_preview_order)
|
12
12
|
end
|
13
13
|
|
14
14
|
def payment_request_to_buyer
|
15
|
-
|
15
|
+
Effective::OrdersMailer.payment_request_to_buyer(build_preview_order)
|
16
16
|
end
|
17
17
|
|
18
18
|
def pending_order_invoice_to_buyer
|
19
|
-
|
19
|
+
Effective::OrdersMailer.pending_order_invoice_to_buyer(build_preview_order)
|
20
20
|
end
|
21
21
|
|
22
22
|
def subscription_payment_succeeded
|
23
|
-
|
23
|
+
Effective::OrdersMailer.subscription_payment_succeeded(preview_customer)
|
24
24
|
end
|
25
25
|
|
26
26
|
def subscription_payment_failed
|
27
|
-
|
27
|
+
Effective::OrdersMailer.subscription_payment_failed(preview_customer)
|
28
28
|
end
|
29
29
|
|
30
30
|
def subscription_created
|
31
|
-
|
31
|
+
Effective::OrdersMailer.subscription_created(preview_customer)
|
32
32
|
end
|
33
33
|
|
34
34
|
def subscription_updated
|
35
|
-
|
35
|
+
Effective::OrdersMailer.subscription_updated(preview_customer)
|
36
36
|
end
|
37
37
|
|
38
38
|
def subscription_canceled
|
39
|
-
|
39
|
+
Effective::OrdersMailer.subscription_canceled(preview_customer)
|
40
40
|
end
|
41
41
|
|
42
42
|
def subscription_trialing
|
43
|
-
|
43
|
+
Effective::OrdersMailer.subscription_trialing(preview_subscribable)
|
44
44
|
end
|
45
45
|
|
46
46
|
def subscription_trial_expired
|
47
|
-
|
47
|
+
Effective::OrdersMailer.subscription_trial_expired(preview_subscribable)
|
48
48
|
end
|
49
49
|
|
50
50
|
def subscription_event_to_admin
|
51
|
-
|
51
|
+
Effective::OrdersMailer.subscription_event_to_admin(:subscription_updated, preview_customer)
|
52
52
|
end
|
53
53
|
|
54
54
|
def order_error
|
55
|
-
|
55
|
+
Effective::OrdersMailer.order_error(order: build_preview_order, error: 'Something did not work out')
|
56
56
|
end
|
57
57
|
|
58
58
|
protected
|
@@ -44,7 +44,7 @@ namespace :effective_orders do
|
|
44
44
|
klass.trialing.find_each do |subscribable|
|
45
45
|
if subscribable.trialing_until == today
|
46
46
|
puts "sending trial expired to #{subscribable}"
|
47
|
-
|
47
|
+
Effective::OrdersMailer.subscription_trial_expired(subscribable).deliver_now
|
48
48
|
end
|
49
49
|
|
50
50
|
next if subscribable.trial_past_due? # We already notified them
|
@@ -53,7 +53,7 @@ namespace :effective_orders do
|
|
53
53
|
|
54
54
|
reminders.each do |remind_at|
|
55
55
|
next unless today == (date + remind_at)
|
56
|
-
|
56
|
+
Effective::OrdersMailer.subscription_trialing(subscribable).deliver_now
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_orders
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.6.
|
4
|
+
version: 4.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
@@ -156,6 +156,7 @@ files:
|
|
156
156
|
- app/models/concerns/acts_as_purchasable.rb
|
157
157
|
- app/models/concerns/acts_as_subscribable.rb
|
158
158
|
- app/models/concerns/acts_as_subscribable_buyer.rb
|
159
|
+
- app/models/effective/access_denied.rb
|
159
160
|
- app/models/effective/cart.rb
|
160
161
|
- app/models/effective/cart_item.rb
|
161
162
|
- app/models/effective/customer.rb
|