> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abacatepay.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PHP

> Integre a AbacatePay em aplicações PHP em minutos.

<Card title="AbacatePay PHP SDK" icon="github" href="https://github.com/AbacatePay/abacatepay-php-sdk">
  Repositório oficial — issues, changelog e contribuições.
</Card>

## Pré-requisitos

* PHP 7.2.5+ e Composer
* SSL habilitado em produção
* Uma chave de API ([criar no dashboard](https://app.abacatepay.com))

## Instalação

```bash theme={null}
composer require abacatepay/php-sdk
```

## Configuração

Armazene sua chave de API em uma variável de ambiente e nunca no código:

```php theme={null}
use AbacatePay\Clients\Client;

Client::setToken($_ENV['ABACATEPAY_API_KEY']);
```

## Primeira cobrança

```php theme={null}
use AbacatePay\Clients\BillingClient;
use AbacatePay\Resources\Billing;
use AbacatePay\Resources\Billing\Product;
use AbacatePay\Resources\Billing\Metadata as BillingMetadata;
use AbacatePay\Enums\Billing\Methods;
use AbacatePay\Enums\Billing\Frequencies;

$billingClient = new BillingClient();

$billing = $billingClient->create(new Billing([
    'frequency' => Frequencies::ONE_TIME,
    'methods'   => [Methods::PIX],
    'products'  => [
        new Product([
            'external_id' => 'PRO-PLAN',
            'name'        => 'Pro plan',
            'quantity'    => 1,
            'price'       => 1000, // em centavos
        ])
    ],
    'metadata' => new BillingMetadata([
        'return_url'     => 'https://meusite.com/app',
        'completion_url' => 'https://meusite.com/pagamento/sucesso',
    ]),
]));

echo $billing->url; // URL de pagamento para o cliente
```

**Resposta:**

```json theme={null}
{
  "success": true,
  "error": null,
  "data": {
    "id": "bill_12345667",
    "url": "https://app.abacatepay.com/pay/bill_12345667",
    "amount": 1000,
    "status": "PENDING",
    "devMode": true,
    "createdAt": "2024-11-04T18:38:28.573Z"
  }
}
```

## Próximos passos

<CardGroup cols={2}>
  <Card title="Configurar webhooks" icon="bell" href="/pages/webhooks">
    Receba notificações em tempo real sobre pagamentos confirmados.
  </Card>

  <Card title="Checkout Transparente" icon="credit-card" href="/pages/transparents/create">
    Aceite PIX e cartão diretamente na sua interface.
  </Card>

  <Card title="Criar clientes" icon="users" href="/pages/client/create">
    Gerencie clientes vinculados às cobranças.
  </Card>

  <Card title="Referência completa" icon="book-open" href="/pages/reference/introduction">
    Todos os endpoints, status codes e formato de resposta.
  </Card>
</CardGroup>
