Esempio n. 1
0
 def get(self, request):
     order_pk = request.session['order_pk']
     order_payment = OrderPayment.objects.get(order_pk=order_pk)
     payment_id = request.data['object']['id']
     Payment.capture(payment_id)
     order = Order.objects.get(pk=order_pk)
     order_products = order.products.all()
     order_products.update(is_ordered=True)
     for product in order_products:
         product.save()
     order.is_ordered = True
     #order.payment = payment
     order.payment.charge_id = payment_id
     order.save()
     return Response(status=200)
Esempio n. 2
0
def yandex_confirm(request):
    if request.method == 'POST':
        response_json = json.loads(request.body)
        data = response_json['object']
        if data['status'] == 'waiting_for_capture':
            payment_id = response_json['object']['id']
            data = Payment.capture(payment_id)
            # если платеж ожидает подтверждения, подтверждаю
            model = PaymentInfo()
        elif data['status'] == 'succeeded':
            model = PaymentInfo()
        else:
            pass
        try:
            model.payment_id = data['id']
            # id платежа из яндекс кассы
            model.phone = '+' + ''.join(re.findall(r'\d', data['description']))
            # привожу + 7 (900) 00-000-00 к +79000000000
            model.money = int(float(data['amount']['value']))
            # привожу строку 100.00 к цыфре 100
            model.paid = True
            model.save_with_bonus()
            mount = str(model.money + model.count_bonus(model.money))
            # Привожу сумму + бонус к строке для передачи в апи
            continue_play(model.phone, mount,
                          1)  # last argument it's time in hours
            status = 200
        except:
            status = 200
        return HttpResponse(status=status)
Esempio n. 3
0
    def post(self, request):
        Configuration.account_id = '718911'
        Configuration.secret_key = 'test_LvcNnzMH8UOAI0Rc6Dw7MvP8O6WAZoQwsF0kW7e5tY4'

        payment_id = request.data['object']['id']

        Payment.capture(payment_id)
        order_id = request.data['object']['metadata']['id']
        order = PaymentModel.objects.get(id=order_id)
        tickets = TicketPay.objects.all()
        send_email = False
        gen_codes = []

        render_tickets = []
        for ticket in tickets:
            if ticket.order == order:
                if not ticket.is_saved:
                    print(ticket.is_payed)
                    ticket.is_payed = True
                    ticket.is_saved = True
                    ticket.save()
                    send_email = True
                    email = ticket.email
                    gen_codes.append(ticket.generated_code)
                    render_tickets.append(ticket)
                    print(ticket.is_payed)
        if send_email:
            gen_codes = ' '.join(gen_codes)
            print(gen_codes)
            print(email)

            context = {
                'tickets': render_tickets,
            }
            # print(context['tickets'][0])
            send_mail('Ваш заказ с билетом(ами)',
                      gen_codes,
                      '*****@*****.**', [email],
                      html_message=get_template('Payment/letter.html').render(
                          context))
            # send_mail('Ваш заказ с билетом(ами)', gen_codes, '*****@*****.**', [email])

        # нужно забрать айдишники, за которые заплачено и привязать тут полю is_payed значение True
        # после отправить на мыло ключ с инфой
        # otpravka email s klyu4om

        return Response(status=200)
Esempio n. 4
0
    def post(self, request):
        """
        Подтверждение платежа и смена статуса заказа
        :param request:
        :return:
        """
        order_id = request.GET.get("order_id", "")
        order = Orders.objects.get(id=order_id)
        payment_id = order.payment_id
        # payment_id = '26fd1b35-000f-5000-a000-14c3cdc3d6c1'
        Payment.capture(payment_id)

        order = Orders.objects.get(id=order_id)
        order.status_order = 3
        order.save()

        return Response(status=200)
Esempio n. 5
0
 def capture(self):
     return Payment.capture(
         self.payment_id,
         {"amount": {
             "value": self.price,
             "currency": "RUB"
         }},
         str(uuid.uuid4())  #idempotence key
     )
Esempio n. 6
0
def pay_notification(request):
    payment_id = request.data['object']['id']
    yandex_payment = YandexPayment.capture(payment_id)
    payment = Payment.objects.get(yandex_payment=payment_id)
    if payment:
        payment.status = yandex_payment.status
        payment.save()
        print(yandex_payment.id)
        print(yandex_payment.status)
        user = payment.enroll.user

        if not payment.notify:
            payment.notify = True
            payment.save()
            pay_user_email_notify(payment)
            pay_specialist_email_notify(payment)

    return Response(status=200)
Esempio n. 7
0
def cart(request):
    try:
        order = Order.objects.get(user=request.session.session_key,
                                  status=Order.PENDING)
        items = OrderItem.objects.filter(
            order=order,
            order__status=Order.PENDING,
        )
        categories = Category.objects.all()
        total = sum([item.item.price * item.quantity for item in items])

        content = {
            'items': items,
            'order': order,
            'categories': categories,
            'total': total
        }

    except mainapp.models.Order.DoesNotExist:
        content = {}

    if request.method == 'POST':
        if request.POST.get('delivery-type', None) == 'card':
            idempotence_key = str(uuid.uuid4())
            payment = Payment.create(
                {
                    "amount": {
                        "value": float(total),
                        "currency": "RUB"
                    },
                    "payment_method_data": {
                        "type": "bank_card",
                        "card": {
                            "number":
                            request.POST.get('card-number', None),
                            "expiry_year":
                            str(request.POST.get('expiry_year', None)),
                            "expiry_month":
                            str(request.POST.get('expiry_month', None)),
                            "cardholder":
                            request.POST.get('cardholder', None),
                        },
                    },
                    "confirmation": {
                        "type": "redirect",
                        "return_url": "https://www.vagonka40.ru/"
                    },
                    "description": "Заказ в vagonka40.ru"
                }, idempotence_key)

            # get confirmation url
            payment_id = payment.id

            idempotence_key = str(uuid.uuid4())
            response = Payment.capture(
                payment_id,
                {"amount": {
                    "value": float(total),
                    "currency": "RUB"
                }}, idempotence_key)

            order.delivery_type = Order.CARD
        else:
            order.delivery_type = Order.PICKUP

        order.email = request.POST['email']
        order.name = request.POST['name']
        order.phone = request.POST['phone']
        order.status = Order.COMPLETED
        order.save()
        return HttpResponseRedirect(reverse('confirmation'))

    return render(request, 'mainapp/cart.html', content)