交付状态ailure中的ruby的notify_url IPN失败 [英] Delivery status Failed notify_url IPN in ruby on rails
问题描述
我收到以下错误:
2015-08-17T18:46:59.095260+00:00 heroku[router]: at=info method=POST path="/payment_notification" status=500
这是我的模特
class Product < ActiveRecord::Base
def paypal_encrypted(return_url, notify_url, cancel_return, useremail)
values = {
:business => 'facilitatoremail@example.com',
:cmd => '_xclick',
:upload => 1,
:return => return_url,
:rm => 1,
:notify_url => notify_url,
:cancel_return => cancel_return,
:custom => useremail,
:cert_id => 'myid'
}
values.merge!({
"amount" => unit_price,
"item_name" => name,
"item_number" => id,
"quantity" => '1'
})
encrypt_for_paypal(values)
end
has_many :payment_notifications
end
PAYPAL_CERT_PEM = File.read("#{Rails.root}/certs/paypal_cert.pem")
APP_CERT_PEM = File.read("#{Rails.root}/certs/app_cert.pem")
APP_KEY_PEM = File.read("#{Rails.root}/certs/app_key.pem")
def encrypt_for_paypal(values)
signed = OpenSSL::PKCS7::sign(OpenSSL::X509::Certificate.new(APP_CERT_PEM), OpenSSL::PKey::RSA.new(APP_KEY_PEM, ''), values.map { |k, v| "#{k}=#{v}" }.join("\n"), [], OpenSSL::PKCS7::BINARY)
OpenSSL::PKCS7::encrypt([OpenSSL::X509::Certificate.new(PAYPAL_CERT_PEM)], signed.to_der, OpenSSL::Cipher::Cipher::new("DES3"), OpenSSL::PKCS7::BINARY).to_s.gsub("\n", "")
end
该帖子的我的控制者是:
My controller for the post is:
class PaymentNotificationController < ApplicationController
protect_from_forgery :except => [:create]
def create
@payment = PaymentNotification.create!(params: params, product_id: 1, status: params[:payment_status], transaction_id: params[:txn_id], email: params[:custom] )
render nothing: true
if @payment.status == 'Completed'
PaymentTransactions.success(@payment).deliver_now
end
end
end
我的按钮:
<%= form_tag "https://www.sandbox.paypal.com/cgi-bin/webscr" do %>
<%= hidden_field_tag :cmd, "_s-xclick" %>
<%= hidden_field_tag :encrypted, @product.paypal_encrypted(root_url, payment_notification_index_url, root_url, :custom) %>
<%= text_field_tag :custom %>
<%= submit_tag 'checkout encrypted' %>
<% end %>
我不确定我在做什么错.
I'm not sure what I'm doing wrong here.
Paypal发送POST,但出现错误STATUS = 500
Paypal sends the POST but I get the error STATUS=500
所有付款都可以正常进行,但我只希望Paypal使用notify_url
进行POST.
All the payment proceed normally but I just want that paypal do a POST using notify_url
.
我正在Heroku
中对此进行测试,因为无法在本地进行测试.
I'm testing this in Heroku
since testing locally will not work.
此外,如果我改用return_url
撰写帖子,它将起作用并返回STATUS = 200.
Also, if I use the return_url
to make the post instead, it will work and return STATUS=200.
但是我不想使用它,因为用户进行交易和被重定向回return_url
之间的差距.
But I don't want to use this since the gap between the user doing the transaction and being redirected back to the return_url
.
编辑
整合Airbrake
之后,这就是我得到的回报
after integrating Airbrake
this is what I got in return
编辑2
我将从PayPal发送的数据的数据编码更改为UTF-8
I changed the data encoding for data sent from PayPal to UTF-8
当我再次尝试时,状态仍然是500,但是我将事务保存在数据库中,但是paypal却一直失败,并不断重试,因此我没有多条记录,而没有保存一条记录
When I tried again, the status was still 500 but I got the transaction saved in the database BUT paypal kept getting a failed attempt and kept retrying so instead of one record being saved I had multiple records
我现在遇到的错误是这个:
The error I'm getting now is this one:
现在至少可以保存交易,但是贝宝似乎无法识别.
Right now at least the transactions are saved but paypal seems to fail to recognized that.
已解决
显然,这是我的邮件程序未在生产环境中配置..我只能评论该部分并放入heroku,然后重试.它成功进入STATUS = 200的低谷,并且在Airbrake
中解决了该错误.
Apparently, it was my mailer that wasn't configured in production.. I was just able to comment that part and push in heroku and tried again. It successfully went trough with a STATUS=200 and the error was solved in Airbrake
.
谢谢大家!
推荐答案
您是否在PayPal帐户中设置了系统编码?它位于个人资料中"PayPal按钮编码"下的某个位置,您应将以相同编码将数据发送给我"设置为UTF-8.
Did you set your system encoding in PayPal account? It's somewhere under 'PayPal button encoding' in your profile, and you should set 'Send the data to me in the same encoding' to UTF-8.
正如在评论中发现的那样,另一个错误是由于邮件配置错误而引起的.请注意,#render调用不会立即将数据发送到客户端,而只是将其排入队列,直到操作结束为止.
As was discovered in comments, another error was due to misconfigured mailer. Note that #render call doesn't send data to client immediately, it just queues it until action ends.
这篇关于交付状态ailure中的ruby的notify_url IPN失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!