Class: OrderProcessor
- Inherits:
-
Struct
- Object
- Struct
- OrderProcessor
- Includes:
- ActionView::Helpers::TextHelper
- Defined in:
- app/models/job/order_processor.rb
Overview
This class manages all the patron-related things we need to do after an order is placed
-
Create donation, purchase actions
-
Process memberships
-
Send confirmation emails if skip_email is true
options can include:
:skip_actions. If set to true, no actions will be generated for this action
:skip_email. If set to true, no email confirmation will be sent
Direct Known Subclasses
Constant Summary collapse
- QUEUE =
"order"
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#order ⇒ Object
Returns the value of attribute order.
Class Method Summary collapse
Instance Method Summary collapse
- #generate_pdf ⇒ Object
- #generate_qr_codes_and_pdf ⇒ Object
-
#initialize(order, options = {}) ⇒ OrderProcessor
constructor
A new instance of OrderProcessor.
- #perform ⇒ Object
- #process_memberships ⇒ Object
- #process_passes ⇒ Object
- #send_confirmation ⇒ Object
- #skip_actions ⇒ Object
- #skip_email ⇒ Object
Constructor Details
#initialize(order, options = {}) ⇒ OrderProcessor
Returns a new instance of OrderProcessor.
16 17 18 19 |
# File 'app/models/job/order_processor.rb', line 16 def initialize(order, = {}) self. = self.order = order end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options
12 13 14 |
# File 'app/models/job/order_processor.rb', line 12 def @options end |
#order ⇒ Object
Returns the value of attribute order
12 13 14 |
# File 'app/models/job/order_processor.rb', line 12 def order @order end |
Class Method Details
.process(order, options = {}) ⇒ Object
21 22 23 24 |
# File 'app/models/job/order_processor.rb', line 21 def self.process(order, = {}) job = order.processor_class.new(order, ) Delayed::Job.enqueue job, :queue => QUEUE end |
Instance Method Details
#generate_pdf ⇒ Object
87 88 89 90 91 92 93 |
# File 'app/models/job/order_processor.rb', line 87 def generate_pdf pdf = PdfGeneration.new(order).generate file = Tempfile.new(["#{order.id}", '.pdf']) file << pdf.force_encoding("UTF-8") order.pdf = file order.save end |
#generate_qr_codes_and_pdf ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/models/job/order_processor.rb', line 38 def generate_qr_codes_and_pdf begin order.tickets.each do |item| item.product.generate_qr_code_without_delay generate_pdf if order.organization.can? :access, :scannable_tickets end rescue Exception => e Exceptional.context(:order_id => order.id) Exceptional.handle(e, "Could not generate PDF for order") end end |
#perform ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/job/order_processor.rb', line 26 def perform ActiveRecord::Base.transaction do self.order.create_donation_actions unless skip_actions self.order.create_purchase_action unless skip_actions process_memberships process_passes end generate_qr_codes_and_pdf send_confirmation end |
#process_memberships ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'app/models/job/order_processor.rb', line 67 def process_memberships unless self.order.memberships.empty? self.order.memberships.each do |membership_item| Member.for(membership_item.product, self.order.person) end self.order.create_generic_action("memberships") end end |
#process_passes ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'app/models/job/order_processor.rb', line 76 def process_passes unless self.order.passes.empty? || order.is_a?(RefundOrder) self.order.passes.each do |pass_item| pass_item.product.person = self.order.person pass_item.product.save end self.order.create_generic_action("passes") PassMailer.pass_info_for(self.order.person, self.order.organization.email,self.order.passes.collect(&:product)).deliver end end |
#send_confirmation ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'app/models/job/order_processor.rb', line 50 def send_confirmation begin OrderMailer.confirmation_for(order).deliver unless skip_email rescue Exception => e Exceptional.context(:order_id => order.id) Exceptional.handle(e, "Could not send order confirmation for order") end end |
#skip_actions ⇒ Object
59 60 61 |
# File 'app/models/job/order_processor.rb', line 59 def skip_actions self.[:skip_actions] == true end |
#skip_email ⇒ Object
63 64 65 |
# File 'app/models/job/order_processor.rb', line 63 def skip_email self.[:skip_email] == true end |