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.
- PHP
$result = $gateway->transaction()->refund('the_transaction_id');
If the transaction can't be found, you'll receive a Braintree\Exception\NotFound
exception.
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.
- PHP
$result->success
# false
Arguments
transactionId
required, stringAdditional Parameters
'amount'
String'commodityCode'
string'description'
string'discountAmount'
String'kind'
stringIndicates whether the line item is a debit (sale) or credit (refund) to the customer. Accepted values:
"debit"
"credit"
'name'
string'productCode'
string'quantity'
String'totalAmount'
String'unitAmount'
String'unitOfMeasure'
string'unitTaxAmount'
String'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 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.
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:
- PHP
$result = $gateway->transaction()->refund('a_transaction_id', '50.00');
$result->success
# true
$result->transaction->type
# 'credit'
$result->transaction->amount
# "50.00"
$result = $gateway->transaction()->refund('a_transaction_id', '10.00');
$result->success
# true
$result->transaction->type
# 'credit'
$result->transaction->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.
Refund 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.
- PHP
$result->success
# false
$result->transaction->status
# "processor_declined"
$result->transaction->processorResponseCode
# e.g. 2005
$result->transaction->processorResponseText
# 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.
- PHP
$result->success
# false
$result->transaction->status
# "settlement_declined"
$result->transaction->processorSettlementResponseCode
# e.g. 4001
$result->transaction->processorSettlementResponseText
# e.g. "Settlement Declined"
Issuing a credit
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.
- PHP
$result = $gateway->creditCard()->credit(
'the_token',
['amount' => '100.00']
);