Example #1
0
    def get_context_data(self, **kwargs):
        context = super(ConfirmLiqpay, self).get_context_data(**kwargs)
        days = self.kwargs.get('days')
        context['price'] = getattr(SettingsFranchise.get_solo(),
                                   'price_{0}'.format(days))
        context['currency'] = SettingsFranchise.get_solo().currency
        context['method'] = 'LiqPay'
        context['title'] = 'Оплата через LiqPay'
        site = Site.objects.get_current()
        liqpay = LiqPay(get_liqpay_public_key(), get_liqpay_signature())
        result_url = site.domain + str(reverse_lazy('liqpay:done_liqpay'))
        server_url = site.domain + str(reverse_lazy('liqpay:callback_liqpay'))
        context['html'] = liqpay.cnb_form({
            "action":
            "pay",
            "amount":
            context['price'],
            "currency":
            context['currency'],
            "description":
            "Продление франшизы " + site.name,
            "order_id":
            self.get_order_count(),
            "version":
            "3",
            # "sandbox": "yes",
            "server_url":
            server_url,
            'result_url':
            result_url,
            'info':
            days,
        })

        return context
Example #2
0
 def get_liqpay_form(self, cart):
     liqpay = LiqPay(LIQPAY_PUBLIC, LIQPAY_PRIVATE)
     liqpay_data = {
         "action":
         "pay",
         "amount":
         str(cart.ticket_type.cost),
         "currency":
         "UAH",
         "description":
         "{} ticket for {}".format(cart.ticket_type.type,
                                   cart.ticket_type.campaign.title),
         "order_id":
         cart.uid,
         "language":
         "ru",
         "sandbox":
         cart.ticket_type.campaign.sandbox,
         "server_url":
         self.request.build_absolute_uri(reverse('api-liqpay')),
         "result_url":
         self.request.build_absolute_uri(cart.get_absolute_url())
     }
     logger.info(liqpay_data)
     html = liqpay.cnb_form(liqpay_data)
     return html
Example #3
0
 def get(self, request, *args, **kwargs):
     if request.session.get('order'):
         order_id = request.session['order'][0]
         order_price = str(request.session['order'][1])
         if Order.objects.filter(pk=int(order_id)).exists():
             liqpay = LiqPay(os.getenv('LIQPAY_PUBLIC_KEY'),
                             os.getenv('LIQPAY_PRIVATE_KEY'))
             params = {
                 'action': 'pay',
                 'amount': str(order_price),
                 'currency': 'UAH',
                 'description': f'Payment for order № {order_id}',
                 'order_id': str(order_id),
                 'version': '3',
                 'sandbox': 1,  # sandbox mode, set to 1 to enable it
                 'server_url':
                 'https://localhost:8008/payback/',  # url to callback view
             }
             signature = liqpay.cnb_signature(params)
             data = liqpay.cnb_form(params)
             st = data.find('value=') + 7
             data2 = data[st:]
             end = data2.find('/>') - 1
             data = data2[:end]
             signature = data2[end:]
             st = signature.find('value=') + 7
             signature = signature[st:]
             end = signature.find('/>') - 1
             signature = signature[:end]
             return render(request, self.template_name, {
                 'signature': signature,
                 'data': data
             })
     raise Http404
Example #4
0
def checkout(request):
    session_key = request.session.session_key
    products_in_basket = ProductInBasket.objects.filter(
        session_key=session_key, is_active=True, order__isnull=True)
    print(products_in_basket)
    for item in products_in_basket:
        print(item.order)

    form = CheckoutContactForm(request.POST or None)
    liqpay = LiqPay("sandbox_i26660223217",
                    "sandbox_u3BM9ppkXfPn0Phd5ZNhpkzieRiVWHmq12iJUJYb")
    html1 = liqpay.cnb_form({
        'action': 'pay',
        'amount': '5',
        'currency': 'USD',
        'description': 'description text',
        'order_id': 'order_id_52',
        'version': '3',
        'result_url': 'http://127.0.0.1:8000/'
    })
    if request.POST:
        print(request.POST)
        if form.is_valid():
            print("yes")
            data = request.POST
            name = data.get("name", "3423453")
            phone = data["phone"]
            user, created = User.objects.get_or_create(
                username=phone, defaults={"first_name": name})

            order = Order.objects.create(user=user,
                                         customer_name=name,
                                         customer_phone=phone,
                                         customer_address=address,
                                         status_id=1)

            for name, value in data.items():
                if name.startswith("product_in_basket_"):
                    product_in_basket_id = name.split("product_in_basket_")[1]
                    product_in_basket = ProductInBasket.objects.get(
                        id=product_in_basket_id)
                    print(type(value))

                    product_in_basket.nmb = value
                    product_in_basket.order = order
                    product_in_basket.save(force_update=True)

                    ProductInOrder.objects.create(
                        product=product_in_basket.product,
                        nmb=product_in_basket.nmb,
                        price_per_item=product_in_basket.price_per_item,
                        total_price=product_in_basket.total_price,
                        order=order)

            return HttpResponseRedirect(request.META['HTTP_REFERER'])
        else:
            print("no")
    return render(request, 'orders/checkout.html', locals())
Example #5
0
def payment(request, sum):
    liqpay = LiqPay(settings.LIQPAY_PUBLIC_KEY, settings.LIQPAY_PRIVATE_KEY)
    html = liqpay.cnb_form({
        'action': 'p2p',
        'amount': '1000',
        'currency': 'UAH',
        'description': 'Заказ недвижимости через DOMUM',
        'order_id': OrderId.objects.first().next(),
        'version': '3',
        'sandbox': 0,
        'server_url': 'http://127.0.0.1:8000/pay-callback/',
    })
    return HttpResponse(html)
Example #6
0
 def get_liqpay_form(self, cart):
     liqpay = LiqPay(LIQPAY_PUBLIC, LIQPAY_PRIVATE)
     liqpay_data = {
         "action": "pay",
         "amount": str(cart.ticket_type.cost),
         "currency": "UAH",
         "description": "{} ticket for {}".format(cart.ticket_type.type, cart.ticket_type.campaign.title),
         "order_id": cart.uid,
         "language": "ru",
         "sandbox": cart.ticket_type.campaign.sandbox,
         "server_url": self.request.build_absolute_uri(reverse('api-liqpay')),
         "result_url": self.request.build_absolute_uri(cart.get_absolute_url())
     }
     logger.info(liqpay_data)
     html = liqpay.cnb_form(liqpay_data)
     return html
Example #7
0
 def get_pay_form(self):
     lq = LiqPay(settings.LIQPAY_MERCHANT_ID, settings.LIQPAY_SIGNATURE)
     payment_params = {
         'version': '3',
         'amount': str(self.amount),
         'currency': 'UAH',
         'description': self.description,
         'order_id': self.order_id,
         'result_url': 'http://ci.ua/accounts/profile/',
         'server_url': 'http://ci.ua/accounts/liqpay/result',
         'type': 'buy',
     }
     # 'sandbox': '1',} # tesst payment
     lq_form = lq.cnb_form(payment_params)
     self.save()
     return lq_form
Example #8
0
def buy(request,id):
    lesson = get_object_or_404(Vlesson, pk=id)
    l = Liqpay()
    l.user = request.user
    l.lesson = lesson
    l.amount = lesson.price
    l.save()
    liqpay = LiqPay(LIQPAY_PUBLIC_KEY, LIQPAY_PRIVATE_KEY)
    form = liqpay.cnb_form({"amount" : lesson.price,
                            "currency" : "UAH",
                            "description" : u"Покупка видеоурока",
                            "order_id" : l.id,
                            "result_url": LIQPAY_RESULT_URL,
                            "server_url": LIQPAY_SERVER_URL,
                            "type" : "buy",
                            "sandbox" : "1"})
    context = {'lesson': lesson, 'button': form}
    return render_to_response('buy.html', context, RequestContext(request))
Example #9
0
def buy(request,id):
    issue = get_object_or_404(Issue, pk=id)
    from liqpay.models import Liqpay
    l = Liqpay()
    l.issue = issue
    l.user = request.user
    l.amount = issue.journal.price
    l.save()
    liqpay = LiqPay(LIQPAY_PUBLIC_KEY, LIQPAY_PRIVATE_KEY)
    form = liqpay.cnb_form({"amount" : "3",
                            "currency" : "RUB",
                            "description" : "Покупка прессы",
                            "order_id" : l.id,
                            "result_url": LIQPAY_RESULT_URL,
                            "server_url": LIQPAY_SERVER_URL,
                            "type" : "buy",
                            "sandbox" : "1"})
    context = {"issue": issue, 'button': form}
    return render_to_response('catalog/buy.html', context, RequestContext(request))