# PHP

### Requisitos previos

Para poder seguir esta guía, primero necesitarás:

* [Obtener un access\_token de Afip SDK](https://app.afipsdk.com)

### 1. Instalación

Agregá la librería de Afip SDK en PHP

{% tabs %}
{% tab title="composer" %}

```bash
composer require afipsdk/afip.php
```

{% endtab %}

{% tab title="Manualmente" %}
**Repositorio:** [**https://github.com/AfipSDK/afip.php**](https://github.com/AfipSDK/afip.php)

1. Clonarlo con `git clone` o descargar el repositorio desde [aqui](https://github.com/AfipSDK/afip.php/archive/refs/heads/master.zip).
2. Copiar el contenido de la carpeta `src` a tu aplicación.
3. Incluir el archivo Afip.php en tu proyecto (el resto de los archivos se incluyen automáticamente).\\

   ```php
   include 'ruta/a/src/Afip.php';
   ```

{% endtab %}
{% endtabs %}

### 2. Crear una instancia de la clase Afip

Para usar los Web Services de ARCA se necesita un certificado digital, pero con Afip SDK podés empezar en modo desarrollo usando el CUIT 20-40937847-2 sin necesidad de uno.

Si preferís [usar tu propio certificado](#usar-tu-propio-certificado-opcional), al final te mostramos cómo.

{% tabs %}
{% tab title="index.php" %}

```php
$afip = new Afip([
    'CUIT' => 20409378472,
    'access_token' => 'TU_ACCESS_TOKEN' // Obtenido de https://app.afipsdk.com
]);
```

{% endtab %}
{% endtabs %}

### 3. Llamar al método del Web Service que necesites

Con la instancia creada ya podés realizar las llamadas a los Web Services que necesites.

{% content-ref url="/pages/mVTz5YrKc8PCEeJKHt0W" %}
[Web services](/siguientes-pasos/web-services.md)
{% endcontent-ref %}

Si el Web Service que necesitás no se encuentra en la lista de la documentación, podés llamarlo siguiendo esta guía:

{% content-ref url="/pages/4zlCsTNGo99FZGfrhpZn" %}
[Otro web service](/siguientes-pasos/web-services/otro-web-service.md)
{% endcontent-ref %}

Podés usar la referencia de la API para obtener ejemplos de cómo usar los métodos de todos los web services de ARCA.

{% embed url="<https://afipsdk.com/docs/api-reference/introduction/>" %}

También tenés un repositorio de ejemplo completo en PHP:

{% embed url="<https://github.com/AfipSDK/afip-sdk-billing-example-php>" %}

También podés usar las guías del blog de Afip SDK para PHP:

{% embed url="<https://afipsdk.com/blog/category/PHP/>" %}

***

### Usar tu propio certificado <sup><sub>(Opcional)<sub></sup>

Primero, obtenemos el certificado siguiendo esta guía.

{% embed url="<https://afipsdk.com/blog/como-obtener-certificado-para-web-services-arca/>" fullWidth="false" %}

Y luego lo agregamos a la instancia de la clase Afip.

{% tabs %}
{% tab title="index.php" %}

```php
// Certificado (Puede estar guardado en archivos, DB, etc)
$cert = file_get_contents('ruta/a/certificado.crt');

// Key (Puede estar guardado en archivos, DB, etc)
$key = file_get_contents('ruta/a/key.key');

// CUIT del certificado
$tax_id = 20111111112;

$afip = new Afip([
    'CUIT' => $tax_id,
    'cert' => $cert,
    'key' => $key,
    'access_token' => 'TU_ACCESS_TOKEN' // Obtenido de https://app.afipsdk.com
]);
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.afipsdk.com/integracion/php.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
