Files
app-agent/README.md
T
2026-08-24 19:44:24 +03:30

112 lines
5.1 KiB
Markdown

# Android App Manager
A Laravel 13 and Filament 5 service for managing multiple Android apps as native Filament tenants. Each app has isolated configuration, API credentials, Cafe Bazaar credentials, purchases, subscriptions, releases, reviews, and integration logs.
## Setup
```bash
composer run setup
php artisan make:filament-user
composer run dev
```
Open `/admin`, sign in, and use **Add Android app** in the tenant menu. The first app registration generates:
- a client key for Android-facing requests;
- a management key for trusted-server and administrative operations.
Open **App settings** from the tenant menu to configure version policy, maintenance mode, remote configuration, feature flags, support information, and Cafe Bazaar credentials. All Bazaar secrets and purchase tokens are encrypted at rest.
## Local test data
Generate or refresh the complete local dataset at any time:
```bash
php artisan db:seed
```
The seeder is idempotent: it replaces only the two reserved demo apps and reuses the local administrator, so repeated runs do not increase record counts. It creates purchases, active/expired/cancelled subscriptions, releases, reviews, API successes and failures, and tenant ownership for:
- `ir.local.cafe`
- `ir.local.wallet`
Sign in to Filament with `admin@example.test` and password `password`. The demo client and management keys are `local-cafe-client-key` / `local-cafe-management-key` and `local-wallet-client-key` / `local-wallet-management-key`.
## Cafe Bazaar configuration
For each app, configure the values supplied by Pishkhan:
- billing and Pishkhan API secret (`CAFEBAZAAR-PISHKHAN-API-SECRET`);
- comments API header name and secret;
- Login with Bazaar client ID, client secret, and registered redirect URL;
- billing RSA public key for server-side signature verification.
The implementation covers the current Persian Cafe Bazaar documentation:
- one-time purchase validation, signature verification, consumption, and refund;
- subscription lookup, active subscriptions, cancellation, and refund;
- Login with Bazaar authorization, token exchange, refresh, and user info;
- reviews listing/filtering, local synchronization, and replies;
- release creation/deletion, APK upload, AAB and BIN flow, bundle status, commit, staged rollout, auto-publish, and latest release lookups.
## Background synchronization
Enable automatic synchronization and choose the subscription interval in each tenant's **App settings**. The scheduler queues one isolated job per app. Each job:
- revalidates known subscriptions at the configured interval, including renewal, cancellation, and expiration state;
- revalidates known purchases daily so later refunds and consumption changes are captured;
- incrementally imports review pages with a one-day overlap to capture edits, and persists the cursor so very large backlogs resume on the next run;
- reconciles the latest uncommitted, committed, and published release states;
- stores status, duration, counters, failures, and the last completed attempt for display in Filament.
Bazaar does not expose a global purchase/subscription export. A token first becomes known when an Android client submits it to this service's validation endpoint; synchronization can then keep that record current. Use **Sync Bazaar now** in App settings to force a complete refresh regardless of freshness windows.
Production needs both Laravel's queue worker and scheduler. For example, supervise the worker:
```bash
php artisan queue:work --timeout=300 --tries=8
```
Run `php artisan schedule:run` every minute from cron, or keep `php artisan schedule:work` supervised. The scheduler checks every five minutes and respects each app's configured interval. Manual operations are also available:
```bash
php artisan bazaar:sync
php artisan bazaar:sync --app=ir.example.app --now --force
```
Bazaar features that run on the Android device—Updater SDK, intents, BNPL checkout, dynamic discounts, and client billing UI—are controlled through tenant configuration and feature flags. The app configuration endpoint returns the package name, Bazaar store/update intent, and enabled capabilities for the Android client.
## API
Interactive API documentation is available at `/docs/api`. The source contract is [`public/openapi.yaml`](public/openapi.yaml).
All routes use this base path:
```text
/api/v1/apps/{package-name}
```
Send the client credential on every request:
```http
X-App-Key: <client-key>
```
Refunds, subscription cancellation, review replies, and every publishing operation additionally require:
```http
X-Management-Key: <management-key>
```
Never embed the management key in an APK. Keep it in a trusted deployment secret store. Use HTTPS in production, validate Bazaar `developerPayload` against the authenticated app user, and grant content only after server-side signature and purchase validation.
## Verification
```bash
php artisan test --compact
vendor/bin/pint --format agent
composer audit
```
Tests prevent real outbound requests and exercise tenant isolation, the Filament tenant dashboard/resources, authentication boundaries, Bazaar billing, RSA verification, OAuth, reviews, publishing, response redaction, and persistence.