# frozen_string_literal: true # Payment # total: float class Payment < ApplicationRecord has_one :order belongs_to :card validate :card_belongs_to_user def card_belongs_to_user return if Order.find_by(id: order_id)&.user_account&.cards&.exists?(card_id) errors.add(:card_id, "doesn't belong to user") end end