public static function factory(array $attributes)
    {
        if (!array_key_exists('object', $attributes)) {
            throw new Payplug\Exception\UnknownAPIResourceException('Missing "object" property.');
        }

        switch ($attributes['object']) {
            case 'payment':
                return Payplug\Resource\Payment::fromAttributes($attributes);
            case 'refund':
                return Payplug\Resource\Refund::fromAttributes($attributes);
            case 'installment_plan':
                return Payplug\Resource\InstallmentPlan::fromAttributes($attributes);
        }

        throw new Payplug\Exception\UnknownAPIResourceException('Unknown "object" property "' . $attributes['object'] . '".');
    }