Module: EffectiveSubscriptionsHelper
- Defined in:
- app/helpers/effective_subscriptions_helper.rb
Instance Method Summary collapse
- #customer_form_with(customer) ⇒ Object
- #render_plan(plan, subscribed: true) ⇒ Object
- #render_plan_partial(plan) ⇒ Object
- #stripe_plans_collection(form) ⇒ Object
- #subscribable_form_with(subscribable) ⇒ Object
- #subscripter_stripe_data(subscripter) ⇒ Object
Instance Method Details
#customer_form_with(customer) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'app/helpers/effective_subscriptions_helper.rb', line 54 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 |
#render_plan(plan, subscribed: true) ⇒ Object
3 4 5 |
# File 'app/helpers/effective_subscriptions_helper.rb', line 3 def render_plan(plan, subscribed: true) render(render_plan_partial(plan), plan: plan, subscribed: subscribed) end |
#render_plan_partial(plan) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'app/helpers/effective_subscriptions_helper.rb', line 7 def render_plan_partial(plan) if lookup_context.template_exists?("effective/subscriptions/#{plan[:id].downcase}", [], true) "effective/subscriptions/#{plan[:id].downcase}" # Render the app's views/effective/subscriptions/_gold.html.haml elsif lookup_context.template_exists?("effective/subscriptions/#{plan[:name].downcase}", [], true) "effective/subscriptions/#{plan[:name].downcase}" # Render the app's views/effective/subscriptions/_gold.html.haml else 'effective/subscriptions/plan' # Render effective_orders default plan panel end end |
#stripe_plans_collection(form) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/helpers/effective_subscriptions_helper.rb', line 17 def stripe_plans_collection(form) raise 'expected an Effective::FormBuilder object' unless form.class.name == 'Effective::FormBuilder' subscripter = form.object raise 'form object must be a subscripter object' unless subscripter.class.name == 'Effective::Subscripter' plans = EffectiveOrders.stripe_plans.values.sort do |x, y| amount = (x[:amount] <=> y[:amount]) (amount != 0) ? amount : x[:name] <=> y[:name] end if (existing = subscripter.customer.stripe_subscription_interval).present? plans.select! { |plan| plan[:interval] == existing } end plans.map do |plan| content = render(partial: render_plan_partial(plan), locals: { f: form, plan: plan, selected: Array(form.object.stripe_plan_id).include?(plan[:id]), subscribable: form.object.subscribable, subscribed: form.object.subscribable.subscribed?(plan[:id]) }) [content, plan[:id]] end end |
#subscribable_form_with(subscribable) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'app/helpers/effective_subscriptions_helper.rb', line 45 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
63 64 65 66 67 68 69 70 71 |
# File 'app/helpers/effective_subscriptions_helper.rb', line 63 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 |