Transaction

Transaction: Refund

You can refund transactions that have a status of settled or settling. If the transaction has not yet begun settlement, use Transaction: Void instead. If you do not specify an amount to refund, the entire transaction amount will be refunded.

Refer to the Transaction response object for more information.

  1. DOTNET
Result<Transaction> result = gateway.Transaction.Refund("the_transaction_id");

If the transaction can't be found, it will throw a NotFoundException.

If the refund fails, then the result will be unsuccessful and will include either validation errors indicating which parameters were invalid, or a processor settlement response code indicating the type of settlement failure.

  1. DOTNET
if (!result.IsSuccess())
{
    List<ValidationError> errors = result.Errors.DeepAll();
}
Arguments
TransactionIdrequired, string
The unique transaction identifier.
Additional Parameters
AmountDecimal
The amount to refund. This value must be greater than 0, and can't exceed the total amount of the transaction. If you do not specify an amount to refund, the entire transaction amount will be refunded. See partial refunds below for more details.
The line items for this transaction. It can include up to 249 line items. Only available for Custom Actions transactions.
Code used to classify items purchased and track the total amount spent across various categories of products and services. Different corporate purchasing organizations may use different standards, but the United Nations Standard Products and Services Code (UNSPSC) is frequently used. Maximum 12 characters. This Braintree line-item field is not used by PayPal.
Item description. Maximum 127 characters.
Discount amount for the line item. Can include up to 2 decimal places. This value can't be negative. This Braintree line-item field is not used by PayPal.
Kindstring

Indicates whether the line item is a debit (sale) or credit (refund) to the customer. Accepted values:

  • "debit"
  • "credit"
Namestring
Item name. Maximum 35 characters.
Product code for the item. Maximum 12 characters.
QuantityDecimal
Number of units of the item purchased. Can include up to 4 decimal places. This value can't be negative or zero.
Quantity x unit amount. Can include up to 2 decimal places.
UnitAmountDecimal
Per-unit price of the item. Maximum 4 decimal places. This value can't be negative or zero.
The unit of measure or the unit of measure code. Maximum 12 characters. This Braintree line-item field is not used by PayPal.
Per-unit tax price of the item. Can include up to 2 decimal places. This value can't be negative or zero.
UpcCodestring
UPC code for the item. Maximum 17 characters. If specified, you must also provide the UPC type.
UpcTypestring

UPC type for the item. If specified, you must also provide the UPC code. Accepted values:

  • "UPC-A"
  • "UPC-B"
  • "UPC-C"
  • "UPC-D"
  • "UPC-E"
  • "UPC-2"
  • "UPC-5"
Urlstring
The URL to product information.

The merchant account ID used to create a transaction. Currency is also determined by merchant account ID. If no merchant account ID is specified, we will use your default merchant account.

OrderIdstring

Use this parameter if you would like to pass an OrderId different than that of the original transaction. Otherwise, the original transaction's OrderId value will be copied over to the refund. On PayPal transactions, this field maps to the PayPal invoice number. PayPal invoice numbers must be unique in your PayPal business account. Maximum 255 characters or 127 for PayPal transactions.

Requirementsanchor

  • Transaction status must be settled or settling.
  • Refund amount can't be greater than remaining non-refunded amount of the original transaction.
  • Transaction can't be refunded again after being completely refunded.
  • Transactions held in escrow can only be refunded in full. Attempts to partially refund an escrow transaction will throw a validation error.

Examplesanchor

Partial refundsanchor

If you only want to refund a portion of the transaction, specify the amount to refund:

  1. C#
Result<Transaction> result = gateway.Transaction.Refund(
    "a_transaction_id",
    50.00M
);

result.IsSuccess()
// true
Transaction refund = result.Target;
refund.Type;
// TransactionType.CREDIT
refund.Amount;
// 50.00

Result<Transaction> result = gateway.Transaction.Refund(
    "a_transaction_id",
    10.00M
);

result.IsSuccess()
// true
Transaction refund = result.Target;
refund.Type;
// TransactionType.CREDIT
refund.Amount;
// 10.00

We support single and multiple partial refunds on a given transaction. You can continue to refund a transaction as many times as you like, as long as the sum of the refund amounts is less than the amount of the initial transaction.

If you have already partially refunded a transaction and you perform another refund without specifying the balance, we will refund the remaining non-refunded amount of the transaction.

note

It's best practice to allow each partial refund call to complete successfully before creating any more for the same transaction. If a single transaction has too many simultaneous refund requests, some are likely to fail, returning an error from the gateway. A wait time of 5-10 seconds between partial refund attempts is strongly recommended to minimize errors.

Refund processor declinesanchor

If using the most current SDK, and the processor declines the refund, the response will have the ProcessorResponseCode available. See the transaction statuses page for additional information on the Processor Declined response. If using an older SDK version, and the processor declines the refund, you may receive a validation error in lieu of a processor response code.

  1. C#
if (!result.IsSuccess())
{
    Transaction transaction = result.Transaction;
    if (transaction.Status == TransactionStatus.PROCESSOR_DECLINED)
    {
        Console.WriteLine(transaction.ProcessorResponseCode);
        // e.g. "2005"
        Console.WriteLine(transaction.ProcessorResponseText);
        // e.g. "Invalid Credit Card Number"
    }
}
note

Realtime decline responses are now available for testing in sandbox. We recommend testing in sandbox to ensure your integration supports the changes outlined above.

Settlement failuresanchor

If the processor declines the capture for the refund transaction, the transaction object will have the ProcessorSettlementResponseCode available. See the transaction statuses page for additional information on the Settlement Declined response.

  1. C#
if (!result.IsSuccess())
{
    Transaction transaction = result.Transaction;
    if (transaction.Status == TransactionStatus.SETTLEMENT_DECLINED)
    {
        Console.WriteLine(transaction.ProcessorSettlementResponseCode);
        // e.g. "4001"
        Console.WriteLine(transaction.ProcessorSettlementResponseText);
        // e.g. "Settlement Declined"
    }
}

Issuing a creditanchor

important

Credit transactions are disabled by default. If an attacker gets your API keys, they could transfer money out of your merchant account and put it on any credit card. If you need credit transactions to be enabled, contact us.

You can use credit transactions to give a customer money. However, you should refund to an existing payment method whenever possible.

The only required parameters to create a credit transaction are the amount and the payment method token.

  1. C#
var result = gateway.Transaction.Credit(
   new TransactionRequest
   {
       Amount = 100.00M,
       PaymentMethodToken = "AToken"
   });