Module: UsageCredits::CreditsHelper

Defined in:
lib/usage_credits/helpers/credits_helper.rb

Overview

View helpers for displaying credit information

Instance Method Summary collapse

Instance Method Details

#credit_pack_button(pack, options = {}) ⇒ Object

Credit pack purchase button



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/usage_credits/helpers/credits_helper.rb', line 18

def credit_pack_button(pack, options = {})
  button_to options[:path] || credit_pack_purchase_path(pack),
            class: options[:class] || "credit-pack-button",
            method: :post,
            data: {
              turbo: false,
              pack_name: pack.name,
              credits: pack.credits,
              bonus_credits: pack.bonus_credits,
              price: pack.price_cents
            } do
    render_credit_pack_button_content(pack)
  end
end

#format_credit_price(cents, currency = nil) ⇒ Object

Format price in currency



12
13
14
15
# File 'lib/usage_credits/helpers/credits_helper.rb', line 12

def format_credit_price(cents, currency = nil)
  currency ||= UsageCredits.configuration.default_currency
  format("%.2f %s", cents / 100.0, currency.to_s.upcase)
end

#format_credits(amount) ⇒ Object

Format credit amount for display



7
8
9
# File 'lib/usage_credits/helpers/credits_helper.rb', line 7

def format_credits(amount)
  UsageCredits.configuration.credit_formatter.call(amount)
end