Module: PaidUp::PlansHelper

Includes:
ActionView::Helpers::NumberHelper
Defined in:
app/helpers/paid_up/plans_helper.rb

Overview

PaidUp Plans Helper

Instance Method Summary collapse

Instance Method Details

#plan_button(plan, text = nil, html_options = {}) ⇒ Object



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
73
74
75
76
77
# File 'app/helpers/paid_up/plans_helper.rb', line 42

def plan_button(plan, text = nil, html_options = {})
  data = {}
  css_class = 'btn '
  disabled_state = false
  link = paid_up.new_plan_subscription_path(plan)
  if user_signed_in?
    text ||= :subscribe.l
    if current_user.stripe_data.delinquent
      icon_class = 'arrow-right'
      css_class += 'btn-info'
    elsif current_user.can_upgrade_to? plan
      icon_class = 'arrow-up'
      css_class += 'btn-success'
    elsif current_user.can_downgrade_to? plan
      icon_class = 'arrow-down'
      css_class += 'btn-danger'
      data[:confirm] = :are_you_sure.l
    elsif current_user.is_subscribed_to? plan
      icon_class = 'ok'
      css_class += 'btn-disabled'
      disabled_state = true
      link = '#'
      text = :already_subscribed.l
    else # Plans are equal in sort_order
      icon_class = 'arrow-right'
      css_class += 'btn-info'
    end
  else
    text ||= :sign_up.l
    icon_class = 'arrow-right'
    css_class += 'btn-success'
  end
  html_options[:method] ||= :get
  html_options[:disabled] ||= disabled_state
  icon_button_to css_class, icon_class, text, link, html_options
end

#plan_charge_human(plan, discount) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/paid_up/plans_helper.rb', line 6

def plan_charge_human(plan, discount)
  if !discount.nil? && !discount.coupon.nil? && plan.amount != 0
    orig_amount = plan.amount
    amount = orig_amount
    amount -= (discount.coupon.percent_off || 0) * 0.01 * amount
    amount -= (discount.coupon.amount_off || 0)
    amount = amount > 0 ? amount : 0

    orig_money = Money.new(orig_amount, plan.currency)
    money = Money.new(amount, plan.currency)

    html = (
      :s,
      (orig_money.format + '/' + plan_period_phrase(plan))
    )
    html << ' '
    html << (
      :span,
      (money.format + '/' + plan_period_phrase(plan)),
      class: 'text-danger'
    )
  else
    html = plan.money.format + '/' + plan_period_phrase(plan)
  end
  html
end

#plan_period_phrase(plan) ⇒ Object



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

def plan_period_phrase(plan)
  period_phrase = ''
  if plan.interval_count > 1
    period_phrase += plan.interval_count.to_s
    period_phrase += ' '
  end
  period_phrase + plan.interval.capitalize
end