403Webshell
Server IP : 103.234.187.230  /  Your IP : 216.73.216.216
Web Server : Apache
System : Linux lserver42043-ind.megavelocity.net 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/api.hellogtx.com/apihellogtx/goflysmartapi/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/api.hellogtx.com/apihellogtx/goflysmartapi/views.py
from django.shortcuts import render
import requests
import datetime
import json
from django.http import Http404
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.status import (
    HTTP_400_BAD_REQUEST,
    HTTP_404_NOT_FOUND,
    HTTP_200_OK,
    HTTP_500_INTERNAL_SERVER_ERROR
)
from goflysmartapi.models import TbAgencyApiKey, TbAgencyApiToken
from goflysmartapi.serializers import TbAgencyApiTokenSerializer


class Login(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            api_source = request.data.get("api_source", None)
            if api_source == 'go_fly_smart' or api_source == 'air_iq':
                if api_source == 'air_iq':
                    TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=4,
                                                                        SecurityKey=Security_Key).first()
                    url = "https://omairiq.azurewebsites.net/login"
                    payload = json.dumps({
                        "Username": TbAgencyApiKeyArray.UserName,
                        "Password": TbAgencyApiKeyArray.SecretKey
                    })
                else:
                    TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=3,
                                                                        SecurityKey=Security_Key).first()
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://goflysmartapi.azure-api.net/prod/api/login"
                    else:
                        url = "https://goflysmartapi.azure-api.net/uat/api/login"
                    payload = json.dumps({
                        "email": TbAgencyApiKeyArray.UserName,
                        "password": TbAgencyApiKeyArray.SecretKey
                    })
                if TbAgencyApiKeyArray is not None:
                    headers = {
                        'api-key': TbAgencyApiKeyArray.ClientCode,
                        'Content-Type': 'application/json'
                    }
                    try:
                        response = requests.request("POST", url, headers=headers, data=payload)
                        x = response.text
                        json_data = json.loads(x)
                        if api_source == 'air_iq':
                            token = json_data.get("token", None)
                            expiration = json_data.get("expiration", None)
                        else:
                            token = json_data.get("access_token", None)
                            expiration = json_data.get("expires_in", None)
                        if token is not None:
                            TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(
                                TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                                .first()
                            if TbAgencyApiTokenArray is not None:
                                tokenArray = {'Token': token, 'ExpireTime': expiration}
                                TbAgencyApiToken.objects.filter(id=TbAgencyApiTokenArray.id).update(**tokenArray)
                            else:
                                tokenArray = {'TbAgencyApiKey': TbAgencyApiKeyArray,
                                              'SecurityKey': Security_Key,
                                              'Token': token, 'ExpireTime': expiration}
                                TbAgencyApiToken.objects.create(**tokenArray)
                            return Response(json_data)
                        else:
                            return Response({'error': 'Please check username and password', "status": False},
                                            status=HTTP_500_INTERNAL_SERVER_ERROR)
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
                else:
                    return Response({'error': "Please contact to administrator", "status": False},
                                    status=HTTP_500_INTERNAL_SERVER_ERROR)
            else:
                return Response({'error': "Please contact to administrator", "status": False},
                                status=HTTP_500_INTERNAL_SERVER_ERROR)
        else:
            return Response({'error': "Please contact to administrator", "status": False},
                            status=HTTP_500_INTERNAL_SERVER_ERROR)


class SearchResults(APIView):
    def post(self, request, format=None):
        json_return = {}
        m = h = s = k = 0
        json_return_supplier = {}
        json_return_x = {}
        json_return_arr = {}
        json_return_arr_supplier = {}
        ddd = {}
        json_return_xarr = {}
        json_travel_z_gear_x = {}
        json_travel_z_gear = {}
        json_book_n_travel_x = {}
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            air_iq_source = request.data.get("air_iq_source", False)
            go_fly_smart_source = request.data.get("go_fly_smart_source", False)
            book_n_travel = request.data.get("book_n_travel", False)
            origin = request.data.get("origin", None)
            destination = request.data.get("destination", None)
            adults = request.data.get("adults", 0)
            child = request.data.get("child", 0)
            infant = request.data.get("infant", 0)
            airline = request.data.get("airline", None)
            departure_date = request.data.get("departure_date", None)
            if book_n_travel:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=8,
                                                                    SecurityKey=Security_Key).first()
                if TbAgencyApiKeyArray is not None:
                    d = datetime.datetime.strptime(departure_date, '%d-%m-%Y')
                    rrr = datetime.date.strftime(d, "%Y-%m-%d")
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://partner.bookntravel.in/fe/api/v1/flight/host/"
                    else:
                        url = "http://82.180.162.77:3003/api/v1/flight/host/"
                    uid = str(TbAgencyApiKeyArray.UserName)
                    agid = str(TbAgencyApiKeyArray.SecretKey)
                    url = url + "search?dep=" + str(origin) + "&arr=" + str(destination) + "&dd=" + str(rrr) + \
                          "&adt=" + str(adults) + "&chd=" + str(child) + "&inf=" + str(infant) + \
                          "&uid=" + uid + "&agid=" + agid + "&cha=B2B&tt=1&srctyp=fltdep&clsvalue=ec"
                    payload = {}
                    files = {}
                    headers = {
                        'Apikey': TbAgencyApiKeyArray.ClientCode,
                    }
                    response = requests.request("GET", url, headers=headers, data=payload, files=files)
                    x = response.text
                    json_data_x = json.loads(x)
                    m = 0
                    if json_data_x['status'] == 'success':
                        for dataArr in json_data_x['payload']:
                            for ik in dataArr['trps']:
                                try:
                                    json_book_n_travel = {
                                        m: {
                                            "api_type": "book_n_travel",
                                            "ticket_id": ik['deps'][0]['tpid'],
                                            "flight_route": None,
                                            "pax": ik['prc'][0]['pr']['st'],
                                            "price": ik['prc'][0]['pr']['tf'],
                                            "infant_price": 0,
                                            "origin": ik['deps'][0]['seg'][0]['da'],
                                            "destination": ik['deps'][0]['seg'][0]['ar'],
                                            "airline": ik['deps'][0]['seg'][0]['ac'],
                                            "departure_date": ik['deps'][0]['seg'][0]['dd'],
                                            "departure_time": ik['deps'][0]['seg'][0]['dt'],
                                            "arival_time": ik['deps'][0]['seg'][0]['at'],
                                            "arival_date": ik['deps'][0]['seg'][0]['ad'],
                                            "flight_number": ik['deps'][0]['seg'][0]['fn'],
                                            "price_breakup": ik['prc'][0]['paxpr'],
                                            "bag": ik['prc'][0]['bag'],
                                            "ukey": dataArr['ukey'],
                                            "rmkey": ik['prc'][0]['pr']['rmkey'],
                                            "serfr": ik['deps'][0]['serfr'],
                                            "class": ik['deps'][0]['cl'],
                                            "fareType": ik['prc'][0]['pr']['fareType'],
                                            "meal": ik['prc'][0]['pr']['ml'],
                                            "re": ik['prc'][0]['pr']['re'],
                                        }
                                    }
                                    json_book_n_travel_x.update(json_book_n_travel)
                                    m = m + 1
                                except KeyError:
                                    continue
            if air_iq_source:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=4,
                                                                    SecurityKey=Security_Key).first()
                TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                    .first()
                if TbAgencyApiTokenArray is not None:
                    air_iq_url = "https://omairiq.azurewebsites.net/search"
                    air_iq_url_supplier = "https://omairiq.azurewebsites.net/suppliersearch"
                    d = datetime.datetime.strptime(departure_date, '%d-%m-%Y')
                    rrr = datetime.date.strftime(d, "%Y/%m/%d")
                    payload_air_iq = json.dumps({
                        "origin": origin,
                        "destination": destination,
                        "departure_date": rrr,
                        "adult": adults,
                        "child": child,
                        "infant": infant,
                        # "airline_code": "UK"
                    })
                    headers_air_iq = {
                        'api-key': TbAgencyApiKeyArray.ClientCode,
                        'Authorization': TbAgencyApiTokenArray.Token,
                        'Content-Type': 'application/json'
                    }
                    response_air_iq_supplier = requests.request("POST", air_iq_url_supplier, headers=headers_air_iq,
                                                                data=payload_air_iq)

                    x_air_iq_supplier = response_air_iq_supplier.text
                    json_data_air_iq_supplier = json.loads(x_air_iq_supplier)
                    code_supplier = json_data_air_iq_supplier.get('code', None)
                    air_iq_data_supplier = json_data_air_iq_supplier.get('data', None)
                    s = m
                    if code_supplier and air_iq_data_supplier is not None:
                        if json_data_air_iq_supplier['code'] == '200' and json_data_air_iq_supplier['status']:
                            for i in json_data_air_iq_supplier['data']:
                                json_return_arr_supplier = {
                                    s: {
                                        "api_type": "air_iq_supplier",
                                        "ticket_id": i['ticket_id'],
                                        "origin": i['origin'],
                                        "destination": i['destination'],
                                        "airline": i['airline'],
                                        "departure_date": i['departure_date'],
                                        "departure_time": i['departure_time'],
                                        "arival_time": i['arival_time'],
                                        "arival_date": i['arival_date'],
                                        "flight_number": i['flight_number'],
                                        "flight_route": i['flight_route'],
                                        "pax": i['pax'],
                                        "price": i['price'],
                                        "infant_price": i['infant_price'],
                                        "price_breakup": null,
                                        "bag": null,
                                        "ukey": null,
                                        "rmkey": null,
                                        "serfr": null,
                                        "class": null,
                                        "fareType": null,
                                        "meal": null,
                                        "re": null
                                    }
                                }
                                json_return_supplier.update(json_return_arr_supplier)
                                s = s + 1
                    response_air_iq = requests.request("POST", air_iq_url, headers=headers_air_iq, data=payload_air_iq)
                    #print(response_air_iq)
                    x_air_iq = response_air_iq.text
                    json_data_air_iq = json.loads(x_air_iq)
                    code = json_data_air_iq.get('code', None)
                    air_iq_data = json_data_air_iq.get('data', None)
                    k = s
                    if code and air_iq_data is not None:
                        if json_data_air_iq['code'] == '200' and json_data_air_iq['status']:
                            for i in json_data_air_iq['data']:
                                json_return_arr = {
                                    k: {
                                        "api_type": "air_iq",
                                        "ticket_id": i['ticket_id'],
                                        "origin": i['origin'],
                                        "destination": i['destination'],
                                        "airline": i['airline'],
                                        "departure_date": i['departure_date'],
                                        "departure_time": i['departure_time'],
                                        "arival_time": i['arival_time'],
                                        "arival_date": i['arival_date'],
                                        "flight_number": i['flight_number'],
                                        "flight_route": i['flight_route'],
                                        "pax": i['pax'],
                                        "price": i['price'],
                                        "infant_price": i['infant_price'],
                                        "price_breakup": "",
                                        "bag": "",
                                        "ukey": "",
                                        "rmkey": "",
                                        "serfr": "",
                                        "class": "",
                                        "fareType": "",
                                        "meal": "",
                                        "re": "",
                                    }
                                }
                                json_return.update(json_return_arr)
                                k = k + 1
                #print(json_return)
                json_return.update(json_return_supplier)
            if go_fly_smart_source:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=3,
                                                                    SecurityKey=Security_Key).first()
                if TbAgencyApiKeyArray is not None:
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://api.nexusdmc.com/api/v1/"
                    else:
                        url = "https://krn.nexusdmc.com/api/v1/"
                    d = datetime.datetime.strptime(departure_date, '%d-%m-%Y')
                    rrr = datetime.date.strftime(d, "%Y%m%d")
                    url = url + "flights/series-search?segment=" + origin + "-" + destination + "-" + str(rrr) + \
                          "&pax=" + str(adults) + "-" + str(child) + "-" + str(infant)
                    payload = {}
                    files = {}
                    headers = {
                        'api-key': TbAgencyApiKeyArray.ClientCode,
                    }
                    response = requests.request("GET", url, headers=headers, data=payload, files=files)
                    x = response.text
                    json_data_x = json.loads(x)
                    h = k
                    if json_data_x['success']:
                        for ik in json_data_x['_data']['flights']:
                            try:
                                json_return_xarr = {
                                    h: {
                                        "api_type": "go_fly_smart",
                                        "ticket_id": ik['key'],
                                        "origin": ik['segments'][0]['legs'][0]['origin'],
                                        "destination": ik['segments'][0]['legs'][0]['destination'],
                                        "airline": ik['segments'][0]['legs'][0]['airline'],
                                        "departure_date": ik['segments'][0]['legs'][0]['departure_time'],
                                        "departure_time": "",
                                        "arival_time": "",
                                        "arival_date": ik['segments'][0]['legs'][0]['arrival_time'],
                                        "flight_number": ik['segments'][0]['legs'][0]['flight_number'],
                                        "flight_route": ik['segments'][0]['legs'],
                                        "pax": ik['seats_available'],
                                        "price": ik['total_price'],
                                        "infant_price": ik['infant_price']
                                    }
                                }
                                json_return_x.update(json_return_xarr)
                                h = h + 1
                            except KeyError:
                                continue
        ddd.update(json_return)
        ddd.update(json_return_x)
        ddd.update(json_book_n_travel_x)
        return Response(ddd)


class BaggageInformation(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            ticket_id = request.data.get("ticket_id", None)
            go_fly_smart_source = request.data.get("go_fly_smart_source", False)
            if ticket_id and go_fly_smart_source is True:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=3,
                                                                    SecurityKey=Security_Key).first()
                TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                    .first()
                if TbAgencyApiTokenArray is not None and TbAgencyApiKeyArray is not None:
                    payload = {}
                    files = {}
                    headers = {
                        'Authorization': TbAgencyApiTokenArray.Token,
                        'api-key': TbAgencyApiKeyArray.ClientCode
                    }
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://goflysmartapi.azure-api.net/prod/"
                    else:
                        url = "https://goflysmartapi.azure-api.net/uat/"
                    url = url + "api/baggage-information?ticket_id=" + str(ticket_id)
                    try:
                        response = requests.request("GET", url, headers=headers, data=payload, files=files)
                        x = response.text
                        json_data = json.loads(x)
                        return Response(json_data)
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


class AvailableDates(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            go_fly_return_json = {}
            air_iq_return_json = {}
            travel_z_gear_json = {}
            book_n_travel_json = {}
            air_iq_return_json_supplier = {}
            air_iq_source = request.data.get("air_iq_source", False)
            go_fly_smart_source = request.data.get("go_fly_smart_source", False)
            travel_z_gear = request.data.get("travel_z_gear", False)
            book_n_travel = request.data.get("book_n_travel", False)
            if book_n_travel is True:
                origin = request.data.get("origin", None)
                destination = request.data.get("destination", None)
                if origin is not None and destination is not None:
                    TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=8,
                                                                        SecurityKey=Security_Key).first()
                    if TbAgencyApiKeyArray is not None:
                        if TbAgencyApiKeyArray.api_mode == 1:
                            url = "https://partner.bookntravel.in/fe/api/v1/flight/host/"
                        else:
                            url = "http://82.180.162.77:3003/api/v1/flight/host/"
                        url = url + "available-dates?dep=" + str(origin) + "&arr=" + str(destination)
                        payload = {}
                        files = {}
                        headers = {
                            'Apikey': TbAgencyApiKeyArray.ClientCode,
                        }
                        try:
                            response = requests.request("GET", url, headers=headers, data=payload, files=files)
                            x = response.text
                            json_data_x = json.loads(x)
                            h = 0
                            if json_data_x['status'] == 'success':
                                for ik in json_data_x['payload']:
                                    try:
                                        json_data_xx = {
                                            h: {"source": 'book_n_travel', "departure_date": ik,
                                                "lowest_price": 0}}
                                        h = h + 1
                                    except Exception as e:
                                        json_data_xx = {}
                                    if json_data_xx:
                                        book_n_travel_json.update(json_data_xx)
                        except Exception as e:
                            book_n_travel_json = {}
                    else:
                        book_n_travel_json = {}
                else:
                    book_n_travel_json = {}
            if travel_z_gear is True:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=5,
                                                                    SecurityKey=Security_Key).first()
                if TbAgencyApiKeyArray is not None:
                    origin = request.data.get("origin", None)
                    destination = request.data.get("destination", None)
                    if origin is not None and destination is not None:
                        if TbAgencyApiKeyArray.api_mode == 1:
                            url = "https://cheapfixdeparture.com/"
                        else:
                            url = "https://travelportal.pro/"
                        url = url + "rest-api/sector-available-dates?from_airport_id=" + str(origin) + "&to_airport_id=" \
                              + str(destination)
                        payload = {}
                        files = {}
                        headers = {
                            'Authorization': 'Bearer ' + TbAgencyApiKeyArray.ClientCode,
                        }
                        try:
                            response = requests.request("GET", url, headers=headers, data=payload, files=files)
                            x = response.text
                            json_data_x = json.loads(x)
                            # print(json_data_x)
                            h = 0
                            for ik in json_data_x:
                                try:
                                    json_data_xx = {
                                        h: {"source": 'travel_z_gear', "departure_date": ik['departure_date'],
                                            "lowest_price": ik['lowest_price']}}
                                    h = h + 1
                                except Exception as e:
                                    json_data_xx = {}
                                if json_data_xx:
                                    travel_z_gear_json.update(json_data_xx)
                        except Exception as e:
                            travel_z_gear_json = {}
                else:
                    travel_z_gear_json = {}
            if go_fly_smart_source is True:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=3,
                                                                    SecurityKey=Security_Key).first()
                if TbAgencyApiKeyArray is not None:
                    origin = request.data.get("origin", None)
                    destination = request.data.get("destination", None)
                    if origin is not None and destination is not None:
                        if TbAgencyApiKeyArray.api_mode == 1:
                            url = "https://api.nexusdmc.com/api/v1/"
                        else:
                            url = "https://krn.nexusdmc.com/api/v1/"
                        url = url + "flights/series-dates?origin=" + str(origin) + "&destination=" + str(destination)
                        payload = {}
                        files = {}
                        headers = {
                            'api-key': TbAgencyApiKeyArray.ClientCode,
                        }
                        try:
                            response = requests.request("GET", url, headers=headers, data=payload, files=files)
                            x = response.text
                            json_data_x = json.loads(x)
                            if json_data_x['_data']['sector']['date']:
                                h = 0
                                for ik in json_data_x['_data']['sector']['date']:
                                    try:
                                        json_data_xx = {
                                            h: {"source": 'go_fly_smart', "Dates": ik}}
                                        h = h + 1
                                    except Exception as e:
                                        json_data_xx = {}
                                    if json_data_xx:
                                        go_fly_return_json.update(json_data_xx)
                        except Exception as e:
                            go_fly_return_json = {}
                else:
                    go_fly_return_json = {}
            if air_iq_source is True:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=4,
                                                                    SecurityKey=Security_Key).first()
                TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                    .first()
                if TbAgencyApiTokenArray is not None and TbAgencyApiKeyArray is not None:
                    origin = request.data.get("origin", None)
                    destination = request.data.get("destination", None)
                    if origin is not None and destination is not None:
                        payload_air_iq = json.dumps({
                            "origin": origin,
                            "destination": destination
                        })
                        url_supplier = "https://omairiq.azurewebsites.net/supplieravailability"
                        headers = {
                            'api-key': TbAgencyApiKeyArray.ClientCode,
                            'Authorization': TbAgencyApiTokenArray.Token,
                            'Content-Type': 'application/json'
                        }

                        try:
                            response_supplier = requests.request("POST", url_supplier, headers=headers,
                                                                 data=payload_air_iq)
                            x_supplier = response_supplier.text
                            json_data_x_supplier = json.loads(x_supplier)
                            if json_data_x_supplier['status'] == 'success' and json_data_x_supplier['code'] == '200':
                                hk = 0
                                for ik in json_data_x_supplier['data']:
                                    try:
                                        json_data_xx_supplier = {
                                            hk: {"source": 'air_iq_supplier', "Dates": ik}}
                                        hk = hk + 1
                                    except Exception as e:
                                        json_data_xx_supplier = {}
                                    if json_data_xx_supplier:
                                        air_iq_return_json_supplier.update(json_data_xx_supplier)
                        except Exception as e:
                            air_iq_return_json_supplier = {}

                        url = "https://omairiq.azurewebsites.net/availability"
                        try:
                            response = requests.request("POST", url, headers=headers, data=payload_air_iq)
                            x = response.text
                            json_data_x = json.loads(x)
                            # print(json_data_x)
                            if json_data_x['status'] == 'success' and json_data_x['code'] == '200':
                                h = hk
                                for ik in json_data_x['data']:
                                    try:
                                        json_data_xx = {
                                            h: {"source": 'air_iq', "Dates": ik}}
                                        h = h + 1
                                    except Exception as e:
                                        json_data_xx = {}
                                    if json_data_xx:
                                        air_iq_return_json.update(json_data_xx)

                        except Exception as e:
                            air_iq_return_json = {}
                    else:
                        air_iq_return_json = {}
                else:
                    air_iq_return_json = {}
            air_iq_return_json.update(air_iq_return_json_supplier)
        ddd = [go_fly_return_json, air_iq_return_json, travel_z_gear_json, book_n_travel_json]
        return Response(ddd)


class AvailableSectors(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            go_fly_return_json = {}
            air_iq_return_json = {}
            travel_z_gear_json = {}
            book_n_travel_json = {}
            air_iq_source = request.data.get("air_iq_source", False)
            go_fly_smart_source = request.data.get("go_fly_smart_source", False)
            travel_z_gear = request.data.get("travel_z_gear", False)
            book_n_travel = request.data.get("book_n_travel", False)
            if book_n_travel is True:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=8,
                                                                    SecurityKey=Security_Key).first()
                if TbAgencyApiKeyArray is not None:
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://partner.bookntravel.in/fe/api/v1/flight/host/"
                    else:
                        url = "http://82.180.162.77:3003/api/v1/flight/host/"
                url = url + "available-destinations"
                payload = {}
                files = {}
                headers = {
                    'Apikey': TbAgencyApiKeyArray.ClientCode,
                }
                try:
                    response = requests.request("GET", url, headers=headers, data=payload, files=files)
                    x = response.text
                    json_data_y = json.loads(x)
                    g = 0
                    for ik in json_data_y['payload']:
                        for arr in ik['arr']:
                            try:
                                json_data_yy = {g: {"source": 'book_n_travel', "Destination": (ik['dep']),
                                                    "Origin": arr['arr']}}
                                g = g + 1
                            except Exception as e:
                                json_data_yy = {}
                            if json_data_yy:
                                book_n_travel_json.update(json_data_yy)
                except Exception as e:
                    return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
            if travel_z_gear is True:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=5,
                                                                    SecurityKey=Security_Key).first()
                if TbAgencyApiKeyArray is not None:
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://cheapfixdeparture.com/rest-api/"
                    else:
                        url = "https://travelportal.pro/rest-api/"
                    url = url + "available-sectors"
                    payload = {}
                    files = {}
                    headers = {
                        'Authorization': 'Bearer ' + TbAgencyApiKeyArray.ClientCode,
                    }
                    try:
                        response = requests.request("GET", url, headers=headers, data=payload, files=files)
                        x = response.text
                        json_data_x = json.loads(x)
                        # print(json_data_x)
                        m = 0
                        for ik in json_data_x:
                            try:
                                json_data_xx = {m: {"source": 'travel_z_gear', "Destination": (ik['to_airport_id']),
                                                    "Origin": ik['from_airport_id']}}
                                m = m + 1
                            except Exception as e:
                                json_data_xx = {}
                            if json_data_xx:
                                travel_z_gear_json.update(json_data_xx)
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
            if go_fly_smart_source is True:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=3,
                                                                    SecurityKey=Security_Key).first()
                if TbAgencyApiKeyArray is not None:
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://api.nexusdmc.com/api/v1/flights/series-sectors/"
                    else:
                        url = "https://krn.nexusdmc.com/api/v1/flights/series-sectors/"
                    payload = {}
                    headers = {
                        'api-key': TbAgencyApiKeyArray.ClientCode
                    }
                    try:
                        response = requests.request("GET", url, headers=headers, data=payload)
                        x = response.text
                        json_data = json.loads(x)
                        m = 0
                        for ik in json_data['_data']['sectors']:
                            try:
                                if 'origin_other' in ik:
                                    for ikk in ik['origin_other']:
                                        json_data_xx = {
                                            m: {"source": 'go_fly_smart', "Destination": (ik['destination']),
                                                "Origin": ikk}}
                                        go_fly_return_json.update(json_data_xx)
                                        m = m + 1
                                elif 'destination_other' in ik:
                                    for jkk in ik['destination_other']:
                                        json_data_xx = {m: {"source": 'go_fly_smart', "Destination": jkk,
                                                            "Origin": ik['origin']}}
                                        go_fly_return_json.update(json_data_xx)
                                        m = m + 1
                                else:
                                    json_data_xx = {m: {"source": 'go_fly_smart', "Destination": (ik['destination']),
                                                        "Origin": ik['origin']}}
                                    go_fly_return_json.update(json_data_xx)
                                    m = m + 1
                            except Exception as e:
                                json_data_xx = {}
                                go_fly_return_json.update(json_data_xx)
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
                else:
                    return Response({'error': "Please check api key", "status": False},
                                    status=HTTP_500_INTERNAL_SERVER_ERROR)
            if air_iq_source is True:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=4,
                                                                    SecurityKey=Security_Key).first()
                TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                    .first()
                if TbAgencyApiTokenArray is not None:
                    url = "https://omairiq.azurewebsites.net/sectors"
                    payload = {}
                    headers = {
                        'api-key': TbAgencyApiKeyArray.ClientCode,
                        'Authorization': TbAgencyApiTokenArray.Token,
                        'Content-Type': 'application/json'
                    }
                    try:
                        response = requests.request("GET", url, headers=headers, data=payload)
                        x = response.text
                        json_data_air_iq = json.loads(x)
                        # print(json_data_air_iq)
                        code = json_data_air_iq.get('code', None)
                        if code:
                            if json_data_air_iq['code'] == '200' and json_data_air_iq['status'] == 'success':
                                h = 0
                                for ik in json_data_air_iq['data']:
                                    try:
                                        if ik['Destination'] is None:
                                            rr = rr + 1
                                        else:
                                            json_data_xxx = {
                                                h: {"source": 'air_iq', "Destination": (ik['Destination']),
                                                    "Origin": ik['Origin']}}
                                            h = h + 1
                                    except Exception as e:
                                        json_data_xxx = {}
                                    if json_data_xxx:
                                        air_iq_return_json.update(json_data_xxx)
                    except Exception as e:
                        air_iq_return_json = {}
                else:
                    air_iq_return_json = {}
        ddd = [air_iq_return_json, travel_z_gear_json, go_fly_return_json, book_n_travel_json]
        return Response(ddd)


class GoFlySmartCheckAvailability(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=3,
                                                                SecurityKey=Security_Key).first()
            if TbAgencyApiKeyArray is not None:
                if TbAgencyApiKeyArray.api_mode == 1:
                    url = "https://api.nexusdmc.com/"
                else:
                    url = "https://krn.nexusdmc.com/"
                url = url + "api/v1/flights/series-check-avail"
                payload = json.dumps(request.data)
                headers = {
                    'api-key': TbAgencyApiKeyArray.ClientCode,
                }
                try:
                    response = requests.request("POST", url, headers=headers, data=payload)
                    x = response.text
                    json_data = json.loads(x)
                    return Response(json_data)
                except Exception as e:
                    return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
            else:
                return Response({'error': "Please check api key", "status": False},
                                status=HTTP_500_INTERNAL_SERVER_ERROR)
        else:
            return Response({'error': "Please check api key", "status": False},
                            status=HTTP_500_INTERNAL_SERVER_ERROR)


class GoFlySmartBooking(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=3,
                                                                SecurityKey=Security_Key).first()
            if TbAgencyApiKeyArray is not None:
                if TbAgencyApiKeyArray.api_mode == 1:
                    url = "https://api.nexusdmc.com/"
                else:
                    url = "https://krn.nexusdmc.com/"
                url = url + "api/v1/flights/series-book"
                payload = json.dumps(request.data)
                headers = {
                    'api-key': TbAgencyApiKeyArray.ClientCode,
                }
                try:
                    response = requests.request("POST", url, headers=headers, data=payload)
                    x = response.text
                    json_data = json.loads(x)
                    return Response(json_data)
                except Exception as e:
                    return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
            else:
                return Response({'error': "Please check api key", "status": False},
                                status=HTTP_500_INTERNAL_SERVER_ERROR)
        else:
            return Response({'error': "Please check api key", "status": False},
                            status=HTTP_500_INTERNAL_SERVER_ERROR)


'''

class TicketDetails(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=3,
                                                                SecurityKey=Security_Key).first()
            TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                .first()
            if TbAgencyApiTokenArray is not None and TbAgencyApiKeyArray is not None:
                ticket_id = request.data.get("ticket_id", None)
                if ticket_id:
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://goflysmartapi.azure-api.net/prod/"
                    else:
                        url = "https://goflysmartapi.azure-api.net/uat/"
                    url = url + "ticket-details/" + str(ticket_id)
                    payload = {}
                    files = {}
                    headers = {
                        'Authorization': TbAgencyApiTokenArray.Token,
                        'api-key': TbAgencyApiKeyArray.ClientCode,
                        '2023-01-01': 'v2'
                    }
                    try:
                        response = requests.request("GET", url, headers=headers, data=payload, files=files)
                        x = response.text
                        json_data = json.loads(x)
                        return Response(json_data)
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
                else:
                    return Response({'error': "Please check request values", "status": False},
                                    status=HTTP_500_INTERNAL_SERVER_ERROR)
            else:
                return Response({'error': "Please check api key", "status": False},
                                status=HTTP_500_INTERNAL_SERVER_ERROR)
        else:
            return Response({'error': "Please check header value", "status": False},
                            status=HTTP_500_INTERNAL_SERVER_ERROR)

'''


class TicketDetails(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=3,
                                                                SecurityKey=Security_Key).first()
            if TbAgencyApiKeyArray is not None:
                ticket_id = request.data.get("ticket_id", None)
                if ticket_id:
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://api.nexusdmc.com/"
                    else:
                        url = "https://krn.nexusdmc.com/"
                    url = url + "api/v1/bookings/reference/" + str(ticket_id)
                    payload = {}
                    files = {}
                    headers = {
                        'api-key': TbAgencyApiKeyArray.ClientCode,
                    }
                    try:
                        response = requests.request("GET", url, headers=headers, data=payload, files=files)
                        x = response.text
                        json_data = json.loads(x)
                        return Response(json_data)
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
                else:
                    return Response({'error': "Please check request values", "status": False},
                                    status=HTTP_500_INTERNAL_SERVER_ERROR)
            else:
                return Response({'error': "Please check api key", "status": False},
                                status=HTTP_500_INTERNAL_SERVER_ERROR)
        else:
            return Response({'error': "Please check header value", "status": False},
                            status=HTTP_500_INTERNAL_SERVER_ERROR)


class GoFlySmartAccountsBalance(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=3,
                                                                SecurityKey=Security_Key).first()
            if TbAgencyApiKeyArray is not None:
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://api.nexusdmc.com/"
                    else:
                        url = "https://krn.nexusdmc.com/"
                    url = url + "api/v1/accounts/balance"
                    payload = {}
                    files = {}
                    headers = {
                        'api-key': TbAgencyApiKeyArray.ClientCode,
                    }
                    try:
                        response = requests.request("GET", url, headers=headers, data=payload, files=files)
                        x = response.text
                        json_data = json.loads(x)
                        return Response(json_data)
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
            else:
                return Response({'error': "Please check api key", "status": False},
                                status=HTTP_500_INTERNAL_SERVER_ERROR)
        else:
            return Response({'error': "Please check header value", "status": False},
                            status=HTTP_500_INTERNAL_SERVER_ERROR)


class AirIqTicketDetail(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=4,
                                                                SecurityKey=Security_Key).first()
            TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                .first()
            if TbAgencyApiTokenArray is not None and TbAgencyApiKeyArray is not None:
                ticket_id = request.data.get("ticket_id", None)
                is_supplier_ticket = request.data.get("is_supplier_ticket", False)
                if ticket_id:

                    if is_supplier_ticket:
                        url = "https://omairiq.azurewebsites.net/supplierticket" \
                              "?booking_id=" + str(ticket_id)
                    else:
                        url = "https://omairiq.azurewebsites.net/ticket" \
                              "?booking_id=" + str(ticket_id)
                    payload = {}
                    headers = {
                        'api-key': TbAgencyApiKeyArray.ClientCode,
                        'Authorization': TbAgencyApiTokenArray.Token,
                        'Content-Type': 'application/json'
                    }
                    try:
                        response = requests.request("GET", url, headers=headers, data=payload)
                        x = response.text
                        json_data = json.loads(x)
                        return Response(json_data)
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
                else:
                    return Response({'error': "Please check request values", "status": False},
                                    status=HTTP_500_INTERNAL_SERVER_ERROR)
            else:
                return Response({'error': "Please check api key", "status": False},
                                status=HTTP_500_INTERNAL_SERVER_ERROR)
        else:
            return Response({'error': "Please check header value", "status": False},
                            status=HTTP_500_INTERNAL_SERVER_ERROR)


class TravelZGearDetail(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=5,
                                                                SecurityKey=Security_Key).first()
            ticket_id = request.data.get("ticket_id", None)
            if TbAgencyApiKeyArray is not None and ticket_id is not None:
                url = "https://cheapfixdeparture.com/rest-api/booking-checkout/" + str(ticket_id)
                payload = {}
                headers = {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json',
                    'Authorization': 'Bearer ' + TbAgencyApiKeyArray.ClientCode,
                }
                try:
                    response = requests.request("GET", url, headers=headers, data=payload)
                    x = response.text
                    json_data = json.loads(x)
                    return Response(json_data)
                except Exception as e:
                    return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
            else:
                return Response({'error': "Please check api key", "status": False},
                                status=HTTP_500_INTERNAL_SERVER_ERROR)
        else:
            return Response({'error': "Please check header value", "status": False},
                            status=HTTP_500_INTERNAL_SERVER_ERROR)


class TravelZGearPayWalletDetail(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=5,
                                                                SecurityKey=Security_Key).first()
            ticket_id = request.data.get("ticket_id", None)
            if TbAgencyApiKeyArray is not None and ticket_id is not None:
                url = "https://cheapfixdeparture.com/rest-api/pay-wallet-booking/" + str(ticket_id)
                payload = {}
                headers = {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json',
                    'Authorization': 'Bearer ' + TbAgencyApiKeyArray.ClientCode,
                }
                try:
                    response = requests.request("POST", url, headers=headers, data=payload)
                    x = response.text
                    json_data = json.loads(x)
                    return Response(json_data)
                except Exception as e:
                    return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
            else:
                return Response({'error': "Please check api key", "status": False},
                                status=HTTP_500_INTERNAL_SERVER_ERROR)
        else:
            return Response({'error': "Please check header value", "status": False},
                            status=HTTP_500_INTERNAL_SERVER_ERROR)


class AirIqBook(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        is_supplier_ticket = request.META.get('HTTP_SUPPLIERTICKET', False)
        if Security_Key:
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=4,
                                                                SecurityKey=Security_Key).first()
            TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                .first()
            if TbAgencyApiTokenArray is not None and TbAgencyApiKeyArray is not None:
                if is_supplier_ticket:
                    url = "https://omairiq.azurewebsites.net/supplierbook"
                else:
                    url = "https://omairiq.azurewebsites.net/book"

                payload = json.dumps(request.data)
                headers = {
                    'api-key': TbAgencyApiKeyArray.ClientCode,
                    'Authorization': TbAgencyApiTokenArray.Token,
                    'Content-Type': 'application/json'
                }
                try:
                    response = requests.request("POST", url, headers=headers, data=payload)
                    x = response.text
                    json_data = json.loads(x)
                    return Response(json_data)
                except Exception as e:
                    return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


class TravelZGear(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=5,
                                                                SecurityKey=Security_Key).first()
            if TbAgencyApiKeyArray is not None:
                url = "https://cheapfixdeparture.com/rest-api/air-ticket-bookings"
                payload = json.dumps(request.data)
                headers = {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json',
                    'Authorization': 'Bearer ' + TbAgencyApiKeyArray.ClientCode,
                }
                try:
                    response = requests.request("POST", url, headers=headers, data=payload)
                    x = response.text
                    json_data = json.loads(x)
                    return Response(json_data)
                except Exception as e:
                    return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
        else:
            return Response({'error': "Please check security key", "status": False},
                            status=HTTP_500_INTERNAL_SERVER_ERROR)


class FareBoutiqueGetSector(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            trip_type = request.data.get("trip_type", 'oneway')
            end_user_ip = request.data.get("end_user_ip", '183.83.43.117')
            travel_z_gear = request.data.get("travel_z_gear", False)
            if travel_z_gear:
                api_source_sys_id = 5
            else:
                api_source_sys_id = 6
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=api_source_sys_id,
                                                                SecurityKey=Security_Key).first()
            if TbAgencyApiKeyArray is not None:
                if travel_z_gear:
                    if trip_type == 'oneway':
                        trip_type = 0
                    else:
                        trip_type = 1
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://api.fareboutique.in/v1/fbapi/sector"
                    else:
                        url = "https://devapi.flightapi.co.in/v1/fbapi/sector"
                else:
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://api.fareboutique.in/v1/api/sector"
                    else:
                        url = "https://devapi.flightapi.co.in/v1/api/sector"
                payload = json.dumps({
                    "trip_type": trip_type,
                    "end_user_ip": TbAgencyApiKeyArray.UserName,
                    "token": TbAgencyApiKeyArray.ClientCode
                })
                files = []
                headers = {'Accept': 'application/json',
                           'Content-Type': 'application/json'}
                print()
                try:
                    response = requests.request("POST", url, headers=headers, data=payload, files=files)
                    x = response.text
                    json_data = json.loads(x)
                    return Response(json_data)
                except Exception as e:
                    return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


class FareBoutiqueDestination(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            trip_type = request.data.get("trip_type", 'oneway')
            end_user_ip = request.data.get("end_user_ip", '183.83.43.117')
            travel_z_gear = request.data.get("travel_z_gear", False)
            if travel_z_gear:
                api_source_sys_id = 5
            else:
                api_source_sys_id = 6
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=api_source_sys_id,
                                                                SecurityKey=Security_Key).first()
            if TbAgencyApiKeyArray is not None:
                if travel_z_gear:
                    if trip_type == 'oneway':
                        trip_type = 0
                    else:
                        trip_type = 1
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://api.fareboutique.in/v1/fbapi/dep_city"
                    else:
                        url = "https://devapi.flightapi.co.in/v1/fbapi/dep_city"
                else:
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://api.fareboutique.in/v1/api/departure_city_list"
                    else:
                        url = "https://devapi.flightapi.co.in/v1/api/departure_city_list"
                payload = json.dumps({
                    "trip_type": trip_type,
                    "end_user_ip": TbAgencyApiKeyArray.UserName,
                    "token": TbAgencyApiKeyArray.ClientCode
                })
                files = []
                headers = {'Accept': 'application/json',
                           'Content-Type': 'application/json'}
                try:
                    response = requests.request("POST", url, headers=headers, data=payload, files=files)
                    x = response.text
                    json_data = json.loads(x)
                    return Response(json_data['data'])
                except Exception as e:
                    return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


class FareBoutiqueArrival(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            trip_type = request.data.get("trip_type", 'oneway')
            end_user_ip = request.data.get("end_user_ip", '183.83.43.117')
            travel_z_gear = request.data.get("travel_z_gear", False)
            if travel_z_gear:
                api_source_sys_id = 5
            else:
                api_source_sys_id = 6
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=api_source_sys_id,
                                                                SecurityKey=Security_Key).first()
            if TbAgencyApiKeyArray is not None:
                if travel_z_gear:
                    if trip_type == 'oneway':
                        trip_type = 0
                    else:
                        trip_type = 1
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://api.fareboutique.in/v1/fbapi/arr_city"
                    else:
                        url = "https://devapi.flightapi.co.in/v1/fbapi/arr_city"
                else:
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://api.fareboutique.in/v1/api/arrival_city_list"
                    else:
                        url = "https://devapi.flightapi.co.in/v1/api/arrival_city_list"

                payload = json.dumps({
                    "trip_type": trip_type,
                    "end_user_ip": TbAgencyApiKeyArray.UserName,
                    "departure_city_code": departure_city_code,
                    "token": TbAgencyApiKeyArray.ClientCode
                })
                files = []
                headers = {'Accept': 'application/json',
                           'Content-Type': 'application/json'}
                try:
                    response = requests.request("POST", url, headers=headers, data=payload, files=files)
                    x = response.text
                    json_data = json.loads(x)
                    return Response(json_data['data'])
                except Exception as e:
                    return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


class FareBoutiqueOnwardDates(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            trip_type = request.data.get("trip_type", 'oneway')
            end_user_ip = request.data.get("end_user_ip", '183.83.43.117')
            departure_city_code = request.data.get("departure_city_code", None)
            arrival_city_code = request.data.get("arrival_city_code", None)
            departure_date = request.data.get("departure_date", None)
            travel_z_gear = request.data.get("travel_z_gear", False)
            if travel_z_gear:
                api_source_sys_id = 5
            else:
                api_source_sys_id = 6
            if departure_city_code and arrival_city_code:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=api_source_sys_id,
                                                                    SecurityKey=Security_Key).first()
                if TbAgencyApiKeyArray is not None:
                    if travel_z_gear:
                        if trip_type == 'oneway':
                            trip_type = 0
                        else:
                            trip_type = 1
                        if TbAgencyApiKeyArray.api_mode == 1:
                            url = "https://api.fareboutique.in/v1/fbapi/onward_date"
                        else:
                            url = "https://devapi.flightapi.co.in/v1/fbapi/onward_date"
                        if trip_type == 0:
                            payload = json.dumps({
                                "trip_type": trip_type,
                                "end_user_ip": TbAgencyApiKeyArray.UserName,
                                "arr_city_code": arrival_city_code,
                                "dep_city_code": departure_city_code,
                                "token": TbAgencyApiKeyArray.ClientCode
                            })
                        else:
                            payload = json.dumps({
                                "trip_type": trip_type,
                                "end_user_ip": TbAgencyApiKeyArray.UserName,
                                "arr_city_code": arrival_city_code,
                                "dep_city_code": departure_city_code,
                                "onward_date": departure_date,
                                "token": TbAgencyApiKeyArray.ClientCode
                            })
                    else:
                        if TbAgencyApiKeyArray.api_mode == 1:
                            url = "https://api.fareboutique.in/v1/api/onward_dates"
                        else:
                            url = "https://devapi.flightapi.co.in/v1/api/onward_dates"
                        if trip_type == 'oneway':
                            payload = json.dumps({
                                "trip_type": trip_type,
                                "end_user_ip": TbAgencyApiKeyArray.UserName,
                                "arrival_city_code": arrival_city_code,
                                "departure_city_code": departure_city_code,
                                "token": TbAgencyApiKeyArray.ClientCode
                            })
                        else:
                            payload = json.dumps({
                                "trip_type": trip_type,
                                "end_user_ip": TbAgencyApiKeyArray.UserName,
                                "arrival_city_code": arrival_city_code,
                                "departure_city_code": departure_city_code,
                                "departure_date": departure_date,
                                "token": TbAgencyApiKeyArray.ClientCode
                            })

                    files = []
                    headers = {'Accept': 'application/json',
                               'Content-Type': 'application/json'}
                    try:
                        response = requests.request("POST", url, headers=headers, data=payload, files=files)
                        x = response.text
                        json_data = json.loads(x)
                        return Response(json_data['data'])
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
                else:
                    return Response({'error': "Please check header value", "status": False},
                                    status=HTTP_500_INTERNAL_SERVER_ERROR)


class FareBoutiqueSearch(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            departure_city_code = request.data.get("departure_city_code", None)
            arrival_city_code = request.data.get("arrival_city_code", None)
            trip_type = request.data.get("trip_type", 0)
            departure_date = request.data.get("departure_date", None)
            return_date = request.data.get("return_date", '')
            adult = request.data.get("adult", 0)
            children = request.data.get("children", 0)
            infant = request.data.get("infant", 0)
            travel_z_gear = request.data.get("travel_z_gear", False)
            if travel_z_gear:
                api_source_sys_id = 5
            else:
                api_source_sys_id = 6
            if departure_city_code and arrival_city_code:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=api_source_sys_id,
                                                                    SecurityKey=Security_Key).first()
                if TbAgencyApiKeyArray is not None:
                    if travel_z_gear:
                        if TbAgencyApiKeyArray.api_mode == 1:
                            url = "https://api.fareboutique.in/v1/fbapi/search"
                        else:
                            url = "https://devapi.flightapi.co.in/v1/fbapi/search"
                        if trip_type == 0:
                            payload = json.dumps({
                                "end_user_ip": TbAgencyApiKeyArray.UserName,
                                "dep_city_code": departure_city_code,
                                "arr_city_code": arrival_city_code,
                                "onward_date": departure_date,
                                "trip_type": trip_type,
                                "adult": int(adult),
                                "children": int(children),
                                "infant": int(infant),
                                "token": TbAgencyApiKeyArray.ClientCode
                            })
                        else:
                            payload = json.dumps({
                                "end_user_ip": TbAgencyApiKeyArray.UserName,
                                "dep_city_code": departure_city_code,
                                "arr_city_code": arrival_city_code,
                                "onward_date": departure_date,
                                "trip_type": trip_type,
                                "return_date": return_date,
                                "adult": int(adult),
                                "children": int(children),
                                "infant": int(infant),
                                "token": TbAgencyApiKeyArray.ClientCode
                            })
                    else:
                        if TbAgencyApiKeyArray.api_mode == 1:
                            url = "https://api.fareboutique.in/v1/api/search"
                        else:
                            url = "https://devapi.flightapi.co.in/v1/api/search"
                        if trip_type == 0:
                            payload = json.dumps({
                                "end_user_ip": TbAgencyApiKeyArray.UserName,
                                "departure_city_code": departure_city_code,
                                "arrival_city_code": arrival_city_code,
                                "departure_date": departure_date,
                                "trip_type": trip_type,
                                "adult": adult,
                                "children": children,
                                "infant": infant,
                                "token": TbAgencyApiKeyArray.ClientCode
                            })
                        else:
                            payload = json.dumps({
                                "end_user_ip": TbAgencyApiKeyArray.UserName,
                                "departure_city_code": departure_city_code,
                                "arrival_city_code": arrival_city_code,
                                "departure_date": departure_date,
                                "trip_type": trip_type,
                                "return_date": return_date,
                                "adult": adult,
                                "children": children,
                                "infant": infant,
                                "token": TbAgencyApiKeyArray.ClientCode
                            })
                    files = []
                    headers = {'Accept': 'application/json',
                               'Content-Type': 'application/json'}
                    try:
                        response = requests.request("POST", url, headers=headers, data=payload, files=files)
                        x = response.text
                        json_data = json.loads(x)
                        return Response(json_data)
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
                else:
                    return Response({'error': "Please check header value", "status": False},
                                    status=HTTP_500_INTERNAL_SERVER_ERROR)


class FareBoutiqueFareQuote(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            travel_z_gear = request.data.get("travel_z_gear", False)
            flight_id = request.data.get("flight_id", None)
            departure_date = request.data.get("departure_date", None)
            adult_children = request.data.get("adult_children", 0)
            infant = request.data.get("infant", 0)
            static = request.data.get("static", None)
            end_user_ip = request.data.get("end_user_ip", '183.83.43.117')
            if travel_z_gear:
                api_source_sys_id = 5
            else:
                api_source_sys_id = 6
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=api_source_sys_id,
                                                                SecurityKey=Security_Key).first()
            if TbAgencyApiKeyArray is not None:
                if travel_z_gear:
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://api.fareboutique.in/v1/fbapi/fare_quote"
                    else:
                        url = "https://devapi.flightapi.co.in/v1/fbapi/fare_quote"
                    if flight_id:
                        payload = json.dumps({
                            "end_user_ip": TbAgencyApiKeyArray.UserName,
                            "token": TbAgencyApiKeyArray.ClientCode,
                            "id": flight_id,
                            "onward_date": departure_date,
                            "adult_children": adult_children,
                            "infant": infant,
                            "static": static
                        })
                else:
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://api.fareboutique.in/v1/api/fare_quote"
                    else:
                        url = "https://devapi.flightapi.co.in/v1/api/fare_quote"
                    if flight_id:
                        payload = json.dumps({
                            "end_user_ip": TbAgencyApiKeyArray.UserName,
                            "token": TbAgencyApiKeyArray.ClientCode,
                            "flight_id": flight_id,
                            "departure_date": departure_date,
                            "adult_children": adult_children,
                            "infant": infant
                        })

                files = []
                headers = {'Accept': 'application/json',
                           'Content-Type': 'application/json'}
                try:
                    response = requests.request("POST", url, headers=headers, data=payload, files=files)
                    x = response.text
                    json_data = json.loads(x)
                    return Response(json_data)
                except Exception as e:
                    return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


class FareBoutiqueBooking(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        flight_data_final = {}
        if Security_Key:
            end_user_ip = request.data.get("end_user_ip", '183.83.43.117')
            travel_z_gear = request.data.get("travel_z_gear", False)
            if travel_z_gear:
                api_source_sys_id = 5
            else:
                api_source_sys_id = 6
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=api_source_sys_id,
                                                                SecurityKey=Security_Key).first()
            if TbAgencyApiKeyArray is not None:
                if travel_z_gear:
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://api.fareboutique.in/v1/fbapi/book"
                    else:
                        url = "https://devapi.flightapi.co.in/v1/fbapi/book"
                else:
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://api.fareboutique.in/v1/api/book_flight"
                    else:
                        url = "https://devapi.flightapi.co.in/v1/api/book_flight"
                if request.data:
                    request.data["token"] = TbAgencyApiKeyArray.ClientCode
                    request.data["end_user_ip"] = TbAgencyApiKeyArray.UserName
                    payload = json.dumps(request.data)
                    files = []
                    headers = {'Accept': 'application/json',
                               'Content-Type': 'application/json'}
                    try:
                        response = requests.request("POST", url, headers=headers, data=payload, files=files)
                        x = response.text
                        json_data = json.loads(x)
                        return Response(json_data)
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


class FareBoutiqueBookingDetail(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            reference_id = request.data.get("reference_id", None)
            transaction_id = request.data.get("transaction_id", 'trip_jack_transaction_id')
            end_user_ip = request.data.get("end_user_ip", '183.83.43.117')
            travel_z_gear = request.data.get("travel_z_gear", False)
            if travel_z_gear:
                api_source_sys_id = 5
            else:
                api_source_sys_id = 6
            if reference_id:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=api_source_sys_id,
                                                                    SecurityKey=Security_Key).first()
                if TbAgencyApiKeyArray is not None:
                    if travel_z_gear:
                        if TbAgencyApiKeyArray.api_mode == 1:
                            url = "https://api.fareboutique.in/v1/fbapi/booking_details"
                        else:
                            url = "https://devapi.flightapi.co.in/v1/fbapi/booking_details"
                        payload = json.dumps({
                            "reference_id": reference_id,
                            "end_user_ip": TbAgencyApiKeyArray.UserName,
                            "token": TbAgencyApiKeyArray.ClientCode,
                            "transaction_id": transaction_id
                        })
                    else:
                        if TbAgencyApiKeyArray.api_mode == 1:
                            url = "https://api.fareboutique.in/v1/api/booking_details"
                        else:
                            url = "https://devapi.flightapi.co.in/v1/api/booking_details"
                        payload = json.dumps({
                            "reference_id": reference_id,
                            "end_user_ip": TbAgencyApiKeyArray.UserName,
                            "token": TbAgencyApiKeyArray.ClientCode

                        })

                    files = []
                    headers = {'Accept': 'application/json',
                               'Content-Type': 'application/json'}
                    try:
                        response = requests.request("POST", url, headers=headers, data=payload, files=files)
                        x = response.text
                        json_data = json.loads(x)
                        return Response(json_data)
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


class checkAvailabilityBookNTravel(APIView):
    def post(self, request, format=None):
        book_n_travel_json = {}
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=8,
                                                                SecurityKey=Security_Key).first()
            if TbAgencyApiKeyArray is not None:
                if TbAgencyApiKeyArray.api_mode == 1:
                    url = "https://partner.bookntravel.in/fe/api/v1/flight/host/availability"
                else:
                    url = "http://82.180.162.77:3003/api/v1/flight/host/availability"

                payload = json.dumps(request.data)
                headers = {
                    'Apikey': TbAgencyApiKeyArray.ClientCode,
                    'Content-Type': 'application/json'
                }
                try:
                    response = requests.request("POST", url, headers=headers, data=payload)
                    x = response.text
                    book_n_travel_json = json.loads(x)
                except Exception as e:
                    book_n_travel_json = {}
        ddd = [book_n_travel_json]
        return Response(ddd)


class BookingRequestBookNTravel(APIView):
    def post(self, request, format=None):
        book_n_travel_json = {}
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=8,
                                                                SecurityKey=Security_Key).first()
            if TbAgencyApiKeyArray is not None:
                if TbAgencyApiKeyArray.api_mode == 1:
                    url = "https://partner.bookntravel.in/fe/api/v1/flight/host/book"
                else:
                    url = "http://82.180.162.77:3003/api/v1/flight/host/book"

                payload = json.dumps(request.data)
                headers = {
                    'Apikey': TbAgencyApiKeyArray.ClientCode,
                    'Content-Type': 'application/json'
                }
                try:
                    response = requests.request("POST", url, headers=headers, data=payload)
                    x = response.text
                    book_n_travel_json = json.loads(x)
                except Exception as e:
                    book_n_travel_json = {}
        ddd = [book_n_travel_json]
        return Response(ddd)


class GoFlySmartSearchSector(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        json_data_xxx = {}
        if Security_Key:
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=3,
                                                                SecurityKey=Security_Key).first()
            if TbAgencyApiKeyArray is not None:
                if TbAgencyApiKeyArray.api_mode == 1:
                    url = "https://api.nexusdmc.com/api/v1/flights/series-sectors/"
                else:
                    url = "https://krn.nexusdmc.com/api/v1/flights/series-sectors/"
                payload = {}
                headers = {
                    'api-key': TbAgencyApiKeyArray.ClientCode
                }
                try:
                    response = requests.request("GET", url, headers=headers, data=payload)
                    x = response.text
                    json_data = json.loads(x)
                    m = 0
                    for ik in json_data['_data']['sectors']:
                        try:
                            if 'origin_other' in ik:
                                for ikk in ik['origin_other']:
                                    json_data_xx = {m: {"source": 'go_fly_smart', "Destination": (ik['destination']),
                                                        "Origin": ikk}}
                                    json_data_xxx.update(json_data_xx)
                                    m = m + 1
                            elif 'destination_other' in ik:
                                for jkk in ik['destination_other']:
                                    json_data_xx = {m: {"source": 'go_fly_smart', "Destination": jkk,
                                                        "Origin": ik['origin']}}
                                    json_data_xxx.update(json_data_xx)
                                    m = m + 1
                            else:
                                json_data_xx = {m: {"source": 'go_fly_smart', "Destination": (ik['destination']),
                                                    "Origin": ik['origin']}}
                                json_data_xxx.update(json_data_xx)
                                m = m + 1
                        except Exception as e:
                            json_data_xx = {}
                            json_data_xxx.update(json_data_xx)
                    return Response(json_data_xxx)
                except Exception as e:
                    return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
            else:
                return Response({'error': "Please check api key", "status": False},
                                status=HTTP_500_INTERNAL_SERVER_ERROR)
        else:
            return Response({'error': "Please check api key", "status": False},
                            status=HTTP_500_INTERNAL_SERVER_ERROR)

Youez - 2016 - github.com/yon3zu
LinuXploit