Advertisement
ilyasbabu

PARTNER SWAGGER APIs

May 17th, 2024
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 29.62 KB | None | 0 0
  1. import sys
  2. import traceback
  3.  
  4. from django.core.exceptions import ValidationError
  5. from rest_framework.response import Response
  6. from rest_framework.views import APIView
  7.  
  8. from accounts.services.authentication import CustomBasicAuthentication
  9. from common.mixins import ExceptionHandlerMixin
  10. from common.services import create_log
  11.  
  12. from ..serializers.partner_enquiry import (
  13.     CRMViewAPISerializer,
  14.     CustomerDetailsAPISerializer,
  15.     FeasibilityCheckAPISerializer,
  16.     InstallationAPISerializer,
  17.     RaiseComplainAPISerializer,
  18.     RechargeAPISerializer,
  19.     SRDetailsGetAPISerializer,
  20.     AdlCustomerCheckAPISerializer,
  21. )
  22. from ..services.partner_enquiry import (
  23.     CustomException,
  24.     decrypt,
  25.     encrypt,
  26.     installation,
  27.     customer_details_get,
  28. )
  29. from drf_yasg.utils import swagger_auto_schema
  30.  
  31.  
  32. class InstallationAPI(ExceptionHandlerMixin, APIView):
  33.     """After getting the feasibility and payment confirmation from the customer,
  34.    This API is called to confirm that customer is ready to connect further for installation.
  35.    """
  36.  
  37.     authentication_classes = [CustomBasicAuthentication]
  38.  
  39.     permission_classes = []
  40.  
  41.     @swagger_auto_schema(
  42.         request_body=InstallationAPISerializer,
  43.         responses={
  44.             200: """{
  45.                        "data": {"status": "Success", "viProspectId": "ENQ-1"},
  46.                        "message": {"message": "", "code": "Success"},
  47.                    }"""
  48.         },
  49.     )
  50.     def post(self, request):
  51.  
  52.         try:
  53.             user = request.user
  54.             if not user or not user.is_authenticated:
  55.                 raise CustomException("FAILED", "Unauthorized Access")
  56.  
  57.             serializer = InstallationAPISerializer(data=decrypt(request.data["data"]))
  58.             serializer.is_valid()
  59.             if serializer.errors:
  60.                 error_list = [
  61.                     f"VALIDATIONERROR! {error}: {serializer.errors[error][0]}"
  62.                     for error in serializer.errors
  63.                 ]
  64.                 raise CustomException("RETRY", error_list[0])
  65.  
  66.             response_data = installation(user, **serializer.validated_data)
  67.             return Response(
  68.                 {
  69.                     "data": response_data,
  70.                     "message": {"message": "", "code": "Success"},
  71.                 }
  72.             )
  73.         except Exception as e:
  74.             code = "FAILED"
  75.             msg = "Something went wrong.Please contact the administrator."
  76.             error_info = "\n".join(traceback.format_exception(*sys.exc_info()))
  77.             print(error_info)
  78.             if isinstance(e, ValidationError):
  79.                 error_info = "\n".join(e.messages)
  80.                 code = "RETRY"
  81.                 msg = error_info
  82.             if isinstance(e, CustomException):
  83.                 code = e.args[0]
  84.                 msg = e.args[1]
  85.             create_log(
  86.                 action="VI Installation",
  87.                 action_details=f"VI Installation API ran into the following error.{error_info}",
  88.                 action_by="Anonymous User",
  89.                 log_type="ERROR",
  90.             )
  91.             return Response(
  92.                 status=406,
  93.                 data={"data": {}, "message": {"message": str(msg), "code": code}},
  94.             )
  95.  
  96.  
  97. class CustomerDetailsAPI(ExceptionHandlerMixin, APIView):
  98.     """Fetch Registered and Closed Customer details based on provided date."""
  99.  
  100.     authentication_classes = [CustomBasicAuthentication]
  101.  
  102.     permission_classes = []
  103.  
  104.     @swagger_auto_schema(
  105.         request_body=CustomerDetailsAPISerializer,
  106.         responses={
  107.             200: """{
  108.                        "data": [
  109.                                    {
  110.                                        "MSISDN": "8849574265",
  111.                                        "AccountNo": "1234567",
  112.                                        "Status ": "Registered",
  113.                                        "LastStatusDate": "21-12-2022 14:00:00",
  114.                                    },
  115.                                    {
  116.                                        "MSISDN": "8849574364",
  117.                                        "AccountNo": "1234568",
  118.                                        "Status ": "Closed",
  119.                                        "LastStatusDate": "01-01-2023 00:00:00",
  120.                                    },
  121.                                    {
  122.                                        "MSISDN": "8849574367",
  123.                                        "AccountNo": "1234566",
  124.                                        "Status ": "Closed",
  125.                                        "LastStatusDate": "02-01-2022 01:00:01",
  126.                                    },
  127.                                    {
  128.                                        "MSISDN": "8849574364",
  129.                                        "AccountNo": "1234564",
  130.                                        "Status ": "Registered",
  131.                                        "LastStatusDate": "02-08-2022 02:02:03",
  132.                                    },
  133.                                ],
  134.                        "message": {"message": "", "code": "Success"},
  135.                    }"""
  136.         },
  137.     )
  138.     def post(self, request):
  139.  
  140.         try:
  141.             user = request.user
  142.             if not user or not user.is_authenticated:
  143.                 raise CustomException("FAILED", "Unauthorized Access")
  144.  
  145.             serializer = CustomerDetailsAPISerializer(data=request.data)
  146.             serializer.is_valid()
  147.             if serializer.errors:
  148.                 error_list = [
  149.                     f"VALIDATIONERROR! {error}: {serializer.errors[error][0]}"
  150.                     for error in serializer.errors
  151.                 ]
  152.                 raise CustomException("RETRY", error_list[0])
  153.  
  154.             response_data = customer_details_get(user, **serializer.validated_data)
  155.             return Response(
  156.                 {
  157.                     "data": response_data,
  158.                     "message": {"message": "", "code": "Success"},
  159.                 }
  160.             )
  161.         except Exception as e:
  162.             code = "FAILED"
  163.             msg = "Something went wrong.Please contact the administrator."
  164.             error_info = "\n".join(traceback.format_exception(*sys.exc_info()))
  165.             print(error_info)
  166.             if isinstance(e, ValidationError):
  167.                 error_info = "\n".join(e.messages)
  168.                 code = "RETRY"
  169.                 msg = error_info
  170.             if isinstance(e, CustomException):
  171.                 code = e.args[0]
  172.                 msg = e.args[1]
  173.             create_log(
  174.                 action="VI Customer Detail",
  175.                 action_details=f"VI Customer Detail API ran into the following error.{error_info}",
  176.                 action_by="Anonymous User",
  177.                 log_type="ERROR",
  178.             )
  179.             return Response(
  180.                 {"data": {}, "message": {"message": str(msg), "code": code}}
  181.             )
  182.  
  183.  
  184. class RechargeAPI(ExceptionHandlerMixin, APIView):
  185.     """API to Initiate payment based on given account no, plan poid,
  186.    mast online plan poid, payment  amount and merchant trans id.
  187.    It will return unique YOUBB order Id."""
  188.  
  189.     authentication_classes = [CustomBasicAuthentication]
  190.  
  191.     permission_classes = []
  192.  
  193.     @swagger_auto_schema(
  194.         request_body=RechargeAPISerializer,
  195.         responses={
  196.             200: """{
  197.                        "data":{
  198.                                    "paymentStatus": "SUCCESS",
  199.                                    "youBBorderId": "10859125",
  200.                                    "planPoid": "1415188680",
  201.                                    "merchantOrderId": "1415179779",
  202.                                },
  203.                        "message": {"message": "", "code": "Success"},
  204.                    }"""
  205.         },
  206.     )
  207.     def post(self, request):
  208.  
  209.         try:
  210.             user = request.user
  211.             if not user or not user.is_authenticated:
  212.                 raise CustomException("FAILED", "Unauthorized Access")
  213.  
  214.             serializer = RechargeAPISerializer(data=request.data)
  215.             serializer.is_valid()
  216.             if serializer.errors:
  217.                 error_list = [
  218.                     f"VALIDATIONERROR! {error}: {serializer.errors[error][0]}"
  219.                     for error in serializer.errors
  220.                 ]
  221.                 raise CustomException("RETRY", error_list[0])
  222.  
  223.             response_data = {
  224.                 "paymentStatus": "SUCCESS",
  225.                 "youBBorderId": "10859125",
  226.                 "planPoid": "1415188680",
  227.                 "merchantOrderId": "1415179779",
  228.             }
  229.             return Response(
  230.                 {
  231.                     "data": response_data,
  232.                     "message": {"message": "", "code": "Success"},
  233.                 }
  234.             )
  235.         except Exception as e:
  236.             code = "FAILED"
  237.             msg = "Something went wrong.Please contact the administrator."
  238.             error_info = "\n".join(traceback.format_exception(*sys.exc_info()))
  239.             print(error_info)
  240.             if isinstance(e, ValidationError):
  241.                 error_info = "\n".join(e.messages)
  242.                 code = "RETRY"
  243.                 msg = error_info
  244.             if isinstance(e, CustomException):
  245.                 code = e.args[0]
  246.                 msg = e.args[1]
  247.             create_log(
  248.                 action="VI Recharge",
  249.                 action_details=f"VI Recharge API ran into the following error.{error_info}",
  250.                 action_by="Anonymous User",
  251.                 log_type="ERROR",
  252.             )
  253.             return Response(
  254.                 {"data": {}, "message": {"message": str(msg), "code": code}}
  255.             )
  256.  
  257.  
  258. class FeasibilityCheckAPI(ExceptionHandlerMixin, APIView):
  259.     """API to check the Feasibility of the lead generated."""
  260.  
  261.     authentication_classes = [CustomBasicAuthentication]
  262.  
  263.     permission_classes = []
  264.  
  265.     @swagger_auto_schema(
  266.         request_body=FeasibilityCheckAPISerializer,
  267.         responses={
  268.             200: """{
  269.                        "data":{
  270.                                    "prospectId": "123456789",
  271.                                    "IsFeasible": "Y",
  272.                                    "message": "Lead is generated.",
  273.                                },
  274.                        "message": {"message": "", "code": "Success"},
  275.                    }"""
  276.         },
  277.     )
  278.     def post(self, request):
  279.  
  280.         try:
  281.             user = request.user
  282.             if not user or not user.is_authenticated:
  283.                 raise CustomException("FAILED", "Unauthorized Access")
  284.  
  285.             serializer = FeasibilityCheckAPISerializer(data=request.data)
  286.             serializer.is_valid()
  287.             if serializer.errors:
  288.                 error_list = [
  289.                     f"VALIDATIONERROR! {error}: {serializer.errors[error][0]}"
  290.                     for error in serializer.errors
  291.                 ]
  292.                 raise CustomException("RETRY", error_list[0])
  293.             response_data = {
  294.                 "prospectId": "123456789",
  295.                 "IsFeasible": "Y",
  296.                 "message": "Lead is generated.",
  297.             }
  298.             return Response(
  299.                 {
  300.                     "data": response_data,
  301.                     "message": {"message": "", "code": "Success"},
  302.                 }
  303.             )
  304.         except Exception as e:
  305.             code = "FAILED"
  306.             msg = "Something went wrong.Please contact the administrator."
  307.             error_info = "\n".join(traceback.format_exception(*sys.exc_info()))
  308.             print(error_info)
  309.             if isinstance(e, ValidationError):
  310.                 error_info = "\n".join(e.messages)
  311.                 code = "RETRY"
  312.                 msg = error_info
  313.             if isinstance(e, CustomException):
  314.                 code = e.args[0]
  315.                 msg = e.args[1]
  316.             create_log(
  317.                 action="VI Feasibility Check",
  318.                 action_details=f"VI Feasibility Check API ran into the following error.{error_info}",
  319.                 action_by="Anonymous User",
  320.                 log_type="ERROR",
  321.             )
  322.             return Response(
  323.                 {"data": {}, "message": {"message": str(msg), "code": code}}
  324.             )
  325.  
  326.  
  327. class CRMViewAPI(ExceptionHandlerMixin, APIView):
  328.     """API to Fetch Customer’s account details who is on convergent plan"""
  329.  
  330.     authentication_classes = [CustomBasicAuthentication]
  331.  
  332.     permission_classes = []
  333.  
  334.     @swagger_auto_schema(
  335.         request_body=CRMViewAPISerializer,
  336.         responses={
  337.             200: """{
  338.                        "data":{
  339.                        "MSISDN": "8849574256",
  340.                        "IsExistingMember": "Y",
  341.                        "customerDetails": {
  342.                            "customerName": "Ravi Kumar",
  343.                            "accountNumber": "2694963",
  344.                            "userId": "",
  345.                            "registeredNumber": "7016655858",
  346.                            "registeredEmailId": "ravikumar@gmail.com",
  347.                            "installedCity": "",
  348.                            "installationAddress": "",
  349.                            "dateOfInstallation": "",
  350.                            "accountStatus": "",
  351.                            "planName": "10053/YOU JACKAL/10Mbps-1Mbps/300GB/3Months/Rs1859",
  352.                            "planValidity": "-90",
  353.                            "balance": {"mbBalance": "307200.0", "dayBalance": "90.0"},
  354.                            "dateOfLastRenewal": "",
  355.                            "framedIPStatus": "",
  356.                        },
  357.                        "installationStatus": {},
  358.                    },
  359.                        "message": {"message": "", "code": "Success"},
  360.                    }"""
  361.         },
  362.     )
  363.     def post(self, request):
  364.  
  365.         try:
  366.             user = request.user
  367.             if not user or not user.is_authenticated:
  368.                 raise CustomException("FAILED", "Unauthorized Access")
  369.  
  370.             serializer = CRMViewAPISerializer(data=request.data)
  371.             serializer.is_valid()
  372.             if serializer.errors:
  373.                 error_list = [
  374.                     f"VALIDATIONERROR! {error}: {serializer.errors[error][0]}"
  375.                     for error in serializer.errors
  376.                 ]
  377.                 raise CustomException("RETRY", error_list[0])
  378.             response_data = {
  379.                 "MSISDN": "8849574256",
  380.                 "IsExistingMember": "Y",
  381.                 "customerDetails": {
  382.                     "customerName": "Ravi Kumar",
  383.                     "accountNumber": "2694963",
  384.                     "userId": "",
  385.                     "registeredNumber": "7016655858",
  386.                     "registeredEmailId": "ravikumar@gmail.com",
  387.                     "installedCity": "",
  388.                     "installationAddress": "",
  389.                     "dateOfInstallation": "",
  390.                     "accountStatus": "",
  391.                     "planName": "10053/YOU JACKAL/10Mbps-1Mbps/300GB/3Months/Rs1859",
  392.                     "planValidity": "-90",
  393.                     "balance": {"mbBalance": "307200.0", "dayBalance": "90.0"},
  394.                     "dateOfLastRenewal": "",
  395.                     "framedIPStatus": "",
  396.                 },
  397.                 "installationStatus": {},
  398.             }
  399.             return Response(
  400.                 {
  401.                     "data": response_data,
  402.                     "message": {"message": "", "code": "Success"},
  403.                 }
  404.             )
  405.         except Exception as e:
  406.             code = "FAILED"
  407.             msg = "Something went wrong.Please contact the administrator."
  408.             error_info = "\n".join(traceback.format_exception(*sys.exc_info()))
  409.             print(error_info)
  410.             if isinstance(e, ValidationError):
  411.                 error_info = "\n".join(e.messages)
  412.                 code = "RETRY"
  413.                 msg = error_info
  414.             if isinstance(e, CustomException):
  415.                 code = e.args[0]
  416.                 msg = e.args[1]
  417.             create_log(
  418.                 action="VI CRM View",
  419.                 action_details=f"VI CRM View API ran into the following error.{error_info}",
  420.                 action_by="Anonymous User",
  421.                 log_type="ERROR",
  422.             )
  423.             return Response(
  424.                 {"data": {}, "message": {"message": str(msg), "code": code}}
  425.             )
  426.  
  427.  
  428. class SRDetailsGetAPI(ExceptionHandlerMixin, APIView):
  429.     """API to Fetch Customer’s account details who is on convergent plan"""
  430.  
  431.     authentication_classes = [CustomBasicAuthentication]
  432.  
  433.     permission_classes = []
  434.  
  435.     @swagger_auto_schema(
  436.         request_body=SRDetailsGetAPISerializer,
  437.         responses={
  438.             200: """{
  439.                        "data":{
  440.                            "SRValues": [
  441.                                {
  442.                                    "srID": "2023060129880",
  443.                                    "customerName": "SAGAR KHATRI ",
  444.                                    "subProcessCode": "4.K",
  445.                                    "description": "ViTopazComplaint",
  446.                                    "SRStatus": "Pending",
  447.                                    "SRDate": "01-Jun-2023 13:06",
  448.                                },
  449.                                {
  450.                                    "srID": "2023053129869",
  451.                                    "customerName": "SAGAR KHATRI ",
  452.                                    "subProcessCode": "2.D",
  453.                                    "description": "ViTopazComplaint",
  454.                                    "SRStatus": "Closed",
  455.                                    "SRDate": "31-May-2023 10:55",
  456.                                },
  457.                            ]
  458.                        },
  459.                        "message": {"message": "", "code": "Success"},
  460.                    }"""
  461.         },
  462.     )
  463.     def post(self, request):
  464.  
  465.         try:
  466.             user = request.user
  467.             if not user or not user.is_authenticated:
  468.                 raise CustomException("FAILED", "Unauthorized Access")
  469.  
  470.             serializer = SRDetailsGetAPISerializer(data=request.data)
  471.             serializer.is_valid()
  472.             if serializer.errors:
  473.                 error_list = [
  474.                     f"VALIDATIONERROR! {error}: {serializer.errors[error][0]}"
  475.                     for error in serializer.errors
  476.                 ]
  477.                 raise CustomException("RETRY", error_list[0])
  478.             response_data = {
  479.                 "SRValues": [
  480.                     {
  481.                         "srID": "2023060129880",
  482.                         "customerName": "SAGAR KHATRI ",
  483.                         "subProcessCode": "4.K",
  484.                         "description": "ViTopazComplaint",
  485.                         "SRStatus": "Pending",
  486.                         "SRDate": "01-Jun-2023 13:06",
  487.                     },
  488.                     {
  489.                         "srID": "2023053129869",
  490.                         "customerName": "SAGAR KHATRI ",
  491.                         "subProcessCode": "2.D",
  492.                         "description": "ViTopazComplaint",
  493.                         "SRStatus": "Closed",
  494.                         "SRDate": "31-May-2023 10:55",
  495.                     },
  496.                 ]
  497.             }
  498.             return Response(
  499.                 {
  500.                     "data": response_data,
  501.                     "message": {"message": "", "code": "Success"},
  502.                 }
  503.             )
  504.         except Exception as e:
  505.             code = "FAILED"
  506.             msg = "Something went wrong.Please contact the administrator."
  507.             error_info = "\n".join(traceback.format_exception(*sys.exc_info()))
  508.             print(error_info)
  509.             if isinstance(e, ValidationError):
  510.                 error_info = "\n".join(e.messages)
  511.                 code = "RETRY"
  512.                 msg = error_info
  513.             if isinstance(e, CustomException):
  514.                 code = e.args[0]
  515.                 msg = e.args[1]
  516.             create_log(
  517.                 action="VI SR Details",
  518.                 action_details=f"VI SR Details API ran into the following error.{error_info}",
  519.                 action_by="Anonymous User",
  520.                 log_type="ERROR",
  521.             )
  522.             return Response(
  523.                 {"data": {}, "message": {"message": str(msg), "code": code}}
  524.             )
  525.  
  526.  
  527. class RaiseComplainAPI(ExceptionHandlerMixin, APIView):
  528.     """Convergent customer can raise complaint if facing any issue with Adl Broadband."""
  529.  
  530.     authentication_classes = [CustomBasicAuthentication]
  531.  
  532.     permission_classes = []
  533.  
  534.     @swagger_auto_schema(
  535.         request_body=RaiseComplainAPISerializer,
  536.         responses={
  537.             200: """{
  538.                        "data":{
  539.                            "outageavail": "True",
  540.                            "outageval": {
  541.                                "outageId": "",
  542.                                "downtime": "",
  543.                                "city": "",
  544.                                "node": "",
  545.                                "area": "",
  546.                                "comments": "",
  547.                                "exp_up_time": "",
  548.                                "status": "",
  549.                                "act_up_time": "",
  550.                                "up_comment": "",
  551.                                "down_uid": "",
  552.                                "up_uid": "",
  553.                                "actdowntime": "",
  554.                                "oms_id": "",
  555.                                "reason": "",
  556.                                "cust_affected": "",
  557.                                "hrs": "24 ",
  558.                                "mins": "",
  559.                            },
  560.                            "compgenerate": "False",
  561.                            "complainId": "",
  562.                            "message": "Outage in Area",
  563.                        },
  564.                        "message": {"message": "", "code": "Success"},
  565.                    }"""
  566.         },
  567.     )
  568.     def post(self, request):
  569.  
  570.         try:
  571.             user = request.user
  572.             if not user or not user.is_authenticated:
  573.                 raise CustomException("FAILED", "Unauthorized Access")
  574.  
  575.             serializer = RaiseComplainAPISerializer(data=request.data)
  576.             serializer.is_valid()
  577.             if serializer.errors:
  578.                 error_list = [
  579.                     f"VALIDATIONERROR! {error}: {serializer.errors[error][0]}"
  580.                     for error in serializer.errors
  581.                 ]
  582.                 raise CustomException("RETRY", error_list[0])
  583.             response_data = {
  584.                 "outageavail": "True",
  585.                 "outageval": {
  586.                     "outageId": "",
  587.                     "downtime": "",
  588.                     "city": "",
  589.                     "node": "",
  590.                     "area": "",
  591.                     "comments": "",
  592.                     "exp_up_time": "",
  593.                     "status": "",
  594.                     "act_up_time": "",
  595.                     "up_comment": "",
  596.                     "down_uid": "",
  597.                     "up_uid": "",
  598.                     "actdowntime": "",
  599.                     "oms_id": "",
  600.                     "reason": "",
  601.                     "cust_affected": "",
  602.                     "hrs": "24 ",
  603.                     "mins": "",
  604.                 },
  605.                 "compgenerate": "False",
  606.                 "complainId": "",
  607.                 "message": "Outage in Area",
  608.             }
  609.             return Response(
  610.                 {
  611.                     "data": response_data,
  612.                     "message": {"message": "", "code": "Success"},
  613.                 }
  614.             )
  615.         except Exception as e:
  616.             code = "FAILED"
  617.             msg = "Something went wrong.Please contact the administrator."
  618.             error_info = "\n".join(traceback.format_exception(*sys.exc_info()))
  619.             print(error_info)
  620.             if isinstance(e, ValidationError):
  621.                 error_info = "\n".join(e.messages)
  622.                 code = "RETRY"
  623.                 msg = error_info
  624.             if isinstance(e, CustomException):
  625.                 code = e.args[0]
  626.                 msg = e.args[1]
  627.             create_log(
  628.                 action="VI Raise Complain",
  629.                 action_details=f"VI Raise Complain API ran into the following error.{error_info}",
  630.                 action_by="Anonymous User",
  631.                 log_type="ERROR",
  632.             )
  633.             return Response(
  634.                 {"data": {}, "message": {"message": str(msg), "code": code}}
  635.             )
  636.  
  637.  
  638. class AdlCustomerCheckAPI(ExceptionHandlerMixin, APIView):
  639.     """Fetch Customer details of Adl based on given account no,username or mobileno."""
  640.  
  641.     authentication_classes = [CustomBasicAuthentication]
  642.  
  643.     permission_classes = []
  644.  
  645.     @swagger_auto_schema(
  646.         request_body=AdlCustomerCheckAPISerializer,
  647.         responses={
  648.             200: """{
  649.                        "data":{
  650.                            "MSISDN": "8849574256",
  651.                            "IsExistingMember": "Y",
  652.                            "customerDetails": [
  653.                                {
  654.                                    "accountNo": "2694963",
  655.                                    "name": "WOLF GREY",
  656.                                    "plan": "10053/YOU JACKAL/10Mbps-1Mbps/300GB/3Months/Rs1859",
  657.                                    "planDescription": "YOU JACKAL 300 GB 3 Months",
  658.                                    "planValidity": "-90",
  659.                                    "planMB": "2048",
  660.                                    "bandwidth": "102399",
  661.                                    "lowerBandwidth": "208",
  662.                                    "status": "INSERVICE",
  663.                                    "rcTag": "MBNOCF",
  664.                                    "city": "SURAT",
  665.                                    "suspendedDays": "0",
  666.                                    "balance": {
  667.                                        "mbBalance": "307200.0",
  668.                                        "hourBalance": "0",
  669.                                        "dayBalance": "90.0",
  670.                                    },
  671.                                    "isCurrentPlanRenewable": "true",
  672.                                    "currentPlanPoid": "1412875777",
  673.                                    "subscriptionAmt": "2500",
  674.                                    "RBSQueue": {},
  675.                                }
  676.                            ],
  677.                        },
  678.                        "message": {"message": "", "code": "Success"},
  679.                    }"""
  680.         },
  681.     )
  682.     def post(self, request):
  683.  
  684.         try:
  685.             user = request.user
  686.             if not user or not user.is_authenticated:
  687.                 raise CustomException("FAILED", "Unauthorized Access")
  688.  
  689.             serializer = AdlCustomerCheckAPISerializer(data=request.data)
  690.             serializer.is_valid()
  691.             if serializer.errors:
  692.                 error_list = [
  693.                     f"VALIDATIONERROR! {error}: {serializer.errors[error][0]}"
  694.                     for error in serializer.errors
  695.                 ]
  696.                 raise CustomException("RETRY", error_list[0])
  697.             response_data = {
  698.                 "MSISDN": "8849574256",
  699.                 "IsExistingMember": "Y",
  700.                 "customerDetails": [
  701.                     {
  702.                         "accountNo": "2694963",
  703.                         "name": "WOLF GREY",
  704.                         "plan": "10053/YOU JACKAL/10Mbps-1Mbps/300GB/3Months/Rs1859",
  705.                         "planDescription": "YOU JACKAL 300 GB 3 Months",
  706.                         "planValidity": "-90",
  707.                         "planMB": "2048",
  708.                         "bandwidth": "102399",
  709.                         "lowerBandwidth": "208",
  710.                         "status": "INSERVICE",
  711.                         "rcTag": "MBNOCF",
  712.                         "city": "SURAT",
  713.                         "suspendedDays": "0",
  714.                         "balance": {
  715.                             "mbBalance": "307200.0",
  716.                             "hourBalance": "0",
  717.                             "dayBalance": "90.0",
  718.                         },
  719.                         "isCurrentPlanRenewable": "true",
  720.                         "currentPlanPoid": "1412875777",
  721.                         "subscriptionAmt": "2500",
  722.                         "RBSQueue": {},
  723.                     }
  724.                 ],
  725.             }
  726.             encrypted_data = encrypt(response_data)
  727.             return Response(
  728.                 {
  729.                     "data": encrypted_data,
  730.                     "message": {"message": "", "code": "Success"},
  731.                 }
  732.             )
  733.         except Exception as e:
  734.             code = "FAILED"
  735.             msg = "Something went wrong.Please contact the administrator."
  736.             error_info = "\n".join(traceback.format_exception(*sys.exc_info()))
  737.             print(error_info)
  738.             if isinstance(e, ValidationError):
  739.                 error_info = "\n".join(e.messages)
  740.                 code = "RETRY"
  741.                 msg = error_info
  742.             if isinstance(e, CustomException):
  743.                 code = e.args[0]
  744.                 msg = e.args[1]
  745.             create_log(
  746.                 action="VI Adl Check",
  747.                 action_details=f"VI Adl Check API ran into the following error.{error_info}",
  748.                 action_by="Anonymous User",
  749.                 log_type="ERROR",
  750.             )
  751.             return Response(
  752.                 {"data": {}, "message": {"message": str(msg), "code": code}}
  753.             )
  754.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement