Module: EffectiveSubscriptionsHelper

Defined in:
app/helpers/effective_subscriptions_helper.rb

Instance Method Summary collapse

Instance Method Details

#customer_form_with(customer) ⇒ Object



19
20
21
22
23
24
25
26
# File 'app/helpers/effective_subscriptions_helper.rb', line 19

def customer_form_with(customer)
  raise 'form object must be an Effective::Customer object' unless customer.kind_of?(Effective::Customer)
  raise 'expected customer user to match current user' if customer.user != current_user

  subscripter = Effective::Subscripter.new(customer: customer, user: customer.user)

  render('effective/customers/form', subscripter: subscripter)
end

#stripe_plans_collection(subscripter = nil) ⇒ Object



3
4
5
6
7
8
# File 'app/helpers/effective_subscriptions_helper.rb', line 3

def stripe_plans_collection(subscripter = nil)
  EffectiveOrders.stripe_plans.values.sort do |x, y|
    amount = (x[:amount] <=> y[:amount])
    (amount != 0) ? amount : x[:name] <=> y[:name]
  end
end

#subscribable_form_with(subscribable) ⇒ Object



10
11
12
13
14
15
16
17
# File 'app/helpers/effective_subscriptions_helper.rb', line 10

def subscribable_form_with(subscribable)
  raise 'form object must be an acts_as_subscribable object' unless subscribable.respond_to?(:subscripter)

  subscripter = subscribable.subscripter
  raise 'subscribable.subscribable_buyer must match current_user' unless subscripter.user == current_user

  render('effective/subscripter/form', subscripter: subscripter)
end

#subscripter_stripe_data(subscripter) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'app/helpers/effective_subscriptions_helper.rb', line 28

def subscripter_stripe_data(subscripter)
  {
    email: current_user.email,
    image: stripe_site_image_url,
    key: EffectiveOrders.stripe[:publishable_key],
    name: EffectiveOrders.stripe[:site_title],
    plans: EffectiveOrders.stripe_plans.values
  }
end