refundTransaction

Refund a specific transaction.

Description

This method refunds a sale. Both credit card and check sale transactions may be refunded. You may choose to refund the entire amount or just a portion of the original sale.

For credit cards, the refund will show up as a separate transaction on the card holder's statement. To cancel the original sale before the batch it is in has been settled, the voidTransaction method should be used instead.

The transaction to be refunded must be retrieved using the reference number (RefNum) assigned to the transaction by the gateway. The RefNum is assigned by the gateway and returned when a transaction is processed. To find a missing RefNum, use the searchTransactions method.

This method pulls forward all of the information such as invoice number from the original sale transaction and saves it with the refund transaction. If you want to override any of this information, use runTransaction with the "Command" parameter set to "Refund" and the "RefNum" parameter set to the transaction refnum of the sale. You can then populate the Details object with any information specific to the refund.

See also runTransaction, voidTransaction

Syntax

TransactionResponse refundTransaction ( ueSecurityToken Token, string RefNum, double Amount )

Arguments

Type Name Description
ueSecurityToken Token Merchant security token: used to identify merchant and validate transaction.
string RefNum Transaction Reference number assigned by the gateway.
double Amount Amount to be refunded (set to 0 if refunding entire original amount)

Return Value

Type Description
TransactionResponse Returns a TransactionResponse object containing the results of the transaction and all relevant data.

PHP

For directions on how to set up the WSDL link, create "$token" and "$client", go to SOAP PHP How-to.

    <?php

    try {

      $refnum="1009411";
      $amount="1.99";

      print_r($client->refundTransaction($token,$refnum, $amount));

    }

    catch(SoapFault $e) {    
      echo $e->getMessage();
      echo "\n\nRequest: " . $client->__getLastRequest();
      echo "\n\nResponse: " . $client->__getLastResponse();

    }

    ?>

A refund with additional information passed.

    $Request=array(
        'AccountHolder' => 'Tester Jones',
        'ClientIP' => '123.123.123.123',
        'CustomerID' => '123456',
        'Command' => 'refund',
        'Details' => array(
            'Amount' => '10.00',
            'Clerk' => 'John Doe',
            'Description' => 'Refund transaction',
            'Invoice' => '44539',
            'OrderID' => '12345',
            'PONum' => '54321',
            'Table' => '1',
            'Terminal' => '27',
        ),
        'RefNum' => $SaleRefNum
    );

    $res=$client->runTransaction($token, $Request);

Java

This example uses the USAePay Java library. For directions on how to install the library and create the token/client objects, go to the Java JAX-WS Howto.

    try {
      //Set RefNum to the Reference Number of transaction you
      //want to refund.
      BigInteger RefNum = _runTransaction();

      TransactionResponse response;

      response = client.refundTransaction(token, RefNum, 10.10);

      System.out.println(response.getStatus());
    } catch (Exception e) {
        System.out.println("Soap Exception: " + e.getMessage());
    }

Visual Basic (.NET)

For directions on how to set up the WSDL link and create the "token" and "client" variables, go to the Visual Basic .Net Soap How-to.

     Dim client As usaepay.usaepayService = New usaepay.usaepayService
            Dim token As usaepay.ueSecurityToken

            token = Me.CreateToken("714SSUxv1uohng2XkMJ7kLpETsu58G66", "1234")

            Dim transaction As usaepay.TransactionRequestObject = New usaepay.TransactionRequestObject
            transaction.Details = New usaepay.TransactionDetail
            transaction.Details.Amount = "11.11"
            transaction.Details.AmountSpecified = "true"
            transaction.Details.Invoice = "123456"

            transaction.AuthCode = "009915"
            transaction.RefNum = "46993455"

            Dim response As usaepay.TransactionResponse = New usaepay.TransactionResponse

            response = client.captureTransaction(token, transaction.RefNum, transaction.Details.Amount)

            If response.ResultCode = "A" Then
                MsgBox("Transaction Approved, Refnum: " & response.RefNum)
            Else
                MsgBox("Transaction Error, Reason: " & response.Error)
            End If

.NET C

For directions on how to set up the WSDL link and create the "token" and "client" variables, go to the C Sharp .Net Soap How-to.


    string refnum;
    double amount;

    refnum = "46973575";
    amount = 10.00;

    usaepay.TransactionResponse response = new usaepay.TransactionResponse();

    try
    {
        response = client.refundTransaction(token, refnum, amount);

        if (response.ResultCode == "A")
        {
            MessageBox.Show(string.Concat("Transaction Approved, RefNum: ",
            response.RefNum));
        }
        else
        {
            MessageBox.Show(string.Concat("Transaction Failed: ",
            response.Error));
        }
    }
    catch (Exception err)
    {
        MessageBox.Show(err.Message);

    }
  ```


### XML

Request:

```xml
    <?xml version="1.0" encoding="UTF-8"?>
       <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:usaepay"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
       SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
          <SOAP-ENV:Body>
             <ns1:refundTransaction>
                <Token xsi:type="ns1:ueSecurityToken">
                   <ClientIP xsi:type="xsd:string">123.123.123.123</ClientIP>
                   <PinHash xsi:type="ns1:ueHash">
                      <HashValue xsi:type="xsd:string">45d3fc860f3baefbaaab7435253d56fd1337b716</HashValue>
                      <Seed xsi:type="xsd:string">1199745214-test</Seed>
                      <Type xsi:type="xsd:string">sha1</Type>
                   </PinHash>
                   <SourceKey xsi:type="xsd:string">_B4P7C4K2w2ZCQQQXRqrxDj6agrS2NIT</SourceKey>
                </Token>
                <RefNum xsi:type="xsd:string">102226408</RefNum>
                <Amount xsi:type="xsd:double">3</Amount>
             </ns1:refundTransaction>
          </SOAP-ENV:Body>
       </SOAP-ENV:Envelope>

Response:

    <?xml version="1.0" encoding="utf-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:usaepay"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
    SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
      <SOAP-ENV:Body>
        <ns1:refundTransactionResponse>
          <refundTransactionReturn xsi:type="ns1:TransactionResponse">
            <AcsUrl xsi:nil="true" />
            <AuthAmount xsi:type="xsd:double">0</AuthAmount>
            <AuthCode xsi:type="xsd:string">102236539</AuthCode>
            <AvsResult xsi:type="xsd:string">Unmapped AVS response ( )</AvsResult>
            <AvsResultCode xsi:type="xsd:string"></AvsResultCode>
            <BatchNum xsi:nil="true" />
            <BatchRefNum xsi:nil="true" />
            <CardCodeResult xsi:type="xsd:string">No CVV2/CVC data available for transaction.</CardCodeResult>
            <CardCodeResultCode xsi:type="xsd:string"></CardCodeResultCode>
            <CardLevelResult xsi:type="xsd:string">Unknown Code</CardLevelResult>
            <CardLevelResultCode xsi:type="xsd:string"></CardLevelResultCode>
            <ConversionRate xsi:type="xsd:double">0</ConversionRate>
            <ConvertedAmount xsi:type="xsd:double">0</ConvertedAmount>
            <ConvertedAmountCurrency xsi:nil="true" />
            <CustNum xsi:type="xsd:string">0</CustNum>
            <Error xsi:type="xsd:string"></Error>
            <ErrorCode xsi:nil="true" />
            <isDuplicate xsi:type="xsd:boolean">false</isDuplicate>
            <Payload xsi:nil="true" />
            <RefNum xsi:type="xsd:sting">102226516</RefNum>
            <Result xsi:type="xsd:string">Approved</Result>
            <ResultCode xsi:type="xsd:string">A</ResultCode>
            <Status xsi:type="xsd:string">Pending</Status>
            <StatusCode xsi:type="xsd:string">P</StatusCode>
            <VpasResultCode xsi:type="xsd:string"></VpasResultCode>
          </refundTransactionReturn>
        </ns1:refundTransactionResponse>
      </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>