收到 Paypal 通知后生成 PDF 文件
收到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后,我确实解决了这个问题,但不确定它是否正确,但效果很好。
我所做的是 - 创建一个新操作只是为了接收来自 Paypal 的通知,然后重定向到实际生成 PDF 文件的操作 pdfbook_for_print 。
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.