收到 Paypal 通知后生成 PDF 文件

发布于 2024-11-16 02:53:02 字数 1473 浏览 2 评论 0原文

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

订单模型:

def paypal_encryption() 
  values = {
    :cert_id => "YR5RRR2MUKRA2",
    :cmd => '_xclick',
    :upload => 1,
    :return => success_payments_url, ,
    :cancel_return => profile_url,
    :business => "[email protected]",
    :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

和虾文件: 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 => notification_url 中的 pdf 参数,不确定。任何帮助将不胜感激。

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 => "[email protected]",
    :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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁与争疯 2024-11-23 02:53:02

最后,我确实解决了这个问题,但不确定它是否正确,但效果很好。
我所做的是 - 创建一个新操作只是为了接收来自 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文