Module: EffectiveOrders
- Includes:
- EffectiveGem
- Defined in:
- lib/effective_orders.rb,
lib/effective_orders/engine.rb,
lib/effective_orders/version.rb,
lib/generators/effective_orders/install_generator.rb
Defined Under Namespace
Modules: Generators Classes: AlreadyPurchasedException, Engine, SoldOutException
Constant Summary collapse
- PENDING =
Order states
'pending'
- CONFIRMED =
New orders are created in a pending state
'confirmed'
- DEFERRED =
Once the order has passed checkout step 1
'deferred'
- PURCHASED =
Deferred providers. Cheque or Phone was selected.
'purchased'
- DECLINED =
Purchased by provider
'declined'
- STATES =
Declined by provider
{ PENDING => PENDING, CONFIRMED => CONFIRMED, DEFERRED => DEFERRED, PURCHASED => PURCHASED, DECLINED => DECLINED }
- ACTIVE =
Subscription statuses (as per stripe)
'active'
- PAST_DUE =
'past_due'
- TRIALING =
'trialing'
- CANCELED =
'canceled'
- STATUSES =
{ ACTIVE => ACTIVE, PAST_DUE => PAST_DUE, CANCELED => CANCELED, TRIALING => TRIALING }
- VERSION =
'4.6.1'.freeze
Class Method Summary collapse
- .can_skip_checkout_step1? ⇒ Boolean
- .cheque? ⇒ Boolean
- .config_keys ⇒ Object
- .deferred? ⇒ Boolean
- .deferred_providers ⇒ Object
- .free? ⇒ Boolean
- .mailer_klass ⇒ Object
- .mark_as_paid? ⇒ Boolean
- .moneris? ⇒ Boolean
-
.payment_providers ⇒ Object
The Effective::Order.payment_provider value must be in this collection.
- .paypal? ⇒ Boolean
- .permitted_params ⇒ Object
- .phone? ⇒ Boolean
- .pretend? ⇒ Boolean
- .refund? ⇒ Boolean
- .single_payment_processor? ⇒ Boolean
- .stripe? ⇒ Boolean
- .stripe_plans ⇒ Object
- .stripe_plans_collection ⇒ Object
- .subscriptions? ⇒ Boolean
- .trial? ⇒ Boolean
Class Method Details
.can_skip_checkout_step1? ⇒ Boolean
130 131 132 133 134 135 136 |
# File 'lib/effective_orders.rb', line 130 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 true end |
.cheque? ⇒ Boolean
52 53 54 |
# File 'lib/effective_orders.rb', line 52 def self.cheque? cheque.kind_of?(Hash) end |
.config_keys ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/effective_orders.rb', line 23 def self.config_keys [ :orders_table_name, :order_items_table_name, :carts_table_name, :cart_items_table_name, :customers_table_name, :subscriptions_table_name, :products_table_name, :layout, :mailer_class_name, :mailer, :orders_collection_scope, :order_tax_rate_method, :obfuscate_order_ids, :use_effective_qb_sync, :billing_address, :shipping_address, :use_address_full_name, :collect_note, :collect_note_required, :collect_note_message, :terms_and_conditions, :terms_and_conditions_label, :minimum_charge, # Features :free_enabled, :mark_as_paid_enabled, :pretend_enabled, :pretend_message, # Payment processors. false or Hash :cheque, :moneris, :paypal, :phone, :refund, :stripe, :subscriptions, :trial ] end |
.deferred? ⇒ Boolean
60 61 62 |
# File 'lib/effective_orders.rb', line 60 def self.deferred? deferred_providers.present? end |
.deferred_providers ⇒ Object
121 122 123 |
# File 'lib/effective_orders.rb', line 121 def self.deferred_providers [('cheque' if cheque?), ('phone' if phone?)].compact end |
.free? ⇒ Boolean
56 57 58 |
# File 'lib/effective_orders.rb', line 56 def self.free? free_enabled == true end |
.mailer_klass ⇒ Object
125 126 127 128 |
# File 'lib/effective_orders.rb', line 125 def self.mailer_klass name = mailer_class_name.presence || 'Effective::OrdersMailer' name.safe_constantize || raise("unable to constantize mailer class. check config.mailer_class_name") end |
.mark_as_paid? ⇒ Boolean
64 65 66 |
# File 'lib/effective_orders.rb', line 64 def self.mark_as_paid? mark_as_paid_enabled == true end |
.moneris? ⇒ Boolean
68 69 70 |
# File 'lib/effective_orders.rb', line 68 def self.moneris? moneris.kind_of?(Hash) end |
.payment_providers ⇒ Object
The Effective::Order.payment_provider value must be in this collection
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/effective_orders.rb', line 105 def self.payment_providers [ ('cheque' if cheque?), ('credit card' if mark_as_paid?), ('free' if free?), ('moneris' if moneris?), ('paypal' if paypal?), ('phone' if phone?), ('pretend' if pretend?), ('refund' if refund?), ('stripe' if stripe?), ('other' if mark_as_paid?), 'none' ].compact end |
.paypal? ⇒ Boolean
72 73 74 |
# File 'lib/effective_orders.rb', line 72 def self.paypal? paypal.kind_of?(Hash) end |
.permitted_params ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/effective_orders.rb', line 43 def self.permitted_params @permitted_params ||= [ :cc, :note, :terms_and_conditions, :confirmed_checkout, billing_address: EffectiveAddresses.permitted_params, shipping_address: EffectiveAddresses.permitted_params, subscripter: [:stripe_plan_id, :stripe_token] ] end |
.phone? ⇒ Boolean
76 77 78 |
# File 'lib/effective_orders.rb', line 76 def self.phone? phone.kind_of?(Hash) end |
.pretend? ⇒ Boolean
80 81 82 |
# File 'lib/effective_orders.rb', line 80 def self.pretend? pretend_enabled == true end |
.refund? ⇒ Boolean
84 85 86 |
# File 'lib/effective_orders.rb', line 84 def self.refund? refund.kind_of?(Hash) end |
.single_payment_processor? ⇒ Boolean
100 101 102 |
# File 'lib/effective_orders.rb', line 100 def self.single_payment_processor? [moneris?, paypal?, stripe?].select { |enabled| enabled }.length == 1 end |
.stripe? ⇒ Boolean
88 89 90 |
# File 'lib/effective_orders.rb', line 88 def self.stripe? stripe.kind_of?(Hash) end |
.stripe_plans ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 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 |
# File 'lib/effective_orders.rb', line 138 def self.stripe_plans return [] unless (stripe? && subscriptions?) @stripe_plans ||= ( Rails.logger.info '[STRIPE] index plans' plans = begin Stripe::Plan.respond_to?(:all) ? Stripe::Plan.all : Stripe::Plan.list rescue => e raise e if Rails.env.production? Rails.logger.info "[STRIPE ERROR]: #{e.}" Rails.logger.info "[STRIPE ERROR]: effective_orders continuing with empty stripe plans. This would fail loudly in Rails.env.production." [] end plans = plans.map do |plan| description = ("$#{'%0.2f' % (plan.amount / 100.0)}" + ' ' + plan.currency.upcase + '/' + plan.interval.to_s) { id: plan.id, product_id: plan.product, name: plan.nickname || description, description: description, amount: plan.amount, currency: plan.currency, interval: plan.interval, interval_count: plan.interval_count, trial_period_days: (plan.trial_period_days if plan.respond_to?(:trial_period_days)) } end.sort do |x, y| val ||= (x[:interval] <=> y[:interval]) val = nil if val == 0 val ||= (x[:amount] <=> y[:amount]) val = nil if val == 0 val ||= (x[:name] <=> y[:name]) val = nil if val == 0 val || (x[:id] <=> y[:id]) end # Calculate savings for any yearly per user plans, based on their matching monthly plans plans.select { |plan| plan[:interval] == 'year' }.each do |yearly| monthly_name = yearly[:name].downcase.gsub('year', 'month') monthly = plans.find { |plan| plan[:interval] == 'month' && plan[:name].downcase == monthly_name } next unless monthly savings = (monthly[:amount].to_i * 12) - yearly[:amount].to_i next unless savings > 0 yearly[:savings] = savings end plans ) end |
.stripe_plans_collection ⇒ Object
196 197 198 |
# File 'lib/effective_orders.rb', line 196 def self.stripe_plans_collection stripe_plans.map { |plan| [plan[:name], plan[:id]] } end |
.subscriptions? ⇒ Boolean
92 93 94 |
# File 'lib/effective_orders.rb', line 92 def self.subscriptions? subscriptions.kind_of?(Hash) end |
.trial? ⇒ Boolean
96 97 98 |
# File 'lib/effective_orders.rb', line 96 def self.trial? trial.kind_of?(Hash) end |