Transaction: Refund
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.
- Java
Result<transaction> result = gateway.transaction().refund("the_transaction_id");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.
- Java
result.isSuccess(); // false
for (ValidationError error : result.getErrors().getAllDeepValidationErrors()) {
System.out.println(error.getMessage());
}Arguments
transactionIdrequired, stringAdditional Parameters
.amount(…)BigDecimal.commodityCode(…)stringCode 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. For Visa CEDP, required for Level 3 interchange.
.description(…)string.discountAmount(…)BigDecimalDiscount 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. For Visa CEDP, must be provided if discount exists.
.kind(…)stringIndicates whether the line item is a debit (sale) or credit (refund) to the customer. Accepted values:
"debit""credit"
.name(…)stringItem name. Maximum 35 characters. Required for Level 3 interchange. For Visa CEDP, the item name should reflect the purchased item and must not be the same as the merchant name; it should not be generic, numeric, or non-descriptive.
.productCode(…)stringProduct code for the item. Maximum 12 characters. For Visa CEDP, required for Level 3 interchange.
.quantity(…)BigDecimal.taxAmount(…)BigDecimalTax amount for the line item. Can include up to 2 decimal places. This value can't be negative. For Visa CEDP, this field is not required; however, if tax amount was paid at the line-item level, the sum of all line-item taxes should be reflected in the transaction-level field. This summation rule is specific to Visa CEDP. For Mastercard, tax_amount can be sent in this field.
.totalAmount(…)BigDecimalQuantity x unit amount. Can include up to 2 decimal places. For Visa CEDP, the line-item total is calculated as (quantity x unit amount) minus the discount per line item.
.unitAmount(…)BigDecimal.unitOfMeasure(…)stringThe unit of measure or the unit of measure code. Maximum 12 characters. It represents the measurement unit corresponding to the product sold. For example, item/box for a countable object, liter/gallon for a liquid, or kilogram/pound for weight. This Braintree line-item field is not used by PayPal. For Visa CEDP, required for Level 3 interchange.
.unitTaxAmount(…)BigDecimal.upcCode(…)string.upcType(…)stringUPC 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"
.url(…)string.merchantAccountId(…)stringThe 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.
.orderId(…)stringUse this parameter if you would like to pass an orderId different than that of the original transaction. Otherwise, the original transaction's getOrderId() 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.
.surchargeAmount(…)BigDecimalRequirements
- 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.
Examples
Partial refunds
If you only want to refund a portion of the transaction, specify the amount to refund:
- Java
Result<transaction> result = gateway.transaction().refund(
"a_transaction_id",
new BigDecimal("50.00")
);
result.isSuccess(); // true
Transaction refund = result.getTarget();
refund.getType(); // Transaction.Type.CREDIT
refund.getAmount(); // 50.00
Result<transaction> result = gateway.transaction().refund(
"a_transaction_id",
new BigDecimal("10.00")
);
result.isSuccess(); // true
Transaction refund = result.getTarget();
refund.getType(); // Transaction.Type.CREDIT
refund.getAmount(); // 10.00Refund processor declines
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.
- Java
Transaction transaction = result.getTransaction();
transaction.getStatus(); // Transaction.Status.PROCESSOR_DECLINED
transaction.getProcessorResponseCode(); // e.g. "2005"
transaction.getProcessorResponseText(); // e.g. "Invalid Credit Card Number"Settlement failures
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.
- Java
Transaction transaction = result.getTransaction();
transaction.getStatus(); // Transaction.Status.SETTLEMENT_DECLINED
transaction.getProcessorSettlementResponseCode(); // e.g. "4001"
transaction.getProcessorSettlementResponseText(); // e.g. "Settlement Declined"Issuing a credit
- Java
TransactionRequest request = new TransactionRequest()
.amount(new BigDecimal("100.00"))
.paymentMethodToken("aToken")
.done();
Result<transaction> result = gateway.transaction().credit(request);