Class: Payola::ReceiptMailer

Inherits:
ActionMailer::Base
  • Object
show all
Defined in:
app/mailers/payola/receipt_mailer.rb

Instance Method Summary collapse

Instance Method Details

#receipt(sale_guid) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/mailers/payola/receipt_mailer.rb', line 6

def receipt(sale_guid)
  ActiveRecord::Base.connection_pool.with_connection do
    @sale = Payola::Sale.find_by(guid: sale_guid)
    @product = @sale.product

    if Payola.pdf_receipt
      require 'docverter'

      pdf = Docverter::Conversion.run do |c|
        c.from = 'html'
        c.to = 'pdf'
        c.content = render_to_string('payola/receipt_mailer/receipt_pdf.html')
      end
      attachments["receipt-#{@sale.guid}.pdf"] = pdf
    end

    mail_params = {
      to: @sale.email,
      from: Payola.support_email,
      subject: @product.respond_to?(:receipt_subject) ? @product.receipt_subject(@sale) : 'Purchase Receipt',
    }

    if @product.respond_to?(:receipt_from_address)
      mail_params[:from] = @product.receipt_from_address(@sale)
    end

    mail(mail_params)
  end
end

#refund(sale_guid) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/mailers/payola/receipt_mailer.rb', line 36

def refund(sale_guid)
  ActiveRecord::Base.connection_pool.with_connection do
    @sale = Payola::Sale.find_by(guid: sale_guid)
    @product = @sale.product

    mail_params = {
      to: @sale.email,
      from: Payola.support_email,
      subject: @product.respond_to?(:refund_subject) ? @product.refund_subject(@sale) : 'Refund Confirmation',
    }

    if @product.respond_to?(:refund_from_address)
      mail_params[:from] = @product.refund_from_address(@sale)
    end

    mail(mail_params)
  end
end