Example #1
1
    def handle(self, *args, **options):
        from sdk.liqpay import liqpay

        for DebCred in LiqPayTrans.objects.filter(status='processing', debit_credit='in'):
            order = DebCred.order
            OrderId = order.id
            d = liqpay("ru", "UAH")
            Dict = d.api("payment/status", {"version": "2", "order_id": str(OrderId)})
            print Dict
            if Dict["status"] == "success":
                if order.status != "processing":
                    DebCred.status = 'canceled'
                    DebCred.save()
                    continue
                order.status = "processing2"
                order.save()
                OutOrderId = Dict["liqpay_order_id"]
                from main.models import check_holds

                check_holds(order)
                add_trans(order.transit_1, order.sum1, d.currency,
                          order.transit_2, order,
                          "payin", OutOrderId, False)

                #hack if privat is wrong
                Comission = Decimal(Dict["receiver_commission"])
                Phone = Dict['sender_phone']
                Desc = Dict['description']
                Signature = Dict['liqpay_order_id']
                Amount = Dict['amount']
                add_trans(order.transit_2, Comission, d.currency,
                          order.transit_1, order,
                          "comission", OutOrderId, False)

                DebCred.status = 'processed'
                DebCred.save()
                order.status = "processed"
                order.save()
                #notify_email(order.user, "deposit_notify", DebCred )
        else:
            DebCred.status = 'canceled'
            DebCred.save()
Example #2
0
    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
Example #3
0
    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)
                     add_trans( order.transit_1 , order.sum1, self.__currency,
                                order.transit_2, order, 
                                "payin", OutOrderId, 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)

                     DebCred =   LiqPayTrans(
                                                  phone = Phone,
                                                  description = Desc,
                                                  #pib = ,
                                                  currency = self.__currency, 
                                                  amnt = Decimal(Amount) , 
                                                  user = order.user ,
                                                  comission = self.__comis,
                                                  user_accomplished_id =  1,
                                                  status = "processed",
                                                  debit_credit = "in",
                                                  confirm_key = Signature,
                                                  order = order
                                                 )
                     DebCred.save()
                     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 ,
                                                  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