0

我们正在使用 Paypal 自适应链式支付来允许在众筹网站上捐款。在付款成功后(在沙箱中),我已经完成了付款并返回到“return_url”的所有工作。

Paypals 关于在沙盒中测试 IPN 的文档很少。也许我错过了某处启用 IPN 回调的设置?

我希望能够使用 IPN 回调来验证付款是否成功。我想查看回调 JSON,以便知道要捕获和比较哪个字段。我找到了示例代码,但是沙盒中似乎没有调用 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
4

1 回答 1

0

事实证明,我的身份验证阻止了贝宝调用我的 ipn 侦听器。

于 2012-07-31T20:44:11.420 回答