2

我正在寻找一种将购买的文件交付给网络应用程序用户的方法。基本上,用户将从我的网站购买“产品”,此时他们可以下载他们购买的文件(可能是我预编译的 zip 文件)

我使用的是 Rails 2.3.8,并且支付处理工作在 Braintree 解决方案中。有没有一种标准的方法来实现这一点,使用短代码,或者其他什么?Braintree 是否有内置的东西,是否存在插件/gem?

我真的只是在寻找一个正确的方向来推动这通常是如何完成的..

谢谢!

4

1 回答 1

1

您可以做的是让每个Product模型都have_many批准用户。当 BrainTree 为您提供用户支付产品的 OK 时,您可以将该用户添加到已批准的用户列表中。因此,在ProductController您检查 current_user 是否是已批准的用户,如果是,请下载文件,否则重定向它们。

对于示例:

产品.rb

class Product < ActiveRecord::Model
  has_many approved_users, :class => User
end

product_controller.rb

class ProductController 
  def download
    @product = Product.find_by_id(:id)
    if @product.approved_users.includes?(current_user)
      # Give them the file
    else
      flash[:notice] = "You must buy the product first!"
      redirect_to product_sales_url(@product)
    end
  end
end 

或类似的东西。我的语法可能有点不对劲,但这应该能让你继续前进。

于 2011-03-14T20:09:07.680 回答