从Paypal收到通知后生成PDF文件

时间:2011-06-20 05:07:08

标签: ruby-on-rails pdf paypal prawn

收到Paypal的通知后,我无法生成PDF文件(使用PRAWN)。我在代码中遗漏了什么吗?这是我的代码:

订单型号:

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",

} 

控制器代码:

def pdfbook_for_print   

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

prawn文件: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 

我怀疑应该有:format => notify_url中的pdf参数,不确定。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

最后,我确实解决了这个问题,但不确定它是否正确,但效果非常好。 我做的是 - 创建一个新动作只是为了从Paypal接收通知然后重定向到实际生成PDF文件的 pdfbook_for_print 动作。

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