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.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +150 -60
  4. data/Rakefile +0 -3
  5. data/active_admin/effective_orders.rb +14 -9
  6. data/app/assets/javascripts/effective_orders.js +2 -0
  7. data/app/assets/javascripts/effective_orders/{stripe_charges.js.coffee → providers/stripe_charges.js.coffee} +1 -1
  8. data/app/assets/javascripts/effective_orders/{stripe_subscriptions.js.coffee → providers/stripe_subscriptions.js.coffee} +1 -1
  9. data/app/assets/stylesheets/effective_orders/_order.scss +9 -3
  10. data/app/controllers/admin/orders_controller.rb +87 -3
  11. data/app/controllers/concerns/acts_as_active_admin_controller.rb +2 -1
  12. data/app/controllers/effective/carts_controller.rb +4 -2
  13. data/app/controllers/effective/orders_controller.rb +101 -60
  14. data/app/controllers/effective/providers/app_checkout.rb +10 -2
  15. data/app/controllers/effective/providers/ccbill.rb +34 -0
  16. data/app/controllers/effective/providers/cheque.rb +30 -0
  17. data/app/controllers/effective/providers/moneris.rb +7 -7
  18. data/app/controllers/effective/providers/paypal.rb +7 -5
  19. data/app/controllers/effective/providers/pretend.rb +22 -0
  20. data/app/controllers/effective/providers/stripe.rb +26 -24
  21. data/app/controllers/effective/webhooks_controller.rb +1 -1
  22. data/app/helpers/effective_carts_helper.rb +59 -29
  23. data/app/helpers/effective_ccbill_helper.rb +25 -0
  24. data/app/helpers/effective_orders_helper.rb +50 -41
  25. data/app/helpers/effective_paypal_helper.rb +11 -11
  26. data/app/mailers/effective/orders_mailer.rb +95 -20
  27. data/app/models/concerns/acts_as_purchasable.rb +14 -22
  28. data/app/models/effective/cart.rb +9 -15
  29. data/app/models/effective/cart_item.rb +15 -13
  30. data/app/models/effective/customer.rb +9 -9
  31. data/app/models/effective/datatables/order_items.rb +14 -8
  32. data/app/models/effective/datatables/orders.rb +56 -69
  33. data/app/models/effective/order.rb +250 -139
  34. data/app/models/effective/order_item.rb +23 -16
  35. data/app/models/effective/product.rb +23 -0
  36. data/app/models/effective/providers/ccbill_postback.rb +85 -0
  37. data/app/models/effective/{stripe_charge.rb → providers/stripe_charge.rb} +1 -1
  38. data/app/models/effective/subscription.rb +16 -12
  39. data/app/models/effective/tax_rate_calculator.rb +45 -0
  40. data/app/views/admin/customers/index.html.haml +2 -5
  41. data/app/views/admin/order_items/index.html.haml +2 -5
  42. data/app/views/admin/orders/_actions.html.haml +2 -0
  43. data/app/views/admin/orders/_form.html.haml +28 -0
  44. data/app/views/admin/orders/_order_item_fields.html.haml +9 -0
  45. data/app/views/admin/orders/index.html.haml +9 -5
  46. data/app/views/admin/orders/new.html.haml +3 -0
  47. data/app/views/effective/carts/_cart.html.haml +3 -12
  48. data/app/views/effective/carts/_cart_actions.html.haml +4 -0
  49. data/app/views/effective/carts/show.html.haml +10 -12
  50. data/app/views/effective/orders/_checkout_step1.html.haml +46 -0
  51. data/app/views/effective/orders/_checkout_step2.html.haml +33 -0
  52. data/app/views/effective/orders/_order.html.haml +2 -0
  53. data/app/views/effective/orders/_order_actions.html.haml +10 -5
  54. data/app/views/effective/orders/_order_footer.html.haml +1 -0
  55. data/app/views/effective/orders/_order_items.html.haml +11 -9
  56. data/app/views/effective/orders/_order_note.html.haml +8 -0
  57. data/app/views/effective/orders/_order_note_fields.html.haml +5 -0
  58. data/app/views/effective/orders/_order_shipping.html.haml +4 -4
  59. data/app/views/effective/orders/_order_user_fields.html.haml +1 -0
  60. data/app/views/effective/orders/_orders_table.html.haml +27 -0
  61. data/app/views/effective/orders/ccbill/_form.html.haml +24 -0
  62. data/app/views/effective/orders/checkout_step1.html.haml +3 -0
  63. data/app/views/effective/orders/checkout_step2.html.haml +3 -0
  64. data/app/views/effective/orders/cheque/_form.html.haml +2 -0
  65. data/app/views/effective/orders/cheque/pay_by_cheque.html.haml +9 -0
  66. data/app/views/effective/orders/declined.html.haml +4 -2
  67. data/app/views/effective/orders/my_purchases.html.haml +1 -1
  68. data/app/views/effective/orders/my_sales.html.haml +1 -1
  69. data/app/views/effective/orders/purchased.html.haml +3 -2
  70. data/app/views/effective/orders/show.html.haml +1 -1
  71. data/app/views/effective/orders/stripe/_form.html.haml +5 -5
  72. data/app/views/effective/orders_mailer/order_error.html.haml +11 -0
  73. data/app/views/effective/orders_mailer/payment_request_to_buyer.html.haml +13 -0
  74. data/app/views/effective/orders_mailer/pending_order_invoice_to_buyer.html.haml +13 -0
  75. data/app/views/layouts/effective_orders_mailer_layout.html.haml +7 -7
  76. data/config/routes.rb +39 -24
  77. data/db/migrate/01_create_effective_orders.rb.erb +20 -1
  78. data/db/upgrade/03_upgrade_effective_orders_from1x.rb.erb +95 -0
  79. data/lib/effective_orders.rb +67 -9
  80. data/lib/effective_orders/app_checkout_service.rb +1 -2
  81. data/lib/effective_orders/engine.rb +46 -14
  82. data/lib/effective_orders/version.rb +1 -1
  83. data/lib/generators/effective_orders/install_generator.rb +1 -0
  84. data/lib/generators/effective_orders/upgrade_from03x_generator.rb +1 -0
  85. data/lib/generators/effective_orders/upgrade_from1x_generator.rb +31 -0
  86. data/lib/generators/templates/effective_orders.rb +131 -66
  87. data/lib/generators/templates/effective_orders_mailer_preview.rb +28 -13
  88. data/spec/controllers/admin/orders_controller_spec.rb +242 -0
  89. data/spec/controllers/ccbill_orders_controller_spec.rb +103 -0
  90. data/spec/controllers/moneris_orders_controller_spec.rb +23 -23
  91. data/spec/controllers/orders_controller_spec.rb +167 -79
  92. data/spec/controllers/stripe_orders_controller_spec.rb +7 -7
  93. data/spec/dummy/app/models/product.rb +0 -8
  94. data/spec/dummy/app/models/product_with_float_price.rb +0 -8
  95. data/spec/dummy/app/models/user.rb +2 -19
  96. data/spec/dummy/config/application.rb +2 -1
  97. data/spec/dummy/config/environments/test.rb +1 -0
  98. data/spec/dummy/config/initializers/effective_orders.rb +109 -64
  99. data/spec/dummy/db/schema.rb +15 -2
  100. data/spec/dummy/db/test.sqlite3 +0 -0
  101. data/spec/dummy/log/test.log +0 -258
  102. data/spec/models/acts_as_purchasable_spec.rb +8 -6
  103. data/spec/models/factories_spec.rb +7 -1
  104. data/spec/models/order_item_spec.rb +1 -1
  105. data/spec/models/order_spec.rb +165 -46
  106. data/spec/models/stripe_charge_spec.rb +5 -5
  107. data/spec/spec_helper.rb +2 -0
  108. data/spec/support/factories.rb +49 -33
  109. metadata +47 -64
  110. data/app/views/effective/orders/_checkout_step_1.html.haml +0 -43
  111. data/app/views/effective/orders/_checkout_step_2.html.haml +0 -25
  112. data/app/views/effective/orders/_my_purchases.html.haml +0 -17
  113. data/app/views/effective/orders/checkout.html.haml +0 -3
  114. data/app/views/effective/orders/new.html.haml +0 -4
  115. data/spec/dummy/log/development.log +0 -82
@@ -1,2 +1,4 @@
1
+ //= require effective_addresses
2
+
1
3
  //= require_tree ./effective_orders
2
4
 
@@ -8,7 +8,7 @@ stripeCheckoutHandler = (key, form) ->
8
8
 
9
9
  alert("An error ocurred when contacting Stripe. Your card has not been charged. Please refresh the page and try again. #{token.error.message}")
10
10
  else
11
- form.find('input#effective_stripe_charge_token').val('' + token['id'])
11
+ form.find('input#effective_providers_stripe_charge_token').val('' + token['id'])
12
12
 
13
13
  form.find("input[type='submit']").prop('disabled', true)
14
14
  $('input[data-disable-with]').each -> try $.rails.disableFormElement($(this))
@@ -7,7 +7,7 @@ stripeCheckoutHandler = (key, form) ->
7
7
  alert("An error ocurred when contacting Stripe. Your card has not been charged. Please refresh the page and try again. #{token.error.message}")
8
8
  else
9
9
  form.find("input[type='submit']").prop('disabled', true)
10
- form.find('input#effective_stripe_subscription_token').val('' + token['id'])
10
+ form.find('input#effective_providers_stripe_subscription_token').val('' + token['id'])
11
11
  form.submit()
12
12
 
13
13
  $(document).on 'click', "#effective-orders-new-subscription-form form input[type='submit']", (event) ->
@@ -1,7 +1,6 @@
1
1
  .effective-order {
2
2
  table {
3
3
  clear: both;
4
- width: 600px;
5
4
  margin-bottom: 25px;
6
5
 
7
6
  tfoot {
@@ -42,8 +41,15 @@
42
41
  }
43
42
  }
44
43
 
44
+ form.new_effective_order {
45
+ .checkbox { margin-top: 30px; }
46
+ .remove-nested-fields { margin-top: 30px; }
47
+ a.remove_fields.dynamic { float: right; }
48
+ }
49
+
45
50
  @media print {
51
+ .effective-orders-page-title { display: none; }
52
+ .effective-orders-page-content { display: none; }
53
+ .effective-order-actions { display: none; }
46
54
  .effective-order-purchase-actions { display: none; }
47
- .print-button { display: none; }
48
- .resend-receipt-button { display: none; }
49
55
  }
@@ -8,15 +8,99 @@ module Admin
8
8
  @datatable = Effective::Datatables::Orders.new() if defined?(EffectiveDatatables)
9
9
  @page_title = 'Orders'
10
10
 
11
- EffectiveOrders.authorized?(self, :admin, :effective_orders)
12
- EffectiveOrders.authorized?(self, :index, Effective::Order)
11
+ authorize_effective_order!
13
12
  end
14
13
 
15
14
  def show
16
15
  @order = Effective::Order.find(params[:id])
17
16
  @page_title = "Order ##{@order.to_param}"
18
17
 
19
- EffectiveOrders.authorized?(self, :show, @order)
18
+ authorize_effective_order!
19
+ end
20
+
21
+ def new
22
+ @order = Effective::Order.new
23
+ @page_title = 'New Order'
24
+
25
+ authorize_effective_order!
26
+ end
27
+
28
+ def create
29
+ @user = User.find_by_id(order_params[:user_id])
30
+ @order = Effective::Order.new(user: @user)
31
+ @order.send_payment_request_to_buyer = order_params[:send_payment_request_to_buyer]
32
+
33
+ authorize_effective_order!
34
+
35
+ if order_params[:order_items_attributes].present?
36
+ order_params[:order_items_attributes].each do |_, item_attrs|
37
+ purchasable = Effective::Product.new(item_attrs[:purchasable_attributes])
38
+ @order.add(purchasable, quantity: item_attrs[:quantity])
39
+ end
40
+ end
41
+
42
+ if @order.create_as_pending
43
+ path_for_redirect = params[:commit] == 'Save and Add New' ? effective_orders.new_admin_order_path : effective_orders.admin_order_path(@order)
44
+ message = 'Successfully created order'
45
+ message << ". #{@order.user.email} has been sent a request for payment." if @order.send_payment_request_to_buyer?
46
+ flash[:success] = message
47
+ redirect_to path_for_redirect
48
+ else
49
+ @page_title = 'New Order'
50
+ flash.now[:danger] = 'Unable to create order'
51
+ render :new
52
+ end
53
+ end
54
+
55
+ def mark_as_paid
56
+ @order = Effective::Order.find(params[:id])
57
+ authorize_effective_order!
58
+
59
+ purchased = @order.purchase!(
60
+ details: 'Marked as paid by admin',
61
+ provider: 'admin',
62
+ card: 'none',
63
+ email: EffectiveOrders.mailer[:send_order_receipts_when_marked_paid_by_admin],
64
+ skip_buyer_validations: true # This will allow a declined order to be marked purchased
65
+ )
66
+
67
+ if purchased
68
+ flash[:success] = 'Order marked as paid successfully'
69
+ redirect_to effective_orders.admin_order_path(@order)
70
+ else
71
+ flash[:danger] = 'Unable to mark order as paid'
72
+ request.referrer ? (redirect_to :back) : (redirect_to effective_orders.admin_orders_path)
73
+ end
74
+ end
75
+
76
+ def send_payment_request
77
+ @order = Effective::Order.find(params[:id])
78
+ authorize_effective_order!
79
+
80
+ if @order.send_payment_request_to_buyer!
81
+ flash[:success] = "Successfully sent payment request to #{@order.user.email}"
82
+ else
83
+ flash[:danger] = 'Unable to send payment request'
84
+ end
85
+
86
+ request.referrer ? (redirect_to :back) : (redirect_to effective_orders.admin_order_path(@order))
87
+ end
88
+
89
+ private
90
+
91
+ def order_params
92
+ params.require(:effective_order).permit(:user_id, :send_payment_request_to_buyer,
93
+ order_items_attributes: [
94
+ :quantity, :_destroy, purchasable_attributes: [
95
+ :title, :price, :tax_exempt
96
+ ]
97
+ ]
98
+ )
99
+ end
100
+
101
+ def authorize_effective_order!
102
+ EffectiveOrders.authorized?(self, :admin, :effective_orders)
103
+ EffectiveOrders.authorized?(self, action_name.to_sym, @order || Effective::Order)
20
104
  end
21
105
 
22
106
  end
@@ -27,9 +27,10 @@ module ActsAsActiveAdminController
27
27
  self.send(:define_method, :resource_path) { |resource| effective_orders.cart_path }
28
28
  else
29
29
  self.send(:define_method, :resource_path) { |resource| public_send(resource_path, resource) }
30
+ self.send(:define_method, :edit_resource_path) { |resource| effective_orders.edit_order_path(resource) }
30
31
  end
31
32
 
32
- helper_method :resource, :resource_path
33
+ helper_method :resource, :resource_path, :edit_resource_path
33
34
  end
34
35
 
35
36
  module ClassMethods
@@ -6,7 +6,9 @@ module Effective
6
6
 
7
7
  def show
8
8
  @cart = current_cart
9
- @page_title ||= 'Shopping Cart'
9
+ @pending_orders = Effective::Order.pending.where(user: current_user) if current_user.present?
10
+
11
+ @page_title ||= 'My Cart'
10
12
  EffectiveOrders.authorized?(self, :show, @cart)
11
13
  end
12
14
 
@@ -32,7 +34,7 @@ module Effective
32
34
  begin
33
35
  raise "Please select a valid #{add_to_cart_params[:purchasable_type] || 'item' }." unless @purchasable
34
36
 
35
- current_cart.add_to_cart(@purchasable, [add_to_cart_params[:quantity].to_i, 1].max)
37
+ current_cart.add_to_cart(@purchasable, quantity: [add_to_cart_params[:quantity].to_i, 1].max)
36
38
  flash[:success] = 'Successfully added item to cart.'
37
39
  rescue EffectiveOrders::SoldOutException
38
40
  flash[:warning] = 'This item is sold out.'
@@ -2,20 +2,28 @@ module Effective
2
2
  class OrdersController < ApplicationController
3
3
  include EffectiveCartsHelper
4
4
 
5
+ include Providers::Cheque if EffectiveOrders.cheque_enabled
5
6
  include Providers::Moneris if EffectiveOrders.moneris_enabled
6
7
  include Providers::Paypal if EffectiveOrders.paypal_enabled
7
8
  include Providers::Stripe if EffectiveOrders.stripe_enabled
8
9
  include Providers::StripeConnect if EffectiveOrders.stripe_connect_enabled
10
+ include Providers::Ccbill if EffectiveOrders.ccbill_enabled
9
11
  include Providers::AppCheckout if EffectiveOrders.app_checkout_enabled
10
12
 
13
+ include Providers::Pretend if EffectiveOrders.allow_pretend_purchase_in_development && !Rails.env.production?
14
+ include Providers::Pretend if EffectiveOrders.allow_pretend_purchase_in_production && Rails.env.production?
15
+
11
16
  layout (EffectiveOrders.layout.kind_of?(Hash) ? EffectiveOrders.layout[:orders] : EffectiveOrders.layout)
12
17
 
13
- before_filter :authenticate_user!, :except => [:paypal_postback]
14
- before_filter :set_page_title
18
+ if defined?(Devise)
19
+ before_filter :authenticate_user!, except: [:paypal_postback, :ccbill_postback]
20
+ end
21
+
22
+ before_filter :set_page_title, except: [:show]
15
23
 
16
24
  # This is the entry point for the "Checkout" buttons
17
25
  def new
18
- @order ||= Order.new(current_cart, current_user)
26
+ @order ||= Effective::Order.new(current_cart, user: current_user)
19
27
 
20
28
  EffectiveOrders.authorized?(self, :new, @order)
21
29
 
@@ -25,16 +33,45 @@ module Effective
25
33
 
26
34
  if @order.errors[:order_items].present?
27
35
  flash[:danger] = @order.errors[:order_items].first
28
- redirect_to effective_orders.cart_path
36
+ redirect_to(effective_orders.cart_path)
37
+ return
29
38
  elsif @order.errors[:total].present?
30
39
  flash[:danger] = @order.errors[:total].first.gsub(EffectiveOrders.minimum_charge.to_i.to_s, view_context.price_to_currency(EffectiveOrders.minimum_charge.to_i))
31
- redirect_to effective_orders.cart_path
40
+ redirect_to(effective_orders.cart_path)
41
+ return
32
42
  end
43
+
44
+ @order.errors.clear
45
+ @order.billing_address.try(:errors).try(:clear)
46
+ @order.shipping_address.try(:errors).try(:clear)
47
+
48
+ render :checkout_step1
49
+ end
50
+
51
+ def edit
52
+ @order ||= Effective::Order.find(params[:id])
53
+
54
+ EffectiveOrders.authorized?(self, :edit, @order)
55
+
56
+ render :checkout_step1
33
57
  end
34
58
 
35
59
  def create
36
- @order ||= Order.new(current_cart, current_user)
60
+ @order ||= Effective::Order.new(current_cart, user: current_user)
61
+ save_order_and_redirect_to_step2
62
+ end
63
+
64
+ # If there is an existing order, it will be posted to the /update action, instead of /create
65
+ def update
66
+ @order ||= Effective::Order.find(params[:id])
67
+ save_order_and_redirect_to_step2
68
+ end
69
+
70
+ def save_order_and_redirect_to_step2
71
+ (redirect_to effective_orders.cart_path and return) if (@order.blank? || current_user.blank?)
72
+
37
73
  @order.attributes = order_params
74
+ @order.user_id = current_user.id
38
75
 
39
76
  if EffectiveOrders.require_shipping_address
40
77
  if @order.shipping_address_same_as_billing? && @order.billing_address.present?
@@ -42,74 +79,100 @@ module Effective
42
79
  end
43
80
  end
44
81
 
45
- EffectiveOrders.authorized?(self, :create, @order)
82
+ EffectiveOrders.authorized?(self, (@order.persisted? ? :update : :create), @order)
46
83
 
47
84
  Effective::Order.transaction do
48
85
  begin
49
- if @order.save_billing_address? && @order.user.respond_to?(:billing_address) && @order.billing_address.try(:empty?) == false
86
+ if @order.save_billing_address? && @order.user.respond_to?(:billing_address=) && @order.billing_address.present?
50
87
  @order.user.billing_address = @order.billing_address
51
88
  end
52
89
 
53
- if @order.save_shipping_address? && @order.user.respond_to?(:shipping_address) && @order.shipping_address.try(:empty?) == false
90
+ if @order.save_shipping_address? && @order.user.respond_to?(:shipping_address=) && @order.shipping_address.present?
54
91
  @order.user.shipping_address = @order.shipping_address
55
92
  end
56
93
 
57
94
  @order.save!
58
95
 
59
96
  if @order.total == 0 && EffectiveOrders.allow_free_orders
60
- order_purchased('automatic purchase of free order.')
97
+ order_purchased(details: 'automatic purchase of free order', provider: 'free', card: 'none')
61
98
  else
62
- redirect_to(effective_orders.order_path(@order))
99
+ redirect_to(effective_orders.order_path(@order)) # This goes to checkout_step2
63
100
  end
64
101
 
65
- return
102
+ return true
66
103
  rescue => e
67
104
  Rails.logger.info e.message
68
- flash.now[:danger] = "An error has occurred: #{e.message}. Please try again."
105
+ flash.now[:danger] = "Unable to save order: #{@order.errors.full_messages.to_sentence}. Please try again."
69
106
  raise ActiveRecord::Rollback
70
107
  end
71
108
  end
72
109
 
73
- render :action => :new
110
+ # Fall back to checkout step 1
111
+ render :checkout_step1
74
112
  end
75
113
 
76
114
  def show
77
- @order = Order.find(params[:id])
115
+ @order = Effective::Order.find(params[:id])
78
116
  EffectiveOrders.authorized?(self, :show, @order)
79
117
 
80
- if @order.purchased? == false
81
- @page_title = 'Checkout'
82
- render(:checkout) and return
83
- end
118
+ @page_title ||= (
119
+ if @order.purchased?
120
+ 'Receipt'
121
+ elsif @order.user != current_user
122
+ @order.pending? ? "Pending Order ##{@order.to_param}" : "Order ##{@order.to_param}"
123
+ else
124
+ 'Checkout'
125
+ end
126
+ )
127
+
128
+ render(:checkout_step2) if @order.purchased? == false && @order.user == current_user
84
129
  end
85
130
 
86
131
  def index
87
- redirect_to effective_orders.my_purchases_path
132
+ @orders = Effective::Order.purchased_by(current_user)
133
+
134
+ EffectiveOrders.authorized?(self, :index, Effective::Order.new(user: current_user))
135
+
136
+ render action: :my_purchases
88
137
  end
89
138
 
90
139
  # Basically an index page.
91
140
  # Purchases is an Order History page. List of purchased orders
92
141
  def my_purchases
93
- @orders = Order.purchased_by(current_user)
142
+ @orders = Effective::Order.purchased_by(current_user)
143
+
94
144
  EffectiveOrders.authorized?(self, :index, Effective::Order.new(user: current_user))
95
145
  end
96
146
 
97
147
  # Sales is a list of what products beign sold by me have been purchased
98
148
  def my_sales
99
- @order_items = OrderItem.sold_by(current_user)
149
+ @order_items = Effective::OrderItem.sold_by(current_user)
100
150
  EffectiveOrders.authorized?(self, :index, Effective::Order.new(user: current_user))
101
151
  end
102
152
 
103
153
  # Thank you for Purchasing this Order. This is where a successfully purchased order ends up
104
154
  def purchased # Thank You!
105
- @order = Order.find(params[:id])
155
+ @order = if params[:id].present?
156
+ Effective::Order.find(params[:id])
157
+ elsif current_user.present?
158
+ Effective::Order.purchased_by(current_user).first
159
+ end
160
+
161
+ if @order.blank?
162
+ redirect_to(effective_orders.my_purchases_path) and return
163
+ end
164
+
106
165
  EffectiveOrders.authorized?(self, :show, @order)
166
+
167
+ redirect_to(effective_orders.order_path(@order)) unless @order.purchased?
107
168
  end
108
169
 
109
170
  # An error has occurred, please try again
110
171
  def declined # An error occurred!
111
- @order = Order.find(params[:id])
172
+ @order = Effective::Order.find(params[:id])
112
173
  EffectiveOrders.authorized?(self, :show, @order)
174
+
175
+ redirect_to(effective_orders.order_path(@order)) unless @order.declined?
113
176
  end
114
177
 
115
178
  def resend_buyer_receipt
@@ -117,34 +180,21 @@ module Effective
117
180
  EffectiveOrders.authorized?(self, :show, @order)
118
181
 
119
182
  if @order.send_order_receipt_to_buyer!
120
- flash[:success] = "Successfully resent order receipt to #{@order.user.email}"
183
+ flash[:success] = "Successfully sent receipt to #{@order.user.email}"
121
184
  else
122
- flash[:danger] = "Unable to send order receipt."
123
- end
124
-
125
- redirect_to(:back) rescue effective_orders.order_path(@order)
126
- end
127
-
128
- def pretend_purchase
129
- @order = Order.find(params[:id])
130
- EffectiveOrders.authorized?(self, :update, @order)
131
-
132
- if (Rails.env.production? == false && EffectiveOrders.allow_pretend_purchase_in_development)
133
- order_purchased('for pretend', params[:purchased_redirect_url], params[:declined_redirect_url])
134
- end
135
-
136
- if (Rails.env.production? == true && EffectiveOrders.allow_pretend_purchase_in_production)
137
- order_purchased('for pretend', params[:purchased_redirect_url], params[:declined_redirect_url])
185
+ flash[:danger] = "Unable to send receipt."
138
186
  end
139
187
 
188
+ redirect_to(request.referer.present? ? :back : effective_orders.order_path(@order))
140
189
  end
141
190
 
142
191
  protected
143
192
 
144
- def order_purchased(details = nil, redirect_url = nil, declined_redirect_url = nil)
193
+ def order_purchased(details: 'none', provider:, card: 'none', redirect_url: nil, declined_redirect_url: nil)
145
194
  begin
146
- @order.purchase!(details)
147
- Cart.where(user_id: @order.user_id).try(:destroy_all) # current_cart won't work for provider post backs here
195
+ @order.purchase!(details: details, provider: provider, card: card)
196
+
197
+ Effective::Cart.where(user_id: @order.user_id).try(:destroy_all) # current_cart won't work for provider post backs here
148
198
 
149
199
  if EffectiveOrders.mailer[:send_order_receipt_to_buyer]
150
200
  flash[:success] = "Payment successful! Please check your email for a receipt."
@@ -155,19 +205,16 @@ module Effective
155
205
  redirect_to (redirect_url.presence || effective_orders.order_purchased_path(':id')).gsub(':id', @order.to_param.to_s)
156
206
  rescue => e
157
207
  flash[:danger] = "An error occurred while processing your payment: #{e.message}. Please try again."
158
- redirect_to (declined_redirect_url.presence || effective_orders.cart_path).gsub(':id', @order.to_param.to_s)
208
+ redirect_to(declined_redirect_url.presence || effective_orders.cart_path).gsub(':id', @order.to_param.to_s)
159
209
  end
160
210
  end
161
211
 
162
- # options:
163
- # flash: What flash message should be displayed
164
- def order_declined(details = nil, redirect_url = nil, options = {})
165
- flash_msg = options.fetch(:flash, "Payment was unsuccessful. Your credit card was declined by the payment processor. Please try again.")
212
+ def order_declined(details: 'none', provider:, card: 'none', redirect_url: nil, message: nil)
213
+ @order.decline!(details: details, provider: provider, card: card) rescue nil
166
214
 
167
- @order.decline!(details) rescue nil
168
- flash[:danger] = flash_msg
215
+ flash[:danger] = message.presence || 'Payment was unsuccessful. Your credit card was declined by the payment processor. Please try again.'
169
216
 
170
- redirect_to (redirect_url.presence || effective_orders.order_declined_path(@order)).gsub(':id', @order.id.to_s)
217
+ redirect_to(redirect_url.presence || effective_orders.order_declined_path(@order)).gsub(':id', @order.id.to_s)
171
218
  end
172
219
 
173
220
  private
@@ -175,13 +222,7 @@ module Effective
175
222
  # StrongParameters
176
223
  def order_params
177
224
  begin
178
- params.require(:effective_order).permit(
179
- :save_billing_address, :save_shipping_address, :shipping_address_same_as_billing,
180
- :billing_address => [:full_name, :address1, :address2, :city, :country_code, :state_code, :postal_code],
181
- :shipping_address => [:full_name, :address1, :address2, :city, :country_code, :state_code, :postal_code],
182
- :user_attributes => (EffectiveOrders.collect_user_fields || []),
183
- :order_items_attributes => [:stripe_coupon_id, :class, :id]
184
- )
225
+ params.require(:effective_order).permit(EffectiveOrders.permitted_params)
185
226
  rescue => e
186
227
  params[:effective_order] || {}
187
228
  end
@@ -189,11 +230,11 @@ module Effective
189
230
 
190
231
  def set_page_title
191
232
  @page_title ||= case params[:action]
233
+ when 'index' ; 'Order History'
192
234
  when 'my_purchases' ; 'Order History'
193
235
  when 'my_sales' ; 'Sales History'
194
236
  when 'purchased' ; 'Thank You'
195
237
  when 'declined' ; 'Payment Declined'
196
- when 'show' ; 'Order Receipt'
197
238
  else 'Checkout'
198
239
  end
199
240
  end