def notify_url_handler(request):
    """
    describe:
      Handler for notify_url for asynchronous updating bill information.
    args:
      request.POST
    return:

    """
    if request.method == 'GET':
        if notify_verify(request.GET):
            # bill_id,trade_status
            tn = request.GET.get('out_trade_no')
            #tenpay - trade_no
            trade_no = request.GET.get('transaction_id')
            trade_status = request.GET.get('trade_state')
            bill_info = Goodsbill.objects.get(bill_id=tn)
            bill_info.trade_status = trade_status
            bill_info.save()
            if trade_status == '0':
                bill_state = bill_info.bill_state
                if bill_state == 'buy':
                    order_str = bill_info.order_list
                    order_list = ast.literal_eval(str(order_str))
                    context = ali_views.buy_return(order_list)
                    return HttpResponse("success")
                else:
                    custom_id = bill_info.custom_id
                    ali_views.cus_return(custom_id)
                    return HttpResponse("success")
            else:
                return HttpResponse("success")
    return HttpResponse("fail")
def return_url_handler(request):
    """
    describe:
      Handler for synchronous updating billing information.
    args:
      request.GET
    return:
      success->account/orders
      fail->error.html
    """
    #import pdb
    # pdb.set_trace()
    if notify_verify(request.GET):
        # bill_info
        tn = request.GET.get('out_trade_no')
        # tenpay pay_id
        trade_no = request.GET.get('transaction_id')
        trade_status = request.GET.get('trade_state')
        bill_info = Goodsbill.objects.get(bill_id=tn)
        bill_info.trade_status = trade_status
        bill_info.save()
        # order_info
        order_str = bill_info.order_list
        order_list = ast.literal_eval(str(order_str))
        if trade_status == '0':
            bill_state = bill_info.bill_state
            if bill_state == 'buy':
                order_str = bill_info.order_list
                order_list = ast.literal_eval(str(order_str))
                context = ali_views.buy_return(order_list)
                return render(request, website.ontheway, context)
            else:
                custom_id = bill_info.custom_id
                ali_views.cus_return(custom_id)
                return HttpResponseRedirect('/account/orders')
        else:
            return HttpResponse("fail")
    return render(request, website.payment_error, None)