module EffectiveOrders
Constants
- ACTIVE
Subscription statuses (as per stripe)
- CANCELED
- PAST_DUE
- STATUSES
- TRIALING
- VERSION
Public Class Methods
Organization()
click to toggle source
# File lib/effective_orders.rb, line 66 def self.Organization klass = organization_class_name&.constantize klass ||= (EffectiveMemberships.Organization if defined?(EffectiveMemberships)) raise('Please set the effective_orders config.organization_class_name') if klass.blank? klass end
admin_payment_providers()
click to toggle source
For the Admin Mark as Paid screen
# File lib/effective_orders.rb, line 171 def self.admin_payment_providers [ ('cheque' if mark_as_paid?), ('credit card' if mark_as_paid?), ('deluxe' if deluxe?), ('etransfer' if etransfer?), #('free' if free?), ('moneris' if moneris?), ('moneris_checkout' if moneris_checkout?), ('paypal' if paypal?), ('phone' if mark_as_paid?), #('pretend' if pretend?), #('refund' if refund?), ('stripe' if stripe?), ('other (non credit card)' if mark_as_paid?), 'none' ].compact end
buyer_purchases_refund?()
click to toggle source
# File lib/effective_orders.rb, line 130 def self.buyer_purchases_refund? buyer_purchases_refund == true end
can_skip_checkout_step1?()
click to toggle source
# File lib/effective_orders.rb, line 219 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?()
click to toggle source
# File lib/effective_orders.rb, line 74 def self.cheque? cheque.kind_of?(Hash) end
config_keys()
click to toggle source
# File lib/effective_orders.rb, line 16 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, :orders_collection_scope, :order_tax_rate_method, :obfuscate_order_ids, :use_effective_qb_sync, :use_effective_qb_online, :billing_address, :shipping_address, :collect_note, :collect_note_required, :collect_note_message, :terms_and_conditions, :terms_and_conditions_label, :minimum_charge, :credit_card_surcharge_percent, :credit_card_surcharge_qb_item_name, # Organization mode :organization_enabled, :organization_class_name, # Mailer :mailer, :parent_mailer, :deliver_method, :mailer_layout, :mailer_sender, :mailer_admin, :mailer_subject, # Emails :send_order_receipt_to_admin, :send_order_receipt_to_buyer, :send_order_declined_to_admin, :send_order_declined_to_buyer, :send_payment_request_to_buyer, :send_pending_order_invoice_to_buyer, :send_order_receipts_when_mark_as_paid, :send_order_receipts_when_free, :send_subscription_events, :send_subscription_trialing, :send_subscription_trial_expired, :send_refund_notification_to_admin, # Features :free_enabled, :mark_as_paid_enabled, :pretend_enabled, :pretend_message, :buyer_purchases_refund, # Payment processors. false or Hash :cheque, :deluxe, :deluxe_delayed, :etransfer, :moneris, :moneris_checkout, :paypal, :phone, :refund, :stripe, :subscriptions, :trial ] end
credit_card_payment_providers()
click to toggle source
# File lib/effective_orders.rb, line 199 def self.credit_card_payment_providers ['credit card', 'deluxe', 'moneris', 'moneris_checkout', 'paypal', 'stripe'] end
deferred?()
click to toggle source
# File lib/effective_orders.rb, line 94 def self.deferred? deferred_providers.present? end
deferred_providers()
click to toggle source
Should not include delayed providers
# File lib/effective_orders.rb, line 191 def self.deferred_providers [('cheque' if cheque?), ('etransfer' if etransfer?), ('phone' if phone?)].compact end
delayed?()
click to toggle source
# File lib/effective_orders.rb, line 98 def self.delayed? delayed_providers.present? end
delayed_providers()
click to toggle source
# File lib/effective_orders.rb, line 195 def self.delayed_providers [('deluxe_delayed' if deluxe_delayed?)].compact end
deluxe?()
click to toggle source
# File lib/effective_orders.rb, line 86 def self.deluxe? deluxe.kind_of?(Hash) end
deluxe_delayed?()
click to toggle source
# File lib/effective_orders.rb, line 90 def self.deluxe_delayed? deluxe_delayed.kind_of?(Hash) end
deluxe_script_url()
click to toggle source
# File lib/effective_orders.rb, line 300 def self.deluxe_script_url case EffectiveOrders.deluxe.fetch(:environment) when 'production' then 'https://hostedpaymentform.deluxe.com/v2/deluxe.js' when 'sandbox' then 'https://hostedform2.deluxe.com/V2/deluxe.js' else raise('unexpected EffectiveOrders.deluxe :environment key. Please check your config/initializers/effective_orders.rb file') end end
etransfer?()
click to toggle source
# File lib/effective_orders.rb, line 78 def self.etransfer? etransfer.kind_of?(Hash) end
free?()
click to toggle source
# File lib/effective_orders.rb, line 82 def self.free? free_enabled == true end
mailer_class()
click to toggle source
# File lib/effective_orders.rb, line 215 def self.mailer_class mailer&.constantize || Effective::OrdersMailer end
mark_as_paid?()
click to toggle source
# File lib/effective_orders.rb, line 102 def self.mark_as_paid? mark_as_paid_enabled == true end
moneris?()
click to toggle source
# File lib/effective_orders.rb, line 106 def self.moneris? moneris.kind_of?(Hash) end
moneris_checkout?()
click to toggle source
# File lib/effective_orders.rb, line 110 def self.moneris_checkout? moneris_checkout.kind_of?(Hash) end
moneris_checkout_script_url()
click to toggle source
# File lib/effective_orders.rb, line 308 def self.moneris_checkout_script_url case EffectiveOrders.moneris_checkout.fetch(:environment) when 'prod' then 'https://gateway.moneris.com/chktv2/js/chkt_v2.00.js' when 'qa' then 'https://gatewayt.moneris.com/chktv2/js/chkt_v2.00.js' else raise('unexpected EffectiveOrders.moneris_checkout :environment key. Please check your config/initializers/effective_orders.rb file') end end
moneris_request_url()
click to toggle source
# File lib/effective_orders.rb, line 316 def self.moneris_request_url case EffectiveOrders.moneris_checkout.fetch(:environment) when 'prod' then 'https://gateway.moneris.com/chktv2/request/request.php' when 'qa' then 'https://gatewayt.moneris.com/chktv2/request/request.php' else raise('unexpected EffectiveOrders.moneris_checkout :environment key. Please check your config/initializers/effective_orders.rb file') end end
organization_enabled?()
click to toggle source
# File lib/effective_orders.rb, line 62 def self.organization_enabled? organization_enabled == true end
payment_providers()
click to toggle source
The Effective::Order.payment_provider value must be in this collection
# File lib/effective_orders.rb, line 151 def self.payment_providers [ ('cheque' if cheque?), ('credit card' if mark_as_paid?), ('deluxe' if deluxe?), ('etransfer' if etransfer?), ('free' if free?), ('moneris' if moneris?), ('moneris_checkout' if moneris_checkout?), ('paypal' if paypal?), ('phone' if phone?), ('pretend' if pretend?), ('refund' if refund?), ('stripe' if stripe?), ('other' if mark_as_paid?), 'none' ].compact end
paypal?()
click to toggle source
# File lib/effective_orders.rb, line 114 def self.paypal? paypal.kind_of?(Hash) end
permitted_params()
click to toggle source
# File lib/effective_orders.rb, line 53 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?()
click to toggle source
# File lib/effective_orders.rb, line 118 def self.phone? phone.kind_of?(Hash) end
pretend?()
click to toggle source
# File lib/effective_orders.rb, line 122 def self.pretend? pretend_enabled == true end
qb_online?()
click to toggle source
# File lib/effective_orders.rb, line 207 def self.qb_online? use_effective_qb_online && defined?(EffectiveQbOnline) end
qb_sync?()
click to toggle source
# File lib/effective_orders.rb, line 203 def self.qb_sync? use_effective_qb_sync && defined?(EffectiveQbSync) end
refund?()
click to toggle source
# File lib/effective_orders.rb, line 126 def self.refund? refund.kind_of?(Hash) end
single_payment_processor?()
click to toggle source
# File lib/effective_orders.rb, line 146 def self.single_payment_processor? [deluxe?, moneris?, moneris_checkout?, paypal?, stripe?].select { |enabled| enabled }.length == 1 end
stripe?()
click to toggle source
# File lib/effective_orders.rb, line 134 def self.stripe? stripe.kind_of?(Hash) end
stripe_plans()
click to toggle source
# File lib/effective_orders.rb, line 238 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 Exception => e raise e if Rails.env.production? Rails.logger.info "[STRIPE ERROR]: #{e.message}" 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()
click to toggle source
# File lib/effective_orders.rb, line 296 def self.stripe_plans_collection stripe_plans.map { |plan| [plan[:name], plan[:id]] } end
subscriptions?()
click to toggle source
# File lib/effective_orders.rb, line 138 def self.subscriptions? subscriptions.kind_of?(Hash) end
surcharge?()
click to toggle source
# File lib/effective_orders.rb, line 211 def self.surcharge? credit_card_surcharge_percent.to_f > 0.0 end
trial?()
click to toggle source
# File lib/effective_orders.rb, line 142 def self.trial? trial.kind_of?(Hash) end
with_stripe() { || ... }
click to toggle source
# File lib/effective_orders.rb, line 227 def self.with_stripe(&block) raise('expected stripe to be enabled') unless stripe? begin ::Stripe.api_key = stripe[:secret_key] yield ensure ::Stripe.api_key = nil end end