Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
allow_origins=[
"http://localhost:3000",
"http://127.0.0.1:3000",
"http://localhost:5173",
"http://127.0.0.1:5173",
"http://localhost:5000",
"http://127.0.0.1:5000",
],
allow_credentials=True,
allow_methods=["*"],
Expand Down
4 changes: 0 additions & 4 deletions app/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ async def verify_staff_access(token: str):
status.HTTP_200_OK,
"Verified",
role=data.get("role"),
stall_id=data.get("stall_id"),
college_id=data.get("college_id")
)

college_id, _ = _get_college_by_domain(email)
Expand Down Expand Up @@ -141,8 +139,6 @@ async def verify_staff_access(token: str):
status.HTTP_200_OK,
"Manager account initialized",
role="manager",
stall_id=found_stall.id,
college_id=college_id
)

return _create_response(
Expand Down
44 changes: 34 additions & 10 deletions app/webhook.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@

# app/webhook.py

import os
import hmac
import hashlib
import random
from fastapi import APIRouter, Request, HTTPException
from firebase_admin import firestore
from .firebase_init import db

router = APIRouter()


@router.post("/webhook/razorpay", tags=["webhook"])
async def razorpay_webhook(request: Request):
signature = request.headers.get('X-Razorpay-Signature')
secret = os.environ.get("RAZORPAY_WEBHOOK_SECRET")
body = await request.body()

try:

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 2 spaces, expected 4 (bad-indentation) Warning

Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
expected_signature = hmac.new(
key=secret.encode(),
msg=body,
Expand All @@ -41,14 +40,39 @@

if internal_order_id:
order_ref = db.collection('orders').document(internal_order_id)
order_ref.update({
"status": "PAID",
"payment_id": payment_id,
"razorpay_payment_data": payment,
"updated_at": firestore.SERVER_TIMESTAMP
})
print(f"✅ Order {internal_order_id} marked as PAID")

transaction = db.transaction()

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 (bad-indentation) Warning

Bad indentation. Found 6 spaces, expected 12 (bad-indentation)

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 2 spaces). Warning

Wrong hanging indentation (add 2 spaces).
@firestore.transactional

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 2 spaces). Warning

Wrong hanging indentation (add 2 spaces).

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 (bad-indentation) Warning

Bad indentation. Found 6 spaces, expected 12 (bad-indentation)
def update_in_transaction(transaction, order_ref):

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 2 spaces). Warning

Wrong hanging indentation (add 2 spaces).

Check warning

Code scanning / Pylint (reported by Codacy)

Missing function docstring Warning

Missing function docstring

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 (bad-indentation) Warning

Bad indentation. Found 6 spaces, expected 12 (bad-indentation)
snapshot = order_ref.get(transaction=transaction)

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 2 spaces). Warning

Wrong hanging indentation (add 2 spaces).

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 Note

Bad indentation. Found 8 spaces, expected 16

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 Note

Bad indentation. Found 8 spaces, expected 16

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 (bad-indentation) Warning

Bad indentation. Found 8 spaces, expected 16 (bad-indentation)
if not snapshot.exists:

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 Note

Bad indentation. Found 8 spaces, expected 16

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 Note

Bad indentation. Found 8 spaces, expected 16

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 (bad-indentation) Warning

Bad indentation. Found 8 spaces, expected 16 (bad-indentation)
print(f"❌ Order {internal_order_id} not found!")

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 10 spaces, expected 20 Note

Bad indentation. Found 10 spaces, expected 20

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 10 spaces, expected 20 Note

Bad indentation. Found 10 spaces, expected 20

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 10 spaces, expected 20 (bad-indentation) Warning

Bad indentation. Found 10 spaces, expected 20 (bad-indentation)
return

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 10 spaces, expected 20 Note

Bad indentation. Found 10 spaces, expected 20

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 10 spaces, expected 20 Note

Bad indentation. Found 10 spaces, expected 20

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 10 spaces, expected 20 (bad-indentation) Warning

Bad indentation. Found 10 spaces, expected 20 (bad-indentation)

current_data = snapshot.to_dict()

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 Note

Bad indentation. Found 8 spaces, expected 16

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 Note

Bad indentation. Found 8 spaces, expected 16

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 (bad-indentation) Warning

Bad indentation. Found 8 spaces, expected 16 (bad-indentation)

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 2 spaces, expected 4 Note

Bad indentation. Found 2 spaces, expected 4

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 2 spaces, expected 4 Note

Bad indentation. Found 2 spaces, expected 4

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 2 spaces, expected 4 (bad-indentation) Warning

Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
if current_data.get("status") == "PAID":

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 Note

Bad indentation. Found 8 spaces, expected 16

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 Note

Bad indentation. Found 8 spaces, expected 16

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 (bad-indentation) Warning

Bad indentation. Found 8 spaces, expected 16 (bad-indentation)
print(f"ℹ️ Order {internal_order_id} was already PAID. Skipping update.")

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 10 spaces, expected 20 Note

Bad indentation. Found 10 spaces, expected 20

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 10 spaces, expected 20 Note

Bad indentation. Found 10 spaces, expected 20

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 10 spaces, expected 20 (bad-indentation) Warning

Bad indentation. Found 10 spaces, expected 20 (bad-indentation)
return

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 10 spaces, expected 20 Note

Bad indentation. Found 10 spaces, expected 20

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 10 spaces, expected 20 Note

Bad indentation. Found 10 spaces, expected 20

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 10 spaces, expected 20 (bad-indentation) Warning

Bad indentation. Found 10 spaces, expected 20 (bad-indentation)

pickup_code = str(random.randint(1000, 9999))

Check warning on line 59 in app/webhook.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/webhook.py#L59

Standard pseudo-random generators are not suitable for security/cryptographic purposes.

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Variable name "e" doesn't conform to snake_case naming style Warning

Variable name "e" doesn't conform to snake_case naming style

Check warning

Code scanning / Pylint (reported by Codacy)

Variable name "e" doesn't conform to snake_case naming style Warning

Variable name "e" doesn't conform to snake_case naming style

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 Note

Bad indentation. Found 8 spaces, expected 16

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 Note

Bad indentation. Found 8 spaces, expected 16

Check notice

Code scanning / Bandit (reported by Codacy)

Standard pseudo-random generators are not suitable for security/cryptographic purposes. Note

Standard pseudo-random generators are not suitable for security/cryptographic purposes.

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 (bad-indentation) Warning

Bad indentation. Found 4 spaces, expected 8 (bad-indentation)

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 (bad-indentation) Warning

Bad indentation. Found 8 spaces, expected 16 (bad-indentation)

transaction.update(order_ref, {

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 Note

Bad indentation. Found 8 spaces, expected 16

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 Note

Bad indentation. Found 8 spaces, expected 16

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 (bad-indentation) Warning

Bad indentation. Found 8 spaces, expected 16 (bad-indentation)
"status": "PAID",
"payment_id": payment_id,
"razorpay_payment_data": payment,
"pickup_code": pickup_code,

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 2 spaces). Warning

Wrong hanging indentation (add 2 spaces).
"updated_at": firestore.SERVER_TIMESTAMP
})
print(f"✅ SUCCESS: Generated Pickup Code {pickup_code} for Order {internal_order_id}")

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 Note

Bad indentation. Found 8 spaces, expected 16

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 Note

Bad indentation. Found 8 spaces, expected 16

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 (bad-indentation) Warning

Bad indentation. Found 8 spaces, expected 16 (bad-indentation)

try:
update_in_transaction(transaction, order_ref)

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 Note

Bad indentation. Found 8 spaces, expected 16

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 Note

Bad indentation. Found 8 spaces, expected 16

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 (bad-indentation) Warning

Bad indentation. Found 8 spaces, expected 16 (bad-indentation)
except Exception as e:

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Catching too general exception Exception Note

Catching too general exception Exception

Check notice

Code scanning / Pylint (reported by Codacy)

Catching too general exception Exception Note

Catching too general exception Exception
print(f"❌ Transaction failed: {e}")

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 Note

Bad indentation. Found 8 spaces, expected 16

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 Note

Bad indentation. Found 8 spaces, expected 16

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 (bad-indentation) Warning

Bad indentation. Found 8 spaces, expected 16 (bad-indentation)

else:
print(f"⚠️ Payment received without internal_order_id: {payment['id']}")

return {"status": "ok"}
return {"status": "ok"}

Check warning

Code scanning / Pylint (reported by Codacy)

Final newline missing Warning

Final newline missing

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Final newline missing Warning

Final newline missing
Loading