# 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 unless order.user_account.cards.find_by(id: card.id).nil? errors.add(:card_id, "doesn't belong to user") end end