【发布时间】:2016-06-19 22:34:05
【问题描述】:
我在 Rails 中有一个控制器操作,它应该检查交易的当前 Braintree 状态是“submitted_for_settlement”还是“authorized”,然后 void 交易,但如果状态是“结算”,然后退款交易。不知何故,控制器正在取消所有交易并且没有像我想要的那样工作。这是我的代码示例:
@transaction = Braintree::Transaction.find(@id)
if @transaction.status == "authorized" || "submitted_for_settlement"
@result = Braintree::Transaction.void(@id)
elsif @transaction.status == "settled"
@result = Braintree::Transaction.refund(@id)
end
if @result.success?
@order.update(status: "voided")
redirect_to orders_path, notice: "transaction successfully voided "
elsif @result.transaction
redirect_to orders_path, alert: "transaction could not be cancelled code: #{@result.transaction.processor_response_code} text: #{@result.transaction.processor_response_text}"
else
errors = @result.errors.map { |error| "Error: #{error.code}: #{error.message}" }
flash[:error] = errors
redirect_to orders
end
我在已结算的交易上收到一条错误消息,上面写着“交易只有在获得授权或提交_for_settlement 的情况下才能作废”,但所有已授权并提交结算的交易都正确触发。
更麻烦的是,即使我收到错误并且braintree结算的交易保持不变,控制器也会取消数据库中的状态。
为什么会出现这个错误?
【问题讨论】:
标签: ruby-on-rails ruby transactions braintree braintree-rails