From 4fa1f4ac81951f9b373d2167413ac3401fd8d060 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Thu, 13 Apr 2023 18:14:25 -0600 Subject: AƱade servicios y validaciones de pago MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/payment.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'app/models/payment.rb') diff --git a/app/models/payment.rb b/app/models/payment.rb index 5d5e862..4839de8 100644 --- a/app/models/payment.rb +++ b/app/models/payment.rb @@ -5,4 +5,11 @@ 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 -- cgit v1.2.3