Sha256: 8c48de86914ee9c7ca07be6dd6b4ab96307eff527ad7eeb51619e3aad8c360ff
Contents?: true
Size: 862 Bytes
Versions: 33
Compression:
Stored size: 862 Bytes
Contents
module Spree module CreditCards class Destroy prepend Spree::ServiceModule::Base def call(card:) ApplicationRecord.transaction do run :invalidate_payments run :void_payments run :destroy end end protected def invalidate_payments(card:) payment_scope(card).checkout.each(&:invalidate!) success(card: card) end def void_payments(card:) payment_scope(card).where.not(state: :checkout).each(&:void!) success(card: card) end def destroy(card:) if card.destroy success(card: card) else failure(card.errors.full_messages.to_sentance) end end def payment_scope(card) card.payments.valid.joins(:order).merge(Spree::Order.incomplete) end end end end
Version data entries
33 entries across 33 versions & 1 rubygems