예제 #1
0
def checkout(request):
    if request.method == "POST":
        name = request.POST.get('name', '')
        amount = request.POST.get('amount', '')
        item_list = request.POST.get('items_list', '')
        address = request.POST.get('address1', '') + " " + request.POST.get(
            'address2', '')
        email = request.POST.get('email', '')
        phone = request.POST.get('phone', '')
        city = request.POST.get('city', '')
        state = request.POST.get('state', '')
        zip_code = request.POST.get('zip_code', '')
        order = Order(name=name,
                      email=email,
                      phone=phone,
                      city=city,
                      state=state,
                      amount=amount,
                      Items_list=item_list,
                      zipcode=zip_code,
                      address=address)
        order.save()
        update = OrderUpdate(order_id=order.order_id,
                             update_disc="The order has been placed")
        update.save()
        thank = True
        id = order.order_id
        #return render(request,'shop/checkout.html',{'thank':thank,'id': id})
        # Request paytm to transfer amount to my account after payment is done by user
        param_dict = {
            'MID': 'Paytm Merchant Account Id',
            'ORDER_ID': str(order.order_id),
            'TXN_AMOUNT': str(amount),
            'CUST_ID': email,
            'INDUSTRY_TYPE_ID': 'Retail',
            'WEBSITE': 'WEBSTAGING',
            'CHANNEL_ID': 'WEB',
        }

        param_dict['CHECKSUMHASH'] = Checksum.generate_checksum_by_str(
            param_dict, MERCHANT_KEY, salt=None)

        return render(request, 'shop/paytm.html', {
            'param_dict': param_dict,
            'thank': True
        })
    return render(request, 'shop/checkout.html')
예제 #2
0
def cancel_order(request, pk):
    order = Orders.objects.get(pk=pk)
    order.status = 'Cancel'
    order.save()

    items = Myorder.objects.filter(order_id=order, canteen_id=request.user)
    for i in items:
        i.status = 'Cancel'
        i.save()

    # body parameters
    paytmParams = dict()
    paytmParams["body"] = {

        # Find your MID in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys
        "mid": MID,

        # This has fixed value for refund transaction
        "txnType": "REFUND",

        # Enter your order id for which refund needs to be initiated
        "orderId": str(order.id),

        # Enter transaction id received from Paytm for respective successful order
        "txnId": str(order.transaction_id),

        # Enter numeric or alphanumeric unique refund id
        "refId": str(order.id),

        # Enter amount that needs to be refunded, this must be numeric
        "refundAmount": str(order.total_price)
    }
    checksum = Checksum.generate_checksum_by_str(
        json.dumps(paytmParams["body"]), MKEY)
    # head parameters
    paytmParams["head"] = {

        # This is used when you have two different merchant keys. In case you have only one please put - C11
        "clientId": str(order.ordered_by.id),

        # put generated checksum value here
        "signature": checksum
    }
    post_data = json.dumps(paytmParams)
    url = "https://securegw-stage.paytm.in/refund/apply"
    response = requests.post(url,
                             data=post_data,
                             headers={
                                 "Content-type": "application/json"
                             }).json()
    #return render(request,'app1/refund.html',{'param_dict':paytmParams})
    post_data = json.dumps(paytmParams)
    print(post_data)
    order = Orders.objects.get(pk=pk)
    order.payment_status = 'Refund'
    order.save()
    '''
	Refund.objects.create(refund_amount=order.total_price,txnId=post_data['body']['resultInfo']['txnId'],order=order,refundId=post_data['body']['resultInfo']['refundId'])
	response['refundId']
	'''
    return redirect(new_order)