示例#1
0
文件: liqpay.py 项目: kostyll/stock2
    def api_callback_pay(self, Params):
           PublicKey = Params["public_key"] 
           Amount =  Params["amount"] 
           CurrencyStr = Params["currency"] 
           Desc = Params["description"]
           Type = Params["type"]
           OrderId = Params["order_id"]
           Status = Params["status"]
           OutOrderId = Params["transaction_id"]
           Phone = Params["sender_phone"]
           Signature = Params["signature"]
           Comission = Decimal(Params["receiver_commission"])
           m = hashlib.sha1(self.__private_key + 
                         Amount +
                         CurrencyStr  +
                         self.__public_key +
                         OrderId +
                         self.__type +
                         self.__description +
                         Status +
                         OutOrderId +
                         Phone
                         )
           
           signature = b64encode( m.digest() )       
           if signature != Signature: 
                    raise TransError("Invalid Signature")
             
           if Status == "failure":
                     order = Orders.objects.get( id = int(OrderId) )
                     order.status = "order_cancel"
                     order.save()
                     Response =  HttpResponse( json.JSONEncoder().encode({"status":True,"signature":True}) )
                     Response['Content-Type'] = 'application/json'
                     return Response
             
           if Status == "wait_secure":
                     order = Orders.objects.get( id = int(OrderId), status="created" )
                     order.status = "wait_secure"
                     order.save()
                     Response =  HttpResponse( json.JSONEncoder().encode({"status":True,"signature":True}) )
                     Response['Content-Type'] = 'application/json'
                     return Response
           ##TODO add system message  
           if Status == "success":
                     order = Orders.objects.get(id = int(OrderId) )
                     if order.status !="created" and order.status !="wait_secure":
                             raise TransError("Invalid order")
                     order.status="processing"
                     order.save()
                     from main.models import check_holds
                     check_holds(order)
                     DebCred =   LiqPayTrans(   phone = Phone,
                                                description = Desc,
                                                  #pib = ,
                                                currency = self.__currency,
                                                amnt = Decimal(Amount) ,
                                                user = order.user,
                                                pub_date = datetime.now(),
                                                comission = self.__comis,
                                                user_accomplished_id =  1,
                                                status = "processed",
                                                debit_credit = "in",
                                                confirm_key = Signature,
                                                order = order
                                            )
                     DebCred.sign_record(self.__private_key)
                     DebCred.save()
                     add_trans(order.transit_1 , order.sum1, self.__currency,
                               order.transit_2, order,
                               "payin", DebCred.id, False)
                     
                     #hack if privat is wrong  
                     HackComis = order.sum1 * self.__comis
                     if Comission < HackComis:
                         Comission = HackComis

                     add_trans( order.transit_2 , Comission, self.__currency,
                                order.transit_1,  order, 
                                "comission", OutOrderId, False)


                     order.status = "processed"
                     order.save()
                     notify_email(order.user, "deposit_notify", DebCred ) 
                     Response =  HttpResponse( json.JSONEncoder().encode({"status":True,"signature":True}) )
                     Response['Content-Type'] = 'application/json'
                     return Response

           if Status == "sandbox":
                     raise TransError("hacker ")
                     order = Orders.objects.get(id = int(OrderId), status = "created")
                     order.status="processing"
                     order.save()
                     check_holds(order)

                     add_trans(order.transit_1, order.sum1, self.__currency,
                               order.transit_2, order, "payin", OutOrderId, False )
                     
                     
                     #Comission = order.sum1 * self.__comis
                     add_trans( order.transit_2, Comission , self.__currency,
                                order.transit_1,  order, 
                                "comission", OutOrderId, False)
                     DebCred =   LiqPayTrans(
                                                  phone = Phone,
                                                  description = Desc, 
                                                  currency = self.__currency, 
                                                  amnt = Decimal(Amount) , 
                                                  user = order.user ,
						                          pub_date = datetime.now(),
                                                  comission = self.__comis,
                                                  user_accomplished_id =  1,
                                                  status = "processed",
                                                  debit_credit = "in",
                                                  confirm_key = Signature,
                                                  order = order
                                                  
                                            )
                     DebCred.save()
                     order.status = "processed"
                     order.save()
                     Response =  HttpResponse( json.JSONEncoder().encode({"status":True,"signature":True}) )
                     Response['Content-Type'] = 'application/json'
                     return Response