Skip to content

SrotDev/service_pledge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pledge Service

Microservice managing donation pledges.

Models

Pledge:

  • id (UUID pk)
  • campaign_id (UUID)
  • user_id (UUID nullable, set from JWT claim user_uuid)
  • guest_name / guest_phone (nullable; required for guest pledges)
  • amount (Decimal 12,2)
  • status (pending|paid|failed)
  • idempotency_key (string, unique)
  • created_at (timestamp)

JWT

Uses rest_framework_simplejwt (shared secret). Pledge creation derives user_id from claim user_uuid. Guests omit Authorization and must provide guest_name and guest_phone.

Endpoints

Base path: /api/

POST /api/pledges/ Create pledge (idempotent via idempotency_key). Body fields:

{
  "campaign_id": "<uuid>",
  "amount": "100.00",
  "idempotency_key": "unique-client-generated-key",
  "guest_name": "Alice",      # required if no JWT
  "guest_phone": "+123456"    # required if no JWT
}

Returns existing pledge if idempotency_key already used.

GET /api/pledges/ List pledges. GET /api/pledges/{id}/ Retrieve pledge. POST /api/pledges/{id}/mark-paid/ Transition to paid. POST /api/pledges/{id}/mark-failed/ Transition to failed.

Installation & Setup

pip install -r requirements.txt
python manage.py makemigrations
python manage.py migrate
python manage.py runserver 8002

Creating a Pledge

Authenticated user:

curl -X POST http://127.0.0.1:8002/api/pledges/ \
  -H "Authorization: Bearer <TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{"campaign_id":"<uuid>","amount":"250.00","idempotency_key":"k-123"}'

Guest user:

curl -X POST http://127.0.0.1:8002/api/pledges/ \
  -H "Content-Type: application/json" \
  -d '{"campaign_id":"<uuid>","amount":"50.00","idempotency_key":"g-456","guest_name":"Bob","guest_phone":"+555"}'

Mark Paid

curl -X POST http://127.0.0.1:8002/api/pledges/<pledge_uuid>/mark-paid/ \
  -H "Authorization: Bearer <TOKEN>"

Notes

  • Idempotent creation ensures clients can safely retry.
  • Extend with validations (e.g. amount > 0) or guest rate limiting as needed.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published