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.
- Ruby
result = gateway.transaction.refund("the_transaction_id")Braintree::NotFoundError. 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.
- Ruby
result.success? #=> false
p result.errorsArguments
transaction_idrequired, StringAdditional Parameters
:amountBigDecimal:commodity_codeString:descriptionString:discount_amountBigDecimal:kindStringIndicates whether the line item is a debit (sale) or credit (refund) to the customer. Accepted values:
"debit""credit"
:nameString:product_codeString:quantityBigDecimal:total_amountBigDecimal:unit_amountBigDecimal:unit_of_measureString:unit_tax_amountBigDecimal:upc_codeString:upc_typeStringUPC 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:merchant_account_idStringThe 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.
:order_idStringUse this parameter if you would like to pass an order_id different than that of the original transaction. Otherwise, the original transaction's order_id 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.
Requirements
- 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:
- Ruby
result = gateway.transaction.refund("j59qrb", "50.00")
result.success? #=> true
result.transaction.amount.to_f #=> 50.00
result = gateway.transaction.refund("j59qrb", "10.00")
result.success? #=> true
result.transaction.amount.to_f #=> 10.00Refund processor declines
If using the most current SDK, and the processor declines the refund, the response will have the
processor_response_code 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.
- Ruby
result.success? #=> false
result.transaction.status #=> "processor_declined"
result.transaction.processor_response_code #=> "2005"
result.transaction.processor_response_text #=> "Invalid Credit Card Number"Settlement failures
If the processor declines the capture for the refund transaction, the transaction object will have
the processor_settlement_response_code available. See the
transaction statuses page
for additional information on the Settlement Declined response.
- Ruby
result.success? #=> false
result.transaction.status #=> "settlement_declined"
result.transaction.processor_settlement_response_code #=> "4001"
result.transaction.processor_settlement_response_text #=> "Settlement Declined"Issuing a credit
- Ruby
result = gateway.credit_card.credit(
"the_token",
:amount => "100.00"
)