Sha256: b9af24d2d26b4af443170c14c0e075ed80f545d399f7a639b9c249c67396e716
Contents?: true
Size: 843 Bytes
Versions: 5
Compression:
Stored size: 843 Bytes
Contents
module Workarea decorate Payment, with: 'gift_cards' do decorated do embeds_many :gift_cards, class_name: 'Workarea::Payment::Tender::GiftCard' delegate :number, to: :gift_card, allow_nil: true, prefix: true validate :gift_card_count_limit end def gift_card? gift_cards.present? end def add_gift_card(attrs) existing = gift_cards.detect do |card| card.number.casecmp?(attrs[:number].strip) end if existing.present? existing.assign_attributes(attrs) else gift_cards.build(attrs) end save end private def gift_card_count_limit max = Workarea.config.max_gift_cards_per_order if gift_cards.size > max errors.add(:base, I18n.t('workarea.gift_cards.max_applied', count: max)) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems