Module: EffectiveStripeHelper
- Included in:
- Effective::Subscription, Effective::SubscriptionsController
- Defined in:
- app/helpers/effective_stripe_helper.rb
Constant Summary collapse
- STRIPE_CONNECT_AUTHORIZE_URL =
'https://connect.stripe.com/oauth/authorize'
- STRIPE_CONNECT_TOKEN_URL =
'https://connect.stripe.com/oauth/token'
Instance Method Summary collapse
- #is_stripe_connect_seller?(user) ⇒ Boolean
- #link_to_new_stripe_connect_customer(opts = {}) ⇒ Object
- #stripe_coupon_description(coupon) ⇒ Object
- #stripe_plan_description(plan) ⇒ Object
-
#stripe_plans_collection(plans) ⇒ Object
Subscriptions Helpers.
Instance Method Details
#is_stripe_connect_seller?(user) ⇒ Boolean
6 7 8 |
# File 'app/helpers/effective_stripe_helper.rb', line 6 def is_stripe_connect_seller?(user) Effective::Customer.for_user(user).try(:is_stripe_connect_seller?) == true end |
#link_to_new_stripe_connect_customer(opts = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/helpers/effective_stripe_helper.rb', line 10 def link_to_new_stripe_connect_customer(opts = {}) client_id = EffectiveOrders.stripe[:connect_client_id] raise ArgumentError.new('effective_orders config: stripe.connect_client_id has not been set') unless client_id.present? = { response_type: :code, client_id: client_id, # This is the Application's ClientID scope: :read_write, state: { form_authenticity_token: form_authenticity_token, # Rails standard CSRF redirect_to: URI.encode(request.original_url) # TODO: Allow this to be customized }.to_json } # Add the stripe_user parameter if it's possible stripe_user_params = opts.delete :stripe_user .merge!({stripe_user: stripe_user_params}) if stripe_user_params.is_a?(Hash) = STRIPE_CONNECT_AUTHORIZE_URL.chomp('/') + '?' + .to_query = {}.merge(opts) link_to image_tag('/assets/effective_orders/stripe_connect.png'), , end |
#stripe_coupon_description(coupon) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'app/helpers/effective_stripe_helper.rb', line 53 def stripe_coupon_description(coupon) amount = coupon.amount_off.present? ? ActionController::Base.helpers.price_to_currency(coupon.amount_off) : "#{coupon.percent_off}%" if coupon.duration_in_months.present? "#{coupon.id} - #{amount} off for #{coupon.duration_in_months} months" else "#{coupon.id} - #{amount} off #{coupon.duration}" end end |
#stripe_plan_description(plan) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/helpers/effective_stripe_helper.rb', line 39 def stripe_plan_description(plan) occurrence = case plan.interval when 'weekly' ; '/week' when 'monthly' ; '/month' when 'yearly' ; '/year' when 'week' ; plan.interval_count == 1 ? '/week' : " every #{plan.interval_count} weeks" when 'month' ; plan.interval_count == 1 ? '/month' : " every #{plan.interval_count} months" when 'year' ; plan.interval_count == 1 ? '/year' : " every #{plan.interval_count} years" else ; plan.interval end "#{plan.name} - #{ActionController::Base.helpers.price_to_currency(plan.amount)} #{plan.currency.upcase}#{occurrence}" end |
#stripe_plans_collection(plans) ⇒ Object
Subscriptions Helpers
35 36 37 |
# File 'app/helpers/effective_stripe_helper.rb', line 35 def stripe_plans_collection(plans) (plans || []).map { |plan| [stripe_plan_description(plan), plan.id, {'data-amount' => plan.amount}] } end |