This repository has been archived on 2026-04-06. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
PayPal-PHP-SDK/sample/payments/RefundCapture.php
japatel 49b80f76af Removing Dependency from SDK Core Project
- Copied files required for Rest API SDK
- Removed PPApiContext and directly connected APIContext with PPConfigManager
- Removed duplicate data storage of configuration and credentials.
- Code Style Fixes
- Remove build.xml file as it is not required anymore
- Updated the samples
- Updated the documentations
2014-10-06 11:16:47 -05:00

71 lines
1.6 KiB
PHP

<?php
// # Refund Capture Sample
// This sample code demonstrates how you can
// process a refund on a Captured transaction.
// API used: /v1/payments/capture/{<captureID>}/refund
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Authorization;
use PayPal\Api\Capture;
use PayPal\Api\Refund;
use PayPal\Api\Amount;
use PayPal\Rest\ApiContext;
try {
// Create a mock authorization to get authorization Id
$authId = createAuthorization($apiContext);
// Get the authorization
$authorization = Authorization::get($authId, $apiContext);
// ### Capture
$amt = new Amount();
$amt->setCurrency("USD")
->setTotal("1.00");
// Create a capture
$captureInfo = new Capture();
$captureInfo->setAmount($amt);
$capture = $authorization->capture($captureInfo, $apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) {
echo "Exception: " . $ex->getMessage() . PHP_EOL;
var_dump($ex->getData());
exit(1);
}
// ### Refund
// Create a refund object indicating
// refund amount and call the refund method
$refund = new Refund();
$refund->setAmount($amt);
try {
// Create a new apiContext object so we send a new
// PayPal-Request-Id (idempotency) header for this resource
$apiContext = getApiContext();
$captureRefund = $capture->refund($refund, $apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) {
echo "Exception: " . $ex->getMessage() . PHP_EOL;
var_dump($ex->getData());
exit(1);
}
?>
<html>
<head>
<title>Refund a captured payment</title>
</head>
<body>
<div>Refund Capture:</div>
<pre><?php echo $captureRefund->toJSON(JSON_PRETTY_PRINT);?></pre>
<a href='../index.html'>Back</a>
</body>
</html>