Rails Spree不能从付款过渡到完成

发布于 2025-01-25 03:03:41 字数 1068 浏览 5 评论 0原文

我将自定义付款方法集成到我的Rails应用程序中。但是我不能这样做我的订单从付款统计数据到完成状态。我可以确保按订单注册的付款处于完整状态,因此我无法弄清楚为什么状态机告诉我“找不到付款”

这是我的代码。

  def perform_payment payment_id, state
    Rails.logger.info("PERFORM PAYMENT => payment_id: #{payment_id}, state: #{state}")
    payment = Spree::Payment.find payment_id
    return unless payment
    order = payment.order
    
    begin
      if state == "accepted"
        payment.started_processing!
        payment.capture!
        Rails.logger.info("PERFORM PAYMENT => order_id:#{order.id}, current_order_state: #{order.state}")
        Rails.logger.info("PERFORM PAYMENT => order_payments:#{order.payments.size}")
        order.next! unless order.state == "completed"
      elsif state == "rejected"
        payment.started_processing!
        payment.failure!
      end
    rescue Exception => e
      Rails.logger.error("Error al procesar pago orden #{order.number}: E -> #{e.message}")
      return false
    end
  end

错误(无法通过:下一步从:付款(s):找不到付款))

这是我遇到的statemachines :: invalidtransition的

I am integrating a custom pay method into my rails app. But I cannot do that my order goes from payment stat to completed state. I am ensure that the payment registered at the order is at completed state, so I cannot figure out why the state machine are telling me "No payment found"

Here's my code.

  def perform_payment payment_id, state
    Rails.logger.info("PERFORM PAYMENT => payment_id: #{payment_id}, state: #{state}")
    payment = Spree::Payment.find payment_id
    return unless payment
    order = payment.order
    
    begin
      if state == "accepted"
        payment.started_processing!
        payment.capture!
        Rails.logger.info("PERFORM PAYMENT => order_id:#{order.id}, current_order_state: #{order.state}")
        Rails.logger.info("PERFORM PAYMENT => order_payments:#{order.payments.size}")
        order.next! unless order.state == "completed"
      elsif state == "rejected"
        payment.started_processing!
        payment.failure!
      end
    rescue Exception => e
      Rails.logger.error("Error al procesar pago orden #{order.number}: E -> #{e.message}")
      return false
    end
  end

Here's the error that I'm getting

StateMachines::InvalidTransition (Cannot transition state via :next from :payment (Reason(s): No payment found))

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

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

发布评论

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

评论(1

才能让你更想念 2025-02-01 03:03:41

实际上,这是@Alex提到的。这只是必要的.netx!在订单上。这样做。您需要确保您以“完成”状态付款。

Actually, It was @Alex mentions. It's only neccesary the .netx! on the order. To do that. you need to ensure that you have a payment in "completed" state.

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