Paypal IPN on Rails应用程序未被调用

时间:2012-07-19 16:36:11

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

我们正在使用Paypal自适应链式付款,以便在众筹网站上提供捐款。在付款成功后(在沙盒中),我已经完成所有工作并付款并返回“return_url”。

有关在Sandbox中测试IPN的Paypals文档很少。也许我错过了某个设置以启用IPN回调?

我希望能够使用IPN回调来验证付款是否成功。我想看看回调JSON,所以我知道要捕获和比较哪个字段。我找到了示例代码,但似乎没有在Sandbox中调用IPN回调。我试图像这样输出参数(也没有调用puts语句):

****backers_controller.rb
class BackersController < ApplicationController    
include ActiveMerchant::Billing::Integrations

  def callback_ipn
    puts "callback: ipn"
    notify = PaypalAdaptivePayment::Notification.new(request.raw_post)
    puts notify.to_yaml
  end

  def callback_return
    puts "callback: return"
    @backer = Backer.find(params[:id])
    @reward = @project.rewards.find_by_id(@backer.reward_id)
    @backer.callback

    respond_to do |format|
      format.html { render :layout => 'application_proj_back_blog' }
      format.json { render json: @backer }
    end
  end

('callback_return'行动正在运作)

****backer.rb
class Backer < ActiveRecord::Base
  include ActionDispatch::Routing::UrlFor
  include Rails.application.routes.url_helpers

def purchase
  project = Project.find(self.project_id)
  default_url_options[:host] = 'localhost:3000'
  proj_owner_email = User.find(project.user_id).email
  recipients = [{:email => PRIMARY_EMAIL,
               :amount => total_pledge,
               :primary => true},
              {:email => project.paypal_email,
               :amount => project_owner_cut,
               :primary => false}
  ]
  response = GATEWAY.setup_purchase(
    :action_type => "PAY_PRIMARY",
    :return_url => callback_return_project_backer_url(project, self),
    :cancel_url => callback_cancel_project_backer_url(project, self),
    :ipn_notification_url => callback_ipn_project_backer_url(project, self),
    :currency_code =>"USD",
    :receiver_list => recipients
  )
  puts response.to_yaml
  pay_key = response["payKey"]

  pledge_transactions.create!(:action => "purchase", :amount => total_pledge, :response => response)
  return response["payKey"]
end

回到backers_controller.rb,'def purchase'调用购买:

****backers_controller.rb
class BackersController < ApplicationController

  def purchase
    @backer = Backer.find(params[:id])
    @backer.purchase

    redirect_to (GATEWAY.redirect_url_for(@backer.purchase))
  end

1 个答案:

答案 0 :(得分:0)

事实证明我的身份验证阻止了paypal调用我的ipn监听器。