Exemplo n.º 1
0
def addOffer(request):
    ms = MerchantService()
    title = None
    description = None
    endDate = None
    code = None
    codeType = "text"
    categoryId = None
    imgUrl =  None
    if not 'title' in request.POST or request.POST['title'] is None:
        return JSONResponse(SSUtil.err("Title  is required"),
                            status=status.HTTP_412_PRECONDITION_FAILED)
    else:
        title =  request.POST['title']
    if 'description' in request.POST and not request.POST['description'] is None:
        description = request.POST['description']
    if 'endDate' in request.POST and not request.POST['endDate'] is None:
        endDate = request.POST['endDate']
    if 'code' in request.POST and not request.POST['code'] is None:
        code = request.POST['code']
    if 'codeType' in request.POST and not request.POST['codeType'] is None:
        codeType = request.POST['codeType']
    if 'imgUrl' in request.FILES and not request.FILES['imgUrl'] is None:
        print "imgurl is not none"
        imgUrl = request.FILES['imgUrl']
#     try:
    ser = MerchantOfferSerializer(ms.addOffer(request.user.id,title,description,
                    code,codeType,endDate,categoryId, imgUrl))
    return JSONResponse(SSUtil.success(ser.data), status=status.HTTP_200_OK)
Exemplo n.º 2
0
def merchant(request, format=None):
    if request.method == 'GET':
        try:
            ser = MerchantSerializer(request.user)
            return JSONResponse(SSUtil.success(ser.data), status=status.HTTP_200_OK)
        except Exception as e:
            return JSONResponse(SSUtil.err(e.message), status=status.HTTP_409_CONFLICT)
    elif  request.method == 'PUT':
        try:
            data = json.loads(request.body)
            name = None
            description = None
            businessHours = None
            if 'name' in data and not data['name'] is None:
               name = data['name']
            if 'description' in data and not data['description'] is None:
               description = data['description']
            if 'businessHours' in data and not data['businessHours'] is None:
               businessHours = data['businessHours']
            ms = MerchantService()
            merchant = ms.updateMerchant(request.user.id, name, description, businessHours)
            ser = MerchantSerializer(merchant)
            return JSONResponse(SSUtil.success(ser.data), status=status.HTTP_200_OK)
        except Exception as e:
            return JSONResponse(SSUtil.err(e.message), status=status.HTTP_409_CONFLICT)
Exemplo n.º 3
0
def processTxn(request):
    data = json.loads(request.body)
    print data
    try:
        validate(data)
    except Exception as e:
        return JSONResponse(SSUtil.err(e.message),
                            status=status.HTTP_412_PRECONDITION_FAILED)
    tvServ = TxnValidatorService()
    txnApprovalVO = tvServ.getApproval(data['cardNum'], data['amount'],
                            data['merchantUuid'], data['merchantName'],
                            data['txType'], data['mccCode'])
    delayed = True
    millisStart = SSUtil.getMillis()
    if delayed:
        asyncRecordTransaction.delay(data['cardNum'], data['amount'],
                            data['merchantUuid'], data['merchantName'],
                            data['txType'], data['mccCode'], txnApprovalVO, request.user)
    else:
        asyncRecordTransaction(data['cardNum'], data['amount'],
                            data['merchantUuid'], data['merchantName'],
                            data['txType'], data['mccCode'], txnApprovalVO, request.user)
    millisEnd = SSUtil.getMillis()
    timeTaken = millisEnd - millisStart
    res={ "flag":txnApprovalVO.immediateApproval,
           "msg":txnApprovalVO.remarks,
           "time":timeTaken
        }
    return JSONResponse(SSUtil.success(res), status=status.HTTP_200_OK)
Exemplo n.º 4
0
def registerCard(request):
    consumer = request.user
    data = json.loads(request.body)
    print data
    # TODO: Need to do it nicely
    if 'cardNum' not in data or data['cardNum'] is None:
        return JSONResponse(SSUtil.err(SSException.CARD_NUM_MISSING),
                            status=status.HTTP_412_PRECONDITION_FAILED)
    elif 'phoneNum' not in data or data['phoneNum'] is None:
        return JSONResponse(SSUtil.err(SSException.PHONE_NUM_MISSING),
                            status=status.HTTP_412_PRECONDITION_FAILED)
    elif 'activationCode' not in data or data['activationCode'] is None:
        return JSONResponse(SSUtil.err(SSException.ACTIVATION_CODE_MISSING),
                            status=status.HTTP_412_PRECONDITION_FAILED)
    else:
        cs = CardService()
        try:
            cc = cs.registerCard(consumer.id, data['cardNum'],
                                 data['activationCode'], data['phoneNum'])
            serializer = ConsumerCardSerializer(cc, many=False)
            return JSONResponse(SSUtil.success(serializer.data),
                                status=status.HTTP_201_CREATED)
        except Exception as ex:
            return JSONResponse(SSUtil.err(ex.args[0]),
                                status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 5
0
def getReviewTemplate(request, merchantId):
    try:
        ms = MerchantService();
        serializer = ReviewTemplateSerializer(ms.getReviewTemplate(merchantId), many=False)
        return JSONResponse(SSUtil.success(serializer.data), status=status.HTTP_200_OK)
    except:
        return JSONResponse(SSUtil.err(SSException.INVALID_INPUT),
                                status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 6
0
def unlockMerchantStatus(request, merchantId):
    try:
        cs = ConsumerService()
        s = cs.unlockMerchantStatus(merchantId, request.user.id)
        return JSONResponse(SSUtil.success(s), status=status.HTTP_200_OK)
    except:
        return JSONResponse(SSUtil.err(SSException.PROCESSING_FAILED),
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Exemplo n.º 7
0
def toggleCardLockStatus(request, cardId):
    try:
        cs = ConsumerService()
        s = cs.toggleCardLockStatus(cardId, request.user.id)
        return JSONResponse(SSUtil.success(s), status=status.HTTP_200_OK)
    except:
        return JSONResponse(SSUtil.err(SSException.PROCESSING_FAILED),
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Exemplo n.º 8
0
def getReviewDtl(request, reviewId):
    try:
        ms = MerchantService();
        res = ms.getReviewDtl(reviewId)
        return JSONResponse(SSUtil.success(res), status=status.HTTP_200_OK)
    except:
        return JSONResponse(SSUtil.err("Invalid data"),
                                status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 9
0
def getOffer(request, offerId):
    print "Here"
    ms = MerchantService();
    try:
        serializer = MerchantOfferSerializer(ms.getOffer(offerId), many=False)
        return JSONResponse(SSUtil.success(serializer.data), status=status.HTTP_200_OK)
    except:
        return JSONResponse(SSUtil.err(SSException.INVALID_INPUT), status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 10
0
def getPrefs(request, cardId):
    try:
        cs = ConsumerService()
        prefJson = cs.getPrefsJson(request.user.id, cardId)
        return JSONResponse(SSUtil.success(prefJson),
                            status=status.HTTP_200_OK)
    except:
        return JSONResponse(SSUtil.err(SSException.PROCESSING_FAILED),
                            status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 11
0
def reviews(request, merchantId):
    try:
        ms = MerchantService();
        ssConst = SSConst()
        data = ms.getReviewSummary(merchantId, ssConst.getStartTime("all_time"))
        return JSONResponse(SSUtil.success(data), status=status.HTTP_200_OK)
    except:
        return JSONResponse(SSUtil.err("No reviews available"),
                                status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 12
0
def searchTxns(request, cardId):
    searchServ = SearchService()
    if request.GET["q"] is None or request.GET["q"] == '':
        return JSONResponse(SSUtil.success(Array()), status=status.HTTP_200_OK)
    else:
        start = request.GET.get('start', 0)
        limit = request.GET.get('start', 10)
        res = searchServ.searchTxns(cardId, request.GET["q"], start, limit)
        return JSONResponse(SSUtil.success(res), status=status.HTTP_200_OK)
Exemplo n.º 13
0
def getTxnAggSummary(request, format=None):
    if 'duration' not in request.GET or request.GET["duration"] is None or request.GET["duration"] == '':
        return JSONResponse(SSUtil.err("Duration is required"),
                            status=status.HTTP_412_PRECONDITION_FAILED)
    try:
        ms = MerchantService();
        data = ms.getTxnAggSummary(request.user.id, request.GET['duration'])
        return JSONResponse(SSUtil.success(data), status=status.HTTP_200_OK)
    except Exception as e:
        return JSONResponse(SSUtil.err(e.message), status=status.HTTP_409_CONFLICT)
Exemplo n.º 14
0
def register(request, format=None):
    token = request.META.get('HTTP_SSTOKEN')
    try:
        if token is None:
            return JSONResponse(SSUtil.err(SSException.DEVICE_TOKEN_MISSING),
                                status=status.HTTP_400_BAD_REQUEST)
        else:
            cs = ConsumerService()
            id = cs.registerDevice(token)
            return JSONResponse(SSUtil.success(id),
                                status=status.HTTP_201_CREATED)
    except:
        return JSONResponse(SSUtil.err(SSException.DEVICE_TOKEN_EXISTS),
                            status=status.HTTP_409_CONFLICT)
Exemplo n.º 15
0
def markOfferStatus(request, offerId):
    ms = MerchantService();

    st = None
    if not 'status' in request.DATA or request.DATA['status'] is None:
        return JSONResponse(SSUtil.err("Status  is required"),
                            status=status.HTTP_412_PRECONDITION_FAILED)
    else:
        st =  request.DATA['status']
    try:
        ser = MerchantOfferSerializer(ms.markOfferStatus(offerId,st))
        return JSONResponse(SSUtil.success(ser.data), status=status.HTTP_200_OK)
    except:
        return JSONResponse(SSUtil.err(SSException.PROCESSING_FAILED),
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Exemplo n.º 16
0
def register(request, format=None):
    data = json.loads(request.body)
    if not 'uuid' in data or data['uuid'] is None:
        return JSONResponse(SSUtil.err("Merchant Id is required"),
                            status=status.HTTP_412_PRECONDITION_FAILED)
    if not 'accessCode' in data or data['accessCode'] is None:
        return JSONResponse(SSUtil.err("Access Code is required"),
                            status=status.HTTP_412_PRECONDITION_FAILED)
    try:
        ms = MerchantService();
        merchant = ms.registerMerchant(data['uuid'], data['accessCode'])
        ser = MerchantSerializer(merchant)
        return JSONResponse(SSUtil.success(ser.data), status=status.HTTP_201_CREATED)
    except Exception as e:
        return JSONResponse(SSUtil.err(e.message), status=status.HTTP_409_CONFLICT)
Exemplo n.º 17
0
def saveLocation(request):
    data = json.loads(request.body)
    if not 'lat' in data or data['lat'] is None:
        return JSONResponse(SSUtil.err("Latitude  is required"),
                            status=status.HTTP_412_PRECONDITION_FAILED)
    if not 'lng' in data or data['lng'] is None:
        return JSONResponse(SSUtil.err("Longitude  is required"),
                            status=status.HTTP_412_PRECONDITION_FAILED)
    try:
        cs = ConsumerService()
        s = cs.saveLocation(request.user.id, data['lat'], data['lng'])
        return JSONResponse(SSUtil.success(s), status=status.HTTP_200_OK)
    except:
        return JSONResponse(SSUtil.err(SSException.PROCESSING_FAILED),
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Exemplo n.º 18
0
def getMerchantOffers(request):
    ms = MerchantService();
    st = None
    if 'status' in request.GET and not request.GET['status'] is None  and request.GET['status'] != '':
        st = request.GET['status']
    serializer = MerchantOfferSerializer(ms.getOffers(request.user.id, st), many=True)
    return JSONResponse(SSUtil.success(serializer.data), status=status.HTTP_200_OK)
Exemplo n.º 19
0
def blockedMerchants(request):
    ms = MerchantService()
    serializer = ConsumerMerchantSerializer(ms.getBlockedMerchants(
        request.user.id),
                                            many=True)
    return JSONResponse(SSUtil.success(serializer.data),
                        status=status.HTTP_200_OK)
Exemplo n.º 20
0
def saveDeviceRegistrationId(request):
    data = json.loads(request.body)
    try:
        if data['registrationId'] is None:
            raise Exception()
    except Exception as e:
        return JSONResponse(SSUtil.err(e.message),
                            status=status.HTTP_412_PRECONDITION_FAILED)
    try:
        cs = ConsumerService()
        s = cs.registerDeviceGCMRegistrationId(data['registrationId'],
                                               request.user.id)
        return JSONResponse(SSUtil.success(s), status=status.HTTP_200_OK)
    except:
        return JSONResponse(SSUtil.err(SSException.PROCESSING_FAILED),
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Exemplo n.º 21
0
def deleteLimitPrefs(request, cardId):
    data = json.loads(request.body)
    if not 'categoryKey' in data or data['categoryKey'] is None:
        return JSONResponse(SSUtil.err("Category key is required"),
                            status=status.HTTP_412_PRECONDITION_FAILED)
    if not 'periodKey' in data or data['periodKey'] is None:
        return JSONResponse(SSUtil.err("Period key is required"),
                            status=status.HTTP_412_PRECONDITION_FAILED)
    try:
        cs = ConsumerService()
        s = cs.deletePref(request.user.id, cardId, data['categoryKey'],
                          data['periodKey'])
        return JSONResponse(SSUtil.success(s), status=status.HTTP_200_OK)
    except:
        return JSONResponse(SSUtil.err(SSException.PROCESSING_FAILED),
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Exemplo n.º 22
0
def unlockTxTypeStatus(request, cardId):
    data = json.loads(request.body)
    try:
        if data['txType'] is None:
            raise Exception()
    except Exception as e:
        return JSONResponse(SSUtil.err(e.message),
                            status=status.HTTP_412_PRECONDITION_FAILED)
    try:
        cs = CardService()
        if data['txType'] == 'Intenational':
            data['txType'] = 'International'
        s = cs.unlockTxTypeStatus(cardId, data['txType'])
        return JSONResponse(SSUtil.success(s), status=status.HTTP_200_OK)
    except:
        return JSONResponse(SSUtil.err(SSException.PROCESSING_FAILED),
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Exemplo n.º 23
0
def offerTargetting(request, offerId, targettingId):
    ms = MerchantService();
    if request.method == 'GET':
        try:
            serializer = MerchantOfferTargettingSerializer(ms.getOfferTargetting(targettingId), many=False)
            return JSONResponse(SSUtil.success(serializer.data), status=status.HTTP_200_OK)
        except:
            return JSONResponse(SSUtil.err(SSException.INVALID_INPUT), status=status.HTTP_400_BAD_REQUEST)
    elif request.method == 'DELETE':
        try:
            flag = ms.deleteOfferTargetting(targettingId)
            if flag:
                return JSONResponse(SSUtil.success(flag), status=status.HTTP_200_OK)
            else:
                return JSONResponse(SSUtil.err(flag), status=status.HTTP_200_OK)
        except:
            return JSONResponse(SSUtil.err(SSException.INVALID_INPUT), status=status.HTTP_400_BAD_REQUEST)
    else:
        data = json.loads(request.body)
        targetType = None
        minVisits = 0
        minTotalSpend = 0
        if 'targetType' in data and not data['targetType'] is None:
            targetType = data['targetType']
        if 'minVisits' in data and not data['minVisits'] is None:
            minVisits = data['minVisits']
        if 'minTotalSpend' in data and not data['minTotalSpend'] is None:
            minTotalSpend = data['minTotalSpend']
        try:
            ser = MerchantOfferTargettingSerializer(ms.updateOfferTargetting(targettingId,
                            targetType, minVisits, minTotalSpend))
            return JSONResponse(SSUtil.success(ser.data), status=status.HTTP_200_OK)
        except:
            return JSONResponse(SSUtil.err(SSException.PROCESSING_FAILED),
                                status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Exemplo n.º 24
0
def reviewTemplate(request):
    if request.method == 'GET':
        try:
            ms = MerchantService();
            serializer = ReviewTemplateSerializer(ms.getReviewTemplate(request.user.id), many=False)
            return JSONResponse(SSUtil.success(serializer.data), status=status.HTTP_200_OK)
        except:
            return JSONResponse(SSUtil.err(SSException.INVALID_INPUT),
                                    status=status.HTTP_400_BAD_REQUEST)
    if request.method == 'PUT':
        data = json.loads(request.body)
        if not 'criteria1' in data or data['criteria1'] is None:
            return JSONResponse(SSUtil.err("Criteria1  is required"),
                                status=status.HTTP_412_PRECONDITION_FAILED)
        if not 'criteria2' in data or data['criteria2'] is None:
            return JSONResponse(SSUtil.err("Criteria2  is required"),
                                status=status.HTTP_412_PRECONDITION_FAILED)
        if not 'criteria3' in data or data['criteria3'] is None:
            return JSONResponse(SSUtil.err("Criteria3  is required"),
                                status=status.HTTP_412_PRECONDITION_FAILED)
        try:
            ms = MerchantService();
            res = ReviewTemplateSerializer(ms.saveReviewTemplate(request.user.id,
                        data['criteria1'], data['criteria2'], data['criteria3']),many=False)
            return JSONResponse(SSUtil.success(res.data), status=status.HTTP_200_OK)
        except:
            return JSONResponse(SSUtil.err(SSException.INVALID_INPUT),
                                    status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 25
0
def addTag(request, txnId):
    data = json.loads(request.body)
    try:
        if data['tag'] is None:
            raise Exception()
    except Exception as e:
        return JSONResponse(SSUtil.err("Tag is missing"),
                            status=status.HTTP_412_PRECONDITION_FAILED)
    print "tag is " + str(data['tag'])
    try:
        ts = TxnService()
        s = ts.addTag(txnId, data['tag'])
        ser = ConsumerTagSerializer(s, many=False)
        return JSONResponse(SSUtil.success(ser.data),
                            status=status.HTTP_200_OK)
    except:
        return JSONResponse(SSUtil.err(SSException.PROCESSING_FAILED),
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Exemplo n.º 26
0
def saveReviewResponse(request, reviewId):
    data = json.loads(request.body)
    if not 'merchantComment' in data or data['merchantComment'] is None:
        return JSONResponse(SSUtil.err("Merchant comment is required"),
                            status=status.HTTP_412_PRECONDITION_FAILED)
    offerId = None
    if 'offerId' in data and not data['offerId'] is None:
       offerId = data['offerId']
    try:
        ms = MerchantService();
        res = ms.saveReviewResponse(reviewId, data['merchantComment'], offerId)
        if res is None:
            return JSONResponse(SSUtil.err(False), status=status.HTTP_200_OK)
        else:
            ser = TxnReviewSerializer(res, many=False)
            return JSONResponse(SSUtil.success(ser.data), status=status.HTTP_200_OK)
    except:
        return JSONResponse(SSUtil.err("Invalid data"),
                                status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 27
0
def getReviews(request):
    limit = 100
    start = 0
    duration = "all_time"
    if 'duration' in request.GET and not request.GET["duration"] is None and request.GET["duration"] != '':
        duration = request.GET["duration"]
    if 'limit' in request.GET and not request.GET["limit"] is None and request.GET["limit"] != '':
        limit = int(request.GET["limit"])
    if 'start' in request.GET and not request.GET["start"] is None and request.GET["start"] != '':
        start = int(request.GET["start"])
    try:
        ms = MerchantService();
        ssConst = SSConst()
        res = ms.getMerchantReviews(request.user.id, ssConst.getStartTime(duration), limit, start)
        serializer = TxnReviewSerializer(res, many=True)
        return JSONResponse(SSUtil.success(serializer.data), status=status.HTTP_200_OK)
    except:
        return JSONResponse(SSUtil.err("No reviews available"),
                                status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 28
0
def testAuth(request, format=None):
    c = request.user
    print "auth called"
    cache.set('a-unique-key', 'this is a string which will be cached')
    print cache.get('a-unique-key')
    content = {
        'user': unicode(c.id),  # `django.contrib.auth.User` instance.
        'auth': unicode(request.auth),  # None
    }
    return JSONResponse(content)
Exemplo n.º 29
0
    def cards(self, request, pk=None):

        if request.method == 'GET':
            cards = ConsumerCard.objects.all()
            serializer = ConsumerCardSerializer(cards, many=True)
            return JSONResponse(SSUtil.success(serializer.data),
                                status=status.HTTP_201_CREATED)

        elif request.method == 'POST':
            consumer = request.user
            cc = ConsumerCard()
            cc.consumerId = consumer.id
            cc.cardNum = '1'
            cc.clientId = 0
            cc.limit = 10000
            cc.amtSpentSS = 1000
            cc.currOS = 1100
            cc.save()
            return JSONResponse(SSUtil.success(cc.id),
                                status=status.HTTP_201_CREATED)
Exemplo n.º 30
0
def getTxnMiscDetails(request, cardId, txnId):
    tServ = TxnService()
    try:
        txs = tServ.getTxnMiscDetails(request.user.id, cardId, txnId)
        if not txs is None:
            return Response(SSUtil.success(txs), status=status.HTTP_200_OK)
        else:
            return Response(SSUtil.err(SSException.INVALID_INPUT),
                            status=status.HTTP_200_OK)
    except:
        return JSONResponse(SSUtil.err(SSException.INVALID_INPUT),
                            status=status.HTTP_400_BAD_REQUEST)