Rails - 付款后提供可下载文件

发布于 2024-10-22 09:06:18 字数 234 浏览 1 评论 0原文

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

我正在使用 Rails 2.3.8,并让付款处理工作布伦特里解决方案。是否有使用短代码或其他方法来实现此目的的标准方法? Braintree 是否有内置的东西,是否存在插件/gem?

我真的只是在寻找正确的方向,以了解通常如何完成此操作。

谢谢!

I am looking for a way to deliver purchased files to users of a web app. Basically a user will purchase a 'product' from my site, at which point they can download the files they purchased (will likely be a zip file that I have precompiled)

I am using Rails 2.3.8, and have the payment processing working the Braintree Solutions. Is there a standard way of acheiving this, using short codes, or something? Does Braintree have something built in, does a plugin/gem exists?

I'm really looking for just a push in the right direction as to how this is typically done..

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

謸气贵蔟 2024-10-29 09:06:18

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

对于示例:

product.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 

或类似的东西。我的语法可能有点偏离,但这应该可以帮助你。

What you could do is have each Product model have_many approved users. When BrainTree gives you the OK that a user paid for a product, you can add that user to the approved users list. So in your ProductController you check if the current_user is a approved user, if so download the file, else redirect them.

For Exsample:

product.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 

Or something like that. My syntax might be a little off, but this should get you going.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文