Ad Campaigns & Marketing API
Paid marketing campaigns management and promotion endpoints
1. Purpose
This API manages paid marketing campaigns created by providers or admins to promote trips.
- Creating ad campaigns linked to specific trips
- Setting budget, duration, and scheduling
- Processing upfront payments
- Tracking spend vs budget
- Managing status (نشطة / مجدولة / متوقفة / منتهية)
- Listing and filtering campaigns
This API powers the full UI of إدارة الإعلانات in the Provider Portal & Admin Panel.
2. Ad Campaign Lifecycle
UI Arabic Label → Enum mapping:
| Arabic UI Label | Internal Enum | Description |
|---|---|---|
| نشطة | ACTIVE | Campaign is running during the date range |
| مجدولة | SCHEDULED | Campaign created but start date is in the future |
| متوقفة | PAUSED | Manually paused by admin/provider |
| منتهية | ENDED | Campaign reached end date or budget is fully consumed |
Allowed transitions:
- SCHEDULED → ACTIVE (automatically when start_date arrives)
- ACTIVE → ENDED (automatically when end_date passes or budget is fully spent)
- ACTIVE → PAUSED (manual)
- PAUSED → ACTIVE (manual)
- Any → ENDED (forced by admin)
3. Endpoints
All endpoints follow the general rules in api-principles-and-versioning.md (pagination, errors, auth).
3.1 List Ad Campaigns (Provider)
/api/v1/provider/ad-campaignsAuth: Provider Admin / Provider Staff
| Parameter | Description |
|---|---|
| search | Optional free-text search (trip name, campaign name) |
| status | One of: ACTIVE, SCHEDULED, PAUSED, ENDED |
| trip_id | Filter by specific trip |
3.1.1 List Ad Campaigns (Admin)
/api/v1/admin/ad-campaignsSame filters and response shape as the provider endpoint, but across all providers.
3.2 Create Ad Campaign (Provider)
/api/v1/provider/ad-campaignsMatches UI modal "إنشاء حملة إعلانية".
- Payment is always upfront.
- VAT is shown as 20% in the UI; this conflicts with the general 15% VAT assumption and is explicitly tracked in open-questions-and-assumptions.md.
3.3 Update Campaign (Provider)
/api/v1/provider/ad-campaigns/{id}Updates are allowed only before the campaign starts (i.e. while status = SCHEDULED).
If status != SCHEDULED → returns CAMPAIGN_NOT_EDITABLE error.
3.4 Change Campaign Status
/api/v1/provider/ad-campaigns/{id}/pausePause
/api/v1/provider/ad-campaigns/{id}/resumeActivate (Resume)
/api/v1/admin/ad-campaigns/{id}/endForce End (Admin only)
3.5 Delete Campaign (Provider)
/api/v1/provider/ad-campaigns/{id}Matches UI modal "حذف الحملة الإعلانية!".
Rules:
- Only allowed if status IN (SCHEDULED, PAUSED)
- Campaign must not have started or spent any money
4. Billing & Payment API (for Ad Campaigns)
Actual payment integrations are described in integrations-hyperpay-stcpay-mada-applepay-maps-sms-email.md. This section focuses on the campaign-specific payment flows.
4.1 Initiate Payment Session
/api/v1/payments/ad-campaigns/sessionUsed internally when creating a paid campaign.
4.2 Payment Callback
/api/v1/payments/ad-campaigns/callbackPayment provider → system notification.
System must update:
- Payment status
- Campaign record
- Financial reports (see payments-and-financials-api.md)
5. Spend Tracking API (Internal)
Triggered by periodic cron (Node.js scheduled jobs).
/api/v1/internal/ad-campaigns/update-spendLogic (current phase):
- Pull spend data (manually simulated for now)
- Update spent amount
- If spent ≥ budget → auto-end campaign (status = ENDED)
6. Validation Rules
start_date < end_date. Duration must be a positive number of days.
Provider can only create campaigns for their own trips.
UI slider minimum must match backend: minimum 100 SAR.
Campaign cannot be saved/activated unless payment succeeds.
7. Error Cases
TRIP_ALREADY_HAS_ACTIVE_CAMPAIGNUNSUPPORTED_PAYMENT_METHODVAT_RATE_INCONSISTENT_WITH_SYSTEMVAT discrepancy is flagged but allowed (pending final business decision)
8. Permissions Summary (High-Level)
| Action | Provider Admin | Provider Staff | Admin | Super Admin |
|---|---|---|---|---|
| Create campaign | ✔️ | ✔️ | ✔️ | ✔️ |
| Update campaign | ✔️ | ✔️ | ✔️ | ✔️ |
| Pause/resume campaign | ✔️ | ✔️ | ✔️ | ✔️ |
| Delete campaign | ✔️ | ✔️ | ✔️ | ✔️ |
| Force end campaign | ❌ | ❌ | ✔️ | ✔️ |
| View all providers' campaigns | ❌ | ❌ | ✔️ | ✔️ |
Full details in 08-rbac/roles-and-permissions-matrix.md