Module: EffectiveOrdersHelper

Defined in:
app/helpers/effective_orders_helper.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_purchasable_path(purchasable, action = :show) ⇒ Object

This is called on the My Sales Page and is intended to be overridden in the app if needed



75
76
77
# File 'app/helpers/effective_orders_helper.rb', line 75

def acts_as_purchasable_path(purchasable, action = :show)
  polymorphic_path(purchasable)
end

#admin_mark_as_paid_payment_providersObject



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'app/helpers/effective_orders_helper.rb', line 152

def admin_mark_as_paid_payment_providers
  providers = EffectiveOrders.admin_payment_providers

  percentage = EffectiveOrders.credit_card_surcharge_percent.to_f
  return providers unless percentage > 0.0

  surcharge_providers = EffectiveOrders.credit_card_payment_providers

  with_surcharge = providers.select { |provider| surcharge_providers.include?(provider) }
  without_surcharge = providers.reject { |provider| surcharge_providers.include?(provider) }

  {
    "With #{rate_to_percentage(percentage)} credit card surcharge": with_surcharge.map { |provider| [provider, provider] },
    'Without credit card surcharge': without_surcharge.map { |provider| [provider, provider] }
  }
end

#checkout_icon_to(path, options = {}) ⇒ Object



148
149
150
# File 'app/helpers/effective_orders_helper.rb', line 148

def checkout_icon_to(path, options = {})
  icon_to('shopping-cart', path, { title: 'Checkout' }.merge(options))
end

#checkout_step1_form_url(order, namespace = nil) ⇒ Object



133
134
135
136
137
138
139
140
141
142
# File 'app/helpers/effective_orders_helper.rb', line 133

def checkout_step1_form_url(order, namespace = nil)
  raise 'expected an order' unless order
  raise 'invalid namespace, expecting nil or :admin' unless [nil, :admin].include?(namespace)

  if order.new_record?
    namespace == nil ? effective_orders.orders_path : effective_orders.admin_orders_path
  else
    namespace == nil ? effective_orders.order_path(order) : effective_orders.checkout_admin_order_path(order)
  end
end

#order_checkout_label(processor = nil) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/helpers/effective_orders_helper.rb', line 41

def order_checkout_label(processor = nil)
  case processor
  when :cheque
    'Pay by Cheque'
  when :deluxe
    'Pay Now'
  when :deluxe_delayed
    'Save card and charge me later'
  when :etransfer
    'Pay by E-transfer'
  when :free
    'Checkout Free'
  when :mark_as_paid
    'Admin: Mark as Paid'
  when :moneris
    'Checkout with Credit Card'
  when :moneris_checkout
    'Pay Now' # Doesn't get displayed anyway
  when :paypal
    'Checkout with PayPal'
  when :phone
    'Pay by Phone'
  when :pretend
    'Purchase Order (skip payment processor)'
  when :refund
    'Accept Refund'
  when :stripe
    'Pay Now'
  else
    'Checkout'
  end
end

#order_item_summary(order_item) ⇒ Object



33
34
35
36
37
38
39
# File 'app/helpers/effective_orders_helper.rb', line 33

def order_item_summary(order_item)
  if order_item.quantity > 1
    (:p, "#{price_to_currency(order_item.total)} total for #{pluralize(order_item.quantity, 'item')}")
  else
    (:p, "#{price_to_currency(order_item.total)} total")
  end
end

#order_page_title(order) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/helpers/effective_orders_helper.rb', line 89

def order_page_title(order)
  raise 'expected an order' unless order.kind_of?(Effective::Order)

  authorized = EffectiveResources.authorized?(self, :update, order)

  if order.purchased? || order.declined?
    order.to_s
  elsif authorized && (controller.action_name == 'edit')
    'Order Review'
  elsif authorized && (order.confirmed? || order.deferred?) && order.errors.blank?
    'Checkout'
  elsif authorized && order.pending?
    'Order Review'
  else
    order.to_s
  end
end

#order_payment_to_html(order) ⇒ Object



79
80
81
82
83
# File 'app/helpers/effective_orders_helper.rb', line 79

def order_payment_to_html(order)
  (:pre) do
    raw JSON.pretty_generate(order.payment).html_safe.gsub('\"', '').gsub("[\n\n    ]", '[]').gsub("{\n    }", '{}')
  end
end

#order_summary(order) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/effective_orders_helper.rb', line 19

def order_summary(order)
  order_item_list = (:ul) do
    order.order_items.map do |item|
      (:li) do
        names = item.name.split('<br>')
        "#{item.quantity}x #{names.first} for #{price_to_currency(item.price)}".tap do |output|
          names[1..-1].each { |line| output << "<br>#{line}" }
        end.html_safe
      end
    end.join.html_safe
  end
  (:p, "#{price_to_currency(order.total)} total for #{pluralize(order.num_items, 'item')}:") + order_item_list
end

#price_to_currency(price) ⇒ Object



2
3
4
5
6
# File 'app/helpers/effective_orders_helper.rb', line 2

def price_to_currency(price)
  price = price || 0
  raise 'price_to_currency expects an Integer representing the number of cents' unless price.kind_of?(Integer)
  number_to_currency(price / 100.0)
end

#rate_to_percentage(rate) ⇒ Object



8
9
10
11
# File 'app/helpers/effective_orders_helper.rb', line 8

def rate_to_percentage(rate)
  rate = rate || 0.0
  number_to_percentage(rate, strip_insignificant_zeros: true)
end

#render_checkout(order, namespace: nil, purchased_url: nil, declined_url: nil, deferred_url: nil) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'app/helpers/effective_orders_helper.rb', line 107

def render_checkout(order, namespace: nil, purchased_url: nil, declined_url: nil, deferred_url: nil)
  raise 'expected an order' unless order.kind_of?(Effective::Order)
  raise 'unable to checkout an order without a user or organization' if order && (order.user.blank? && order.organization.blank?)

  locals = { order: order, purchased_url: purchased_url, declined_url: declined_url, deferred_url: deferred_url, namespace: namespace }

  if order.purchased?
    render(partial: 'effective/orders/order', locals: locals)
  elsif (order.confirmed? || order.deferred?) && order.errors.blank?
    render(partial: 'effective/orders/checkout_step2', locals: locals)
  else
    render(partial: 'effective/orders/checkout_step1', locals: locals)
  end
end

#render_checkout_step1(order, namespace: nil, purchased_url: nil, declined_url: nil, deferred_url: nil, skip_deferred: false, skip_order: nil) ⇒ Object



122
123
124
125
# File 'app/helpers/effective_orders_helper.rb', line 122

def render_checkout_step1(order, namespace: nil, purchased_url: nil, declined_url: nil, deferred_url: nil, skip_deferred: false, skip_order: nil)
  locals = { order: order, purchased_url: purchased_url, declined_url: declined_url, deferred_url: deferred_url, namespace: namespace, skip_deferred: skip_deferred, skip_order: skip_order }
  render(partial: 'effective/orders/checkout_step1', locals: locals)
end

#render_checkout_step2(order, namespace: nil, purchased_url: nil, declined_url: nil, deferred_url: nil, skip_deferred: false, skip_order: nil) ⇒ Object



127
128
129
130
131
# File 'app/helpers/effective_orders_helper.rb', line 127

def render_checkout_step2(order, namespace: nil, purchased_url: nil, declined_url: nil, deferred_url: nil, skip_deferred: false, skip_order: nil)
  skip_order = order.delayed_payment_date_upcoming? if skip_order.nil?
  locals = { order: order, purchased_url: purchased_url, declined_url: declined_url, deferred_url: deferred_url, namespace: namespace, skip_deferred: skip_deferred, skip_order: skip_order }
  render(partial: 'effective/orders/checkout_step2', locals: locals)
end

#render_order(order) ⇒ Object



85
86
87
# File 'app/helpers/effective_orders_helper.rb', line 85

def render_order(order)
  render(partial: 'effective/orders/order', locals: { order: order })
end

#render_orders(orders, opts = {}) ⇒ Object



144
145
146
# File 'app/helpers/effective_orders_helper.rb', line 144

def render_orders(orders, opts = {})
  render(partial: 'effective/orders/orders_table', locals: { orders: orders }.merge(opts))
end

#tax_rate_to_percentage(tax_rate, options = {}) ⇒ Object

Deprecated.



14
15
16
17
# File 'app/helpers/effective_orders_helper.rb', line 14

def tax_rate_to_percentage(tax_rate, options = {})
  options[:strip_insignificant_zeros] = true if options[:strip_insignificant_zeros].nil?
  number_to_percentage(tax_rate, strip_insignificant_zeros: true)
end