未调用 Rails 应用程序上的 Paypal IPN
Posted
技术标签:
【中文标题】未调用 Rails 应用程序上的 Paypal IPN【英文标题】:Paypal IPN on Rails app not being called 【发布时间】:2012-07-18 21:43:56 【问题描述】:我们正在使用 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
【问题讨论】:
【参考方案1】:原来我的身份验证阻止了贝宝调用我的 ipn 监听器。
【讨论】:
以上是关于未调用 Rails 应用程序上的 Paypal IPN的主要内容,如果未能解决你的问题,请参考以下文章
在 Rails 上的 Paypal 自适应付款给了错误的成功
让 ActiveMerchant PayPal Gateway 在 Rails 3 上工作的问题
是否有任何 gem 可以将 paypal 按钮 api 集成到 rails 应用程序? [关闭]
gem mysql2未安装在rails上的ruby上[重复]