传递状态在 ruby​​ on rails 中失败 notify_url IPN [英] Delivery status Failed notify_url IPN in ruby on rails

查看:15
本文介绍了传递状态在 ruby​​ on rails 中失败 notify_url IPN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误:

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("
"), [], 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("
", "")
end

我的帖子控制器是:

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

所有付款都正常进行,但我只希望贝宝使用 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

我现在遇到的错误是:

现在至少交易已保存,但 paypal 似乎无法识别.

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.

这篇关于传递状态在 ruby​​ on rails 中失败 notify_url IPN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆