简体   繁体   中英

Generate PDF file after notification received from Paypal

I'm not being able to generate PDF file (using PRAWN) after the notification from Paypal is received. Am I missing something in my code ? Here's my code:

order model :

def paypal_encryption() 
  values = {
    :cert_id => "YR5RRR2MUKRA2",
    :cmd => '_xclick',
    :upload => 1,
    :return => success_payments_url, ,
    :cancel_return => profile_url,
    :business => "seller_1306231025_biz@spt.com",
    :item_name => "FMN Book",
    :amount => self.price,
    :quantity => self.quantity,
    :rm => 2, 
    :cbt => "Return to Forgetmenotbook",
    :currency_code => self.currency,  
    :notify_url => "http://home.spt.com/payments/pdfbook_for_print",

} 

The controller code:

def pdfbook_for_print   

  respond_to do |format|
    format.pdf {} 
  end
end

And the prawn file: pdfbook_for_print.pdf.prawn

require "open-uri"
require "rubygems"
require "sanitize"

Prawn::Document.generate("#{Rails.root.to_s}/public/print-pdf-print.pdf", :page_size    
=>  [590,590], :left_margin => 50,:right_margin => 50, :page_layout => :portrait,    
:skip_page_creation => true, :skip_encoding => true) do |pdf|
  pdf.start_new_page 
  pdf.fill_color "981a00"
  pdf.move_down(50)  
  pdf.text "Testing pdf for printing", :size => 13

end 

I'm suspecting that there should be something like :format => pdf parameter in the notify_url, not sure. Any help will be much appreciated.

Finally, I did solve the issue but not sure if its the right way but it worked perfectly fine. What I did was - created a new action just to receive the notification from Paypal then redirected to the action pdfbook_for_print which actually generates the PDF file.

def notification_from_paypal 
 redirect_to :action => 'pdfbook_for_printing', :format => 'pdf'
end 

def pdfbook_for_print   
  respond_to do |format|
    format.pdf {} 
  end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM