effective_orders 1.8.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -3,17 +3,25 @@ module Effective
3
3
  module AppCheckout
4
4
  extend ActiveSupport::Concern
5
5
 
6
+ included do
7
+ if defined?(CanCan)
8
+ skip_authorization_check only: [:app_checkout]
9
+ end
10
+ end
11
+
6
12
  def app_checkout
7
13
  @order = Order.find(params[:id])
8
14
  checkout = EffectiveOrders.app_checkout[:service].call(order: @order)
9
15
  if checkout.success?
10
- order_purchased(payment_details(checkout))
16
+ order_purchased(details: payment_details(checkout), provider: 'app_checkout', card: 'none')
11
17
  else
12
18
  flash = EffectiveOrders.app_checkout[:declined_flash]
13
- order_declined(payment_details(checkout), nil, flash: flash)
19
+ order_declined(details: payment_details(checkout), message: flash, provider: 'app_checkout', card: 'none')
14
20
  end
15
21
  end
16
22
 
23
+ private
24
+
17
25
  def payment_details(checkout)
18
26
  default = 'App Checkout'
19
27
  if checkout.respond_to?(:payment_details)
@@ -0,0 +1,34 @@
1
+ module Effective
2
+ module Providers
3
+ module Ccbill
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ skip_before_filter :verify_authenticity_token, only: [:ccbill_postback]
8
+
9
+ if defined?(CanCan)
10
+ skip_authorization_check only: [:ccbill_postback]
11
+ end
12
+ end
13
+
14
+ def ccbill_postback
15
+ postback = Effective::Providers::CcbillPostback.new(params)
16
+ @order ||= Effective::Order.find(postback.order_id)
17
+
18
+ if @order.present? && postback.verified?
19
+ if @order.purchased?
20
+ order_purchased(details: postback.order_details, provider: 'ccbill')
21
+ elsif postback.approval? && postback.matches?(@order)
22
+ order_purchased(details: postback.order_details, provider: 'ccbill')
23
+ else
24
+ order_declined(details: postback.order_details, provider: 'ccbill')
25
+ end
26
+ end
27
+
28
+ head(:ok)
29
+ end
30
+ end
31
+
32
+ end
33
+ end
34
+
@@ -0,0 +1,30 @@
1
+ module Effective
2
+ module Providers
3
+ module Cheque
4
+ extend ActiveSupport::Concern
5
+
6
+ def pay_by_cheque
7
+ @order ||= Order.find(params[:id])
8
+
9
+ @order.purchase_state = EffectiveOrders::PENDING
10
+ @order.payment_provider = 'cheque'
11
+
12
+ EffectiveOrders.authorized?(self, :update, @order)
13
+
14
+ @page_title = 'Payment Required'
15
+
16
+ if @order.save
17
+ @order.send_pending_order_invoice_to_buyer!
18
+ current_cart.try(:destroy)
19
+ flash.now[:success] = 'Successfully indicated order will be payed by cheque.'
20
+ else
21
+ flash[:danger] = "Unable to save your order: #{@order.errors.full_messages.to_sentence}. Please try again."
22
+ redirect_to effective_orders.order_path(@order)
23
+ return
24
+ end
25
+
26
+ render 'effective/orders/cheque/pay_by_cheque'
27
+ end
28
+ end
29
+ end
30
+ end
@@ -4,7 +4,7 @@ module Effective
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- prepend_before_filter :find_authenticity_token_from_moneris, :only => [:moneris_postback]
7
+ prepend_before_filter :find_authenticity_token_from_moneris, only: [:moneris_postback]
8
8
  end
9
9
 
10
10
  def moneris_postback
@@ -17,7 +17,7 @@ module Effective
17
17
  declined_redirect_url = params.delete(:rvar_declined_redirect_url)
18
18
 
19
19
  if @order.purchased? # Fallback to a success condition of the Order is already purchased
20
- order_purchased(params, purchased_redirect_url)
20
+ order_purchased(details: params, provider: 'moneris', card: params[:card], redirect_url: purchased_redirect_url)
21
21
  return
22
22
  end
23
23
 
@@ -27,19 +27,19 @@ module Effective
27
27
  response_code = verify_params[:response_code].to_i # Sometimes moneris sends us the string 'null'
28
28
 
29
29
  if response_code > 0 && response_code < 50 # Less than 50 means a successful validation
30
- order_purchased(params.merge(verify_params), purchased_redirect_url)
30
+ order_purchased(details: params.merge(verify_params), provider: 'moneris', card: params[:card], redirect_url: purchased_redirect_url)
31
31
  else
32
- order_declined(params.merge(verify_params), declined_redirect_url)
32
+ order_declined(details: params.merge(verify_params), provider: 'moneris', card: params[:card], redirect_url: declined_redirect_url)
33
33
  end
34
34
  else
35
- order_declined(params, declined_redirect_url)
35
+ order_declined(details: params, provider: 'moneris', card: params[:card], redirect_url: declined_redirect_url)
36
36
  end
37
37
  end
38
38
 
39
39
  private
40
40
 
41
41
  def parse_moneris_response(text)
42
- text.split("<br>").inject(Hash.new()) { |h, i| h[i.split(' ').first.to_sym] = i.split(' ').last ; h } rescue {:response => text}
42
+ text.split("<br>").inject(Hash.new()) { |h, i| h[i.split(' ').first.to_sym] = i.split(' ').last ; h } rescue {response: text}
43
43
  end
44
44
 
45
45
  def send_moneris_verify_request(verify_key)
@@ -93,4 +93,4 @@ end
93
93
  # Sent to your server as a POST
94
94
  # Response URL: http://ourwebsite.com/orders/moneris_postback
95
95
 
96
- # Displayed as key/value pairs on our server. ????
96
+ # Displayed as key/value pairs on our server
@@ -5,20 +5,22 @@ module Effective
5
5
 
6
6
  included do
7
7
  skip_before_filter :verify_authenticity_token, :only => [:paypal_postback]
8
+
9
+ if defined?(CanCan)
10
+ skip_authorization_check only: [:paypal_postback]
11
+ end
8
12
  end
9
13
 
10
14
  def paypal_postback
11
15
  @order ||= Effective::Order.where(id: (params[:invoice].to_i rescue 0)).first
12
16
 
13
- EffectiveOrders.authorized?(self, :update, @order)
14
-
15
17
  if @order.present?
16
18
  if @order.purchased?
17
- order_purchased(params)
19
+ order_purchased(details: params, provider: 'paypal', card: params[:payment_type])
18
20
  elsif (params[:payment_status] == 'Completed' && params[:custom] == EffectiveOrders.paypal[:secret])
19
- order_purchased(params)
21
+ order_purchased(details: params, provider: 'paypal', card: params[:payment_type])
20
22
  else
21
- order_declined(params)
23
+ order_declined(details: params, provider: 'paypal', card: params[:payment_type])
22
24
  end
23
25
  end
24
26
 
@@ -0,0 +1,22 @@
1
+ module Effective
2
+ module Providers
3
+ module Pretend
4
+ extend ActiveSupport::Concern
5
+
6
+ def pretend_purchase
7
+ @order ||= Order.find(params[:id])
8
+
9
+ EffectiveOrders.authorized?(self, :update, @order)
10
+
11
+ order_purchased(
12
+ details: 'for pretend',
13
+ provider: 'pretend',
14
+ card: 'none',
15
+ redirect_url: params[:purchased_redirect_url],
16
+ declined_redirect_url: params[:declined_redirect_url]
17
+ )
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -3,21 +3,23 @@ module Effective
3
3
  module Stripe
4
4
  extend ActiveSupport::Concern
5
5
 
6
- included do
7
- end
8
-
9
6
  def stripe_charge
10
7
  @order ||= Effective::Order.find(stripe_charge_params[:effective_order_id])
11
- @stripe_charge = Effective::StripeCharge.new(stripe_charge_params)
8
+ @stripe_charge = Effective::Providers::StripeCharge.new(stripe_charge_params)
12
9
  @stripe_charge.order = @order
13
10
 
14
11
  EffectiveOrders.authorized?(self, :update, @order)
15
12
 
16
13
  if @stripe_charge.valid? && (response = process_stripe_charge(@stripe_charge)) != false
17
- order_purchased(response) # orders_controller#order_purchased
14
+ order_purchased(
15
+ details: response,
16
+ provider: (EffectiveOrders.stripe_connect_enabled ? 'stripe_connect' : 'stripe'),
17
+ card: (response['charge']['card']['brand'] rescue nil)
18
+ )
18
19
  else
19
- flash[:danger] = @stripe_charge.errors.full_messages.join(',')
20
- render 'checkout'
20
+ @page_title = 'Checkout'
21
+ flash.now[:danger] = @stripe_charge.errors.full_messages.to_sentence
22
+ render :checkout_step2
21
23
  end
22
24
  end
23
25
 
@@ -44,16 +46,16 @@ module Effective
44
46
  end
45
47
 
46
48
  def charge_with_stripe(charge, buyer)
47
- results = {:subscriptions => {}, :charge => nil}
49
+ results = {subscriptions: {}, charge: nil}
48
50
 
49
51
  # Process subscriptions.
50
52
  charge.subscriptions.each do |subscription|
51
53
  next if subscription.stripe_plan_id.blank?
52
54
 
53
55
  stripe_subscription = if subscription.stripe_coupon_id.present?
54
- buyer.stripe_customer.subscriptions.create({:plan => subscription.stripe_plan_id, :coupon => subscription.stripe_coupon_id})
56
+ buyer.stripe_customer.subscriptions.create({plan: subscription.stripe_plan_id, coupon: subscription.stripe_coupon_id})
55
57
  else
56
- buyer.stripe_customer.subscriptions.create({:plan => subscription.stripe_plan.id})
58
+ buyer.stripe_customer.subscriptions.create({plan: subscription.stripe_plan.id})
57
59
  end
58
60
 
59
61
  subscription.stripe_subscription_id = stripe_subscription.id
@@ -63,15 +65,15 @@ module Effective
63
65
  end
64
66
 
65
67
  # Process regular order_items.
66
- amount = (charge.order_items.collect(&:total).sum) # A positive integer in cents representing how much to charge the card. The minimum amount is 50 cents.
68
+ amount = charge.order_items.map { |oi| oi.total }.sum # A positive integer in cents representing how much to charge the card. The minimum amount is 50 cents.
67
69
  description = "Charge for Order ##{charge.order.to_param}"
68
70
 
69
71
  if amount > 0
70
72
  results[:charge] = JSON.parse(::Stripe::Charge.create(
71
- :amount => amount,
72
- :currency => EffectiveOrders.stripe[:currency],
73
- :customer => buyer.stripe_customer.id,
74
- :description => description
73
+ amount: amount,
74
+ currency: EffectiveOrders.stripe[:currency],
75
+ customer: buyer.stripe_customer.id,
76
+ description: description
75
77
  ).to_json)
76
78
  end
77
79
 
@@ -85,22 +87,22 @@ module Effective
85
87
 
86
88
  # We do all these Tokens first, so if one throws an exception no charges are made
87
89
  items.each do |seller, _|
88
- seller.token = ::Stripe::Token.create({:customer => buyer.stripe_customer.id}, seller.stripe_connect_access_token)
90
+ seller.token = ::Stripe::Token.create({customer: buyer.stripe_customer.id}, seller.stripe_connect_access_token)
89
91
  end
90
92
 
91
93
  # Make one charge per seller, for all his order_items
92
94
  items.each do |seller, order_items|
93
- amount = order_items.sum(&:total)
95
+ amount = order_items.map { |oi| oi.total }.sum
94
96
  description = "Charge for Order ##{charge.order.to_param} with OrderItems ##{order_items.map(&:id).join(', #')}"
95
97
  application_fee = order_items.sum(&:stripe_connect_application_fee)
96
98
 
97
99
  results[seller.id] = JSON.parse(::Stripe::Charge.create(
98
100
  {
99
- :amount => amount,
100
- :currency => EffectiveOrders.stripe[:currency],
101
- :card => seller.token.id,
102
- :description => description,
103
- :application_fee => application_fee
101
+ amount: amount,
102
+ currency: EffectiveOrders.stripe[:currency],
103
+ card: seller.token.id,
104
+ description: description,
105
+ application_fee: application_fee
104
106
  },
105
107
  seller.stripe_connect_access_token
106
108
  ).to_json)
@@ -112,9 +114,9 @@ module Effective
112
114
  # StrongParameters
113
115
  def stripe_charge_params
114
116
  begin
115
- params.require(:effective_stripe_charge).permit(:token, :effective_order_id)
117
+ params.require(:effective_providers_stripe_charge).permit(:token, :effective_order_id)
116
118
  rescue => e
117
- params[:effective_stripe_charge]
119
+ params[:effective_providers_stripe_charge]
118
120
  end
119
121
  end
120
122
 
@@ -68,7 +68,7 @@ module Effective
68
68
  # Now we have to purchase it
69
69
  @order = Effective::Order.new(subscription)
70
70
  @order.user = @customer.user
71
- @order.purchase!("via Stripe webhook #{event.id}")
71
+ @order.purchase!(details: "Webhook #{event.id}", provider: 'stripe')
72
72
  end
73
73
 
74
74
  end
@@ -4,12 +4,12 @@ module EffectiveCartsHelper
4
4
  user = for_user || (current_user rescue nil) # rescue protects me against Devise not being installed
5
5
 
6
6
  if user.present?
7
- Effective::Cart.where(:user_id => user.id).first_or_create.tap do |user_cart|
7
+ Effective::Cart.where(user_id: user.id).first_or_create.tap do |user_cart|
8
8
  if session[:cart].present?
9
- session_cart = Effective::Cart.where('user_id IS NULL').where(:id => session[:cart]).first
9
+ session_cart = Effective::Cart.where('user_id IS NULL').where(id: session[:cart]).first
10
10
 
11
11
  if session_cart.present?
12
- session_cart.cart_items.update_all(:cart_id => user_cart.id)
12
+ session_cart.cart_items.update_all(cart_id: user_cart.id)
13
13
  session_cart.destroy
14
14
  user_cart.reload
15
15
  end
@@ -18,7 +18,7 @@ module EffectiveCartsHelper
18
18
  end
19
19
  end
20
20
  elsif session[:cart].present?
21
- Effective::Cart.where('user_id IS NULL').where(:id => session[:cart]).first_or_create
21
+ Effective::Cart.where('user_id IS NULL').where(id: session[:cart]).first_or_create
22
22
  else
23
23
  cart = Effective::Cart.create!
24
24
  session[:cart] = cart.id
@@ -28,73 +28,103 @@ module EffectiveCartsHelper
28
28
  end
29
29
 
30
30
  def link_to_current_cart(opts = {})
31
- options = {:id => 'current_cart', :rel => :nofollow}.merge(opts)
31
+ options = {
32
+ label: 'My Cart',
33
+ id: 'current_cart',
34
+ rel: :nofollow,
35
+ class: 'btn btn-default'
36
+ }.merge(opts)
37
+
38
+ label = options.delete(:label)
39
+ options[:class] = ((options[:class] || '') + ' btn-current-cart')
32
40
 
33
- label = options.delete(:label) || 'Cart'
34
41
  link_to (current_cart.size == 0 ? label : "#{label} (#{current_cart.size})"), effective_orders.cart_path, options
35
42
  end
36
43
 
37
44
  def link_to_add_to_cart(purchasable, opts = {})
38
- raise ArgumentError.new('expecting an acts_as_purchasable object') unless purchasable.respond_to?(:is_effectively_purchasable?)
45
+ raise ArgumentError.new('expecting an acts_as_purchasable object') unless purchasable.kind_of?(ActsAsPurchasable)
39
46
 
40
- options = {:class => 'btn', :rel => :nofollow, 'data-disable-with' => 'Adding...'}.merge(opts)
47
+ options = {
48
+ label: 'Add to Cart',
49
+ class: 'btn btn-primary',
50
+ rel: :nofollow,
51
+ data: {
52
+ disable_with: 'Adding...'
53
+ }
54
+ }.merge(opts)
55
+
56
+ label = options.delete(:label)
41
57
  options[:class] = ((options[:class] || '') + ' btn-add-to-cart')
42
58
 
43
- link_to (options.delete(:label) || 'Add to Cart'), effective_orders.add_to_cart_path(:purchasable_type => purchasable.class.name, :purchasable_id => purchasable.id.to_i), options
59
+ link_to label, effective_orders.add_to_cart_path(purchasable_type: purchasable.class.name, purchasable_id: purchasable.id.to_i), options
44
60
  end
45
61
 
46
62
  def link_to_remove_from_cart(cart_item, opts = {})
47
63
  raise ArgumentError.new('expecting an Effective::CartItem object') unless cart_item.kind_of?(Effective::CartItem)
48
64
 
49
65
  options = {
50
- :rel => :nofollow,
51
- :data => {
52
- :confirm => 'Are you sure? This cannot be undone!',
53
- :disable_with => 'Removing...'
66
+ label: 'Remove',
67
+ class: 'btn btn-primary',
68
+ rel: :nofollow,
69
+ data: {
70
+ confirm: 'Are you sure? This cannot be undone!',
71
+ disable_with: 'Removing...'
54
72
  },
55
- :method => :delete
73
+ method: :delete
56
74
  }.merge(opts)
57
75
 
76
+ label = options.delete(:label)
58
77
  options[:class] = ((options[:class] || '') + ' btn-remove-from-cart')
59
78
 
60
- link_to (options.delete(:label) || 'Remove'), effective_orders.remove_from_cart_path(cart_item), options
79
+ link_to(label, effective_orders.remove_from_cart_path(cart_item), options)
61
80
  end
62
81
 
63
82
  def link_to_empty_cart(opts = {})
64
83
  options = {
65
- :rel => :nofollow,
66
- :class => 'btn',
67
- :data => {
68
- :confirm => 'This will clear your entire cart. Are you sure? This cannot be undone!',
69
- :disable_with => 'Emptying...'
84
+ label: 'Empty Cart',
85
+ class: 'btn btn-danger',
86
+ rel: :nofollow,
87
+ data: {
88
+ confirm: 'This will clear your entire cart. Are you sure?',
89
+ disable_with: 'Emptying...'
70
90
  },
71
- :method => :delete
91
+ method: :delete
72
92
  }.merge(opts)
73
93
 
74
- options[:class] = ((options[:class] || '') + ' btn-empty-cart btn-danger')
94
+ label = options.delete(:label)
95
+ options[:class] = ((options[:class] || '') + ' btn-empty-cart')
75
96
 
76
- link_to (options.delete(:label) || 'Empty Cart'), effective_orders.cart_path, options
97
+ link_to(label, effective_orders.cart_path, options)
77
98
  end
78
99
 
79
100
  def link_to_checkout(opts = {})
80
101
  options = {
81
- :class => 'btn',
82
- :rel => :nofollow,
83
- :disable_with => 'Proceeding...'
102
+ label: 'Checkout',
103
+ class: 'btn btn-primary',
104
+ rel: :nofollow,
105
+ data: {
106
+ disable_with: 'Continuing...'
107
+ },
84
108
  }.merge(opts)
85
109
 
110
+ order = options.delete(:order)
111
+ label = options.delete(:label)
86
112
  options[:class] = ((options[:class] || '') + ' btn-checkout')
87
113
 
88
- link_to (options.delete(:label) || 'Proceed to Checkout'), effective_orders.new_order_path, options
114
+ if order.present?
115
+ link_to(label, effective_orders.edit_order_path(order), options)
116
+ else
117
+ link_to(label, effective_orders.new_order_path, options)
118
+ end
89
119
  end
90
120
 
91
121
  def render_cart(cart = nil)
92
122
  cart ||= current_cart
93
- render(:partial => 'effective/carts/cart', :locals => {:cart => cart})
123
+ render(partial: 'effective/carts/cart', locals: {cart: cart})
94
124
  end
95
125
 
96
126
  def render_purchasables(*purchasables)
97
- render(:partial => 'effective/orders/order_items', :locals => {:order => Effective::Order.new(purchasables)})
127
+ render(partial: 'effective/orders/order_items', locals: {order: Effective::Order.new(purchasables)})
98
128
  end
99
129
 
100
130
  end