示例#1
0
文件: views.py 项目: burugo/gaizuowen
def alipay_notify(request,type,id):
    if request.method == "POST":
      try:
        logging.info("access type:%s,id:%s now:%s " % (type, id, str(datetime.datetime.now())))
        alipay = Alipay()
        valid, infos = alipay.validate(request)
        if valid:
            trade_status = infos['trade_status']
            logging.info("trade:%s,id:%s" % (trade_status, id))
            if trade_status == 'TRADE_SUCCESS' or trade_status == "TRADE_FINISHED":
                record, to_process = process_record_or_no(infos)
                logging.info("to process:%s" % to_process)
                if to_process:
                    profile = record.user.profile
                    profile.money += record.money
                    profile.save()
                    logging.info("user money:%g,record money:%g" % (profile.money, record.money))
                #    msg = Message("success", "您成功充值了%s元!" % total_fee)
                    if type == "pay" and id and record:
                        composition.views.checkin(request,id,user=record.user)
                    else :
                        logging.info("false to checkin ")
            else:
                pass
                #msg = Message("error", "支付未完成!")
            logging.info("success")
            return HttpResponse("success")
      except:
        printinfo("error") 

    logging.info("fail")

    return HttpResponse("fail")
示例#2
0
文件: views.py 项目: burugo/gaizuowen
def alipay_return(request,type,id,template="accounts/alipay_return.html"):
    if request.method == "GET":
        ext_ctx={"pay_type":type,"pay_status":"success"}
        alipay = Alipay()
        valid, infos = alipay.validate(request)
        if valid:
            trade_status = infos['trade_status']
            total_fee = infos['total_fee']
            ext_ctx["money"]=total_fee
            if trade_status == 'TRADE_SUCCESS' or trade_status == "TRADE_FINISHED":
                record,to_process=process_record_or_no(infos)
                if to_process:
                    profile=request.user.profile
                    profile.money += record.money
                    profile.save() 
                #    msg = Message("success", "您成功充值了%s元!" % total_fee)
                    if type=="pay" and id and record:
                        #logging.info("to checkin:%s,uid:%d,profile money:%g" % (id,record.user.id,profile.money))
                        composition.views.checkin(request,id,user=record.user)
                    else:
                        raise Exception
            else:
                ext_ctx["pay_status"]="fail"
                #msg = Message("error", "支付未完成!")
        else:
            ext_ctx["pay_status"]="fail"   
        return render_to_response(template,ext_ctx,RequestContext(request))