require 'active_model/serializer'

module SpreeSignifyd
  class CreditCardSerializer < ActiveModel::Serializer
    self.root = false

    attributes :cardHolderName, :last4, :expiryMonth, :expiryYear

    def cardHolderName
      "#{object.first_name} #{object.last_name}"
    end

    def last4
      object.last_digits
    end

    def expiryMonth
      object.month
    end

    def expiryYear
      object.year
    end
  end
end

require 'active_model/serializer'

module SpreeSignifyd
  class CreditCardSerializer < ActiveModel::Serializer
    self.root = false

    attributes :cardHolderName, :last4

    # this is how to conditionally include attributes in AMS
    def attributes(*args)
      hash = super
      hash[:expiryMonth] = object.month if object.month
      hash[:expiryYear] = object.year if object.year
      hash
    end

    def cardHolderName
      "#{object.first_name} #{object.last_name}"
    end

    def last4
      object.last_digits
    end
  end
end

Make CreditCard expiryMonth and expiryYear optional
Make CreditCard expiryMonth and expiryYear optional

These are about to become numbers, null is not a number.
