Module: EffectiveOrders

Defined in:
lib/effective_orders.rb,
lib/effective_orders/engine.rb,
lib/effective_orders/version.rb,
lib/effective_orders/app_checkout_service.rb,
lib/generators/effective_orders/install_generator.rb

Defined Under Namespace

Modules: Generators Classes: AlreadyPurchasedException, AppCheckoutService, Engine, SoldOutException

Constant Summary collapse

ABANDONED =
'abandoned'
PURCHASED =
'purchased'
DECLINED =
'declined'
PENDING =
'pending'
PURCHASE_STATES =
{ nil => ABANDONED, PURCHASED => PURCHASED, DECLINED => DECLINED, PENDING => PENDING }
VERSION =
'3.1.6'.freeze

Class Method Summary collapse

Class Method Details

.authorize!(controller, action, resource) ⇒ Object



103
104
105
# File 'lib/effective_orders.rb', line 103

def self.authorize!(controller, action, resource)
  raise Effective::AccessDenied unless authorized?(controller, action, resource)
end

.authorized?(controller, action, resource) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/effective_orders.rb', line 90

def self.authorized?(controller, action, resource)
  @_exceptions ||= [Effective::AccessDenied, (CanCan::AccessDenied if defined?(CanCan)), (Pundit::NotAuthorizedError if defined?(Pundit))].compact

  return !!authorization_method unless authorization_method.respond_to?(:call)
  controller = controller.controller if controller.respond_to?(:controller)

  begin
    !!(controller || self).instance_exec((controller || self), action, resource, &authorization_method)
  rescue *@_exceptions
    false
  end
end

.can_skip_checkout_step1?Boolean

Returns:

  • (Boolean)


148
149
150
151
152
153
154
155
156
# File 'lib/effective_orders.rb', line 148

def self.can_skip_checkout_step1?
  return false if require_billing_address
  return false if require_shipping_address
  return false if collect_note
  return false if terms_and_conditions
  return false if collect_user_fields.present?

  true
end

.other_payment_providersObject

One of these is used when Admin marks as paid



144
145
146
# File 'lib/effective_orders.rb', line 144

def self.other_payment_providers
  ['credit card', 'none', 'other']
end

.payment_providersObject

The Effective::Order.payment_provider value must be in this collection



129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/effective_orders.rb', line 129

def self.payment_providers
  @payment_providers ||= [
    ('app_checkout' if app_checkout_enabled),
    ('ccbill' if ccbill_enabled),
    ('cheque' if cheque_enabled),
    ('free' if allow_free_orders),
    ('moneris' if moneris_enabled),
    ('paypal' if paypal_enabled),
    ('pretend' if (allow_pretend_purchase_in_production && Rails.env.production?) || (allow_pretend_purchase_in_development && !Rails.env.production?)),
    ('stripe' if stripe_enabled),
    ('stripe_connect' if stripe_connect_enabled)
  ].compact
end

.permitted_paramsObject



107
108
109
110
111
112
113
114
115
# File 'lib/effective_orders.rb', line 107

def self.permitted_params
  [
    :note, :terms_and_conditions,
    billing_address: EffectiveAddresses.permitted_params,
    shipping_address: EffectiveAddresses.permitted_params,
    user_attributes: (EffectiveOrders.collect_user_fields || []),
    subscripter: [:stripe_plan_id, :stripe_token]
  ]
end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



86
87
88
# File 'lib/effective_orders.rb', line 86

def self.setup
  yield self
end

.single_payment_processor?Boolean

Returns:

  • (Boolean)


117
118
119
120
121
122
123
124
125
126
# File 'lib/effective_orders.rb', line 117

def self.single_payment_processor?
  [
    moneris_enabled,
    paypal_enabled,
    stripe_enabled,
    cheque_enabled,
    ccbill_enabled,
    app_checkout_enabled
  ].select { |enabled| enabled }.length == 1
end

.stripe_plansObject



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/effective_orders.rb', line 158

def self.stripe_plans
  return {} unless (stripe_enabled && subscriptions_enabled)

  @stripe_plans ||= (
    plans = Stripe::Plan.all.inject({}) do |h, plan|
      occurrence = case plan.interval
        when 'daily'    ; '/day'
        when 'weekly'   ; '/week'
        when 'monthly'  ; '/month'
        when 'yearly'   ; '/year'
        when 'day'      ; plan.interval_count == 1 ? '/day' : " every #{plan.interval_count} days"
        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

      h[plan.id] = {
        id: plan.id,
        name: plan.name,
        amount: plan.amount,
        currency: plan.currency,
        description: "$#{'%0.2f' % (plan.amount / 100.0)} #{plan.currency.upcase}#{occurrence}",
        occurrence: "#{occurrence}",
        interval: plan.interval,
        interval_count: plan.interval_count
      }; h
    end

    if subscription.kind_of?(Hash)
      plans['trial'] = {
        id: 'trial',
        amount: 0,
        name: (subscription[:trial_name] || 'Free Trial'),
        description: (subscription[:trial_description] || 'Free Trial')
      }
    end

    plans
  )
end