コード例 #1
0
ファイル: views.py プロジェクト: pombredanne/minishop
def return_request(request):
    p24 = Privat24Integration()
    post_data, payment, result = p24.get_transaction(request)
    if payment:
        order = None
        try:
            order, order_json = get_order(post_data.get("order"))
        except FraudAttemptError as e:
            logger.error(u"return_request: Have error: %s" % e.message)
        if order:
            local_json = order2json(order)
            if local_json == order_json:
                if order.transaction_id == payment.pk:
                    pass
                else:
                    order.transaction = payment
                    order.save()
                valid_statuses = p24.get_valid_statuses(True)
                # logger.info("return_request: valid_statuses: %s" % valid_statuses)
                # logger.info("return_request: payment state: %s" % payment.state)
                if payment.state in valid_statuses:
                    if payment.state == P24_STATE_WAIT:
                        pass
                    else:
                        if can_proceed(order.pay):
                            order.pay()
                            order.save()
                    # request.session[ORDER_ID] = order.pk
                    to = reverse("payments-thank-you")
                    return redirect(to)
            else:
                logger.error("return_request: Order properties is not identical:")
                logger.error("return_request:   Local: %s" % local_json)
                logger.error("return_request:  Remote: %s" % order_json)
    return redirect("home")
コード例 #2
0
ファイル: signals.py プロジェクト: pombredanne/minishop
def update_order(transaction):
    import logging
    from django_fsm import can_proceed
    from orders.utils import get_order, order2json, FraudAttemptError
    from privat24.integration import Privat24Integration
    logger = logging.getLogger('app')
    try:
        order, order_json = get_order(transaction.get('order'))
    except FraudAttemptError as e:
        logger.error(u'update_order: Have error: %s' % e.message)
    if order:
        local_json = order2json(order)
        if local_json == order_json:
            if order.transaction_id == transaction.pk:
                pass
            else:
                order.transaction = transaction
                order.save()
            p24 = Privat24Integration()
            valid_statuses = p24.get_valid_statuses()
            if transaction.state in valid_statuses:
                if can_proceed(order.pay):
                    order.pay()
                    order.save()
        else:
            logger.error("update_order: Order properties is not identical:")
            logger.error("update_order:   Local: %s" % local_json)
            logger.error("update_order:  Remote: %s" % order_json)
    return None
コード例 #3
0
def validate(request):
    order = get_order(request)
    promo_code = PromoCode.objects.get_valid(request.GET.get('code'))

    if promo_code is None or order is None:
        return JsonResponse({'status': False}, status=404)

    order.apply_promo_code(promo_code)

    return JsonResponse({
        'status': True,
        'code': promo_code.code,
        'discount': promo_code.discount,
        'total': order.total
    })
コード例 #4
0
def create(request):
    form = ShippingAddressForm(request.POST or None)

    if request.method == 'POST' and form.is_valid():
        shipping_address = form.save(commit=False)
        shipping_address.user = request.user
        shipping_address.default = not request.user.has_address()
        shipping_address.save()

        if request.GET.get('next'):
            order = get_order(request)
            order.shipping_address = shipping_address
            order.save()

            return HttpResponseRedirect(request.GET['next'])

        messages.success(request, 'Dirección creada exitosamente.')
        return redirect('shipping_addresses:shipping_addresses')

    return render(request, 'shipping_addresses/create.html', {'form': form})