1

我试图弄清楚这个对 PayPal 的回应有一段时间了,这让我抓狂。我需要在某个地方将其发回以阻止 PayPal 重新发送 IPN。到目前为止,这是我用于 IPN 侦听器的代码,如何发送 IPN 响应?只是在做 ppr.valid?创建一个已验证的响应,但 IPN 消息不断出现,所以我猜这不算作 IPN 响应。有效吗?线路总是失败,因为它找不到电子邮件和卖家 ID,我还需要把它们放在某个地方(这些东西需要文档)。在此处查看 gem 文档:https ://github.com/fnando/paypal-recurring

def ipn
  subscription = Subscription.where(:email => params[:payer_email], :status => "Active").last
  if subscription
    ppr = PayPal::Recurring::Notification.new(params)

    PaymentsNotification.create!(:params => params.to_json, :status => params[:payment_status], :transaction_id => params[:txn_id])

    if ppr.valid? && (ppr.express_checkout? || ppr.recurring_payment?)
       #business logic
    end
end

我最终得到了这段代码:

def ipn
subscription = Subscription.where(:email => params[:payer_email], :status => "Active").last
if subscription
  PaymentsNotification.create!(:params => params.to_json.gsub("\"", "'"), :status => params[:payment_status], :transaction_id => params[:txn_id])
  ppr = PayPal::Recurring::Notification.new(params)
  ppr.response #send back the response to confirm IPN, stops further IPN notifications from being sent out
  if ppr.verified? && ppr.completed?
    if ppr.express_checkout? || ppr.recurring_payment?
      #do stuff here
    end
  else
    #raise response.errors.inspect
  end
end
render :nothing => true

结尾

4

0 回答 0