Skip to content

Commit

Permalink
Merge pull request #2076 from gtech-mulearn/dev-server
Browse files Browse the repository at this point in the history
Prod: feat: Launchpad Dashboard
  • Loading branch information
Kochouseph26John authored Jun 17, 2024
2 parents 7b688d0 + ad0664f commit 26f71f4
Show file tree
Hide file tree
Showing 10 changed files with 482 additions and 39 deletions.
4 changes: 3 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ RAZORPAY_SECRET=

PROTECTED_API_KEY =

SYSTEM_ADMIN_ID =
SYSTEM_ADMIN_ID =

LAUNCHPAD_ADMIN_EMAIL =
35 changes: 35 additions & 0 deletions alter-scripts/alter-1.50.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
import sys
import uuid
from decouple import config
import django

from connection import execute

os.chdir('..')
sys.path.append(os.getcwd())
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mulearnbackend.settings')
django.setup()

from db.launchpad import LaunchPadUsers
from utils.types import LaunchPadRoles

def create_launchpad_admin():
query = f"SELECT id FROM launchpad_user WHERE email = '{config('LAUNCHPAD_ADMIN_EMAIL')}'"
if execute(query):
return
query = f"""
INSERT INTO launchpad_user (id, email, role, created_at, updated_at)
VALUES (
'{uuid.uuid4()}',
'{config('LAUNCHPAD_ADMIN_EMAIL')}',
'{LaunchPadRoles.ADMIN.value}',
UTC_TIMESTAMP,
UTC_TIMESTAMP
)
"""
execute(query)

if __name__ == '__main__':
create_launchpad_admin()
execute("UPDATE system_setting SET value = '1.50', updated_at = now() WHERE `key` = 'db.version';")
19 changes: 19 additions & 0 deletions api/donate/donate_serializer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import uuid

from rest_framework import serializers
from django.conf import settings

from db.donor import Donor
from utils.utils import DateTimeUtils


class DonorSerializer(serializers.ModelSerializer):

class Meta:
model = Donor
exclude = ['created_by', 'created_at', 'id']

def create(self, validated_data):
validated_data["created_by_id"] = settings.SYSTEM_ADMIN_ID
validated_data["id"] = uuid.uuid4()
return Donor.objects.create(**validated_data)
36 changes: 27 additions & 9 deletions api/donate/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import razorpay
from io import BytesIO
from reportlab.pdfgen import canvas

from django.http import HttpResponse
from rest_framework.views import APIView

from utils.response import CustomResponse
from .donate_serializer import DonorSerializer
from mulearnbackend.settings import RAZORPAY_ID, RAZORPAY_SECRET

from reportlab.lib.pagesizes import letter
Expand Down Expand Up @@ -65,20 +65,28 @@ def create_receipt(transaction_details):
class RazorPayOrderAPI(APIView):
def post(self, request):
try:
serializer = DonorSerializer(data=request.data)
if not serializer.is_valid():
return CustomResponse(general_message=serializer.errors).get_failure_response()
validated_data = serializer.validated_data

data = {
"amount": int(float(request.data.get("amount")) * 100),
"currency": request.data.get("currency", "INR"),
"amount": int(float(validated_data.get("amount")) * 100),
"currency": validated_data.get("currency"),
"payment_capture": 1,
"notes": {
"email": request.data.get("email"),
"name": request.data.get("name"),
"company": request.data.get("company", None),
"email": validated_data.get("email"),
"name": validated_data.get("name"),
"phone_number": validated_data.get("phone_number", None),
"company": validated_data.get("company", None),
"pan_number": validated_data.get("pan_number", None),
"validated_data": validated_data
},
}
order = razorpay_client.order.create(data)
return CustomResponse(response=order).get_success_response()
except razorpay.errors.BadRequestError as e:
return CustomResponse(message=str(e)).get_error_response()
return CustomResponse(message=str(e)).get_failure_response()


class RazorPayVerification(APIView):
Expand All @@ -101,8 +109,18 @@ def post(self, request):
"Currency": data['currency'],
"Name": data['notes']['name'],
"Email": data['notes']['email'],
"Company": data['notes']['company']
}
if extra_data := data['notes'].get('company', None):
transaction_details["Company"] = extra_data
if extra_data := data['notes'].get('phone_number', None):
transaction_details["Phone Number"] = extra_data
if extra_data := data['notes'].get('pan_number', None):
transaction_details["PAN number"] = extra_data

serializer = DonorSerializer(data=data['notes']['validated_data'])
# if serializer.is_valid():
# serializer.save()

return create_receipt(transaction_details)
except razorpay.errors.SignatureVerificationError as e:
return CustomResponse(message=str(e)).get_error_response()
return CustomResponse(message=str(e)).get_failure_response()
Loading

0 comments on commit 26f71f4

Please sign in to comment.