Exemple #1
0
def start_process(ta):
    """
    No payment method was required, so just mark everything done right away.
    """

    # Since no payment is required, just mark everything done right away
    ta.payment_method_name = 'No payment'
    ta.save()
    ta.refresh_from_db()

    ta_common.handle_payment(ta)

    # All done, redirect user
    return reverse('store:pm:no-method-success')
Exemple #2
0
def start_process(ta):
    """
    No payment method was required, so just mark everything done right away.
    """

    # Since no payment is required, just mark everything done right away
    ta.payment_method_name = 'No payment'
    ta.save()
    ta.refresh_from_db()

    ta_common.handle_payment(ta)

    # All done, redirect user
    return reverse('store:pm:no-method-success')
Exemple #3
0
def handle_notify(request):
    """ Handles the actual success notification 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 & handle
    if paytrail.validate_success(order_number, timestamp, paid, method, authcode, secret):
        # Get transaction
        ta = get_object_or_404(StoreTransaction, pk=int(order_number))
        if ta.is_paid:
            logger.warning('Somebody is trying to pay an already paid transaction (%s).', ta.id)
            return HttpResponse("")

        # Use common functions to handle the payment
        # If handling the payment fails, cause 404.
        # This will tell paytrail to try notifying again later.
        if not ta_common.handle_payment(ta):
            raise Http404
    else:
        logger.warning("Error while attempting to validate paytrail notification!")
        raise Http404

    # Just respond with something
    return HttpResponse("")
Exemple #4
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("")
Exemple #5
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("")