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

# Basic usage example

> Minimal end-to-end TypeScript example using the GoPay client.

# Basic usage example

<Tip>
  Drop the script into your app (e.g. `src/main.ts`), install `gopay-sdk`, set the env vars below, then run with `tsx` / `ts-node` or compile and run with `node`.
</Tip>

## Script

```ts theme={null}
import { Currency, StatementFormat, createGoPayClient } from 'gopay-sdk';

async function main(): Promise<void> {
  const client = createGoPayClient({
    goid: 8123456789,
    clientId: process.env.GOPAY_CLIENT_ID ?? 'YOUR_CLIENT_ID',
    clientSecret: process.env.GOPAY_CLIENT_SECRET ?? 'YOUR_CLIENT_SECRET',
    gatewayUrl: process.env.GOPAY_GATEWAY_URL ?? 'https://gw.sandbox.gopay.com/api',
  });

  const payment = await client.createPayment({
    amount: 10000,
    currency: Currency.CZK,
    order_number: `ORDER-${Date.now()}`,
    payer: {
      contact: {
        email: 'john.doe@example.com',
      },
    },
    callback: {
      return_url: 'https://example.com/return',
      notification_url: 'https://example.com/notify',
    },
  });

  console.log('Payment created:', payment.id, payment.gw_url);

  if (payment.id) {
    const status = await client.getPayment(payment.id);
    console.log('Current payment state:', status.state);
  }

  const statement = await client.getAccountStatement({
    date_from: '2024-01-01',
    date_to: '2024-01-31',
    goid: 8123456789,
    currency: Currency.CZK,
    format: StatementFormat.CSV_A,
  });

  console.log('Statement content type:', statement.contentType);
  console.log('Statement preview:', statement.toText().slice(0, 120));
}

main().catch((error) => {
  console.error('Example failed:', error);
  process.exit(1);
});
```

## Run it

* `GOPAY_CLIENT_ID`, `GOPAY_CLIENT_SECRET`, and optionally `GOPAY_GATEWAY_URL` should match your sandbox account.
* Execute with your usual TypeScript runner (`tsx`, `ts-node`, or compile then `node`).
