> ## 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.

# Swift

> Integre a AbacatePay em aplicações iOS e macOS em minutos.

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

## Pré-requisitos

* Swift 5.5+ / Xcode 13+
* iOS 14+ ou macOS 11+
* Uma chave de API ([criar no dashboard](https://app.abacatepay.com))

## Instalação

<CodeGroup>
  ```swift Package.swift theme={null}
  dependencies: [
      .package(url: "https://github.com/AbacatePay/abacatepay-swift-sdk", from: "1.0.0")
  ]
  ```

  ```
  Xcode → File → Add Package Dependencies
  URL: https://github.com/AbacatePay/abacatepay-swift-sdk
  ```
</CodeGroup>

## Configuração

Armazene sua chave de API em variáveis de configuração ou no Keychain e nunca no código:

```swift theme={null}
import AbacatePay

let abacatePay = AbacatePay(apiKey: ProcessInfo.processInfo.environment["ABACATEPAY_API_KEY"]!)
```

## Primeira cobrança

```swift theme={null}
let billingData = CreateBillingData(
    frequency:    .oneTime,
    methods:      [.pix],
    returnUrl:    "https://meusite.com/app",
    completionUrl: "https://meusite.com/pagamento/sucesso",
    products: [
        .init(externalId: "PRO-PLAN", name: "Pro plan", quantity: 1, price: 1000)
    ]
)

do {
    let billing = try await abacatePay.billing.create(data: billingData)
    print(billing.url) // URL de pagamento para o cliente
} catch {
    print("Erro:", error)
}
```

**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>
