我在rails中有一个控制器操作,它应该检查交易的当前braintree状态是“submitted_for_settlement”还是“authorized”,然后使交易无效,但如果状态为“settled”,则退还交易。不知何故,控制器正在取消所有交易并且没有像我想要的那样工作。这是我的代码示例:
@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已结算的交易保持不变,控制器也会取消数据库中的状态。
为什么我会收到此错误?