refund() public method

Refund a completed payment by passing the sale_id in the request URI. In addition, include an empty JSON payload in the request body for a full refund. For a partial refund, include an amount object in the request body.
Deprecation: Please use #refundSale instead.
public refund ( Refund $refund, ApiContext $apiContext = null, PayPalRestCall $restCall = null ) : Refund
$refund Refund
$apiContext PayPal\Rest\ApiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
$restCall PayPalRestCall is the Rest Call Service that is used to make rest calls
return Refund
Ejemplo n.º 1
1
use PayPal\Api\Sale;
// ### Refund amount
// Includes both the refunded amount (to Payer)
// and refunded fee (to Payee). Use the $amt->details
// field to mention fees refund details.
$amt = new Amount();
$amt->setCurrency('USD')->setTotal(0.01);
// ### Refund object
$refund = new Refund();
$refund->setAmount($amt);
// ###Sale
// A sale transaction.
// Create a Sale object with the
// given sale transaction id.
$sale = new Sale();
$sale->setId($saleId);
try {
    // Create a new apiContext object so we send a new
    // PayPal-Request-Id (idempotency) header for this resource
    $apiContext = getApiContext($clientId, $clientSecret);
    // Refund the sale
    // (See bootstrap.php for more on `ApiContext`)
    $refundedSale = $sale->refund($refund, $apiContext);
} catch (Exception $ex) {
    // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
    ResultPrinter::printError("Refund Sale", "Sale", $refundedSale->getId(), $refund, $ex);
    exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Refund Sale", "Sale", $refundedSale->getId(), $refund, $refundedSale);
return $refundedSale;
Ejemplo n.º 2
1
 public function refundSale($saleId, $refundAmount, $currency = CurrencyConst::EURO)
 {
     $apiContext = $this->connectionService->getApiContext();
     $amount = new Amount();
     $amount->setCurrency($currency)->setTotal($refundAmount);
     $refund = new Refund();
     $refund->setAmount($amount);
     $sale = new Sale();
     $sale->setId($saleId);
     $refundSale = $sale->refund($refund, $apiContext);
     return $refundSale;
 }
Ejemplo n.º 3
0
$amt = new Amount();
$amt->setCurrency('USD');
$amt->setTotal('0.01');
$refund = new Refund();
$refund->setAmount($amt);
$saleId = '3RM92092UW5126232';
// ###Sale
// A sale transaction.
// Create a Sale object with the
// given sale transaction id.
$sale = new Sale();
$sale->setId($saleId);
try {
    // Refund the sale
    // (See bootstrap.php for more on `ApiContext`)
    $sale->refund($refund, $apiContext);
} catch (\PPConnectionException $ex) {
    echo "Exception:" . $ex->getMessage() . PHP_EOL;
    var_dump($ex->getData());
    exit(1);
}
?>
<html>
<body>
	<div>Refunding sale id: <?php 
echo $saleId;
?>
</div>
	<pre><?php 
var_dump($sale);
?>
Ejemplo n.º 4
0
 /**
  * @dataProvider mockProvider
  * @param Sale $obj
  */
 public function testRefund($obj, $mockApiContext)
 {
     $mockPPRestCall = $this->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock();
     $mockPPRestCall->expects($this->any())->method('execute')->will($this->returnValue(RefundTest::getJson()));
     $refund = RefundTest::getObject();
     $result = $obj->refund($refund, $mockApiContext, $mockPPRestCall);
     $this->assertNotNull($result);
 }