masaruk Logo

analysis/04-functional-spec/ad-campaigns-module.md

Ad Campaigns

Ad Campaigns Module – Functional Specification

1. Purpose

The Ad Campaigns Module allows providers to create paid promotional campaigns for their trips. A campaign is linked to a single trip and requires immediate online payment to activate it.

This module manages:

  • Creating an ad campaign
  • Setting budget and campaign duration
  • Payment flow
  • Campaign lifecycle (scheduled, active, stopped, ended)
  • Reporting financial outcomes

4. Ad Campaign Entity Fields

FieldTypeNotes
idPK
provider_idFK
trip_idFKTrip linked to campaign
budgetDecimalBudget amount
spentDecimalTotal spent amount
start_dateDate
end_dateDate
statusEnumActive / Scheduled / Paused / Ended
payment_transaction_idFKmandatory — campaign cannot exist without payment
created_attimestamp
updated_attimestamp

5. Statuses

ActiveScheduledPausedEnded
UI LabelEnumMeaning
ActiveACTIVECampaign running within date range
ScheduledSCHEDULEDStarts in the future
PausedPAUSEDManually paused by provider
EndedENDEDEnd date passed

6. Business Rules

BR-1. Mandatory payment to create a campaign

The UI forces payment immediately during campaign creation. No 'Save Draft', no campaign record unless payment is successful.

BR-2. Budget must be selected via slider

Budget is user-selected using a slider component. The final chosen number is stored as budget.

BR-3. Campaign can only target one trip

trip_id is required. Trips must be owned by provider and status = Active.

BR-4. Status lifecycle controlled by date + manual flags

  • If now < start_date → SCHEDULED
  • If start_date <= now <= end_date → ACTIVE
  • If manually paused → PAUSED
  • If now > end_date → ENDED

BR-5. Spent amount is read-only

Provider cannot modify spent — it's calculated by the advertising backend.

BR-6. Editing campaign

Only allowed fields: Dates, Budget, Pause/Resume. Trip cannot be changed after creation.

BR-7. Deleting campaign

Deletion not allowed if payment transaction exists AND is irreversible, or campaign is currently active. Soft-delete recommended.

BR-8. VAT inconsistency ⚠️

UI shows VAT = 20% for ad campaigns. Booking VAT = 15%. This is flagged as an open question.

7. Actions & Behaviors

A-1. Create Ad Campaign

Modal sections:

  1. Select Trip – dropdown
  2. Campaign Duration – start_date + end_date
  3. Set your campaign budget – slider
  4. Your ad preview – preview card
  5. Payment details – card entry fields
  6. Payment summary – budget + VAT 20% + total
  7. Pay [amount] – action creates campaign upon payment

Payment options:

  • Credit Card / Mada
  • STC Pay
  • SADAD

A-2. Edit Campaign

Provider can modify: Dates, Budget, Pause/Resume. Preview updates accordingly.

A-3. Delete Campaign

Triggered from table row. Confirmation modal required. Blocks if campaign active or financial lock exists.

8. Validation Rules

Required fields

  • trip_id
  • start_date
  • end_date
  • budget
  • card details (if payment via card)

Validation

  • Dates: end_date > start_date
  • Budget > 0
  • Card format (Luhn)
  • CVV (3–4 digits)
  • Name on card required

9. Error Cases

CaseMessage
Missing required fieldsPlease complete all required fields
Invalid cardCard details are incorrect
Payment failedPayment failed, please try again
Budget too lowPlease select a valid budget
Attempt to delete active campaignCannot delete an active campaign
Trip not foundCannot select this trip

11. Cross-Module Relations

  • Trip Module → campaign belongs to one trip
  • Financial Reports Module → VAT, totals, and transaction appear in reports
  • Payments Module → payment transaction generated
  • Provider Module → provider_id ensures ownership scope