Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CardknoxResponse parsing issue #36

Closed
davidfried opened this issue Jan 16, 2020 · 2 comments
Closed

CardknoxResponse parsing issue #36

davidfried opened this issue Jan 16, 2020 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@davidfried
Copy link

davidfried commented Jan 16, 2020

When charging a card twice with the same amount in the same minute cardknox rejects the charge with a 'Duplicate charge' error message

for some reason, the response has in it the xAvsResultCode key but its empty.

now, since the parsing code is not handled for exceptions this line raises an exception

AvsResultCode = (AvsResponseType)Enum.Parse(typeof(AvsResponseType), _values["xAvsResultCode"]);

Please update the CardknoxResponse constructor to handle exceptions like this

here is my 2 cents

` public CardknoxResponse(NameValueCollection _values)
{
if (_values.AllKeys.Contains("xResult"))
{
try
{
Result = (ResultType)Enum.Parse(typeof(ResultType), _values["xResult"]);
}
catch { }
}

        if (_values.AllKeys.Contains("xError"))
            Error = _values["xError"];

        if (_values.AllKeys.Contains("xErrorCode"))
            ErrorCode = _values["xErrorCode"];

        if (_values.AllKeys.Contains("xStatus"))
            Status = (StatusType)Enum.Parse(typeof(StatusType), _values["xStatus"]);

        if (_values.AllKeys.Contains("xRefNum"))
            RefNum = _values["xRefNum"];

        if (_values.AllKeys.Contains("xAuthCode"))
            AuthCode = _values["xAuthCode"];

        if (_values.AllKeys.Contains("xBatch"))
            Batch = _values["xBatch"];

        if (_values.AllKeys.Contains("xAvsResultCode"))
        {
            try
            {
                AvsResultCode = (AvsResponseType)Enum.Parse(typeof(AvsResponseType), _values["xAvsResultCode"]);
            }
            catch { }
        }

        if (_values.AllKeys.Contains("xAvsResult"))
        {
            try
            {
                AvsResult = HttpUtility.UrlDecode(_values["xAvsResult"]);
            }
            catch { }
        }

        if (_values.AllKeys.Contains("xAuthAmount"))
        {
            try
            {
                AuthAmount = Decimal.Parse(_values["xAuthAmount"]);
            }
            catch { }                
        }
        else AuthAmount = null;

        if (_values.AllKeys.Contains("xMaskedCardNumber"))
            MaskedCardNumber = _values["xMaskedCardNumber"];

        if (_values.AllKeys.Contains("xCardType"))
        {
            try
            {
                CardType = (CardType)Enum.Parse(typeof(CardType), _values["xCardType"]);
            }
            catch { }
        }

        if (_values.AllKeys.Contains("xToken"))
            Token = _values["xToken"];

        if (_values.AllKeys.Contains("xEntryMethod"))
            EntryMethod = _values["xEntryMethod"];

} `

@ahwm
Copy link
Member

ahwm commented Jan 16, 2020

You make a great point!

@ahwm ahwm self-assigned this Jan 16, 2020
@ahwm ahwm added the bug Something isn't working label Jan 16, 2020
@ahwm ahwm closed this as completed in e8be33e Jan 16, 2020
@ahwm
Copy link
Member

ahwm commented Jan 16, 2020

The fix for this is now live in 4.5.3.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants