Ejemplo n.º 1
0
def handle_notify(request):
    """ Handles the actual success notification from Paytrail """
    
    # Get data, and make sure it looks right
    try:
        data = json.loads(request.body)
        transaction_id = int(data['posData'])
        bitpay_id = data['id']
        status = data['status']
    except Exception as ex:
        logger.error("%s" % (ex,))
        raise Http404
    
    # Try to find correct transaction
    # If transactions is not found, this will throw 404.
    ta_is_valid = False
    try:
        ta = StoreTransaction.objects.get(pk=transaction_id, token=bitpay_id)
        
        # If transaction is paid and confirmed, stop here.
        if ta.is_paid:
            return HttpResponse("")
        
        # Okay, transaction found and it's good.
        ta_is_valid = True
    except StoreTransaction.DoesNotExist:
        logger.warning("Error while attempting to validate bitpay notification!")
        raise Http404
    
    # We have a valid transaction. Do something about it.
    if ta_is_valid:
        if status == 'confirmed' or status == 'complete':
            # Paid and confirmed.
            if not ta_common.handle_payment(ta):
                raise Http404
            return HttpResponse("")
            
        if status == 'paid':
            # Paid but not confirmed
            ta_common.handle_pending(ta)
            return HttpResponse("")
                        
        if status == 'expired':
            # Paument expired, assume cancelled
            ta_common.handle_cancellation(ta)
            return HttpResponse("")

    logger.warning("Unhandled bitpay notification '%s' for id %d." % (status,ta.id,))

    # Just respond with something
    return HttpResponse("")
Ejemplo n.º 2
0
def handle_notify(request):
    """ Handles the actual success notification from Paytrail """

    # Get data, and make sure it looks right
    try:
        data = json.loads(request.body.decode('utf-8'))
        transaction_id = int(data['posData'])
        bitpay_id = data['id']
        status = data['status']
    except Exception as ex:
        logger.error("%s.", ex)
        raise Http404

    # Try to find correct transaction
    # If transactions is not found, this will throw 404.
    try:
        ta = StoreTransaction.objects.get(pk=transaction_id, token=bitpay_id)
    except StoreTransaction.DoesNotExist:
        logger.warning(
            "Error while attempting to validate bitpay notification!")
        raise Http404

    # If transaction is paid and confirmed, stop here.
    if ta.is_paid:
        return HttpResponse("")

    # We have a valid transaction. Do something about it.
    if status == 'confirmed' or status == 'complete':
        # Paid and confirmed.
        if not ta_common.handle_payment(ta):
            raise Http404
        return HttpResponse("")

    if status == 'paid':
        # Paid but not confirmed
        ta_common.handle_pending(ta)
        return HttpResponse("")

    if status == 'expired':
        # Payment expired, assume cancelled
        ta_common.handle_cancellation(ta)
        return HttpResponse("")

    logger.warning("Unhandled bitpay notification '%s' for id %d.", status,
                   ta.id)

    # Just respond with something
    return HttpResponse("")
Ejemplo n.º 3
0
def handle_success(request):
    """ Handles the success user redirect from Paytrail """
    
    # Get parameters
    order_number = request.GET.get('ORDER_NUMBER', '')
    timestamp = request.GET.get('TIMESTAMP', '')
    paid = request.GET.get('PAID', '')
    method = request.GET.get('METHOD', '')
    authcode = request.GET.get('RETURN_AUTHCODE', '')
    secret = settings.VMAKSUT_SECRET

    # Validate, and mark transaction as pending
    if paytrail.validate_success(order_number, timestamp, paid, method, authcode, secret):
        ta = get_object_or_404(StoreTransaction, pk=int(order_number))
        ta_common.handle_pending(ta)
    
    return render_to_response('store/success.html')
Ejemplo n.º 4
0
def handle_success(request):
    """ Handles the success user redirect from Paytrail """
    
    # Get parameters
    order_number = request.GET.get('ORDER_NUMBER', '')
    timestamp = request.GET.get('TIMESTAMP', '')
    paid = request.GET.get('PAID', '')
    method = request.GET.get('METHOD', '')
    authcode = request.GET.get('RETURN_AUTHCODE', '')
    secret = settings.VMAKSUT_SECRET

    # Validate, and mark transaction as pending
    if paytrail.validate_success(order_number, timestamp, paid, method, authcode, secret):
        ta = get_object_or_404(StoreTransaction, pk=int(order_number))
        ta_common.handle_pending(ta)
        return HttpResponseRedirect(reverse('store:pm:paytrail-success'))

    return render(request, 'store/success.html')