红宝石轨道 - 无法自动捕获付款



我无法在狂欢中自动捕获付款。我已经尝试过使用PaymentMethod::Check方法和我的自定义方法(通过在管理面板中将自动捕获选项设置为 true),但它始终使付款方式处于pending状态。我的自定义方法基于PaymentMethod::Check源代码,如下所示:

module Spree
  class PaymentMethod::CashOnDelivery < PaymentMethod
    def actions
      %w{purchase capture void}
    end
    # Indicates whether its possible to capture the payment
    def can_capture?(payment)
      ['checkout', 'pending'].include?(payment.state)
    end
    # Indicates whether its possible to void the payment.
    def can_void?(payment)
      payment.state != 'void'
    end
    def purchase(*args)
      throw 'purchase'
    end
    def capture(*args)
      ActiveMerchant::Billing::Response.new(true, "", {}, {})
    end
    def cancel(response); end
    def void(*args)
      ActiveMerchant::Billing::Response.new(true, "", {}, {})
    end
    def source_required?
      false
    end
    def auto_capture?
      true
    end
  end
end

但是,这不会引发任何例外,也不会改变付款状态。这一切看起来我做错了什么,误解了什么,或者疯狂地认为我的付款方式是不可自动捕获的。

提前感谢您提供任何线索!

首先,您应该了解状态机的Spree使用。使用此宝石更改顺序状态。在 checkout_controller.rb 中,写着"@order.next",这是统计机器发挥作用并相应地更改顺序状态的地方。

本教程可能会帮助您了解状态机 Gem 的工作原理。我认为Spree的大部分状态机代码都存在于checkout.rb模型中。

我认为您的事务发生正常,但状态不会更改,因为您没有在类中处理状态机。

在更改此类付款修改时,您还需要了解其他流程。这是施普雷最难理解的领域之一。

您的source_required?返回false 。如果您的PaymentMethod不需要来源,Spree 不会自动处理付款。即使您的auto_capture?设置为 true .使用您的付款方式进行的付款需要在后台手动捕获。

来自狂欢文档。

如果付款方式需要来源,并且付款有来源 与之关联,然后 Spree 将尝试处理付款。 否则,付款将需要手动处理

Solidus是从Spree克隆而来的,他们的文档在这里提供了更多详细信息:

付款不能使用流程处理! 方法在少数 情况 下:

  • [...
  • Spree::PaymentMethod不需要付款来源。
  • [...

最新更新