Mbonea commited on
Commit
27be269
·
1 Parent(s): b856986

semi-complete

Browse files
App/Users/UserRoutes.py CHANGED
@@ -31,8 +31,8 @@ async def register_user(user: RegisterUserRequest):
31
  existing_user = await User.filter(phoneNumber=user.phoneNumber).first()
32
  if existing_user:
33
  raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="User already exists.")
34
-
35
  user.hash_password()
 
36
  new_user = await User.create(**user.dict())
37
  return BaseResponse(code=200, message="User created successfully", payload={"user_id": new_user.id})
38
 
 
31
  existing_user = await User.filter(phoneNumber=user.phoneNumber).first()
32
  if existing_user:
33
  raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="User already exists.")
 
34
  user.hash_password()
35
+
36
  new_user = await User.create(**user.dict())
37
  return BaseResponse(code=200, message="User created successfully", payload={"user_id": new_user.id})
38
 
App/Users/utils.py ADDED
File without changes
App/Webhooks/webhookRoute.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Request, HTTPException,APIRouter
2
+ from pydantic import BaseModel
3
+
4
+
5
+ webhook_router = APIRouter(tags=["Webhooks"])
6
+
7
+ WEBHOOK_SECRET = "your_webhook_secret" # Replace with your secret
8
+
9
+ class WebhookPayload(BaseModel):
10
+ event: str
11
+ data: dict
12
+
13
+ # Endpoint to receive webhook events
14
+ @webhook_router.post("/webhook/sms_received/")
15
+ async def handle_webhook(request: Request):
16
+
17
+
18
+ # Parse the webhook payload
19
+ payload = await request.json()
20
+ event = payload.get("event")
21
+ data = payload.get("data")
22
+
23
+ # Handle different event types
24
+ if event == "payment_success":
25
+ # Process payment success
26
+ print("Payment was successful:", data)
27
+ elif event == "user_registered":
28
+ # Process new user registration
29
+ print("New user registered:", data)
30
+ else:
31
+ print("Received unknown event:", event)
32
+
33
+ # Return a response
34
+ return {"status": "received"}
35
+
36
+ # # Optional: Verify the webhook signature
37
+ # def verify_signature(request: Request, signature: str) -> bool:
38
+ # if not signature:
39
+ # return False
40
+ # body = await request.body()
41
+ # computed_signature = hmac.new(
42
+ # WEBHOOK_SECRET.encode(),
43
+ # body,
44
+ # hashlib.sha256
45
+ # ).hexdigest()
46
+ # return hmac.compare_digest(computed_signature, signature)
App/app.py CHANGED
@@ -1,6 +1,7 @@
1
  from fastapi import FastAPI
2
  from tortoise import Tortoise, run_async
3
  from .Users.UserRoutes import user_router
 
4
  from .modelInit import TORTOISE_ORM
5
 
6
  app = FastAPI()
@@ -18,7 +19,7 @@ async def landing_page():
18
 
19
 
20
  app.include_router(user_router)
21
-
22
 
23
 
24
  async def main():
 
1
  from fastapi import FastAPI
2
  from tortoise import Tortoise, run_async
3
  from .Users.UserRoutes import user_router
4
+ from .Webhooks.webhookRoute import webhook_router
5
  from .modelInit import TORTOISE_ORM
6
 
7
  app = FastAPI()
 
19
 
20
 
21
  app.include_router(user_router)
22
+ app.include_router(webhook_router)
23
 
24
 
25
  async def main():
App/modelInit.py CHANGED
@@ -1,4 +1,7 @@
1
  from App.discovery import discover_models
 
 
 
2
 
3
  DATABASE_URL = "sqlite://db.sqlite3" # Example: SQLite for local development
4
 
@@ -12,24 +15,4 @@ TORTOISE_ORM = {
12
  },
13
  }
14
 
15
- # HOST=aws.connect.psdb.cloud
16
- # USERNAME=kn9rzjlad1tw8bvojqg9
17
- # PASSWORD=pscale_pw_hSBO8rcekvnQp74bezC9gjnShhAWgkJYUS8GjGdrBKn
18
- # DATABASE=movie-website
19
-
20
-
21
- # database = databases.Database(
22
- # "postgresql+asyncpg://postgres:[email protected]:5432/postgres"
23
- # )
24
- # database = databases.Database(
25
- # "postgresql+asyncpg://user:password@db:5432/mydatabase"
26
- # )
27
-
28
- # #mysql
29
- # database = databases.Database(
30
- # 'mysql+asyncmy://kn9rzjlad1tw8bvojqg9:pscale_pw_hSBO8rcekvnQp74bezC9gjnShhAWgkJYUS8GjGdrBKn@aws.connect.psdb.cloud/movie-website'
31
- # ,)
32
-
33
-
34
- # databases = databases.Database(**args)
35
 
 
1
  from App.discovery import discover_models
2
+ import asyncio
3
+
4
+
5
 
6
  DATABASE_URL = "sqlite://db.sqlite3" # Example: SQLite for local development
7
 
 
15
  },
16
  }
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18