Refund Sales
Important: These
/v1/payments
and general-purpose REST SDKs are deprecated. See our current SDK offerings, which include the/v2/checkout
and Payouts use cases. For other APIs, use direct integration.
To refund a portion or full amount of a sale, complete these steps:
1. | Set the refund object. |
2. | Execute the refund. |
Set the refund object
The refund object enables you to set a partial amount for the refund. Set the currency and total for the refund.
var data = { amount: { total: '1.31', currency: 'USD' } };
use PayPal\Api\Amount; use PayPal\Api\Refund; use PayPal\Api\Sale; $amt = new Amount(); $amt->setTotal(1.31) ->setCurrency('USD'); $refund = new Refund(); $refund->setAmount($amt);
from paypalrestsdk import Sale sale = Sale.find("4ER05306238362254") refund = sale.refund({ "amount": { "total": "1.31", "currency": "USD" } })
sale = Sale.find("7DY409201T7922549") refund = sale.refund({ :amount => { :total => "1.31", :currency => "USD" } })
import com.paypal.api.payments.Amount; import com.paypal.api.payments.Refund; import com.paypal.api.payments.Sale; import com.paypal.base.rest.APIContext; import com.paypal.base.rest.PayPalRESTException; Refund refund = new Refund(); Amount amount = new Amount(); amount.setTotal("1.31"); amount.setCurrency("USD"); refund.setAmount(amount);
Coming soon
Execute the refund
To execute the refund, get the sale ID that was provided in the response object when the payment was created. Once captured, call the refund method, passing in the sale ID and the refund object to issue the refund.
var saleid = "4ER05306238362254"; paypal.sale.refund(saleid, data, function (error, refund){ if (error){ console.error(JSON.stringify(error)); } else { console.log("Refund Sale Response"); console.log(JSON.stringify(refund)); } });
$sale = new Sale(); $sale->setId("4ER05306238362254"); try { $refundedSale = $sale->refund($refund, $apiContext); } catch (PayPal\Exception\PayPalConnectionException $ex) { echo $ex->getCode(); echo $ex->getData(); die($ex); } catch (Exception $ex) { die($ex); }
if refund.success(): print("Refund[%s] Success" % (refund.id)) else: print(refund.error)
if refund.success? logger.info "Refund[#{refund.id}] Success" else logger.error refund.error.inspect end
Sale sale = new Sale(); sale.setId("7DY409201T7922549"); try { // Refund sale sale.refund(apiContext, refund); } catch (PayPalRESTException e) { System.err.println(e.getDetails()); }
Coming soon
Additional information
-
SDK Repositories:
- Show refund details API endpoint