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

# Collect with Laravel

> Collect payments with the Dollr API in a Laravel application using the HTTP client.

<Note>
  **Invoices vs orders:** These guides walk through **invoices** (formal billing, line items, publish). The collect flow is the same for **orders** — use `/v1/orders/*` instead of `/v1/invoices/*` and set `source_type: "ORDER"` on the checkout session. See [Orders](/api/orders) and [Parties & counterparties](/concepts/parties-and-counterparties).

  **Hosted checkout:** To skip party, invoice, session, and execute steps entirely, see [Hosted checkout](/guides/hosted-checkout).
</Note>

Use Laravel’s **HTTP client** (Guzzle) from a controller, job, or action — never from Blade views with secrets.

<Note>
  **API Reference:** [Obtain token](/api-reference/jwt/client-obtain-token) · [Collect](/api-reference/executions/collect)
</Note>

## Prerequisites

* Laravel 10+ (or 11+)
* `config/services.php` entries for `dollr.client_id` and `dollr.client_secret`

```php theme={null}
// config/services.php
'dollr' => [
    'base_url'      => env('DOLLR_BASE_URL', 'https://api.heydollr.app'),
    'client_id'     => env('DOLLR_CLIENT_ID'),
    'client_secret' => env('DOLLR_CLIENT_SECRET'),
],
```

## Steps

<Steps>
  <Step title="Service helper">
    ```php theme={null}
    // app/Services/DollrClient.php
    namespace App\Services;

    use Illuminate\Support\Facades\Http;
    use Illuminate\Support\Str;

    class DollrClient
    {
        public function token(): string
        {
            $base = config('services.dollr.base_url');
            $res = Http::post("$base/v1/jwt/client/obtain/token", [
                'client_id'     => config('services.dollr.client_id'),
                'client_secret' => config('services.dollr.client_secret'),
            ])->throw();
            return $res->json('access_token');
        }

        public function authed()
        {
            return Http::withToken($this->token())
                ->baseUrl(config('services.dollr.base_url'))
                ->acceptJson();
        }
    }
    ```
  </Step>

  <Step title="Create invoice flow">
    ```php theme={null}
    $http = app(DollrClient::class)->authed();

    $party = $http->post('/v1/parties/create', [
        'fullname' => 'Amara Kamara', 'phone' => '231771234567',
        'country_code' => 'LR',
    ])->json();

    $cp = $http->post('/v1/counterparties/create', [
        'relationship_type' => 'CUSTOMER', 'party_id' => $party['id'],
    ])->json();

    $invoice = $http->post('/v1/invoices/create', [
        'counterparty_id' => $cp['id'], 'currency' => 'USD',
        'fee_bearer' => 'PAYER', 'as_payment_link' => true,
    ])->json();
    ```
  </Step>

  <Step title="Publish and collect">
    ```php theme={null}
    $id = $invoice['id'];
    $http->post("/v1/invoices/$id/items/add", [
        'name' => 'Strategy Session', 'currency' => 'USD', 'qty' => 1, 'amount' => 250,
    ]);
    $http->put("/v1/invoices/publish/$id");

    $referenceId = (string) Str::uuid();
    $session = $http->post('/v1/sessions/checkout', [
        'source_id' => $id, 'source_type' => 'INVOICE',
    ])->json();

    $http->post('/v1/executions/collection', [
        'session_id'         => (string) $session['id'],
        'payment_account_id' => $paymentAccountId,
        'currency'           => 'USD',
        'reference_id'       => $referenceId,
    ]);
    ```
  </Step>

  <Step title="Poll in a queued job">
    ```php theme={null}
    $status = $http->get("/v1/status/collection/$referenceId")->json('status');
    ```

    Use [Payment status patterns](/guides/payment-status-patterns) — poll status in a queued job or use [realtime keys](/guides/realtime-status) for live UI. Dollr does not expose inbound webhooks in the Open API.
  </Step>
</Steps>

## Try it yourself

<CardGroup cols={3}>
  <Card title="Hosted checkout" icon="window-maximize" href="/guides/hosted-checkout">
    Mobile money and card on a Dollr-hosted page — fastest path.
  </Card>

  <Card title="Orders" icon="box" href="/api/orders">
    Same collect flow with `source_type: ORDER` and `/v1/orders/*`.
  </Card>

  <Card title="Direct checkout" icon="cart-shopping" href="/guides/collect-via-checkout">
    One API call to create source — API-embedded flow.
  </Card>
</CardGroup>

## Related

* [Hosted checkout](/guides/hosted-checkout) · [Orders](/api/orders)
* [Collect via checkout](/guides/collect-via-checkout)
* [Choose your integration](/guides/choose-integration)
* [Error handling](/guides/error-handling)
* [Sessions & executions](/concepts/sessions-and-executions)
