Пример #1
0
def customer_add_order(request):
    """
        params:
            access_token
            registration_id
            address
            order_details (json format), example:
                [{"meal_id": 1, "quantity": 2},{"meal_id": 2, "quantity": 3}]
            stripe_token

        return:
            {"status": "success"}
    """

    if request.method == "POST":

        ## Get Paytm param Details
        MERCHANT_KEY = settings.PAYTM_MERCHANT_KEY
        MERCHANT_ID = settings.PAYTM_MERCHANT_ID
        CHANNEL_ID = settings.CHANNEL_ID
        WEBSITE = settings.WEBSITE
        INDUSTRY_TYPE_ID = settings.INDUSTRY_TYPE_ID

        ## Get token
        access_token = AccessToken.objects.get(
            token=request.POST.get("access_token"), expires__gt=timezone.now())

        ## Get profile
        customer = access_token.user.customer

        ##get order details
        order_details = json.loads(request.POST["order_details"])
        order_total = 0
        for meal in order_details:
            order_total += Meal.objects.get(
                id=meal["meal_id"]).price * meal["quantity"]
        bill_amount = str(order_total)

        ## Generating unique  ids
        order_id = Checksum.__id_generator__()
        CALLBACK_URL = settings.CALLBACK_URL + order_id

        data_dict = {
            'MERCHANT_ID': MERCHANT_ID,
            'ORDER_ID': order_id,
            'TXN_AMOUNT': bill_amount,
            'CUST_ID': customer.user.username,
            'CALLBACK_URL': CALLBACK_URL,
            'CHANNEL_ID': CHANNEL_ID,
            'WEBSITE': WEBSITE,
            'INDUSTRY_TYPE_ID': INDUSTRY_TYPE_ID,
        }
        param_dict = data_dict
        param_dict['CHECKSUMHASH'] = Checksum.generate_checksum(
            data_dict, MERCHANT_KEY)

        return JsonResponse(param_dict)
Пример #2
0
def response(request):
    if request.method == "POST":
        MERCHANT_KEY = settings.PAYTM_MERCHANT_KEY
        data_dict = {}
        for key in request.POST:
            data_dict[key] = request.POST[key]
        verify = Checksum.verify_checksum(data_dict, MERCHANT_KEY,
                                          data_dict['CHECKSUMHASH'])
        if verify:
            PaytmHistory.objects.create(user=request.user, **data_dict)
            return HttpResponse(
                "checksum verify successful"
            )  #render(request,"response.html",{"paytm":data_dict})
        else:
            return HttpResponse("checksum verify failed")
    return HttpResponse(status=200)
Пример #3
0
def response(request):


   if request.method == "POST":

        MERCHANT_KEY = settings.PAYTM_MERCHANT_KEY
        MERCHANT_ID = settings.PAYTM_MERCHANT_ID
        orderId=request.POST['ORDER_ID']
    

        ## Get token
        try:
            access_token = TokenModel.objects.get(key = request.POST.get("access_token"))
        except TokenModel.DoesNotExist:
            access_token = AccessToken.objects.get(token = request.POST.get("access_token"),expires__gt = timezone.now())


        ## Get profile
        customer = access_token.user.customer

        ## Get Order Details
        order_details = json.loads(request.POST["order_details"])

        order_total = 0
        for meal in order_details:
            if 'meal_id' in meal:
               order_total += Meal.objects.get(id = meal["meal_id"]).price * meal["quantity"]
            if 'drink_id' in meal:
               order_total += Drink.objects.get(id = meal["drink_id"]).price * meal["quantity"]
        bill_amount = str(order_total)

        ## initialize a dictionary
        paytmParams = dict()
        paytmParams["MID"] = MERCHANT_ID
        paytmParams["ORDERID"] = orderId
        ## Generate checksum by parameters we have in body
        checksum = Checksum.generate_checksum(paytmParams, MERCHANT_KEY)
        ## put generated checksum value here
        paytmParams["CHECKSUMHASH"] = checksum
        ## prepare JSON string for request
        post_data = json.dumps(paytmParams)

        url = settings.VERIFY_URL
        pay_res = requests.post(url, data = post_data, headers = {"Content-type": "application/json"}).json()
        
        if('ErrorMsg' in pay_res):
            return JsonResponse({'PAY_STATUS':pay_res['ErrorMsg']})

        status=pay_res['STATUS']
        back_response={
                'PAY_STATUS':status,
            }



        if status== 'TXN_SUCCESS':


            ##Step 2 - Create an Order
            order = Order.objects.create(
               customer =customer,
               registration_id =request.POST["registration_id"],
               total = order_total,
               status = Order.COOKING,
               address = request.POST["address"]
            )

            ## Step 3 - Create Order details
            for meal in order_details:                
                OD=OrderDetails()
                OD.order = order
                OD.quantity = meal["quantity"]
   
                if 'meal_id' in meal:
                   OD.meal_id= meal["meal_id"]
                   OD.sub_total=Meal.objects.get(id = meal["meal_id"]).price * meal["quantity"]
                if 'drink_id' in meal:
                   OD.drink_id= meal["drink_id"]
                   OD.sub_total=Drink.objects.get(id = meal["drink_id"]).price * meal["quantity"]
                OD.save()

            ## step 4 save the payment
            PaytmHistory.objects.create(customer=customer,order=order,**pay_res)
            return JsonResponse(back_response)
        return JsonResponse(back_response)
Пример #4
0
def response(request):


   if request.method == "POST":

        MERCHANT_KEY = settings.PAYTM_MERCHANT_KEY
        MERCHANT_ID = settings.PAYTM_MERCHANT_ID
        orderId=request.POST['ORDER_ID']
    

        ## Get token
        access_token = AccessToken.objects.get(token = request.POST.get("access_token"),expires__gt = timezone.now())

        ## Get profile
        customer = access_token.user.customer

        # Check whether customer has any order that is not delivered
        if Order.objects.filter(customer = customer).exclude(status = Order.DELIVERED):
            return JsonResponse({"status": "failed", "error": " on Response Your last order must be completed."})

        # Check Address
        if not request.POST["address"]:
            return JsonResponse({"status": "failed", "error": "on Response Address is required."})

        ## Get Order Details
        order_details = json.loads(request.POST["order_details"])

        order_total = 0
        for meal in order_details:
            order_total += Meal.objects.get(id = meal["meal_id"]).price * meal["quantity"]
        bill_amount = str(order_total)

        ## initialize a dictionary
        paytmParams = dict()
        paytmParams["MID"] = MERCHANT_ID
        paytmParams["ORDERID"] = orderId
        ## Generate checksum by parameters we have in body
        checksum = Checksum.generate_checksum(paytmParams, MERCHANT_KEY)
        ## put generated checksum value here
        paytmParams["CHECKSUMHASH"] = checksum
        ## prepare JSON string for request
        post_data = json.dumps(paytmParams)

        url = settings.VERIFY_URL
        pay_res = requests.post(url, data = post_data, headers = {"Content-type": "application/json"}).json()
        
        if('ErrorMsg' in pay_res):
            return JsonResponse({'PAY_STATUS':pay_res['ErrorMsg']})

        status=pay_res['STATUS']
        back_response={
                'PAY_STATUS':status,
            }



        if status== 'TXN_SUCCESS':


            ##Step 2 - Create an Order
            order = Order.objects.create(
               customer =customer,
               registration_id =request.POST["registration_id"],
               total = order_total,
               status = Order.COOKING,
               address = request.POST["address"]
            )

            ## Step 3 - Create Order details
            for meal in order_details:
                OrderDetails.objects.create(
                   order = order,
                   meal_id = meal["meal_id"],
                   quantity = meal["quantity"],
                   sub_total = Meal.objects.get(id = meal["meal_id"]).price * meal["quantity"]
                   )
            ## step 4 save the payment
            PaytmHistory.objects.create(customer=customer,order=order,**pay_res)
            return JsonResponse(back_response)
        return JsonResponse(back_response)
Пример #5
0
def customer_add_order(request):
    """
        params:
            access_token
            registration_id
            address
            order_details (json format), example:
                [{"meal_id": 1, "quantity": 2},{"meal_id": 2, "quantity": 3}]
            stripe_token

        return:
            {"status": "success"}
    """

    if request.method == "POST":
        # Get token
        flag = "success"
        #access_token = AccessToken.objects.get(token = request.POST.get("access_token"),expires__gt = timezone.now())

        # Get profile
        #customer = access_token.user.customer

        # Check whether customer has any order that is not delivered
        #if Order.objects.filter(customer = customer).exclude(status = Order.DELIVERED):
        #flag='Your last order must be completed.' #JsonResponse({"status": "failed", "error": "Your last order must be completed."})

        # Check Address
        #if not request.POST["address"]:
        #flag="Address is required" # return JsonResponse({"status": "failed", "error": "Address is required."})

        # Get Order Details
        order_details = json.loads(request.POST["order_details"])

        order_total = 0
        for meal in order_details:
            order_total += Meal.objects.get(
                id=meal["meal_id"]).price * meal["quantity"]

        MERCHANT_KEY = settings.PAYTM_MERCHANT_KEY
        MERCHANT_ID = settings.PAYTM_MERCHANT_ID
        #get_lang = "/" + get_language() if get_language() else ''
        # CALLBACK_URL = settings.HOST_URL + get_lang + settings.PAYTM_CALLBACK_URL
        # Generating unique temporary ids
        order_id = Checksum.__id_generator__()
        if len(order_details) >= 0:
            bill_amount = str(order_total)
            #if bill_amount:
            data_dict = {
                'MERCHANT_ID': MERCHANT_ID,
                'ORDER_ID': order_id,
                'TXN_AMOUNT': bill_amount,
                'CUST_ID': '*****@*****.**',
                #'INDUSTRY_TYPE_ID':'Retail',
                #  'WEBSITE': settings.PAYTM_WEBSITE,
                #'CHANNEL_ID':'WEB',
                'payt_STATUS': flag
                #'CALLBACK_URL':CALLBACK_URL,
            }
            param_dict = data_dict
            param_dict['CHECKSUMHASH'] = Checksum.generate_checksum(
                data_dict, MERCHANT_KEY)
            #return render(request,"response.html",{"paytm":param_dict})
            return JsonResponse(param_dict)
        else:
            return JsonResponse({'payt_STATUS': 'error'})