def checkout(request): """Оформление заказа - Подтверждение заказа""" mh_vars = order_vars.copy() context = {} q_string = {} containers = {} shopper = get_shopper(request) if request.is_ajax(): return JsonResponse(context, safe=False) template = 'web/order/checkout.html' page = SearchLink(q_string, request, containers) if not page: page = Blocks(name=order_vars['singular_obj']) context['breadcrumbs'] = [{ 'name': 'Подтверждение заказа', 'link': reverse('%s:%s' % (CUR_APP, 'checkout')), }] context['page'] = page context['containers'] = containers cart = calc_cart(shopper, min_info=False) context['cart'] = cart # Оформление заказа context.update(**create_new_order(request, shopper, cart)) if 'order' in context and context['order']: template = 'web/order/confirmed.html' return render(request, template, context)
def checkout(request): """Оформление заказа - Подтверждение заказа""" mh_vars = order_vars.copy() context = {} q_string = {} containers = {} shopper = get_shopper(request) if request.is_ajax(): return JsonResponse(context, safe=False) template = 'web/order/checkout.html' page = SearchLink(q_string, request, containers) if not page: page = Blocks(name=order_vars['singular_obj']) context['breadcrumbs'] = [{ 'name': 'Подтверждение заказа', 'link': reverse('%s:%s' % (CUR_APP, 'checkout')), }] context['page'] = page context['containers'] = containers cart = calc_cart(shopper, min_info=False) context['cart'] = cart # Оформление заказа comments = None wrist_size = request.POST.get('wrist_size') birthday = request.POST.get('birthday') if wrist_size or birthday: comments = [] if wrist_size: comments.append('Размер запястья %s' % wrist_size) if birthday: comments.append('День рождения %s' % birthday) comments = ', '.join(comments) context.update(**create_new_order(request, shopper, cart, comments)) if 'order' in context and context['order']: template = 'web/order/confirmed.html' payment = YandexKassa().create_payment( domain='%s%s' % ('https://' if request.is_secure() else 'http://', request.META['HTTP_HOST']), summa='%s' % context['order'].total, desc='Оплата заказа №%s' % context['order'].id, ) if 'confirmation' in payment: context['yandex_payment_link'] = payment['confirmation'][ 'confirmation_url'] Transactions.objects.create(order=context['order'], uuid=payment['id'], ptype=1) return render(request, template, context)
def checkout(request): """Оформление заказа - Подтверждение заказа""" mh_vars = order_vars.copy() context = {} q_string = {} containers = {} shopper = get_shopper(request) if request.is_ajax(): return JsonResponse(context, safe=False) template = 'web/order/checkout.html' page = SearchLink(q_string, request, containers) if not page: page = Blocks(name=order_vars['singular_obj']) context['breadcrumbs'] = [{ 'name': 'Подтверждение заказа', 'link': reverse('%s:%s' % (CUR_APP, 'checkout')), }] context['page'] = page context['containers'] = containers cart = calc_cart(shopper, min_info=False) context['cart'] = cart # Оформление заказа context.update(**create_new_order(request, shopper, cart)) if 'order' in context and context['order']: template = 'web/order/confirmed.html' # Если пользователь вернулся # на страничку оформленного заказа, # например, для оплаты if request.GET.get('order_id'): order_id = request.GET['order_id'] if order_id.isdigit(): order = Orders.objects.filter(pk=order_id, shopper=shopper).first() if order: template = 'web/order/confirmed.html' context['order'] = order return render(request, template, context)
def checkout(request): """Оформление заказа - Подтверждение заказа""" mh_vars = order_vars.copy() context = {} q_string = {} containers = {} shopper = get_shopper(request) if request.is_ajax(): return JsonResponse(context, safe=False) template = 'web/order/checkout.html' page = SearchLink(q_string, request, containers) if not page: page = Blocks(name=order_vars['singular_obj']) context['breadcrumbs'] = [{ 'name': 'Подтверждение заказа', 'link': reverse('%s:%s' % (CUR_APP, 'checkout')), }] context['page'] = page context['containers'] = containers cart = calc_cart(shopper, min_info=False) context['cart'] = cart # Оформление заказа context.update(**create_new_order(request, shopper, cart)) if 'order' in context and context['order']: template = 'web/order/confirmed.html' # Если пользователь вернулся # на страничку оформленного заказа, # например, для оплаты if request.GET.get('order_id'): order_id = request.GET['order_id'] if order_id.isdigit(): order = Orders.objects.filter(pk=order_id, shopper=shopper).first() if order: template = 'web/order/confirmed.html' context['order'] = order sber = SberPaymentProovider() order_status = sber.get_order_status(order.external_number, order.id) context['order_status'] = order_status # ----------------------------------------- # Если пользователь пытается оплатить заказ # ----------------------------------------- if 'order' in context and request.GET.get('pay') == 'sbrf': order = context['order'] scheme = 'http://' if request.is_secure(): scheme = 'https://' host = '%s%s' % (scheme, request.META['HTTP_HOST']) env = '' if settings.DEBUG: env = 'test_%s' % str(time.time()) params = { 'amount': int(order.total * 100), 'orderNumber': '%s%s' % (env, order.id), 'returnUrl': '%s/payment/sbrf/success/' % host, 'failUrl': '%s/payment/sbrf/fail/' % host, #'description': 'Тестовый заказ', 'clientId': shopper.id, 'email': shopper.email, 'phone': shopper.phone, } sber = SberPaymentProovider() register_order = sber.register_do(**params) context.update(register_order) # ------------------------ # Переадресация на форму и # запись номера заказа # ------------------------ if 'formUrl' in register_order: Orders.objects.filter(pk=order.id).update(external_number=register_order['orderId']) return redirect(register_order['formUrl']) return render(request, template, context)