# API gateway controller map

`ApiGatewayController.php` is the route entry point. Its methods are composed from
the traits below in `Concerns/`; routes in `routes/web.php` still target the same
controller and action names. These traits are parts of this controller, not
standalone services. Private helpers can be called across its traits.

Read the row relevant to the task, then only the helpers it calls.

| File in `Concerns/` | Methods / responsibility | Relevant tests in `tests/Feature/` |
| --- | --- | --- |
| `HandlesCampaignPricing.php` | `priceView`, `campaignPrices`, `flattenPriceData`, `findPriceValue` | `PackagePriceTest`, `MediaCampaignApiTest` |
| `HandlesCampaignQueries.php` | `lbaEstimate`, `profileDropdownList`, `campaignReport`, `trackEvent` | `LbaEstimateTest`, `CampaignSmsReportTest`, `MmsTargetingApiTest` |
| `HandlesSmsTargetedCampaigns.php` | `targetedAdd`, SMS targeted name generation; dispatches MMS to `mmsCampaignAdd` | `SmsSubmissionFeedbackTest`, `CampaignPaymentProtectionTest` |
| `HandlesSmsLbaCampaigns.php` | `lbaAdd`, SMS LBA name generation; dispatches MMS to `mmsCampaignAdd` | `SmsSubmissionFeedbackTest`, `CampaignPaymentProtectionTest` |
| `HandlesMmsCampaigns.php` | `mmsCampaignAdd`, `authorizeMmsRetry`; upload, schedule, locking and recovery | `MmsTargetingApiTest`, `MediaCampaignApiTest` |
| `HandlesWabaCampaigns.php` | `wabaTemplateList`, `wabaDisplayNameList`, `wabaLbaAdd`, `wabaTargetedAdd`, WABA name generation | `CampaignPaymentProtectionTest` |
| `InteractsWithGatewayTokens.php` | Gateway/access token lookup, refresh callbacks, JWT expiry inspection | `ApiSessionExpiryTest`, `MmsTargetingApiTest` |
| `FormatsCampaignInput.php` | Recipient count, invoice email, date/time, schedule validation, message, profile and phone formatting | `SmsSubmissionFeedbackTest`, `MmsTargetingApiTest` |

The listed tests are related regression checks, not a claim of complete coverage
for every method. For changes across concerns, run the full PHP test suite.

## Main-balance-only submission

SMS Targeted/LBA set `useBonusBalance=0`; MMS also sets `usePackage=0`.
Do not restore membership payment bypasses or QRIS checks in these traits.
`HandlesGatewayPayments.php` and its initiate/status/download actions are removed.
`CampaignPaymentProtectionTest` checks main-balance selection;
`CampaignBillingTest` checks direct API submission, balance errors and request keys;
`MainBalancePagesTest` checks that campaign pages do not offer QRIS.

## Related code

- `app/Services/MyadsApiClient.php`: HTTP transport and upstream endpoint methods.
- `app/Services/CampaignPriceFields.php`: shared price key lookup.
- `app/Services/MediaCampaignCatalog.php`: MMS/RCS catalog and pricing.
- `app/Services/BroadcastAudience.php`: audience phone normalization used by MMS.
- `app/Services/GatewayValidationException.php`: definitive gateway rejection.
- `app/Http/Controllers/CampaignSubmissionController.php`: authenticated main-balance lookup for review.
- `app/Http/Controllers/MmsCampaignController.php`: MMS pages and drafts.
- `app/Http/Controllers/RcsCampaignController.php`: RCS flows.
- `app/Http/Controllers/BroadcastController.php`: broadcast flows.

Keep imports in each trait's namespace. Preserve method visibility and signatures
when moving code. Keep public route actions available on `ApiGatewayController`.
Do not weaken MMS uncertain-send/retry protections or change gateway payloads as
part of a formatting or file-organization task.
