summaryrefslogtreecommitdiff
path: root/app/models/payment.rb
blob: 8be9c7f52240e672e48f9bf7e052e1739887acc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 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