# Myads API client map

`../MyadsApiClient.php` retains the constructor and base URL properties and
composes the traits in `Concerns/`. Controllers, dependency injection and mocks
still use `App\Services\MyadsApiClient`. Traits share its private methods and
properties; they are not separately instantiated services.

The upstream contract is `API_REFERENCE.md` in the repository root. Features
without a route there are listed in `API_MISSING.md`; their client methods keep
their signatures and throw a "belum tersedia di API ShopAds" `RuntimeException`
without sending a request (`unsupportedEndpoint`).

Start with the endpoint group for the task. Read transport helpers only when
investigating HTTP behavior, authorization, retries or error handling.

| File in `Concerns/` | Responsibility / methods |
| --- | --- |
| `CreatesHttpClients.php` | `client`, `bearerClient`, `directClient`, `hasDirectApiConfig`: HTTP defaults and direct API headers |
| `AuthenticatesUsers.php` | `login` (`/api/auth/login`), `getMe` (`/api/auth/me`), `getGatewayToken` (returns the access token), unsupported register/refresh |
| `SendsGatewayRequests.php` | `postGw`, `sendGetApi`, `wrapApiResponse`, `detail`/DigitalCore error extraction, `unsupportedEndpoint`, `isMmsFileXssRejection` |
| `ManagesCampaigns.php` | `/api/balance`, `/package_price`, `/api/pricebook`, `/api/profiles/list`, `campaignList`/`campaignReports` (`/api/reports/campaigns`), `campaignReport`/`campaignReportDetail` (`/api/reports/campaigns/{channel}/{local_id}`), SMS/MMS/WABA `/add` routes and per-schema payload filtering |
| `ManagesShortLinks.php` | `createShortLink` (`POST /api/short-links`), `openShortLink` (public `GET /api/short-links/{code}/open`); used by `ShortLinkController` (form button and the public `/{code}` redirect) |
| `ManagesWabaTemplates.php` | `/api/waba/templates/list`, `/api/waba/templates/add`, `/api/waba/display-names` |
| `UploadsMedia.php` | `/api/content/upload`, upload preparation; RCS upload is unsupported |
| `ManagesBilling.php` | Invoice methods (unsupported; the merchant's membership comes from `/api/auth/me`) |
| `ManagesAdministration.php` | `managementRequest` (`/api/management/users`, `prices`, `summary`, `memberships`; also used for `/api/membership/join`), `transferBalance`/`balanceTransfers` (`/api/balance/transfers`); other `/api/management/*` and event tracking are unsupported |

## Response and authentication contract

- Every route uses the login JWT as `Authorization: Bearer`. There is no gateway
  token or refresh token; callers still pass a "gateway token", which is the
  access token. The session access token takes precedence.
- The API returns DigitalCore JSON unchanged and local JSON without a wrapper.
  `wrapApiResponse` returns `{ success: true, data: <API JSON> }`, so callers keep
  reading `data.data.*`. A nonzero `code` in HTTP 200 is a failure.
- Campaign creation succeeds only with HTTP 2xx, `code: 0` and a non-null
  `data.campaignId`; otherwise the outcome is uncertain. `X-Local-Campaign-Id`
  is returned as `local_campaign_id`.
- Unknown request fields are rejected (422). `campaignPayload` keeps only schema
  fields, so local keys such as `email_invoice` never reach the API.

## Main-balance-only contract

The API owns balance validation and debit; the website does not initiate QRIS
payments or a separate quote/fund checkout. `paymentInitiate`, `paymentStatus`,
and `joinMembership` are removed. The merchant's ShopAds membership join is different: it posts to
the API's `/api/membership/join` through `managementRequest` (MembershipController::join), and the
API pays it from main balance. Preserve `x-campaign-request-key` when
changing campaign transport.

## Contracts and verification

- Preserve constructor parameters and public method signatures, including static
  `isMmsFileXssRejection`, so existing dependency injection and mocks keep working.
- Preserve request headers, payload field names, request keys and exception types.
- `GatewayValidationException` belongs to `App\Services`; import it explicitly
  from the trait namespace. Definitive rejections (422) and uncertain sends
  (timeouts, 503, missing campaignId) have different retry behavior. Keep opaque
  upload tokens unchanged.
- HTTP tests use `Http::fake` / `Http::preventStrayRequests`. Do not call live
  campaign endpoints to verify a refactor.
- Relevant tests in `tests/Feature/`: `AuthLoginTest`, `ApiSessionExpiryTest`,
  `MmsTargetingApiTest`, `MediaCampaignApiTest`, `LbaEstimateTest`,
  `PackagePriceTest`, `CampaignPaymentProtectionTest`, `CampaignBillingTest`,
  `CampaignSmsReportTest`, `MembershipFlowTest`, and `RoleManagementTest`.
  `RcsCampaignApiTest` is skipped until RCS routes exist.
- Run `php artisan test --compact` when shared transport or multiple endpoint
  groups change; the map above does not imply complete endpoint test coverage.
