Module: EffectiveOrders

Defined in:
lib/generators/effective_orders/upgrade_price_column_generator.rb,
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,
lib/generators/effective_orders/upgrade_from1x_generator.rb,
lib/generators/effective_orders/upgrade_from03x_generator.rb

Overview

bundle exec rails generate effective_orders:upgrade_price_column TABLE COLUMN

Defined Under Namespace

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

Constant Summary collapse

PURCHASED =
'purchased'
DECLINED =
'declined'
PENDING =
'pending'
VERSION =
'2.1.15'.freeze

Class Method Summary collapse

Class Method Details

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

Returns:

  • (Boolean)


99
100
101
102
103
104
# File 'lib/effective_orders.rb', line 99

def self.authorized?(controller, action, resource)
  if authorization_method.respond_to?(:call) || authorization_method.kind_of?(Symbol)
    raise Effective::AccessDenied.new() unless (controller || self).instance_exec(controller, action, resource, &authorization_method)
  end
  true
end

.minimum_chargeObject



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

def self.minimum_charge
  if @@minimum_charge.nil? || @@minimum_charge.kind_of?(Integer)
    @@minimum_charge
  else
    ActiveSupport::Deprecation.warn('EffectiveOrders.minimum_charge config option is a non-integer. It should be an Integer representing the number of cents.  Continuing with (price * 100.0).round(0).to_i conversion') unless EffectiveOrders.silence_deprecation_warnings
    ((@@minimum_charge * 100.0).round(0).to_i rescue nil)
  end
end

.other_payment_providersObject



155
156
157
# File 'lib/effective_orders.rb', line 155

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

.payment_providersObject

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



141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/effective_orders.rb', line 141

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



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

def self.permitted_params
  [
    :note, :save_billing_address, :save_shipping_address, :terms_and_conditions,
    billing_address: EffectiveAddresses.permitted_params,
    shipping_address: EffectiveAddresses.permitted_params,
    user_attributes: (EffectiveOrders.collect_user_fields || []),
    order_items_attributes: [:stripe_coupon_id, :class, :id]
  ]
end

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

Yields:

  • (_self)

Yield Parameters:



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/effective_orders.rb', line 85

def self.setup
  yield self

  if EffectiveOrders.stripe_enabled
    begin
      require 'stripe'
    rescue Exception
      raise "unable to load stripe.  Plese add gem 'stripe' to your Gemfile and then 'bundle install'"
    end

    ::Stripe.api_key = stripe[:secret_key]
  end
end

.single_payment_processor?Boolean

Returns:

  • (Boolean)


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

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

.tax_rate_method=(*args) ⇒ Object



159
160
161
# File 'lib/effective_orders.rb', line 159

def self.tax_rate_method=(*args)
  raise 'EffectiveOrders.tax_rate_method has been removed and renamed to EffectiveOrders.order_tax_rate_method.  Its expected value is now different too. Return 5.25 for 5.25% tax. Please refer to the readme for more info.'
end

.use_active_admin?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/effective_orders.rb', line 115

def self.use_active_admin?
  use_active_admin && defined?(ActiveAdmin)
end