Search code examples
payment-gatewayauthorize.net

Is it possible to refund a transaction in Authorize.Net sandbox account?


I am posting the code below from Authorize.Net website live API console

Request

{
    "createTransactionRequest": {
        "merchantAuthentication": {
            "name": "5KP3u95bQpv",
            "transactionKey": "346HZ32z3fP4hTG2"
        },
        "refId": "123456",
        "transactionRequest": {
            "transactionType": "refundTransaction",
            "amount": "5.00",
            "payment": {
                "creditCard": {
                    "cardNumber": "0015",
                    "expirationDate": "XXXX"
                }
            },
            "refTransId": "1234567890"
        }
    }
}

Response

{
    "transactionResponse": {
        "responseCode": "3",
        "authCode": "",
        "avsResultCode": "P",
        "cvvResultCode": "",
        "cavvResultCode": "",
        "transId": "0",
        "refTransID": "1234567890",
        "transHash": "",
        "testRequest": "0",
        "accountNumber": "",
        "accountType": "",
        "errors": [
            {
                "errorCode": "54",
                "errorText": "The referenced transaction does not meet the criteria for issuing a credit."
            }
        ],
        "shipTo": {},
        "transHashSha2": "B3BF913B110E1C82C4FB83DA0EFE096C5D383A9257123AE2A7E9582AF977A537CA2C7A78F13B6FCF0E9C83A9C7FCF16DB4FC6F999A23C9DE24AFC4BFB765E602",
        "SupplementalDataQualificationIndicator": 0
    },
    "refId": "123456",
    "messages": {
        "resultCode": "Error",
        "message": [
            {
                "code": "E00027",
                "text": "The transaction was unsuccessful."
            }
        ]
    }
}

The API transaction key is the same as the one on Authorize.Net's site but even with Authorize.Net's own key the refund transaction is failing. How do I test refund in sandbox or is it even possible to test refund in sandbox?

EDIT: I am getting the same error while development as well and I do have the right data but my app in production is using different AuthNet credentials and for testing purpose I am using credentials from an entirely different AuthNet sandbox account. So even though I have the right data, I think my issue here is the data from the original transaction does not exist on my sandbox account. Help would be appreciated.


Solution

  • You can test refunds in the sandbox but it must meet all the same criteria as a production environment. Their example may have stale data but if you use fresh data it will work for you.

    To issue a refund the following criteria must all be met:

    1. The transaction was originally processed and successfully settled through the payment gateway (Authorize.Net).
    2. The transaction is submitted with the valid transaction ID (x_trans_id) of an original, successfully settled transaction.
    3. The amount being requested for refund is less than or equal to the original settled amount.
    4. The sum of multiple Credit transactions submitted against the original transaction is less than or equal to the original settled amount.
    5. At least the last four digits of the credit card number (x_card_num) used for the original, successfully settled transaction are submitted. An expiration date is not required.
    6. The transaction is submitted within 120 days of the settlement date of the original transaction.

    Here's an test I just made:

    AUTH_CAPTURE

    {
       "createTransactionRequest":{
          "merchantAuthentication":{
             "name":"",
             "transactionKey":""
          },
          "refId":49782069,
          "transactionRequest":{
             "transactionType":"authCaptureTransaction",
             "amount":5,
             "payment":{
                "creditCard":{
                   "cardNumber":"4427802641004797",
                   "expirationDate":"122020",
                   "cardCode":"999"
                }
             },
             "order":{
                "invoiceNumber":"1324567890",
                "description":"this is a test transaction"
             },
             "lineItems":{
                "lineItem":[
                   {
                      "itemId":"1",
                      "name":"vase",
                      "description":"Cannes logo",
                      "quantity":"18",
                      "unitPrice":"45.00"
                   },
                   {
                      "itemId":"2",
                      "name":"desk",
                      "description":"Big Desk",
                      "quantity":"10",
                      "unitPrice":"85.00"
                   }
                ]
             },
             "tax":{
                "amount":"4.26",
                "name":"level2 tax name",
                "description":"level2 tax"
             },
             "duty":{
                "amount":"8.55",
                "name":"duty name",
                "description":"duty description"
             },
             "shipping":{
                "amount":"4.26",
                "name":"level2 tax name",
                "description":"level2 tax"
             },
             "poNumber":"456654",
             "customer":{
                "id":"18",
                "email":"[email protected]"
             },
             "billTo":{
                "firstName":"Ellen",
                "lastName":"Johnson",
                "company":"Souveniropolis",
                "address":"14 Main Street",
                "city":"Pecan Springs",
                "state":"TX",
                "zip":"44628",
                "country":"USA"
             },
             "shipTo":{
                "firstName":"China",
                "lastName":"Bayles",
                "company":"Thyme for Tea",
                "address":"12 Main Street",
                "city":"Pecan Springs",
                "state":"TX",
                "zip":"44628",
                "country":"USA"
             },
             "customerIP":"192.168.1.1",
             "transactionSettings":{
                "setting":[
                   {
                      "settingName":"allowPartialAuth",
                      "settingValue":"false"
                   },
                   {
                      "settingName":"duplicateWindow",
                      "settingValue":"0"
                   },
                   {
                      "settingName":"emailCustomer",
                      "settingValue":"false"
                   },
                   {
                      "settingName":"recurringBilling",
                      "settingValue":"false"
                   },
                   {
                      "settingName":"testRequest",
                      "settingValue":"false"
                   }
                ]
             },
             "userFields":{
                "userField":[
                   {
                      "name":"MerchantDefinedFieldName1",
                      "value":"MerchantDefinedFieldValue1"
                   },
                   {
                      "name":"favorite_color",
                      "value":"blue"
                   }
                ]
             }
          }
       }
    }
    
    RESPONSE
    
    {
       "transactionResponse":{
          "responseCode":"1",
          "authCode":"A2XE99",
          "avsResultCode":"Y",
          "cvvResultCode":"P",
          "cavvResultCode":"2",
          "transId":"40047374169",
          "refTransID":"",
          "transHash":"",
          "testRequest":"0",
          "accountNumber":"XXXX4797",
          "accountType":"Visa",
          "messages":[
             {
                "code":"1",
                "description":"This transaction has been approved."
             }
          ],
          "userFields":[
             {
                "name":"MerchantDefinedFieldName1",
                "value":"MerchantDefinedFieldValue1"
             },
             {
                "name":"favorite_color",
                "value":"blue"
             }
          ],
          "transHashSha2":"D8C48317CB529C6DFCC472F4548CAAC18F17F505BAD9077E54C117854D8791BADBC76DF6ECEA330E0462E0F9C4C60FDC13BEBDA068E5431EAA551DEB97F358DF",
          "SupplementalDataQualificationIndicator":3,
          "networkTransId":"A3HTA7GK9GEC0S1889A0M5O"
       },
       "refId":"49782069",
       "messages":{
          "resultCode":"Ok",
          "message":[
             {
                "code":"I00001",
                "text":"Successful."
             }
          ]
       }
    }
    

    REFUND

    {
       "createTransactionRequest":{
          "merchantAuthentication":{
             "name":"",
             "transactionKey":""
          },
          "refId":49782069,
          "transactionRequest":{
             "transactionType":"refundTransaction",
             "amount":5,
             "payment":{
                "creditCard":{
                   "cardNumber":"4427802641004797",
                   "expirationDate":"122020"
                }
             },
             "authCode":"A2XE99"
          }
       }
    }
    
    RESPONSE
    
    {
       "transactionResponse":{
          "responseCode":"1",
          "authCode":"",
          "avsResultCode":"P",
          "cvvResultCode":"",
          "cavvResultCode":"",
          "transId":"40047374178",
          "refTransID":"",
          "transHash":"",
          "testRequest":"0",
          "accountNumber":"XXXX4797",
          "accountType":"Visa",
          "messages":[
             {
                "code":"1",
                "description":"This transaction has been approved."
             }
          ],
          "transHashSha2":"A5390A4933681142E2A41FEC37BF0303FC5FF30D9DF9CBD05FABEC2FA87FE3E241F0705B559924313E972E5457A633CCFA62B7C52A63D93BBB67ACC102D9984B",
          "SupplementalDataQualificationIndicator":0
       },
       "refId":"49782069",
       "messages":{
          "resultCode":"Ok",
          "message":[
             {
                "code":"I00001",
                "text":"Successful."
             }
          ]
       }
    }