在Rails中使用paypal-recurring gem进行IPN处理

时间:2013-05-07 14:20:10

标签: ruby-on-rails-3 paypal-ipn

我试图把这个回应弄清楚回到PayPal一段时间,它让我疯狂。某处我需要将其发送回来以阻止PayPal重新发送IPN。到目前为止,这是我的IPN监听器代码,如何发送IPN响应?刚做ppr.valid?创建一个VERIFIED响应,但IPN消息不断出现所以我想这不算作IPN响应。有效吗?行总是失败,因为它找不到电子邮件和seller_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

0 个答案:

没有答案