Example #1
0
    if request.POST.get('HASH','') != hash:
        flag = 'Invalid hash %s. Hash string \n%s' % (request.POST.get('HASH',''), s)
    else:
        if ipn.is_valid():
            try:
                #When commit = False, object is returned without saving to DB.
                ipn_obj = ipn.save(commit = False)
            except Exception, e:
                flag = "Exception while processing. (%s)" % e
        else:
            flag = "Invalid form. (%s)" % ipn.errors



    if ipn_obj is None:
        ipn_obj = PayUIPN()

    #Set query params and sender's IP address
    ipn_obj.initialize(request)

    if flag is not None:
        #We save errors in the flag field
        ipn_obj.set_flag(flag)

    ipn_obj.save()
    ipn_obj.send_signals()

    date = datetime.now(pytz.UTC).strftime('%Y%m%d%H%M%S')
    hash = hmac.new(MERCHANT_KEY,'00014%s' % date).hexdigest()
    return HttpResponse('<EPAYMENT>%s|%s</EPAYMENT>' % (date,hash))
Example #2
0
    hash = hmac.new(MERCHANT_KEY, s).hexdigest()
    if request.POST.get('HASH', '') != hash:
        flag = 'Invalid hash %s. Hash string \n%s' % (request.POST.get(
            'HASH', ''), s)
    else:
        if ipn.is_valid():
            try:
                #When commit = False, object is returned without saving to DB.
                ipn_obj = ipn.save(commit=False)
            except Exception, e:
                flag = "Exception while processing. (%s)" % e
        else:
            flag = "Invalid form. (%s)" % ipn.errors

    if ipn_obj is None:
        ipn_obj = PayUIPN()

    #Set query params and sender's IP address
    ipn_obj.initialize(request)

    if flag is not None:
        #We save errors in the flag field
        ipn_obj.set_flag(flag)

    ipn_obj.save()
    ipn_obj.send_signals()

    date = datetime.now(pytz.UTC).strftime('%Y%m%d%H%M%S')
    hash = hmac.new(MERCHANT_KEY, '00014%s' % date).hexdigest()
    return HttpResponse('<EPAYMENT>%s|%s</EPAYMENT>' % (date, hash))
def test_payu_model_order_status(order, authorized, completed):
    model = PayUIPN(ORDERSTATUS=order)
    assert model.is_authorized == authorized
    assert model.is_completed == completed
Example #4
0
    expected_hash = hmac.new(PAYU_MERCHANT_KEY, validation_hash, hashlib.md5).hexdigest()
    request_hash = request.POST.get('HASH', '')

    if request_hash != expected_hash:
        error = 'Invalid hash %s. Hash string \n%s' % (request_hash, expected_hash)
    else:
        if ipn_form.is_valid():
            try:
                ipn_obj = ipn_form.save(commit=False)
            except Exception, exception:
                error = "Exception while processing. (%s)" % exception
        else:
            error = "Invalid form. (%s)" % ipn_form.errors

    if not ipn_obj:
        ipn_obj = PayUIPN()

    # Set query params and sender's IP address
    ipn_obj.response = getattr(request, request.method).urlencode()
    ipn_obj.ip_address = request.META.get('REMOTE_ADDR', '')

    if error:
        # We save errors in the error field
        ipn_obj.set_flag(error)

    ipn_obj.save()

    # Check for a token in the request and save it if found
    IPN_CC_TOKEN = request.POST.get('IPN_CC_TOKEN')
    IPN_CC_MASK = request.POST.get('IPN_CC_MASK')
    IPN_CC_EXP_DATE = request.POST.get('IPN_CC_EXP_DATE')
    model = G(PayUIPN, flag=True)
    mock_flagged.send.assert_called_once_with(sender=model)


@pytest.mark.parametrize('payload, merchant_key, signature', [
    ({'a': '1'}, '1', '1be4474db26a37bd5660ca396b5a9160'),
    ({}, '0', '477f91ddbcc6839b9950045977da3530'),
    ({'MERCHANT': '1', 'ORDER_REF': 1, 'ORDER_AMOUNT': 1, 'ORDER_CURRENCY': 'RON'},
     '0', 'f05323c0b185b5264c49c8bae8ffc2d1'),
])
def test_idn_signature(payload, merchant_key, signature):
    assert PayUIDN.signature(payload, merchant_key) == signature


@pytest.mark.parametrize('payu_idn, merchant, merchant_key, now, expected_payload', [
    (PayUIPN(REFNO=1, IPN_TOTALGENERAL=1, CURRENCY='USD'), '123', '1', 1,
     {
         'MERCHANT': '123',
         'ORDER_REF': 1,
         'ORDER_AMOUNT': 1,
         'ORDER_CURRENCY': 'USD',
         'IDN_DATE': 1,
         'ORDER_HASH': '5d275f182089bab5a5351613067b95dc'
     }),
    (PayUIPN(), '123', '1', 1,
     {
         'MERCHANT': '123',
         'ORDER_REF': -1,
         'ORDER_AMOUNT': 0,
         'ORDER_CURRENCY': 'RON',
         'IDN_DATE': 1,
def test_payu_model_flag(flag_info, extra_info):
    model = PayUIPN(flag_info=flag_info)
    model.set_flag(extra_info)
    assert model.flag_info == flag_info + extra_info
    assert model.flag
Example #7
0
    expected_hash = hmac.new(MERCHANT_KEY, validation_hash, hashlib.md5).hexdigest()
    request_hash = request.POST.get('HASH', '')

    if request_hash != expected_hash:
        error = 'Invalid hash %s. Hash string \n%s' % (request_hash, expected_hash)
    else:
        if ipn_form.is_valid():
            try:
                ipn_obj = ipn_form.save(commit=False)
            except Exception, exception:
                error = "Exception while processing. (%s)" % exception
        else:
            error = "Invalid form. (%s)" % ipn_form.errors

    if not ipn_obj:
        ipn_obj = PayUIPN()

    # Set query params and sender's IP address
    ipn_obj.response = getattr(request, request.method).urlencode()
    ipn_obj.ip_address = request.META.get('REMOTE_ADDR', '')

    if error:
        # We save errors in the error field
        ipn_obj.set_flag(error)

    ipn_obj.save()
    ipn_obj.send_signals()

    # Check for a token in the request and save it if found
    IPN_CC_TOKEN = request.POST.get('IPN_CC_TOKEN')
    IPN_CC_MASK = request.POST.get('IPN_CC_MASK')
Example #8
0
def test_payu_model_flagged_signals(mock_flagged):
    model = PayUIPN(flag=True)
    model.send_signals()

    mock_flagged.send.assert_called_once_with(sender=model)
Example #9
0
def test_payu_model_completed_signals(mock_completed):
    model = PayUIPN(ORDERSTATUS='COMPLETE')
    model.send_signals()

    mock_completed.send.assert_called_once_with(sender=model)
Example #10
0
def test_payu_model_authorized_signals(mock_authorized):
    model = PayUIPN(ORDERSTATUS='TEST')
    model.send_signals()

    mock_authorized.send.assert_called_once_with(sender=model)
Example #11
0
    for k in ['SALEDATE', 'PAYMENTDATE', 'COMPLETE_DATE', 'REFNO', 'REFNOEXT', 'ORDERNO', 'ORDERSTATUS', 'PAYMETHOD', 'PAYMETHOD_CODE', ]:
        if request.POST.has_key(k):
            s += '%s%s' % (len(request.POST.get(k)), request.POST.get(k))

    hash = hmac.new(MERCHANT_KEY, s).hexdigest()
    if request.POST.get('HASH', '') != hash:
        flag = 'Invalid hash %s. Hash string \n%s' % (request.POST.get('HASH', ''), s)
    else:
        if ipn.is_valid():
            try:
                ipn_obj = ipn.save(commit=False) # When commit = False, object is returned without saving to DB.
            except Exception, e:
                flag = "Exception while processing. (%s)" % e
        else:
            flag = "Invalid form. (%s)" % ipn.errors

    if ipn_obj is None:
        ipn_obj = PayUIPN()

    ipn_obj.initialize(request) # Set query params and sender's IP address

    if flag is not None:
        ipn_obj.set_flag(flag) # We save errors in the flag field

    ipn_obj.save()
    ipn_obj.send_signals()

    date = datetime.now(pytz.UTC).strftime('%Y%m%d%H%M%S')
    hash = hmac.new(MERCHANT_KEY, '00014%s' % date).hexdigest()
    return HttpResponse('<EPAYMENT>%s|%s</EPAYMENT>' % (date, hash))