2

我一直在尝试使用我的 rails 应用程序设置 wepay-rails gem https://github.com/adamthedeveloper/wepay-rails,并且成功地这样做了,但是我意识到由于我的设置,它是可能的用户继续完成部分订单,然后打开一个新选项卡,创建一个新订单,然后返回第一个选项卡,这允许他们完成对第一个项目的结帐,但将第二个项目标记为已付款。

我已按照自述文件中的指南进行操作,以实现我当前的设置:

class Purchase::CheckoutController < ApplicationController
  include WepayRails::Payments
  def index
    begin
      @order = Order.find(session[:order_id])
    rescue
      redirect_to :root
      flash[:warning] = "You do not currently have any pending orders."
      return
    end
    @item = Item.find(@order.item_id)
    checkout_params = {
      :amount => @order.total.to_f,
      :short_description => "Order",
      :long_description => "Your order for #{@order.quantity} #{@item.name.pluralize(@order.quantity)} ",
    }
    init_checkout_and_send_user_to_wepay(checkout_params)
  end
end

以及用户在返回时被重定向到的控制器:

class Purchase::FinalizeController < ApplicationController
  def index
    # Fetch the WepayCheckoutRecord that was stored for the checkout
    wcr  = WepayCheckoutRecord.find_by_checkout_id(params[:checkout_id])

    @order = Order.find(session[:order_id])
    @order.wepay_checkout_record = wcr
    @order.paid = true if wcr.state == 'authorized'
   @order.save

    redirect_to :root, :notice => "You have completed your purchase."
  end
end

安全问题本身非常明显,如果您在订单中间更改会话 ID,则返回错误的订单会被批准。问题是 init_checkout_and_send_user_to_wepay 没有返回值,我无法立即将订单和结帐记录绑定在一起。我使用这个插件是错误的,还是只是遗漏了一些明显的东西?

谢谢大家的帮助!

4

0 回答 0