def state=(value)
      return if @state == :closed
      unless PERMITTED_STATE_TRANSITIONS[@state].include?(value)
        raise ArgumentError, "Invalid state transition: #{@state.inspect} -> #{value.inspect}"
      end

      case value
      when :pending, :closed
        @stats["state"].update(value.to_s)
        @state = value
      when :authorized, :unauthorized, :expired, :failed
        if value != @state
          @stats["state"].update(value.to_s)
          @state = value
          (@status_callbacks || []).each do |callback|
            begin
              callback.call(:auth, @state)
            rescue StandardError => e
              ErrorTracker.log(self, "Failed status callback", e, nil, :caller)
            end
          end
        end
      else
        raise ArgumentError, "Unknown state: #{value.inspect}"
      end
      @state
    end
def state=(value)
      return if @state == :closed
      unless PERMITTED_STATE_TRANSITIONS[@state].include?(value)
        raise ArgumentError, "Invalid state transition: #{@state.inspect} -> #{value.inspect}"
      end

      case value
      when :pending, :closed
        @stats["state"].update(value.to_s)
        @state = value
      when :authorized, :unauthorized, :expired, :failed
        if value != @state
          @stats["state"].update(value.to_s)
          @state = value
          (@status_callbacks || []).each do |callback|
            begin
              callback.call(:auth, @state)
            rescue StandardError => e
              ErrorTracker.log(self, "Failed status callback", e, nil, :caller)
            end
          end
        end
      else
        raise ArgumentError, "Unknown state: #{value.inspect}"
      end
      @state
    end
Update authorization state
 If state has changed, make external callbacks to notify of change
 Do not update state once set to :closed

 @param [Hash] value for new state

 @return [Symbol] updated state

 @raise [ArgumentError] invalid state transition