ruby-on-rails - 我可以在 Ruby on Rails 中将 attr_accessible 用于 PayPal IPN 吗?

标签 ruby-on-rails paypal

我使用这个 RailsCast 创建了购物车系统的一部分,http://railscasts.com/episodes/142-paypal-notifications

PayPal 会调用一段代码来发出通知。

def create
  PaymentNotification.create!(:params => params, :cart_id => params[:invoice], :status => params[:payment_status], :transaction_id => params[:txn_id])
  render :nothing => true
end

我在 Heroku 上试过了,没有警告也没有错误。 PaymentNotification 对象已在数据库中成功创建 - 但除了 id 之外,一切都是零!我打开 heroku 控制台并尝试:

irb(main):002:0> PaymentNotification.create!(:cart_id => "2", :status => "Complete", :transaction_id => "XYZXYZXYZXYZXYZ")
< => "2", :status => "Complete", :transaction_id => "XYZXYZXYZXYZXYZ")

这给了我这个,

WARNING: Can't mass-assign protected attributes: cart_id, status, transaction_id

为什么这个警告没有出现在 Heroku 日志中?为什么还是创建成功了(是不是只是警告,不是错误?)

我可以只对这些东西使用 attr_accessible 吗?无论如何都必须验证通知 ( https://www.paypal.com/cgi-bin/webscr?cmd=p/acc/ipn-info-outside )

最佳答案

为了应用安全,您必须将 attr_accessible 添加到您的属性中。

在 rails 4 上添加了这个 gem https://github.com/rails/strong_parameters 。还有

我建议您使用自适应支付。你可以看看这个帖子:

Paypal Adaptive Payment for Ruby

关于ruby-on-rails - 我可以在 Ruby on Rails 中将 attr_accessible 用于 PayPal IPN 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14490106/

相关文章:

mysql - 尝试为 rails 安装 mysql 支持时出错

ruby-on-rails - Ruby on Rails - Has_many 通过连接表属性限制和排序

php - Merchant SDK for Express Checkout API 在 Paypal 上的 Composer 问题

Paypal 订阅错误 : The link you have used to enter the PayPal system is invalid. 请检查链接并重试

mysql - Rails/Mysql 复杂连接和 where 查询

ruby-on-rails - 在 Rails 中使用哈希数组进行分页?

ruby-on-rails - 请求测试中的 RSpec 3 错误未定义方法 `get'

paypal - 使用 Paypal Payouts API 退款并避免重复付款

paypal - 授权不会过期的 PayPal 账单

joomla - 如何在 joomla 中使用 Virtuamart 2 拦截 paypal 付款确认