effective_orders 2.2.4 → 3.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.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +124 -84
  4. data/app/assets/javascripts/effective_orders/customers.js.coffee +39 -0
  5. data/app/assets/javascripts/effective_orders/providers/{stripe_charges.js.coffee → stripe.js.coffee} +15 -13
  6. data/app/assets/javascripts/effective_orders/subscriptions.js.coffee +73 -0
  7. data/app/assets/stylesheets/effective_orders.scss +2 -1
  8. data/app/assets/stylesheets/effective_orders/_order.scss +16 -8
  9. data/app/assets/stylesheets/effective_orders/_subscriptions.scss +14 -0
  10. data/app/controllers/admin/customers_controller.rb +11 -8
  11. data/app/controllers/admin/order_items_controller.rb +4 -8
  12. data/app/controllers/admin/orders_controller.rb +133 -87
  13. data/app/controllers/effective/carts_controller.rb +18 -8
  14. data/app/controllers/effective/concerns/purchase.rb +39 -0
  15. data/app/controllers/effective/customers_controller.rb +43 -0
  16. data/app/controllers/effective/orders_controller.rb +73 -119
  17. data/app/controllers/effective/providers/app_checkout.rb +3 -1
  18. data/app/controllers/effective/providers/ccbill.rb +4 -6
  19. data/app/controllers/effective/providers/cheque.rb +20 -11
  20. data/app/controllers/effective/providers/free.rb +33 -0
  21. data/app/controllers/effective/providers/mark_as_paid.rb +33 -0
  22. data/app/controllers/effective/providers/moneris.rb +9 -17
  23. data/app/controllers/effective/providers/paypal.rb +4 -6
  24. data/app/controllers/effective/providers/pretend.rb +4 -4
  25. data/app/controllers/effective/providers/refund.rb +39 -0
  26. data/app/controllers/effective/providers/stripe.rb +19 -40
  27. data/app/controllers/effective/providers/stripe_connect.rb +2 -6
  28. data/app/controllers/effective/webhooks_controller.rb +44 -95
  29. data/app/datatables/effective_customers_datatable.rb +21 -29
  30. data/app/datatables/effective_order_items_datatable.rb +77 -79
  31. data/app/datatables/effective_orders_datatable.rb +67 -57
  32. data/app/helpers/effective_carts_helper.rb +17 -14
  33. data/app/helpers/effective_orders_helper.rb +40 -56
  34. data/app/helpers/effective_paypal_helper.rb +3 -3
  35. data/app/helpers/effective_stripe_helper.rb +47 -18
  36. data/app/helpers/effective_subscriptions_helper.rb +79 -0
  37. data/app/mailers/effective/orders_mailer.rb +125 -2
  38. data/app/models/concerns/acts_as_purchasable.rb +23 -33
  39. data/app/models/concerns/acts_as_subscribable.rb +68 -0
  40. data/app/models/concerns/acts_as_subscribable_buyer.rb +22 -0
  41. data/app/models/effective/cart.rb +53 -24
  42. data/app/models/effective/cart_item.rb +6 -12
  43. data/app/models/effective/customer.rb +51 -54
  44. data/app/models/effective/order.rb +160 -147
  45. data/app/models/effective/order_item.rb +18 -21
  46. data/app/models/effective/product.rb +7 -7
  47. data/app/models/effective/providers/ccbill_postback.rb +1 -1
  48. data/app/models/effective/providers/stripe_charge.rb +8 -19
  49. data/app/models/effective/subscripter.rb +230 -0
  50. data/app/models/effective/subscription.rb +27 -76
  51. data/app/models/effective/tax_rate_calculator.rb +10 -7
  52. data/app/views/admin/customers/_actions.html.haml +1 -2
  53. data/app/views/admin/customers/index.html.haml +1 -1
  54. data/app/views/admin/customers/show.html.haml +6 -0
  55. data/app/views/admin/orders/_actions.html.haml +9 -7
  56. data/app/views/admin/orders/_form.html.haml +11 -7
  57. data/app/views/admin/orders/_order_actions.html.haml +2 -1
  58. data/app/views/admin/orders/_order_item_fields.html.haml +1 -1
  59. data/app/views/admin/orders/edit.html.haml +4 -0
  60. data/app/views/admin/orders/index.html.haml +1 -4
  61. data/app/views/admin/orders/new.html.haml +1 -1
  62. data/app/views/admin/orders/show.html.haml +5 -6
  63. data/app/views/effective/carts/_cart.html.haml +2 -2
  64. data/app/views/effective/carts/show.html.haml +2 -2
  65. data/app/views/effective/customers/_customer.html.haml +152 -0
  66. data/app/views/effective/customers/_fields.html.haml +12 -0
  67. data/app/views/effective/customers/_form.html.haml +13 -0
  68. data/app/views/effective/customers/edit.html.haml +3 -0
  69. data/app/views/effective/orders/_checkout_step1.html.haml +8 -15
  70. data/app/views/effective/orders/_checkout_step2.html.haml +34 -21
  71. data/app/views/effective/orders/_order.html.haml +8 -9
  72. data/app/views/effective/orders/_order_actions.html.haml +7 -8
  73. data/app/views/effective/orders/_order_header.html.haml +1 -1
  74. data/app/views/effective/orders/_order_items.html.haml +11 -5
  75. data/app/views/effective/orders/_order_note.html.haml +4 -7
  76. data/app/views/effective/orders/_orders_table.html.haml +26 -26
  77. data/app/views/effective/orders/app_checkout/_form.html.haml +2 -2
  78. data/app/views/effective/orders/ccbill/_form.html.haml +1 -1
  79. data/app/views/effective/orders/cheque/_form.html.haml +3 -1
  80. data/app/views/effective/orders/declined.html.haml +1 -1
  81. data/app/views/effective/orders/{checkout_step1.html.haml → edit.html.haml} +0 -0
  82. data/app/views/effective/orders/free/_form.html.haml +4 -0
  83. data/app/views/effective/orders/index.html.haml +2 -4
  84. data/app/views/effective/orders/mark_as_paid/_form.html.haml +32 -0
  85. data/app/views/effective/orders/moneris/_form.html.haml +6 -6
  86. data/app/views/effective/orders/{checkout_step2.html.haml → new.html.haml} +1 -1
  87. data/app/views/effective/orders/paypal/_form.html.haml +2 -2
  88. data/app/views/effective/orders/pretend/_form.html.haml +2 -2
  89. data/app/views/effective/orders/purchased.html.haml +3 -0
  90. data/app/views/effective/orders/refund/_form.html.haml +32 -0
  91. data/app/views/effective/orders/show.html.haml +4 -1
  92. data/app/views/effective/orders/stripe/_form.html.haml +5 -5
  93. data/app/views/effective/orders_mailer/subscription_canceled.html.haml +9 -0
  94. data/app/views/effective/orders_mailer/subscription_payment_failed.html.haml +9 -0
  95. data/app/views/effective/orders_mailer/subscription_payment_succeeded.html.haml +9 -0
  96. data/app/views/effective/orders_mailer/subscription_trial_expired.html.haml +5 -0
  97. data/app/views/effective/orders_mailer/subscription_trial_expiring.html.haml +7 -0
  98. data/app/views/effective/subscriptions/_fields.html.haml +16 -0
  99. data/app/views/effective/subscriptions/_plan.html.haml +21 -0
  100. data/app/views/layouts/effective_orders_mailer_layout.html.haml +6 -8
  101. data/config/effective_orders.rb +41 -20
  102. data/config/routes.rb +48 -48
  103. data/db/migrate/01_create_effective_orders.rb.erb +19 -5
  104. data/lib/effective_orders.rb +78 -42
  105. data/lib/effective_orders/engine.rb +36 -82
  106. data/lib/effective_orders/version.rb +1 -1
  107. data/lib/generators/effective_orders/install_generator.rb +2 -2
  108. data/lib/generators/templates/effective_orders_mailer_preview.rb +39 -4
  109. data/lib/tasks/effective_orders_tasks.rake +42 -0
  110. data/spec/controllers/carts_controller_spec.rb +1 -1
  111. data/spec/controllers/moneris_orders_controller_spec.rb +4 -4
  112. data/spec/controllers/orders_controller_spec.rb +4 -4
  113. data/spec/controllers/stripe_orders_controller_spec.rb +2 -2
  114. data/spec/controllers/webhooks_controller_spec.rb +1 -1
  115. data/spec/dummy/config/initializers/effective_orders.rb +1 -7
  116. data/spec/dummy/db/schema.rb +1 -0
  117. data/spec/dummy/db/test.sqlite3 +0 -0
  118. data/spec/dummy/log/test.log +3 -0
  119. data/spec/models/acts_as_purchasable_spec.rb +0 -56
  120. data/spec/models/customer_spec.rb +3 -3
  121. data/spec/models/order_spec.rb +2 -2
  122. data/spec/spec_helper.rb +1 -1
  123. data/spec/support/factories.rb +2 -1
  124. metadata +37 -49
  125. data/active_admin/effective_carts.rb +0 -14
  126. data/active_admin/effective_orders.rb +0 -112
  127. data/app/assets/javascripts/effective_orders/providers/stripe_subscriptions.js.coffee +0 -28
  128. data/app/controllers/concerns/acts_as_active_admin_controller.rb +0 -69
  129. data/app/controllers/effective/subscriptions_controller.rb +0 -126
  130. data/app/models/effective/datatables/customers.rb +0 -40
  131. data/app/models/effective/datatables/order_items.rb +0 -101
  132. data/app/models/effective/datatables/orders.rb +0 -91
  133. data/app/models/inputs/price_field.rb +0 -63
  134. data/app/models/inputs/price_form_input.rb +0 -7
  135. data/app/models/inputs/price_formtastic_input.rb +0 -9
  136. data/app/models/inputs/price_input.rb +0 -19
  137. data/app/models/inputs/price_simple_form_input.rb +0 -8
  138. data/app/views/admin/orders/_form_mark_as_paid.html.haml +0 -33
  139. data/app/views/admin/orders/_order_payment_details.html.haml +0 -5
  140. data/app/views/admin/orders/mark_as_paid.html.haml +0 -7
  141. data/app/views/effective/orders/stripe/_subscription_fields.html.haml +0 -7
  142. data/app/views/effective/subscriptions/index.html.haml +0 -22
  143. data/app/views/effective/subscriptions/new.html.haml +0 -9
  144. data/app/views/effective/subscriptions/show.html.haml +0 -49
  145. data/db/upgrade/02_upgrade_effective_orders_from03x.rb.erb +0 -29
  146. data/db/upgrade/03_upgrade_effective_orders_from1x.rb.erb +0 -98
  147. data/db/upgrade/upgrade_price_column_on_table.rb.erb +0 -17
  148. data/lib/generators/effective_orders/upgrade_from03x_generator.rb +0 -31
  149. data/lib/generators/effective_orders/upgrade_from1x_generator.rb +0 -27
  150. data/lib/generators/effective_orders/upgrade_price_column_generator.rb +0 -30
@@ -4,27 +4,12 @@ module EffectiveOrders
4
4
 
5
5
  config.autoload_paths += Dir["#{config.root}/app/models/**/"]
6
6
 
7
- # Include Helpers to base application
8
- initializer 'effective_orders.action_controller' do |app|
9
- ActiveSupport.on_load :action_controller do
10
- helper EffectiveOrdersHelper
11
- helper EffectiveCartsHelper
12
- helper EffectivePaypalHelper if EffectiveOrders.paypal_enabled
13
- helper EffectiveStripeHelper if EffectiveOrders.stripe_enabled
14
- helper EffectiveCcbillHelper if EffectiveOrders.ccbill_enabled
15
- end
16
- end
17
-
18
7
  # Include acts_as_addressable concern and allow any ActiveRecord object to call it
19
8
  initializer 'effective_orders.active_record' do |app|
20
9
  ActiveSupport.on_load :active_record do
21
10
  ActiveRecord::Base.extend(ActsAsPurchasable::ActiveRecord)
22
- end
23
- end
24
-
25
- initializer 'effective_orders.action_view' do |app|
26
- ActiveSupport.on_load :action_view do
27
- ActionView::Helpers::FormBuilder.send(:include, Inputs::PriceFormInput)
11
+ ActiveRecord::Base.extend(ActsAsSubscribable::ActiveRecord)
12
+ ActiveRecord::Base.extend(ActsAsSubscribableBuyer::ActiveRecord)
28
13
  end
29
14
  end
30
15
 
@@ -34,97 +19,88 @@ module EffectiveOrders
34
19
  end
35
20
 
36
21
  # Set up mail delivering config option
37
- initializer "effective_orders.mailer", after: :load_config_initializers do |app|
22
+ initializer 'effective_orders.mailer', after: :load_config_initializers do |app|
38
23
  deliver_method = Rails.gem_version >= Gem::Version.new('4.2') ? :deliver_now : :deliver
39
24
  EffectiveOrders.mailer[:deliver_method] ||= deliver_method
40
25
  end
41
26
 
42
- # Set up our Stripe API Key
43
- initializer "effective_orders.stripe_api_key", after: :load_config_initializers do |app|
44
- if EffectiveOrders.stripe_enabled
45
- begin
46
- require 'stripe'
47
- rescue Exception
48
- raise "unable to load stripe. Plese add gem 'stripe' to your Gemfile and then 'bundle install'"
49
- end
50
- end
51
- end
52
-
53
27
  initializer 'effective_orders.moneris_config_validation', after: :load_config_initializers do
54
28
  if EffectiveOrders.moneris_enabled
55
- unless EffectiveOrders.moneris.is_a?(Hash)
56
- raise ArgumentError, "expected EffectiveOrders.moneris to be a Hash but it is a #{EffectiveOrders.moneris.class}"
57
- end
58
- missing = EffectiveOrders.moneris.select {|_config, value| value.blank? }
29
+ raise 'expected EffectiveOrders.moneris to be a Hash' unless EffectiveOrders.moneris.is_a?(Hash)
59
30
 
60
- raise "Missing effective_orders Moneris configuration values: #{missing.keys.join(', ')}" if missing.present?
31
+ missing = EffectiveOrders.moneris.select { |_, value| value.blank? }
32
+ raise "Missing EffectiveOrders.moneris config values: #{missing.keys.join(', ')}" if missing.present?
61
33
  end
62
34
  end
63
35
 
64
36
  initializer 'effective_orders.paypal_config_validation', after: :load_config_initializers do
65
37
  if EffectiveOrders.paypal_enabled
66
- unless EffectiveOrders.paypal.is_a?(Hash)
67
- raise ArgumentError, "expected EffectiveOrders.paypal to be a Hash but it is a #{EffectiveOrders.paypal.class}"
68
- end
69
- missing = EffectiveOrders.paypal.select {|_config, value| value.blank? }
38
+ raise 'expected EffectiveOrders.paypal to be a Hash' unless EffectiveOrders.paypal.is_a?(Hash)
70
39
 
71
- raise "Missing effective_orders PayPal configuration values: #{missing.keys.join(', ')}" if missing.present?
40
+ missing = EffectiveOrders.paypal.select { |_, value| value.blank? }
41
+ raise "Missing EffectiveOrders.paypal config values: #{missing.keys.join(', ')}" if missing.present?
72
42
  end
73
43
  end
74
44
 
75
45
  initializer 'effective_orders.stripe_config_validation', after: :load_config_initializers do
76
46
  if EffectiveOrders.stripe_enabled
77
- unless EffectiveOrders.stripe.is_a?(Hash)
78
- raise ArgumentError, "expected EffectiveOrders.stripe to be a Hash but it is a #{EffectiveOrders.stripe.class}"
47
+ begin
48
+ require 'stripe'
49
+ rescue Exception
50
+ raise "unable to load stripe. Plese add gem 'stripe' to your Gemfile and then 'bundle install'"
79
51
  end
80
- missing = EffectiveOrders.stripe.select {|_config, value| value.blank? }
52
+
53
+ raise 'expected EffectiveOrders.stripe to be a Hash' unless EffectiveOrders.stripe.is_a?(Hash)
54
+
55
+ missing = EffectiveOrders.stripe.select { |_, value| value.blank? }
81
56
  required = [:secret_key, :publishable_key, :currency, :site_title]
82
- stripe_connect_required = [:connect_client_id]
83
- required += stripe_connect_required if EffectiveOrders.stripe_connect_enabled
57
+ required += [:connect_client_id] if EffectiveOrders.stripe_connect_enabled
84
58
 
85
59
  # perform an intersection operation between missing and required configs
86
60
  missing_required = missing.keys & required
87
- raise "Missing effective_orders Stripe configuration values: #{missing_required.join(', ')}" if missing_required.present?
61
+ raise "Missing EffectiveOrders.stripe config values: #{missing_required.join(', ')}" if missing_required.present?
62
+ end
63
+ end
64
+
65
+ initializer 'effective_orders.stripe_api_key', after: :load_config_initializers do |app|
66
+ if EffectiveOrders.stripe_enabled
67
+ ::Stripe.api_key = EffectiveOrders.stripe[:secret_key]
88
68
  end
89
69
  end
90
70
 
91
71
  initializer 'effective_orders.ccbill_config_validation', after: :load_config_initializers do
92
72
  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
73
+ raise 'expected EffectiveOrders.ccbill to be a Hash' unless EffectiveOrders.ccbill.is_a?(Hash)
74
+
96
75
  EffectiveOrders.ccbill[:form_period] ||= 365
97
76
 
98
- missing = EffectiveOrders.stripe.select {|_config, value| value.blank? }
77
+ missing = EffectiveOrders.stripe.select { |_, value| value.blank? }
99
78
  required = [:client_accnum, :client_subacc, :form_name, :currency_code, :dynamic_pricing_salt]
100
79
 
101
80
  # perform an intersection operation between missing and required configs
102
81
  missing_required = missing.keys & required
103
- raise "Missing effective_orders Stripe configuration values: #{missing_required.join(', ')}" if missing_required.present?
82
+ raise "Missing EffectiveOrders.ccbill config values: #{missing_required.join(', ')}" if missing_required.present?
104
83
  end
105
84
  end
106
85
 
107
86
  initializer 'effective_orders.app_checkout_config_validation', after: :load_config_initializers do
108
87
  if EffectiveOrders.app_checkout_enabled
109
- unless EffectiveOrders.app_checkout.is_a?(Hash)
110
- raise ArgumentError, "expected EffectiveOrders.app_checkout to be a Hash but it is a #{EffectiveOrders.app_checkout.class}"
111
- end
112
- missing = EffectiveOrders.app_checkout.select {|_config, value| value.blank? }
88
+ raise 'expected EffectiveOrders.app_checkout to be a Hash' unless EffectiveOrders.app_checkout.is_a?(Hash)
89
+
90
+ missing = EffectiveOrders.app_checkout.select { |_, value| value.blank? }
113
91
  missing = missing | [:service] unless EffectiveOrders.app_checkout.has_key?(:service)
114
92
 
115
93
  raise "Missing effective_orders App Checkout configuration values: #{missing.keys.join(', ')}" if missing.present?
94
+
116
95
  unless EffectiveOrders.app_checkout[:service].respond_to?(:call)
117
- msg = "EffectiveOrders.app_checkout[:service] is not a compatible service object. Inherit from EffectiveOrders::AppCheckoutService or implement a similar API"
118
- raise ArgumentError, msg
96
+ raise 'EffectiveOrders.app_checkout[:service] is not a compatible service object. Inherit from EffectiveOrders::AppCheckoutService or implement a similar API'
119
97
  end
120
98
  end
121
99
  end
122
100
 
123
101
  initializer 'effective_orders.cheque_config_validation', after: :load_config_initializers do
124
102
  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
103
+ raise 'expected EffectiveOrders.cheque to be a Hash' unless EffectiveOrders.cheque.is_a?(Hash)
128
104
  end
129
105
  end
130
106
 
@@ -133,32 +109,10 @@ module EffectiveOrders
133
109
  begin
134
110
  require 'effective_obfuscation'
135
111
  rescue Exception
136
- raise "unable to load effective_obfuscation. Plese add gem 'effective_obfuscation' to your Gemfile and then 'bundle install'"
112
+ raise "unable to load effective_obfuscation. Please add gem 'effective_obfuscation' to your Gemfile and then 'bundle install'"
137
113
  end
138
114
  end
139
115
  end
140
116
 
141
- # Use ActiveAdmin (optional)
142
- initializer 'effective_orders.active_admin' do
143
- if EffectiveOrders.use_active_admin?
144
- begin
145
- require 'activeadmin'
146
- rescue Exception
147
- raise "unable to load activeadmin. Plese add gem 'activeadmin' to your Gemfile and then 'bundle install'"
148
- end
149
-
150
- ActiveAdmin.application.load_paths.unshift *Dir["#{config.root}/active_admin"]
151
-
152
- Rails.application.config.to_prepare do
153
- ActiveSupport.on_load :action_controller do
154
- ApplicationController.extend(ActsAsActiveAdminController::ActionController)
155
- Effective::OrdersController.send(:acts_as_active_admin_controller, 'orders')
156
- Effective::CartsController.send(:acts_as_active_admin_controller, 'carts')
157
- end
158
- end
159
-
160
- end
161
- end
162
-
163
117
  end
164
118
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '2.2.4'.freeze
2
+ VERSION = '3.0.0'.freeze
3
3
  end
@@ -8,7 +8,7 @@ module EffectiveOrders
8
8
  source_root File.expand_path('../../templates', __FILE__)
9
9
 
10
10
  def self.next_migration_number(dirname)
11
- if not ActiveRecord::Base.timestamped_migrations
11
+ unless ActiveRecord::Base.timestamped_migrations
12
12
  Time.new.utc.strftime("%Y%m%d%H%M%S")
13
13
  else
14
14
  "%.3d" % (current_migration_number(dirname) + 1)
@@ -29,7 +29,7 @@ module EffectiveOrders
29
29
  if mailer_preview_path.present?
30
30
  template 'effective_orders_mailer_preview.rb', File.join(mailer_preview_path, 'effective_orders_mailer_preview.rb')
31
31
  else
32
- puts "couldn't find action_mailer.preview_path. Skipping effective_orders_mailer_preview."
32
+ puts "couldn't find action_mailer.preview_path. Skipping effective_orders_mailer_preview."
33
33
  end
34
34
  end
35
35
 
@@ -11,7 +11,6 @@ class EffectiveOrdersMailerPreview < ActionMailer::Preview
11
11
  Effective::OrdersMailer.order_receipt_to_buyer(build_preview_order)
12
12
  end
13
13
 
14
- # This email is only sent to sellers having sold items via StripeConnect
15
14
  def order_receipt_to_seller
16
15
  order = build_preview_order
17
16
  Effective::OrdersMailer.order_receipt_to_seller(order, preview_customer, order.order_items)
@@ -25,8 +24,28 @@ class EffectiveOrdersMailerPreview < ActionMailer::Preview
25
24
  Effective::OrdersMailer.pending_order_invoice_to_buyer(build_preview_order)
26
25
  end
27
26
 
27
+ def subscription_payment_succeeded
28
+ Effective::OrdersMailer.subscription_payment_succeeded(preview_customer)
29
+ end
30
+
31
+ def subscription_payment_failed
32
+ Effective::OrdersMailer.subscription_payment_failed(preview_customer)
33
+ end
34
+
35
+ def subscription_canceled
36
+ Effective::OrdersMailer.subscription_canceled(preview_customer)
37
+ end
38
+
39
+ def subscription_trial_expiring
40
+ Effective::OrdersMailer.subscription_trial_expiring(preview_subscribable)
41
+ end
42
+
43
+ def subscription_trial_expired
44
+ Effective::OrdersMailer.subscription_trial_expired(preview_subscribable)
45
+ end
46
+
28
47
  def order_error
29
- Effective::OrdersMailer.order_error(order: build_preview_order, error: "Something didn't work out")
48
+ Effective::OrdersMailer.order_error(order: build_preview_order, error: 'Something did not work out')
30
49
  end
31
50
 
32
51
  protected
@@ -57,7 +76,7 @@ class EffectiveOrdersMailerPreview < ActionMailer::Preview
57
76
  end
58
77
 
59
78
  def preview_user
60
- User.new(email: 'buyer@example.com').tap do |user|
79
+ User.new(email: 'buyer@website.com').tap do |user|
61
80
  user.name = 'Valued Customer' if user.respond_to?(:name=)
62
81
  user.full_name = 'Valued Customer' if user.respond_to?(:full_name=)
63
82
 
@@ -71,6 +90,22 @@ class EffectiveOrdersMailerPreview < ActionMailer::Preview
71
90
  end
72
91
 
73
92
  def preview_customer
74
- Effective::Customer.new(user: preview_user)
93
+ Effective::Customer.new(user: preview_user, active_card: '**** **** **** 1234 Visa 04/20')
94
+ end
95
+
96
+ def preview_subscribable
97
+ Class.new do
98
+ include ActiveModel::Model
99
+ attr_accessor :buyer
100
+
101
+ def to_s
102
+ 'My cool service'
103
+ end
104
+
105
+ def trial_expires_at
106
+ Time.zone.now + 1.day
107
+ end
108
+ end.new(buyer: preview_user)
75
109
  end
110
+
76
111
  end
@@ -1,3 +1,5 @@
1
+ # rake effective_orders:overwrite_order_item_titles
2
+
1
3
  namespace :effective_orders do
2
4
  desc 'Overwrite all order item titles with current acts_as_purchasable object title'
3
5
  task overwrite_order_item_titles: :environment do
@@ -25,4 +27,44 @@ namespace :effective_orders do
25
27
  end
26
28
  end
27
29
  end
30
+
31
+ desc 'Sends trial expiring and expired emails to each subscribable. Schedule me to run once per day.'
32
+ task send_trial_expiring_emails: :environment do
33
+ trial_remind_at = Array(EffectiveOrders.subscription[:trial_remind_at]).compact
34
+ exit unless trial_remind_at.present? && trial_remind_at.all? { |x| x.present? }
35
+
36
+ Rails.application.eager_load!
37
+
38
+ today = Time.zone.now.beginning_of_day
39
+ reminders = trial_remind_at.select { |remind_at| remind_at.kind_of?(ActiveSupport::Duration) }
40
+
41
+ begin
42
+ ActsAsSubscribable.descendants.each do |klass|
43
+ klass.trialing.find_each do |subscribable|
44
+ if subscribable.trial_expires_at == today
45
+ puts "sending trial expired to #{subscribable}"
46
+ Effective::OrdersMailer.subscription_trial_expired(subscribable).deliver_now
47
+ end
48
+
49
+ next if subscribable.trial_expired? # We already notified them
50
+
51
+ reminders.each do |remind_at|
52
+ next unless subscribable.trial_expires_at == (today + remind_at)
53
+
54
+ puts "sending trial expiring to #{subscribable}. expires in #{(subscribable.trial_expires_at - today) / 1.day.to_i} days."
55
+ Effective::OrdersMailer.subscription_trial_expiring(subscribable).deliver_now
56
+ end
57
+ end
58
+ end
59
+
60
+ puts 'send_trial_expiring_emails completed'
61
+ EffectiveLogger.success('scheduled task send_trial_expiring_emails completed') if defined?(EffectiveLogger)
62
+ rescue => e
63
+ ExceptionNotifier.notify_exception(e) if defined?(ExceptionNotifier)
64
+ raise e
65
+ end
66
+
67
+ true
68
+ end
69
+
28
70
  end
@@ -105,7 +105,7 @@ describe Effective::CartsController, type: :controller do
105
105
 
106
106
  get :show
107
107
  assigns(:cart).user.should eq cart.user
108
- assigns(:cart).size.should eq 4 # the 3 from my factory, and 1 more we just created
108
+ assigns(:cart).cart_items.length.should eq 4 # the 3 from my factory, and 1 more we just created
109
109
  assigns(:cart).find(product).present?.should eq true
110
110
 
111
111
  Effective::Cart.where(:id => session_cart).should eq []
@@ -116,15 +116,15 @@ describe Effective::OrdersController, type: :controller do
116
116
  end
117
117
 
118
118
  describe 'redirect urls' do
119
- it 'redirects to the purchased_redirect_url on purchase' do
119
+ it 'redirects to the purchased_url on purchase' do
120
120
  allow(subject).to receive(:parse_moneris_response).and_return({response_code: 1}) # success
121
- post :moneris_postback, moneris_params.tap { |x| x[:rvar_purchased_redirect_url] = '/something' }
121
+ post :moneris_postback, moneris_params.tap { |x| x[:rvar_purchased_url] = '/something' }
122
122
  response.should redirect_to '/something'
123
123
  end
124
124
 
125
- it 'redirects to the declined_redirect_url on decline' do
125
+ it 'redirects to the declined_url on decline' do
126
126
  allow(subject).to receive(:parse_moneris_response).and_return({response_code: 'null'}) # failure
127
- post :moneris_postback, moneris_params.tap { |x| x[:rvar_declined_redirect_url] = '/something' }
127
+ post :moneris_postback, moneris_params.tap { |x| x[:rvar_declined_url] = '/something' }
128
128
  response.should redirect_to '/something'
129
129
  end
130
130
  end
@@ -37,7 +37,7 @@ describe Effective::OrdersController, type: :controller do
37
37
  assigns(:order).user.should eq cart.user
38
38
 
39
39
  assigns(:order).order_items.size.should eq cart.cart_items.size
40
- assigns(:order).total.should eq cart.total
40
+ assigns(:order).total.should eq cart.subtotal
41
41
  end
42
42
 
43
43
  it 'redirects if there is an empty order' do
@@ -81,11 +81,11 @@ describe Effective::OrdersController, type: :controller do
81
81
  end
82
82
 
83
83
  it 'should assign an @order based off the user cart' do
84
- post :create
84
+ post :create, effective_order: {}
85
85
 
86
86
  assigns(:order).user.should eq cart.user
87
87
  assigns(:order).order_items.size.should eq cart.cart_items.size
88
- assigns(:order).total.should eq cart.total
88
+ assigns(:order).total.should eq cart.subtotal
89
89
  assigns(:order).purchased?.should eq false
90
90
  end
91
91
 
@@ -330,7 +330,7 @@ describe Effective::OrdersController, type: :controller do
330
330
  describe '#order_purchased (with a free order)' do
331
331
  before(:each) do
332
332
  sign_in cart.user
333
- cart.cart_items.each { |cart_item| cart_item.purchasable.update_attributes(price: 0.0) }
333
+ cart.cart_items.each { |cart_item| cart_item.purchasable.update_attributes(price: 0) }
334
334
  end
335
335
 
336
336
  it 'creates a purchased order' do
@@ -10,7 +10,7 @@ describe Effective::OrdersController, type: :controller do
10
10
 
11
11
  let(:stripe_helper) { StripeMock.create_test_helper }
12
12
  let(:order) { FactoryGirl.create(:order) }
13
- let(:buyer) { Effective::Customer.for_user(order.user) }
13
+ let(:buyer) { Effective::Customer.for_buyer(order.user) }
14
14
  let(:token) { stripe_helper.generate_card_token }
15
15
  let(:stripe_charge_params) do
16
16
  {:effective_providers_stripe_charge => {'effective_order_id' => order.to_param, 'token' => token}}
@@ -91,7 +91,7 @@ describe Effective::OrdersController, type: :controller do
91
91
 
92
92
  describe '#stripe_charge with a subscription' do
93
93
  let(:order) { FactoryGirl.create(:order_with_subscription) }
94
- let(:buyer) { Effective::Customer.for_user(order.user) }
94
+ let(:buyer) { Effective::Customer.for_buyer(order.user) }
95
95
  let(:subscription) { order.order_items[1].purchasable }
96
96
  let(:token) { stripe_helper.generate_card_token }
97
97
  let(:stripe_charge_params) do
@@ -7,7 +7,7 @@ describe Effective::WebhooksController, type: :controller do
7
7
  after { StripeMock.stop }
8
8
 
9
9
  let(:order) { FactoryGirl.create(:order) }
10
- let(:buyer) { Effective::Customer.for_user(order.user) }
10
+ let(:buyer) { Effective::Customer.for_buyer(order.user) }
11
11
 
12
12
  let(:event_hash) { event.to_hash }
13
13
 
@@ -31,15 +31,9 @@ EffectiveOrders.setup do |config|
31
31
  # config.authorization_method = false
32
32
  config.authorization_method = Proc.new { |controller, action, resource| true }
33
33
 
34
- # Register Effective::Order with ActiveAdmin if ActiveAdmin is present
35
- config.use_active_admin = true
36
-
37
34
  # Use effective_obfuscation gem to change order.id into a seemingly random 10-digit number
38
35
  config.obfuscate_order_ids = true
39
36
 
40
- # Silence the price deprecation warnings
41
- config.silence_deprecation_warnings = true
42
-
43
37
  # Require these addresses when creating a new Order. Works with effective_addresses gem
44
38
  config.require_billing_address = true
45
39
  config.require_shipping_address = true
@@ -211,7 +205,7 @@ EffectiveOrders.setup do |config|
211
205
 
212
206
  # Stripe configuration
213
207
  config.stripe_enabled = true
214
- config.stripe_subscriptions_enabled = true # https://stripe.com/docs/subscriptions
208
+ config.subscriptions_enabled = true # https://stripe.com/docs/subscriptions
215
209
  config.stripe_connect_enabled = false # https://stripe.com/docs/connect
216
210
  config.stripe_connect_application_fee_method = Proc.new { |order_item| order_item.total * 0.10 } # 10 percent
217
211