예제 #1
0
 def post(self, request, id, *args, **kwargs):
     booking = Booking.objects.get(pk=id)
     liq_pay = LiqPay(settings.LIQPAY_PUBLIC_KEY,
                      settings.LIQPAY_PRIVATE_KEY)
     data = request.POST.get('data')
     signature = request.POST.get('signature')
     sign = liq_pay.str_to_sign(settings.LIQPAY_PRIVATE_KEY + data +
                                settings.LIQPAY_PRIVATE_KEY)
     if sign == signature:
         booking.is_paid = True
         booking.save()
     response = liq_pay.decode_data_from_str(data)
     print('callback data', response)
     return HttpResponse()
예제 #2
0
파일: views.py 프로젝트: Konovalov-Kos/shop
 def post(self, request, *args, **kwargs):
     liqpay = LiqPay(os.getenv('LIQPAY_PUBLIC_KEY'),
                     os.getenv('LIQPAY_PRIVATE_KEY'))
     data = request.POST.get('data')
     signature = request.POST.get('signature')
     sign = liqpay.str_to_sign(
         os.getenv('LIQPAY_PRIVATE_KEY') + data +
         os.getenv('LIQPAY_PRIVATE_KEY'))
     if sign == signature:
         print('callback is valid')
     response = ''
     base64.b64decode(data, response)
     print('callback data', response)
     if request.session.get('order'):
         request.session.pop('order')
     return HttpResponse()
예제 #3
0
def pay_callback(request):
    liqpay = LiqPay(get_liqpay_public_key(), get_liqpay_signature())
    data = request.POST.get('data')
    signature = request.POST.get('signature')
    sign = liqpay.str_to_sign(get_liqpay_signature() + data +
                              get_liqpay_signature())
    if sign == str(signature):
        qdict = QueryDict('', mutable=True)
        qdict.update(json.loads(base64.b64decode(data)))
        form = LiqPayTransactionForm(qdict)
        if form.is_valid():
            form.save()
            day = qdict.get('info')
            if isinstance(day, unicode):
                day = int(day)
            active_franchise = ActiveFranchise.get_solo()
            active_franchise.active_franchise += datetime.timedelta(days=day)
            active_franchise.save()
        else:
            print(form.errors)
        return HttpResponse(status=200)
    return HttpResponse(status=500)
예제 #4
0
def liqpay(request):
    pay_result = json.loads(base64.decodestring(request.POST['data']))
    lq = LiqPay(LIQPAY_MERCHANT_ID, LIQPAY_SIGNATURE)
    signature = lq.str_to_sign(LIQPAY_SIGNATURE + request.POST['data'] +
                               LIQPAY_SIGNATURE)
    payment = UserPayment.objects.get(order_id=pay_result['order_id'])
    payment.status = pay_result['status']
    payment.transaction_id = pay_result['transaction_id']
    if 'sender_phone' in pay_result:
        payment.sender_phone = pay_result['sender_phone'][-10:]
    if request.POST['signature'] != signature:
        payment.status = payment.status + ' signature missmatch'
    elif payment.status == 'success':
        user = payment.user
        if payment.service:
            if 'base_' in payment.service.name:
                payment.useroperation_set.add(
                    user.set_ab_status(payment.service,
                                       payment.duration,
                                       info=u'оплата liqpay'))
            elif 'adv_' in payment.service.name:
                payment.useroperation_set.add(
                    payment.advert.activate_service(service=payment.service,
                                                    term=payment.duration))
        elif 'balance' in payment.description:
            user.current_balance += payment.amount
            user.save()
            UserWalletHistory.objects.create(user=user,
                                             new_sum=user.current_balance,
                                             deposit=payment,
                                             info=payment.pay_way)
    elif payment.status == 'sandbox':
        payment.annotation = 'test payment'
    payment.save()
    response = HttpResponse('ok')
    return response
예제 #5
0
 def calculate_signature(self, data):
     liqpay = LiqPay(LIQPAY_PUBLIC, LIQPAY_PRIVATE)
     calc_sign = liqpay.str_to_sign(LIQPAY_PRIVATE.encode() +
                                    data.encode() +
                                    LIQPAY_PRIVATE.encode()).decode()
     return calc_sign
예제 #6
0
파일: pay.py 프로젝트: slava2498/vie
class Pay:
    def __init__(self):
        if settings.DEBUG:
            key_1, key_2 = '', ''
        else:
            key_1, key_2 = '', ''

        self.sign_str = ''.format(key_1, key_2)

        self.liqpay = LiqPay(key_1, key_2)
        self.data = ''

    def font(self, type_font, message):
        font_array = {
            'bold': '<b>' + str(message) + '</b>',
            'light': '<i>' + str(message) + '</i>'
        }
        return font_array[type_font]

    def create_pay(self, amount, order_id, type_tr):
        res = self.liqpay.api(
            "request", {
                "action": "invoice_bot",
                "version": "3",
                "amount": amount,
                "currency": "UAH",
                "order_id": '_'.join([order_id, type_tr]),
                "phone": "",
                "server_url": '{}/liqpay'.format(settings.URL_HOST)
            })

        self.data = res['token']

    def pay(self, json_data):
        data = base64.b64decode(json_data['data']).decode('utf-8')
        sign = self.liqpay.str_to_sign(self.sign_str.format(json_data['data']))
        json_string = json.loads(data)

        print(json_data['signature'])
        print(sign)
        self.state = False
        if (json_data['signature'] == sign
                and json_string['status'] == 'success'):
            order = json_string['order_id'].split('_')
            pay_liq_id = order[0]
            type_tr = order[1]

            transactions = Payliq.objects.filter(id=pay_liq_id).first()
            if (not transactions.state):
                transactions.state = True
                transactions.json = str(json_string)
                transactions.save(update_fields=['state', 'json'])

                self.client = Clients.objects.filter(
                    id=transactions.client.id).first()
                self.client.balance += transactions.amount_one
                self.client.save(update_fields=['balance'])

                Transactions_log.objects.create(client=self.client,
                                                amount=transactions.amount_one,
                                                type_transactions='payliq')

                if type_tr == 'balance':
                    pass

                elif type_tr == 'task':
                    pass

                self.state = True
예제 #7
0
파일: api_views.py 프로젝트: itkpi/tickets
 def calculate_signature(self, data):
     liqpay = LiqPay(LIQPAY_PUBLIC, LIQPAY_PRIVATE)
     calc_sign = liqpay.str_to_sign(LIQPAY_PRIVATE.encode() + data.encode() + LIQPAY_PRIVATE.encode()).decode()
     return calc_sign