effective_orders 4.6.3 → 5.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +14 -86
- data/app/controllers/admin/customers_controller.rb +5 -16
- data/app/controllers/admin/order_items_controller.rb +6 -9
- data/app/controllers/admin/orders_controller.rb +18 -82
- data/app/controllers/effective/carts_controller.rb +10 -6
- data/app/controllers/effective/concerns/purchase.rb +12 -19
- data/app/controllers/effective/customers_controller.rb +4 -2
- data/app/controllers/effective/orders_controller.rb +26 -23
- data/app/controllers/effective/providers/cheque.rb +3 -1
- data/app/controllers/effective/providers/free.rb +3 -2
- data/app/controllers/effective/providers/mark_as_paid.rb +5 -4
- data/app/controllers/effective/providers/moneris.rb +3 -1
- data/app/controllers/effective/providers/paypal.rb +3 -2
- data/app/controllers/effective/providers/phone.rb +3 -1
- data/app/controllers/effective/providers/pretend.rb +4 -3
- data/app/controllers/effective/providers/refund.rb +4 -3
- data/app/controllers/effective/providers/stripe.rb +4 -3
- data/app/controllers/effective/subscripter_controller.rb +4 -2
- data/app/controllers/effective/webhooks_controller.rb +12 -3
- data/app/datatables/admin/effective_customers_datatable.rb +7 -3
- data/app/datatables/admin/effective_orders_datatable.rb +4 -7
- data/app/datatables/effective_orders_datatable.rb +3 -7
- data/app/helpers/effective_orders_helper.rb +1 -7
- data/app/mailers/effective/orders_mailer.rb +131 -96
- data/app/models/concerns/acts_as_purchasable.rb +0 -11
- data/app/models/concerns/acts_as_subscribable.rb +0 -6
- data/app/models/effective/cart.rb +7 -5
- data/app/models/effective/cart_item.rb +7 -4
- data/app/models/effective/customer.rb +7 -6
- data/app/models/effective/order.rb +58 -61
- data/app/models/effective/order_item.rb +20 -8
- data/app/models/effective/product.rb +11 -6
- data/app/models/effective/subscription.rb +13 -12
- data/app/views/admin/orders/_form.html.haml +5 -9
- data/app/views/admin/orders/_order_item_fields.html.haml +8 -12
- data/app/views/effective/orders/_checkout_step2.html.haml +1 -2
- data/app/views/effective/orders/_order_actions.html.haml +2 -2
- data/app/views/effective/orders/show.html.haml +4 -0
- data/config/effective_orders.rb +8 -32
- data/config/routes.rb +16 -17
- data/db/migrate/01_create_effective_orders.rb.erb +4 -0
- data/lib/effective_orders.rb +34 -76
- data/lib/effective_orders/engine.rb +0 -7
- 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 -3
- data/app/models/effective/access_denied.rb +0 -17
@@ -1,10 +1,12 @@
|
|
1
1
|
module Effective
|
2
2
|
class CustomersController < ApplicationController
|
3
|
-
|
3
|
+
before_action(:authenticate_user!) if defined?(Devise)
|
4
4
|
|
5
5
|
include Effective::CrudController
|
6
6
|
|
7
|
-
|
7
|
+
if (config = EffectiveOrders.layout)
|
8
|
+
layout(config.kind_of?(Hash) ? (config[:customers] || config[:application]) : config)
|
9
|
+
end
|
8
10
|
|
9
11
|
submit :save, 'Save', success: -> { 'Successfully updated card.' }
|
10
12
|
page_title 'Customer Settings'
|
@@ -1,18 +1,21 @@
|
|
1
1
|
module Effective
|
2
2
|
class OrdersController < ApplicationController
|
3
|
+
include Effective::CrudController
|
3
4
|
include Concerns::Purchase
|
4
5
|
|
5
|
-
include Providers::Cheque
|
6
|
-
include Providers::Free
|
7
|
-
include Providers::MarkAsPaid
|
8
|
-
include Providers::Moneris
|
9
|
-
include Providers::Paypal
|
10
|
-
include Providers::Phone
|
11
|
-
include Providers::Pretend
|
12
|
-
include Providers::Refund
|
13
|
-
include Providers::Stripe
|
14
|
-
|
15
|
-
|
6
|
+
include Providers::Cheque
|
7
|
+
include Providers::Free
|
8
|
+
include Providers::MarkAsPaid
|
9
|
+
include Providers::Moneris
|
10
|
+
include Providers::Paypal
|
11
|
+
include Providers::Phone
|
12
|
+
include Providers::Pretend
|
13
|
+
include Providers::Refund
|
14
|
+
include Providers::Stripe
|
15
|
+
|
16
|
+
if (config = EffectiveOrders.layout)
|
17
|
+
layout(config.kind_of?(Hash) ? (config[:orders] || config[:application]) : config)
|
18
|
+
end
|
16
19
|
|
17
20
|
before_action :authenticate_user!, except: [:ccbill_postback, :free, :paypal_postback, :moneris_postback, :pretend]
|
18
21
|
before_action :set_page_title, except: [:show]
|
@@ -26,7 +29,7 @@ module Effective
|
|
26
29
|
def new
|
27
30
|
@order ||= Effective::Order.new(view_context.current_cart)
|
28
31
|
|
29
|
-
|
32
|
+
EffectiveResources.authorize!(self, :new, @order)
|
30
33
|
|
31
34
|
unless @order.valid?
|
32
35
|
flash[:danger] = "Unable to proceed: #{flash_errors(@order)}. Please try again."
|
@@ -38,7 +41,7 @@ module Effective
|
|
38
41
|
# Confirms an order from the cart.
|
39
42
|
def create
|
40
43
|
@order ||= Effective::Order.new(view_context.current_cart)
|
41
|
-
|
44
|
+
EffectiveResources.authorize!(self, :create, @order)
|
42
45
|
|
43
46
|
@order.assign_attributes(checkout_params)
|
44
47
|
|
@@ -57,7 +60,7 @@ module Effective
|
|
57
60
|
# Might render step1 or step2
|
58
61
|
def show
|
59
62
|
@order = Effective::Order.find(params[:id])
|
60
|
-
|
63
|
+
EffectiveResources.authorize!(self, :show, @order)
|
61
64
|
|
62
65
|
@page_title ||= ((@order.user == current_user && !@order.purchased?) ? 'Checkout' : @order.to_s)
|
63
66
|
end
|
@@ -65,13 +68,13 @@ module Effective
|
|
65
68
|
# Always step1
|
66
69
|
def edit
|
67
70
|
@order ||= Effective::Order.not_purchased.find(params[:id])
|
68
|
-
|
71
|
+
EffectiveResources.authorize!(self, :edit, @order)
|
69
72
|
end
|
70
73
|
|
71
74
|
# Confirms the order from existing order
|
72
75
|
def update
|
73
76
|
@order ||= Effective::Order.not_purchased.find(params[:id])
|
74
|
-
|
77
|
+
EffectiveResources.authorize!(self, :update, @order)
|
75
78
|
|
76
79
|
@order.assign_attributes(checkout_params)
|
77
80
|
|
@@ -86,28 +89,28 @@ module Effective
|
|
86
89
|
# My Orders History
|
87
90
|
def index
|
88
91
|
@datatable = EffectiveOrdersDatatable.new(user_id: current_user.id)
|
89
|
-
|
92
|
+
EffectiveResources.authorize!(self, :index, Effective::Order.new(user: current_user))
|
90
93
|
end
|
91
94
|
|
92
95
|
# Thank you for Purchasing this Order. This is where a successfully purchased order ends up
|
93
96
|
def purchased # Thank You!
|
94
97
|
@order = Effective::Order.purchased.find(params[:id])
|
95
|
-
|
98
|
+
EffectiveResources.authorize!(self, :show, @order)
|
96
99
|
end
|
97
100
|
|
98
101
|
def deferred
|
99
102
|
@order = Effective::Order.deferred.find(params[:id])
|
100
|
-
|
103
|
+
EffectiveResources.authorize!(self, :show, @order)
|
101
104
|
end
|
102
105
|
|
103
106
|
def declined
|
104
107
|
@order = Effective::Order.declined.find(params[:id])
|
105
|
-
|
108
|
+
EffectiveResources.authorize!(self, :show, @order)
|
106
109
|
end
|
107
110
|
|
108
111
|
def send_buyer_receipt
|
109
112
|
@order = Effective::Order.purchased.find(params[:id])
|
110
|
-
|
113
|
+
EffectiveResources.authorize!(self, :show, @order)
|
111
114
|
|
112
115
|
if @order.send_order_receipt_to_buyer!
|
113
116
|
flash[:success] = "A receipt has been sent to #{@order.emails_send_to}"
|
@@ -128,10 +131,10 @@ module Effective
|
|
128
131
|
@orders = Effective::Order.purchased.where(id: params[:ids])
|
129
132
|
|
130
133
|
begin
|
131
|
-
|
134
|
+
EffectiveResources.authorize!(self, :index, Effective::Order.new(user: current_user))
|
132
135
|
|
133
136
|
@orders.each do |order|
|
134
|
-
next unless
|
137
|
+
next unless EffectiveResources.authorized?(self, :show, order)
|
135
138
|
order.send_order_receipt_to_buyer!
|
136
139
|
end
|
137
140
|
|
@@ -4,9 +4,11 @@ module Effective
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
def cheque
|
7
|
+
raise('cheque provider is not available') unless EffectiveOrders.cheque?
|
8
|
+
|
7
9
|
@order ||= Order.find(params[:id])
|
8
10
|
|
9
|
-
|
11
|
+
EffectiveResources.authorize!(self, :update, @order)
|
10
12
|
|
11
13
|
flash[:success] = EffectiveOrders.cheque[:success]
|
12
14
|
|
@@ -4,9 +4,11 @@ module Effective
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
def free
|
7
|
+
raise('free provider is not available') unless EffectiveOrders.free?
|
8
|
+
|
7
9
|
@order ||= Order.find(params[:id])
|
8
10
|
|
9
|
-
|
11
|
+
EffectiveResources.authorize!(self, :update, @order)
|
10
12
|
|
11
13
|
unless @order.free?
|
12
14
|
flash[:danger] = 'Unable to process free order with a non-zero total'
|
@@ -19,7 +21,6 @@ module Effective
|
|
19
21
|
provider: 'free',
|
20
22
|
card: 'none',
|
21
23
|
purchased_url: free_params[:purchased_url],
|
22
|
-
declined_url: free_params[:declined_url],
|
23
24
|
email: false
|
24
25
|
)
|
25
26
|
end
|
@@ -4,10 +4,12 @@ module Effective
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
def mark_as_paid
|
7
|
+
raise('mark_as_paid provider is not available') unless EffectiveOrders.mark_as_paid?
|
8
|
+
|
7
9
|
@order ||= Order.find(params[:id])
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
+
EffectiveResources.authorize!(self, :update, @order)
|
12
|
+
EffectiveResources.authorize!(self, :admin, :effective_orders)
|
11
13
|
|
12
14
|
@order.assign_attributes(mark_as_paid_params.except(:payment, :payment_provider, :payment_card))
|
13
15
|
|
@@ -17,8 +19,7 @@ module Effective
|
|
17
19
|
card: mark_as_paid_params[:payment_card],
|
18
20
|
email: @order.send_mark_as_paid_email_to_buyer?,
|
19
21
|
skip_buyer_validations: true,
|
20
|
-
purchased_url: effective_orders.admin_order_path(@order)
|
21
|
-
declined_url: effective_orders.admin_order_path(@order)
|
22
|
+
purchased_url: effective_orders.admin_order_path(@order)
|
22
23
|
)
|
23
24
|
end
|
24
25
|
|
@@ -10,9 +10,11 @@ module Effective
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def moneris_postback
|
13
|
+
raise('moneris provider is not available') unless EffectiveOrders.moneris?
|
14
|
+
|
13
15
|
@order ||= Effective::Order.find(params[:response_order_id])
|
14
16
|
|
15
|
-
(
|
17
|
+
(EffectiveResources.authorize!(self, :update, @order) rescue false)
|
16
18
|
|
17
19
|
# Delete the Purchased and Declined Redirect URLs
|
18
20
|
purchased_url = params.delete(:rvar_purchased_url)
|
@@ -10,9 +10,11 @@ module Effective
|
|
10
10
|
# TODO: Make paypal postback work with admin checkout workflow
|
11
11
|
|
12
12
|
def paypal_postback
|
13
|
+
raise('paypal provider is not available') unless EffectiveOrders.paypal?
|
14
|
+
|
13
15
|
@order ||= Effective::Order.where(id: (params[:invoice].to_i rescue 0)).first
|
14
16
|
|
15
|
-
(
|
17
|
+
(EffectiveResources.authorize!(self, :update, @order) rescue false)
|
16
18
|
|
17
19
|
if @order.present?
|
18
20
|
if @order.purchased?
|
@@ -27,7 +29,6 @@ module Effective
|
|
27
29
|
head(:ok)
|
28
30
|
end
|
29
31
|
|
30
|
-
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
@@ -4,9 +4,11 @@ module Effective
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
def phone
|
7
|
+
raise('phone provider is not available') unless EffectiveOrders.phone?
|
8
|
+
|
7
9
|
@order ||= Order.find(params[:id])
|
8
10
|
|
9
|
-
|
11
|
+
EffectiveResources.authorize!(self, :update, @order)
|
10
12
|
|
11
13
|
flash[:success] = EffectiveOrders.phone[:success]
|
12
14
|
|
@@ -4,16 +4,17 @@ module Effective
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
def pretend
|
7
|
+
raise('pretend provider is not available') unless EffectiveOrders.pretend?
|
8
|
+
|
7
9
|
@order ||= Order.find(params[:id])
|
8
10
|
|
9
|
-
|
11
|
+
EffectiveResources.authorize!(self, :update, @order)
|
10
12
|
|
11
13
|
order_purchased(
|
12
14
|
payment: 'for pretend',
|
13
15
|
provider: 'pretend',
|
14
16
|
card: 'none',
|
15
|
-
purchased_url: pretend_params[:purchased_url]
|
16
|
-
declined_url: pretend_params[:declined_url]
|
17
|
+
purchased_url: pretend_params[:purchased_url]
|
17
18
|
)
|
18
19
|
end
|
19
20
|
|
@@ -4,9 +4,11 @@ module Effective
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
def refund
|
7
|
+
raise('refund provider is not available') unless EffectiveOrders.refund?
|
8
|
+
|
7
9
|
@order ||= Order.find(params[:id])
|
8
10
|
|
9
|
-
|
11
|
+
EffectiveResources.authorize!(self, :update, @order)
|
10
12
|
|
11
13
|
unless @order.refund?
|
12
14
|
flash[:danger] = 'Unable to process refund order with a positive total'
|
@@ -19,8 +21,7 @@ module Effective
|
|
19
21
|
order_purchased(
|
20
22
|
payment: 'refund. no payment required.',
|
21
23
|
provider: 'refund',
|
22
|
-
purchased_url: refund_params[:purchased_url]
|
23
|
-
declined_url: refund_params[:declined_url]
|
24
|
+
purchased_url: refund_params[:purchased_url]
|
24
25
|
)
|
25
26
|
end
|
26
27
|
|
@@ -4,10 +4,12 @@ module Effective
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
def stripe
|
7
|
+
raise('stripe provider is not available') unless EffectiveOrders.stripe?
|
8
|
+
|
7
9
|
@order = Order.find(params[:id])
|
8
10
|
@customer = Effective::Customer.for_user(@order.user)
|
9
11
|
|
10
|
-
|
12
|
+
EffectiveResources.authorize!(self, :update, @order)
|
11
13
|
|
12
14
|
payment = validate_stripe_payment(stripe_params[:payment_intent_id])
|
13
15
|
|
@@ -24,8 +26,7 @@ module Effective
|
|
24
26
|
payment: payment,
|
25
27
|
provider: 'stripe',
|
26
28
|
card: payment[:card],
|
27
|
-
purchased_url: stripe_params[:purchased_url]
|
28
|
-
declined_url: stripe_params[:declined_url]
|
29
|
+
purchased_url: stripe_params[:purchased_url]
|
29
30
|
)
|
30
31
|
end
|
31
32
|
|
@@ -1,9 +1,11 @@
|
|
1
1
|
module Effective
|
2
2
|
class SubscripterController < ApplicationController
|
3
|
-
layout (EffectiveOrders.layout.kind_of?(Hash) ? EffectiveOrders.layout[:subscriptions] : EffectiveOrders.layout)
|
4
|
-
|
5
3
|
include Effective::CrudController
|
6
4
|
|
5
|
+
if (config = EffectiveOrders.layout)
|
6
|
+
layout(config.kind_of?(Hash) ? (config[:subscriptions] || config[:application]) : config)
|
7
|
+
end
|
8
|
+
|
7
9
|
submit :save, 'Save', redirect: :back, success: -> { 'Successfully updated plan.' }
|
8
10
|
|
9
11
|
def resource
|
@@ -89,9 +89,18 @@ module Effective
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
def send_email(email, *
|
93
|
-
|
94
|
-
|
92
|
+
def send_email(email, *args)
|
93
|
+
raise('expected args to be an Array') unless args.kind_of?(Array)
|
94
|
+
|
95
|
+
if defined?(Tenant)
|
96
|
+
tenant = Tenant.current || raise('expected a current tenant')
|
97
|
+
args << { tenant: tenant }
|
98
|
+
end
|
99
|
+
|
100
|
+
deliver_method = EffectiveOrders.mailer[:deliver_method] || EffectiveResources.deliver_method
|
101
|
+
|
102
|
+
EffectiveOrders.mailer_klass.send(email, *args).send(deliver_method)
|
103
|
+
EffectiveOrders.mailer_klass.send(:subscription_event_to_admin, email.to_s, *args).send(deliver_method)
|
95
104
|
end
|
96
105
|
|
97
106
|
def run_subscribable_buyer_callbacks!
|
@@ -2,8 +2,12 @@ class Admin::EffectiveCustomersDatatable < Effective::Datatable
|
|
2
2
|
datatable do
|
3
3
|
|
4
4
|
col :id, visible: false
|
5
|
-
|
6
|
-
col
|
5
|
+
|
6
|
+
col :user, search: :string
|
7
|
+
|
8
|
+
col :email do |customer|
|
9
|
+
customer.user.email
|
10
|
+
end
|
7
11
|
|
8
12
|
if EffectiveOrders.stripe?
|
9
13
|
col :stripe_customer_id
|
@@ -17,6 +21,6 @@ class Admin::EffectiveCustomersDatatable < Effective::Datatable
|
|
17
21
|
end
|
18
22
|
|
19
23
|
collection do
|
20
|
-
Effective::Customer.
|
24
|
+
Effective::Customer.includes(:user).all
|
21
25
|
end
|
22
26
|
end
|
@@ -14,7 +14,7 @@ class Admin::EffectiveOrdersDatatable < Effective::Datatable
|
|
14
14
|
end
|
15
15
|
|
16
16
|
filters do
|
17
|
-
|
17
|
+
unless attributes[:skip_filters]
|
18
18
|
scope :purchased, default: true
|
19
19
|
scope :deferred
|
20
20
|
scope :refunds
|
@@ -40,7 +40,7 @@ class Admin::EffectiveOrdersDatatable < Effective::Datatable
|
|
40
40
|
end
|
41
41
|
|
42
42
|
if attributes[:user_id].blank?
|
43
|
-
col :user
|
43
|
+
col :user, search: :string
|
44
44
|
col :billing_name, visible: false
|
45
45
|
col :email, visible: false
|
46
46
|
end
|
@@ -84,13 +84,14 @@ class Admin::EffectiveOrdersDatatable < Effective::Datatable
|
|
84
84
|
end
|
85
85
|
|
86
86
|
collection do
|
87
|
-
scope = Effective::Order.all.
|
87
|
+
scope = Effective::Order.all.deep
|
88
88
|
|
89
89
|
if EffectiveOrders.orders_collection_scope.respond_to?(:call)
|
90
90
|
scope = EffectiveOrders.orders_collection_scope.call(scope)
|
91
91
|
end
|
92
92
|
|
93
93
|
if attributes[:user_id].present?
|
94
|
+
user = current_user.class.find(attributes[:user_id])
|
94
95
|
scope = scope.where(user: user)
|
95
96
|
end
|
96
97
|
|
@@ -101,8 +102,4 @@ class Admin::EffectiveOrdersDatatable < Effective::Datatable
|
|
101
102
|
scope
|
102
103
|
end
|
103
104
|
|
104
|
-
def user
|
105
|
-
@user ||= User.find(attributes[:user_id])
|
106
|
-
end
|
107
|
-
|
108
105
|
end
|
@@ -6,8 +6,6 @@ class EffectiveOrdersDatatable < Effective::Datatable
|
|
6
6
|
scope :purchased, default: true
|
7
7
|
scope :deferred
|
8
8
|
scope :refunds
|
9
|
-
scope :not_purchased
|
10
|
-
scope :all
|
11
9
|
end
|
12
10
|
end
|
13
11
|
|
@@ -61,7 +59,9 @@ class EffectiveOrdersDatatable < Effective::Datatable
|
|
61
59
|
end
|
62
60
|
|
63
61
|
collection do
|
64
|
-
|
62
|
+
user = current_user.class.find(attributes[:user_id])
|
63
|
+
|
64
|
+
scope = Effective::Order.all.deep.where(user: user)
|
65
65
|
|
66
66
|
if EffectiveOrders.orders_collection_scope.respond_to?(:call)
|
67
67
|
scope = EffectiveOrders.orders_collection_scope.call(scope)
|
@@ -78,8 +78,4 @@ class EffectiveOrdersDatatable < Effective::Datatable
|
|
78
78
|
scope
|
79
79
|
end
|
80
80
|
|
81
|
-
def user
|
82
|
-
@user ||= User.find(attributes[:user_id])
|
83
|
-
end
|
84
|
-
|
85
81
|
end
|