# Workflow: set up the project

> Resource, credentials, webhook and code: what the agent provisions in Bankemes and implements in the application.

## Provision

1. `bankemes_create_resource({ url, cashier_id? })` — idempotent by origin.
2. `bankemes_provision_integration({ resource_id, environments: ["test"] })` — the test token.
3. `bankemes_provision_integration({ resource_id, environments: ["live"] })` — returns `approval_required` with `approval_url`; the owner approves in the cabinet; then repeat the same call to receive the live token delivery.
4. `bankemes_configure_webhook({ resource_id, url })` — the URL must be on the application’s domain or a subdomain.

## Secrets reach the project, never the chat

Token and webhook secrets are returned as one-time delivery links (valid 10 minutes, single use). Run the returned command in the application root:

Shell:

```
curl -fsS 'https://bankemes.kz/api/agent/deliveries/<one-time id>' >> .env
```

Variables: `BANKEMES_TEST_API_TOKEN`, `BANKEMES_API_TOKEN` (live), `BANKEMES_WEBHOOK_SECRET`. Keep `.env` out of Git and out of frontend bundles. If a link expired, call the tool again with `rotate: true` / `rotate_secret: true`.

## Implement

- Server-side: `POST /api/v1/payments` with `Authorization: Bearer <token>`, `Idempotency-Key`, `{ order_id, amount }`; redirect the buyer to `checkout_url`.
- Webhook handler: verify `Bankemes-Signature` (`t=…,v1=HMAC-SHA256(secret, "t.raw_body")`) on the raw body, reject old timestamps, answer 2xx fast, deduplicate by event id.
- Before fulfilling an order, re-read `GET /api/v1/payments/{id}` server-side and check `status`, `amount` and `livemode`.
- Get the exact contract with `bankemes_get_integration_guide`, or see [OpenAPI](https://bankemes.kz/openapi.json).

Source: https://bankemes.kz/for-agents/workflows/setup-project
