sample-code-python icon indicating copy to clipboard operation
sample-code-python copied to clipboard

Python examples show failed transactions as successful

Open skullydazed opened this issue 10 years ago • 3 comments

The examples show checking response.messages.resultCode=="Ok", however it's possible for a transaction to be reported as "Ok" but still not charged. Take this response I received for an Auth/Capture as an example:

2016-02-29 07:18:17,210 Received response: <?xml version="1.0" ?>
<createTransactionResponse xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <refId>NantucketSel-170</refId>
    <messages>
        <resultCode>Ok</resultCode>
        <message>
            <code>I00001</code>
            <text>Successful.</text>
        </message>
    </messages>
    <transactionResponse>
        <responseCode>2</responseCode>
        <authCode>XXXXXX</authCode>
        <avsResultCode>S</avsResultCode>
        <cvvResultCode/>
        <cavvResultCode/>
        <transId>XXXXXXXXXX</transId>
        <refTransID>XXXXXXXXXX</refTransID>
        <transHash>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</transHash>
        <testRequest>0</testRequest>
        <accountNumber>XXXX7095</accountNumber>
        <accountType>Visa</accountType>
        <errors>
            <error>
                <errorCode>27</errorCode>
                <errorText>The transaction has been declined because of an AVS mismatch. The address provided does not match billing address of cardholder.</errorText>
            </error>
        </errors>
    </transactionResponse>
</createTransactionResponse>

Please add examples that show how to detect all failed transactions.

skullydazed avatar Feb 29 '16 16:02 skullydazed

This is a problem with the Python (and Ruby) examples. As they stand presently they cannot be used and assure that a successful transaction is not declined. After I got bit by this I looked at the code examples for PHP for charging a payment profile just as a sample. This Python example just looks for resultCode == "Ok", where the PHP example correctly considers responseCode and it's various values.

The fact that the repos come with tests that pass is alarming, all failure states should be tested and not just perfect transactions that clear.

danielatdattrixdotcom avatar Jul 25 '16 20:07 danielatdattrixdotcom

Hi @skullydazed & @danielatdattrixdotcom, We have updated our sample codes (for all the languages) to demonstrate the various scenarios of response handling. For example, you can take a look at our charge a credit card sample @ https://github.com/AuthorizeNet/sample-code-python/blob/master/PaymentTransactions/charge-credit-card.py

You can also use : http://developer.authorize.net/api/reference/dist/json/responseCodes.json to check for details about all the possible response/error codes to handle them appropriately in your code.

Let us know if anything is not clear.

akankaria avatar Aug 30 '16 05:08 akankaria

@akankaria That is more helpful, I have a few suggestions.

  1. Drop the semi-colons at the end of the print statements since this is Python.
  2. Change the wording "Successfully created transaction.." to just "Created transaction..". The use of the word success could imply successfully charged.
  3. Following up on not making a success state confusing I would simply add a comment above the first print statement for the creation of a transaction that reads: "response.transactionResponse.responseCode should be used to determine status of transaction; Approved, Declined, etc."
  4. Spaces for indent is preferred, but of course not required.

I'd apply those considerations to all updated examples so that anyone who wants to just grab the example for a quick path to implementation only need to make minor revisions inside the relevant condition blocks.

danielatdattrixdotcom avatar Aug 30 '16 19:08 danielatdattrixdotcom