effective_orders 1.8.1 → 2.0.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.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +150 -60
- data/Rakefile +0 -3
- data/active_admin/effective_orders.rb +14 -9
- data/app/assets/javascripts/effective_orders.js +2 -0
- data/app/assets/javascripts/effective_orders/{stripe_charges.js.coffee → providers/stripe_charges.js.coffee} +1 -1
- data/app/assets/javascripts/effective_orders/{stripe_subscriptions.js.coffee → providers/stripe_subscriptions.js.coffee} +1 -1
- data/app/assets/stylesheets/effective_orders/_order.scss +9 -3
- data/app/controllers/admin/orders_controller.rb +87 -3
- data/app/controllers/concerns/acts_as_active_admin_controller.rb +2 -1
- data/app/controllers/effective/carts_controller.rb +4 -2
- data/app/controllers/effective/orders_controller.rb +101 -60
- data/app/controllers/effective/providers/app_checkout.rb +10 -2
- data/app/controllers/effective/providers/ccbill.rb +34 -0
- data/app/controllers/effective/providers/cheque.rb +30 -0
- data/app/controllers/effective/providers/moneris.rb +7 -7
- data/app/controllers/effective/providers/paypal.rb +7 -5
- data/app/controllers/effective/providers/pretend.rb +22 -0
- data/app/controllers/effective/providers/stripe.rb +26 -24
- data/app/controllers/effective/webhooks_controller.rb +1 -1
- data/app/helpers/effective_carts_helper.rb +59 -29
- data/app/helpers/effective_ccbill_helper.rb +25 -0
- data/app/helpers/effective_orders_helper.rb +50 -41
- data/app/helpers/effective_paypal_helper.rb +11 -11
- data/app/mailers/effective/orders_mailer.rb +95 -20
- data/app/models/concerns/acts_as_purchasable.rb +14 -22
- data/app/models/effective/cart.rb +9 -15
- data/app/models/effective/cart_item.rb +15 -13
- data/app/models/effective/customer.rb +9 -9
- data/app/models/effective/datatables/order_items.rb +14 -8
- data/app/models/effective/datatables/orders.rb +56 -69
- data/app/models/effective/order.rb +250 -139
- data/app/models/effective/order_item.rb +23 -16
- data/app/models/effective/product.rb +23 -0
- data/app/models/effective/providers/ccbill_postback.rb +85 -0
- data/app/models/effective/{stripe_charge.rb → providers/stripe_charge.rb} +1 -1
- data/app/models/effective/subscription.rb +16 -12
- data/app/models/effective/tax_rate_calculator.rb +45 -0
- data/app/views/admin/customers/index.html.haml +2 -5
- data/app/views/admin/order_items/index.html.haml +2 -5
- data/app/views/admin/orders/_actions.html.haml +2 -0
- data/app/views/admin/orders/_form.html.haml +28 -0
- data/app/views/admin/orders/_order_item_fields.html.haml +9 -0
- data/app/views/admin/orders/index.html.haml +9 -5
- data/app/views/admin/orders/new.html.haml +3 -0
- data/app/views/effective/carts/_cart.html.haml +3 -12
- data/app/views/effective/carts/_cart_actions.html.haml +4 -0
- data/app/views/effective/carts/show.html.haml +10 -12
- data/app/views/effective/orders/_checkout_step1.html.haml +46 -0
- data/app/views/effective/orders/_checkout_step2.html.haml +33 -0
- data/app/views/effective/orders/_order.html.haml +2 -0
- data/app/views/effective/orders/_order_actions.html.haml +10 -5
- data/app/views/effective/orders/_order_footer.html.haml +1 -0
- data/app/views/effective/orders/_order_items.html.haml +11 -9
- data/app/views/effective/orders/_order_note.html.haml +8 -0
- data/app/views/effective/orders/_order_note_fields.html.haml +5 -0
- data/app/views/effective/orders/_order_shipping.html.haml +4 -4
- data/app/views/effective/orders/_order_user_fields.html.haml +1 -0
- data/app/views/effective/orders/_orders_table.html.haml +27 -0
- data/app/views/effective/orders/ccbill/_form.html.haml +24 -0
- data/app/views/effective/orders/checkout_step1.html.haml +3 -0
- data/app/views/effective/orders/checkout_step2.html.haml +3 -0
- data/app/views/effective/orders/cheque/_form.html.haml +2 -0
- data/app/views/effective/orders/cheque/pay_by_cheque.html.haml +9 -0
- data/app/views/effective/orders/declined.html.haml +4 -2
- data/app/views/effective/orders/my_purchases.html.haml +1 -1
- data/app/views/effective/orders/my_sales.html.haml +1 -1
- data/app/views/effective/orders/purchased.html.haml +3 -2
- data/app/views/effective/orders/show.html.haml +1 -1
- data/app/views/effective/orders/stripe/_form.html.haml +5 -5
- data/app/views/effective/orders_mailer/order_error.html.haml +11 -0
- data/app/views/effective/orders_mailer/payment_request_to_buyer.html.haml +13 -0
- data/app/views/effective/orders_mailer/pending_order_invoice_to_buyer.html.haml +13 -0
- data/app/views/layouts/effective_orders_mailer_layout.html.haml +7 -7
- data/config/routes.rb +39 -24
- data/db/migrate/01_create_effective_orders.rb.erb +20 -1
- data/db/upgrade/03_upgrade_effective_orders_from1x.rb.erb +95 -0
- data/lib/effective_orders.rb +67 -9
- data/lib/effective_orders/app_checkout_service.rb +1 -2
- data/lib/effective_orders/engine.rb +46 -14
- data/lib/effective_orders/version.rb +1 -1
- data/lib/generators/effective_orders/install_generator.rb +1 -0
- data/lib/generators/effective_orders/upgrade_from03x_generator.rb +1 -0
- data/lib/generators/effective_orders/upgrade_from1x_generator.rb +31 -0
- data/lib/generators/templates/effective_orders.rb +131 -66
- data/lib/generators/templates/effective_orders_mailer_preview.rb +28 -13
- data/spec/controllers/admin/orders_controller_spec.rb +242 -0
- data/spec/controllers/ccbill_orders_controller_spec.rb +103 -0
- data/spec/controllers/moneris_orders_controller_spec.rb +23 -23
- data/spec/controllers/orders_controller_spec.rb +167 -79
- data/spec/controllers/stripe_orders_controller_spec.rb +7 -7
- data/spec/dummy/app/models/product.rb +0 -8
- data/spec/dummy/app/models/product_with_float_price.rb +0 -8
- data/spec/dummy/app/models/user.rb +2 -19
- data/spec/dummy/config/application.rb +2 -1
- data/spec/dummy/config/environments/test.rb +1 -0
- data/spec/dummy/config/initializers/effective_orders.rb +109 -64
- data/spec/dummy/db/schema.rb +15 -2
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +0 -258
- data/spec/models/acts_as_purchasable_spec.rb +8 -6
- data/spec/models/factories_spec.rb +7 -1
- data/spec/models/order_item_spec.rb +1 -1
- data/spec/models/order_spec.rb +165 -46
- data/spec/models/stripe_charge_spec.rb +5 -5
- data/spec/spec_helper.rb +2 -0
- data/spec/support/factories.rb +49 -33
- metadata +47 -64
- data/app/views/effective/orders/_checkout_step_1.html.haml +0 -43
- data/app/views/effective/orders/_checkout_step_2.html.haml +0 -25
- data/app/views/effective/orders/_my_purchases.html.haml +0 -17
- data/app/views/effective/orders/checkout.html.haml +0 -3
- data/app/views/effective/orders/new.html.haml +0 -4
- data/spec/dummy/log/development.log +0 -82
@@ -5,8 +5,19 @@ class CreateEffectiveOrders < ActiveRecord::Migration
|
|
5
5
|
t.string :purchase_state
|
6
6
|
t.datetime :purchased_at
|
7
7
|
|
8
|
+
t.text :note
|
9
|
+
|
8
10
|
t.text :payment
|
9
11
|
|
12
|
+
t.string :payment_provider
|
13
|
+
t.string :payment_card
|
14
|
+
|
15
|
+
t.decimal :tax_rate, :precision => 6, :scale => 3
|
16
|
+
|
17
|
+
t.integer :subtotal
|
18
|
+
t.integer :tax
|
19
|
+
t.integer :total
|
20
|
+
|
10
21
|
t.timestamps
|
11
22
|
end
|
12
23
|
|
@@ -23,7 +34,6 @@ class CreateEffectiveOrders < ActiveRecord::Migration
|
|
23
34
|
t.integer :quantity
|
24
35
|
t.integer :price, :default => 0
|
25
36
|
t.boolean :tax_exempt
|
26
|
-
t.decimal :tax_rate, :precision => 5, :scale => 3, :default => 0.0
|
27
37
|
|
28
38
|
t.timestamps
|
29
39
|
end
|
@@ -78,6 +88,14 @@ class CreateEffectiveOrders < ActiveRecord::Migration
|
|
78
88
|
|
79
89
|
add_index <%= @subscriptions_table_name %>, :customer_id
|
80
90
|
add_index <%= @subscriptions_table_name %>, :stripe_subscription_id
|
91
|
+
|
92
|
+
create_table <%= @products_table_name %> do |t|
|
93
|
+
t.string :title
|
94
|
+
t.integer :price, :default => 0
|
95
|
+
t.boolean :tax_exempt, :default => false
|
96
|
+
|
97
|
+
t.timestamps
|
98
|
+
end
|
81
99
|
end
|
82
100
|
|
83
101
|
def self.down
|
@@ -87,5 +105,6 @@ class CreateEffectiveOrders < ActiveRecord::Migration
|
|
87
105
|
drop_table <%= @cart_items_table_name %>
|
88
106
|
drop_table <%= @customers_table_name %>
|
89
107
|
drop_table <%= @subscriptions_table_name %>
|
108
|
+
drop_table <%= @products_table_name %>
|
90
109
|
end
|
91
110
|
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
class UpgradeEffectiveOrdersFrom1x < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table <%= @products_table_name %> do |t|
|
4
|
+
t.string :title
|
5
|
+
t.integer :price, :default => 0
|
6
|
+
t.boolean :tax_exempt, :default => false
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
|
11
|
+
add_column <%= @orders_table_name %>, :note, :text
|
12
|
+
add_column <%= @orders_table_name %>, :payment_provider, :string
|
13
|
+
add_column <%= @orders_table_name %>, :payment_card, :string
|
14
|
+
|
15
|
+
add_column <%= @orders_table_name %>, :tax_rate, :decimal, :precision => 6, :scale => 3
|
16
|
+
add_column <%= @orders_table_name %>, :subtotal, :integer
|
17
|
+
add_column <%= @orders_table_name %>, :tax, :integer
|
18
|
+
add_column <%= @orders_table_name %>, :total, :integer
|
19
|
+
|
20
|
+
puts 'Resaving all Effective::Order objects to assign new database column values.'
|
21
|
+
|
22
|
+
Effective::Order.reset_column_information
|
23
|
+
|
24
|
+
Effective::Order.find_each do |order|
|
25
|
+
order.tax_rate = ((order.order_items.first.try(:tax_rate) || 0.0) * 100.0)
|
26
|
+
update_payment_provider_and_card(order)
|
27
|
+
order.save(validate: false)
|
28
|
+
print '.'
|
29
|
+
end
|
30
|
+
print "\n" if Effective::Order.any?
|
31
|
+
|
32
|
+
remove_column <%= @order_items_table_name %>, :tax_rate
|
33
|
+
|
34
|
+
puts 'Done'
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.down
|
38
|
+
add_column <%= @order_items_table_name %>, :tax_rate, :decimal, :precision => 5, :scale => 3
|
39
|
+
Effective::OrderItem.reset_column_information
|
40
|
+
Effective::OrderItem.find_each { |order_item| order_item.update_column(:tax_rate, (order_item.try(:order).tax_rate || 0.0) / 100.0) }
|
41
|
+
|
42
|
+
remove_column <%= @orders_table_name %>, :note
|
43
|
+
remove_column <%= @orders_table_name %>, :payment_provider
|
44
|
+
remove_column <%= @orders_table_name %>, :payment_card
|
45
|
+
|
46
|
+
remove_column <%= @orders_table_name %>, :tax_rate
|
47
|
+
remove_column <%= @orders_table_name %>, :subtotal
|
48
|
+
remove_column <%= @orders_table_name %>, :tax
|
49
|
+
remove_column <%= @orders_table_name %>, :total
|
50
|
+
end
|
51
|
+
|
52
|
+
def update_payment_provider_and_card(order)
|
53
|
+
return unless order.payment.present?
|
54
|
+
|
55
|
+
payment = HashWithIndifferentAccess.new(order.payment)
|
56
|
+
charge = HashWithIndifferentAccess.new(payment[:charge])
|
57
|
+
|
58
|
+
# Try to figure out the payment provider
|
59
|
+
provider =
|
60
|
+
if payment[:response_code] && payment[:transactionKey]
|
61
|
+
'moneris'
|
62
|
+
elsif charge[:id] && charge[:customer] && charge[:application_fee].present?
|
63
|
+
'stripe_connect'
|
64
|
+
elsif charge[:id] && charge[:customer]
|
65
|
+
'stripe'
|
66
|
+
elsif payment[:payer_email]
|
67
|
+
'paypal'
|
68
|
+
elsif (payment[:details] || '').include?('free')
|
69
|
+
'free'
|
70
|
+
else
|
71
|
+
'admin'
|
72
|
+
end
|
73
|
+
|
74
|
+
card =
|
75
|
+
case provider
|
76
|
+
when 'moneris'
|
77
|
+
payment[:card]
|
78
|
+
when 'stripe_connect'
|
79
|
+
(charge['card']['brand'] rescue nil)
|
80
|
+
when 'stripe'
|
81
|
+
(charge['card']['brand'] rescue nil)
|
82
|
+
when 'paypal'
|
83
|
+
payment[:payment_type]
|
84
|
+
when 'free'
|
85
|
+
'none'
|
86
|
+
when 'admin'
|
87
|
+
'none'
|
88
|
+
end
|
89
|
+
|
90
|
+
order.payment_provider = provider.presence || 'admin'
|
91
|
+
order.payment_card = card.presence || 'unknown'
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
end
|
data/lib/effective_orders.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'haml-rails'
|
2
|
-
require 'migrant'
|
3
2
|
require 'simple_form'
|
4
3
|
require 'effective_addresses'
|
5
|
-
require 'effective_obfuscation'
|
6
4
|
require 'effective_orders/engine'
|
7
5
|
require 'effective_orders/version'
|
8
6
|
require 'effective_orders/app_checkout_service'
|
@@ -10,6 +8,7 @@ require 'effective_orders/app_checkout_service'
|
|
10
8
|
module EffectiveOrders
|
11
9
|
PURCHASED = 'purchased'
|
12
10
|
DECLINED = 'declined'
|
11
|
+
PENDING = 'pending'
|
13
12
|
|
14
13
|
# The following are all valid config keys
|
15
14
|
mattr_accessor :orders_table_name
|
@@ -18,12 +17,18 @@ module EffectiveOrders
|
|
18
17
|
mattr_accessor :cart_items_table_name
|
19
18
|
mattr_accessor :customers_table_name
|
20
19
|
mattr_accessor :subscriptions_table_name
|
20
|
+
mattr_accessor :products_table_name
|
21
21
|
|
22
22
|
mattr_accessor :authorization_method
|
23
|
-
|
23
|
+
|
24
|
+
mattr_accessor :skip_mount_engine
|
25
|
+
mattr_accessor :orders_collection_scope
|
26
|
+
|
27
|
+
mattr_accessor :order_tax_rate_method
|
24
28
|
|
25
29
|
mattr_accessor :layout
|
26
30
|
mattr_accessor :simple_form_options
|
31
|
+
mattr_accessor :admin_simple_form_options
|
27
32
|
|
28
33
|
mattr_accessor :use_active_admin
|
29
34
|
mattr_accessor :active_admin_namespace
|
@@ -42,20 +47,25 @@ module EffectiveOrders
|
|
42
47
|
mattr_accessor :collect_user_fields
|
43
48
|
mattr_accessor :skip_user_validation
|
44
49
|
|
50
|
+
mattr_accessor :collect_note
|
51
|
+
mattr_accessor :collect_note_required
|
52
|
+
mattr_accessor :collect_note_message
|
53
|
+
|
45
54
|
mattr_accessor :minimum_charge
|
46
55
|
mattr_accessor :allow_free_orders
|
56
|
+
mattr_accessor :show_order_history_button
|
47
57
|
|
58
|
+
mattr_accessor :cheque_enabled
|
48
59
|
mattr_accessor :paypal_enabled
|
49
60
|
mattr_accessor :moneris_enabled
|
61
|
+
mattr_accessor :ccbill_enabled
|
50
62
|
mattr_accessor :app_checkout_enabled
|
51
63
|
|
52
|
-
mattr_accessor :show_order_history_button
|
53
|
-
|
54
|
-
# application fee is required if stripe_connect_enabled is true
|
55
64
|
mattr_accessor :stripe_enabled
|
56
|
-
|
57
65
|
mattr_accessor :stripe_subscriptions_enabled
|
58
66
|
mattr_accessor :stripe_connect_enabled
|
67
|
+
|
68
|
+
# application fee is required if stripe_connect_enabled is true
|
59
69
|
mattr_accessor :stripe_connect_application_fee_method
|
60
70
|
|
61
71
|
# These are hashes of configs
|
@@ -63,12 +73,24 @@ module EffectiveOrders
|
|
63
73
|
mattr_accessor :paypal
|
64
74
|
mattr_accessor :moneris
|
65
75
|
mattr_accessor :stripe
|
76
|
+
mattr_accessor :ccbill
|
66
77
|
mattr_accessor :app_checkout
|
78
|
+
mattr_accessor :cheque
|
67
79
|
|
68
80
|
mattr_accessor :deliver_method
|
69
81
|
|
70
82
|
def self.setup
|
71
83
|
yield self
|
84
|
+
|
85
|
+
if EffectiveOrders.stripe_enabled
|
86
|
+
begin
|
87
|
+
require 'stripe'
|
88
|
+
rescue Exception
|
89
|
+
raise "unable to load stripe. Plese add gem 'stripe' to your Gemfile and then 'bundle install'"
|
90
|
+
end
|
91
|
+
|
92
|
+
::Stripe.api_key = stripe[:secret_key]
|
93
|
+
end
|
72
94
|
end
|
73
95
|
|
74
96
|
def self.authorized?(controller, action, resource)
|
@@ -91,12 +113,48 @@ module EffectiveOrders
|
|
91
113
|
use_active_admin && defined?(ActiveAdmin)
|
92
114
|
end
|
93
115
|
|
116
|
+
def self.permitted_params
|
117
|
+
[
|
118
|
+
:note, :save_billing_address, :save_shipping_address, :shipping_address_same_as_billing,
|
119
|
+
billing_address: [:full_name, :address1, :address2, :city, :country_code, :state_code, :postal_code],
|
120
|
+
shipping_address: [:full_name, :address1, :address2, :city, :country_code, :state_code, :postal_code],
|
121
|
+
user_attributes: (EffectiveOrders.collect_user_fields || []),
|
122
|
+
order_items_attributes: [:stripe_coupon_id, :class, :id]
|
123
|
+
]
|
124
|
+
end
|
125
|
+
|
94
126
|
def self.single_payment_processor?
|
95
|
-
[
|
127
|
+
[
|
128
|
+
moneris_enabled,
|
129
|
+
paypal_enabled,
|
130
|
+
stripe_enabled,
|
131
|
+
cheque_enabled,
|
132
|
+
ccbill_enabled,
|
133
|
+
app_checkout_enabled
|
134
|
+
].select { |enabled| enabled }.length == 1
|
135
|
+
end
|
136
|
+
|
137
|
+
# The Effective::Order.payment_provider value must be in this collection
|
138
|
+
def self.payment_providers
|
139
|
+
@payment_providers ||= [
|
140
|
+
'admin',
|
141
|
+
('app_checkout' if app_checkout_enabled),
|
142
|
+
('ccbill' if ccbill_enabled),
|
143
|
+
('cheque' if cheque_enabled),
|
144
|
+
('free' if allow_free_orders),
|
145
|
+
('moneris' if moneris_enabled),
|
146
|
+
('paypal' if paypal_enabled),
|
147
|
+
('pretend' if (allow_pretend_purchase_in_production && Rails.env.production?) || (allow_pretend_purchase_in_development && !Rails.env.production?)),
|
148
|
+
('stripe' if stripe_enabled),
|
149
|
+
('stripe_connect' if stripe_connect_enabled)
|
150
|
+
].compact
|
151
|
+
end
|
152
|
+
|
153
|
+
def self.tax_rate_method=(*args)
|
154
|
+
raise 'EffectiveOrders.tax_rate_method has been removed and renamed to EffectiveOrders.order_tax_rate_method. Its expected value is now different too. Return 5.25 for 5.25% tax. Please refer to the readme for more info.'
|
96
155
|
end
|
97
156
|
|
98
157
|
class SoldOutException < Exception; end
|
99
158
|
class AlreadyPurchasedException < Exception; end
|
100
|
-
class AlreadyDeclinedException < Exception; end
|
101
159
|
|
102
160
|
end
|
@@ -11,6 +11,7 @@ module EffectiveOrders
|
|
11
11
|
helper EffectiveCartsHelper
|
12
12
|
helper EffectivePaypalHelper if EffectiveOrders.paypal_enabled
|
13
13
|
helper EffectiveStripeHelper if EffectiveOrders.stripe_enabled
|
14
|
+
helper EffectiveCcbillHelper if EffectiveOrders.ccbill_enabled
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
@@ -28,31 +29,28 @@ module EffectiveOrders
|
|
28
29
|
end
|
29
30
|
|
30
31
|
# Set up our default configuration options.
|
31
|
-
initializer "effective_orders.defaults", :
|
32
|
+
initializer "effective_orders.defaults", before: :load_config_initializers do |app|
|
32
33
|
eval File.read("#{config.root}/lib/generators/templates/effective_orders.rb")
|
34
|
+
end
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
:deliver
|
39
|
-
end
|
36
|
+
# Set up mail delivering config option
|
37
|
+
initializer "effective_orders.mailer", after: :load_config_initializers do |app|
|
38
|
+
deliver_method = Rails.gem_version >= Gem::Version.new('4.2') ? :deliver_now : :deliver
|
39
|
+
EffectiveOrders.mailer[:deliver_method] ||= deliver_method
|
40
40
|
end
|
41
41
|
|
42
42
|
# Set up our Stripe API Key
|
43
|
-
initializer "effective_orders.stripe_api_key", :
|
43
|
+
initializer "effective_orders.stripe_api_key", after: :load_config_initializers do |app|
|
44
44
|
if EffectiveOrders.stripe_enabled
|
45
45
|
begin
|
46
46
|
require 'stripe'
|
47
47
|
rescue Exception
|
48
48
|
raise "unable to load stripe. Plese add gem 'stripe' to your Gemfile and then 'bundle install'"
|
49
49
|
end
|
50
|
-
|
51
|
-
::Stripe.api_key = EffectiveOrders.stripe[:secret_key]
|
52
50
|
end
|
53
51
|
end
|
54
52
|
|
55
|
-
initializer 'effective_orders.moneris_config_validation', :
|
53
|
+
initializer 'effective_orders.moneris_config_validation', after: :load_config_initializers do
|
56
54
|
if EffectiveOrders.moneris_enabled
|
57
55
|
unless EffectiveOrders.moneris.is_a?(Hash)
|
58
56
|
raise ArgumentError, "expected EffectiveOrders.moneris to be a Hash but it is a #{EffectiveOrders.moneris.class}"
|
@@ -63,7 +61,7 @@ module EffectiveOrders
|
|
63
61
|
end
|
64
62
|
end
|
65
63
|
|
66
|
-
initializer 'effective_orders.paypal_config_validation', :
|
64
|
+
initializer 'effective_orders.paypal_config_validation', after: :load_config_initializers do
|
67
65
|
if EffectiveOrders.paypal_enabled
|
68
66
|
unless EffectiveOrders.paypal.is_a?(Hash)
|
69
67
|
raise ArgumentError, "expected EffectiveOrders.paypal to be a Hash but it is a #{EffectiveOrders.paypal.class}"
|
@@ -74,7 +72,7 @@ module EffectiveOrders
|
|
74
72
|
end
|
75
73
|
end
|
76
74
|
|
77
|
-
initializer 'effective_orders.stripe_config_validation', :
|
75
|
+
initializer 'effective_orders.stripe_config_validation', after: :load_config_initializers do
|
78
76
|
if EffectiveOrders.stripe_enabled
|
79
77
|
unless EffectiveOrders.stripe.is_a?(Hash)
|
80
78
|
raise ArgumentError, "expected EffectiveOrders.stripe to be a Hash but it is a #{EffectiveOrders.stripe.class}"
|
@@ -90,7 +88,23 @@ module EffectiveOrders
|
|
90
88
|
end
|
91
89
|
end
|
92
90
|
|
93
|
-
initializer 'effective_orders.
|
91
|
+
initializer 'effective_orders.ccbill_config_validation', after: :load_config_initializers do
|
92
|
+
if EffectiveOrders.ccbill_enabled
|
93
|
+
unless EffectiveOrders.ccbill.is_a?(Hash)
|
94
|
+
raise ArgumentError, "expected EffectiveOrders.ccbill to be a Hash but it is a #{EffectiveOrders.ccbill.class}"
|
95
|
+
end
|
96
|
+
EffectiveOrders.ccbill[:form_period] ||= 365
|
97
|
+
|
98
|
+
missing = EffectiveOrders.stripe.select {|_config, value| value.blank? }
|
99
|
+
required = [:client_accnum, :client_subacc, :form_name, :currency_code, :dynamic_pricing_salt]
|
100
|
+
|
101
|
+
# perform an intersection operation between missing and required configs
|
102
|
+
missing_required = missing.keys & required
|
103
|
+
raise "Missing effective_orders Stripe configuration values: #{missing_required.join(', ')}" if missing_required.present?
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
initializer 'effective_orders.app_checkout_config_validation', after: :load_config_initializers do
|
94
108
|
if EffectiveOrders.app_checkout_enabled
|
95
109
|
unless EffectiveOrders.app_checkout.is_a?(Hash)
|
96
110
|
raise ArgumentError, "expected EffectiveOrders.app_checkout to be a Hash but it is a #{EffectiveOrders.app_checkout.class}"
|
@@ -106,6 +120,24 @@ module EffectiveOrders
|
|
106
120
|
end
|
107
121
|
end
|
108
122
|
|
123
|
+
initializer 'effective_orders.cheque_config_validation', after: :load_config_initializers do
|
124
|
+
if EffectiveOrders.cheque_enabled
|
125
|
+
unless EffectiveOrders.cheque.is_a?(Hash)
|
126
|
+
raise ArgumentError, "expected EffectiveOrders.cheque to be a Hash but it is a #{EffectiveOrders.cheque.class}"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
initializer 'effective_orders.obfuscate_order_ids_validation' do
|
132
|
+
if EffectiveOrders.obfuscate_order_ids
|
133
|
+
begin
|
134
|
+
require 'effective_obfuscation'
|
135
|
+
rescue Exception
|
136
|
+
raise "unable to load effective_obfuscation. Plese add gem 'effective_obfuscation' to your Gemfile and then 'bundle install'"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
109
141
|
# Use ActiveAdmin (optional)
|
110
142
|
initializer 'effective_orders.active_admin' do
|
111
143
|
if EffectiveOrders.use_active_admin?
|
@@ -36,6 +36,7 @@ module EffectiveOrders
|
|
36
36
|
@cart_items_table_name = ':' + EffectiveOrders.cart_items_table_name.to_s
|
37
37
|
@customers_table_name = ':' + EffectiveOrders.customers_table_name.to_s
|
38
38
|
@subscriptions_table_name = ':' + EffectiveOrders.subscriptions_table_name.to_s
|
39
|
+
@products_table_name = ':' + EffectiveOrders.products_table_name.to_s
|
39
40
|
|
40
41
|
migration_template '../../../db/migrate/01_create_effective_orders.rb.erb', 'db/migrate/create_effective_orders.rb'
|
41
42
|
end
|
@@ -22,6 +22,7 @@ module EffectiveOrders
|
|
22
22
|
@cart_items_table_name = ':' + EffectiveOrders.cart_items_table_name.to_s
|
23
23
|
@customers_table_name = ':' + EffectiveOrders.customers_table_name.to_s
|
24
24
|
@subscriptions_table_name = ':' + EffectiveOrders.subscriptions_table_name.to_s
|
25
|
+
@products_table_name = ':' + EffectiveOrders.products_table_name.to_s
|
25
26
|
|
26
27
|
migration_template '../../../db/upgrade/02_upgrade_effective_orders_from03x.rb.erb', 'db/migrate/upgrade_effective_orders_from03x.rb'
|
27
28
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module EffectiveOrders
|
2
|
+
module Generators
|
3
|
+
class UpgradeFrom1xGenerator < Rails::Generators::Base
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
|
6
|
+
desc 'Upgrade effective_orders from the 1.x branch'
|
7
|
+
|
8
|
+
source_root File.expand_path('../../templates', __FILE__)
|
9
|
+
|
10
|
+
def self.next_migration_number(dirname)
|
11
|
+
ActiveRecord::Migration.new.next_migration_number(1) #=> “20160114171807"
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_migration_file
|
15
|
+
@orders_table_name = ':' + EffectiveOrders.orders_table_name.to_s
|
16
|
+
@order_items_table_name = ':' + EffectiveOrders.order_items_table_name.to_s
|
17
|
+
@carts_table_name = ':' + EffectiveOrders.carts_table_name.to_s
|
18
|
+
@cart_items_table_name = ':' + EffectiveOrders.cart_items_table_name.to_s
|
19
|
+
@customers_table_name = ':' + EffectiveOrders.customers_table_name.to_s
|
20
|
+
@subscriptions_table_name = ':' + EffectiveOrders.subscriptions_table_name.to_s
|
21
|
+
@products_table_name = ':' + EffectiveOrders.products_table_name.to_s
|
22
|
+
|
23
|
+
migration_template '../../../db/upgrade/03_upgrade_effective_orders_from1x.rb.erb', 'db/migrate/upgrade_effective_orders_from1x.rb'
|
24
|
+
end
|
25
|
+
|
26
|
+
def show_readme
|
27
|
+
readme 'README' if behavior == :invoke
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|