forked from LiveCarta/PayPal-PHP-SDK
Updates to Sample Code
- Updated UI Presentation on samples - Fixed Bugs
This commit is contained in:
@@ -4,61 +4,21 @@
|
||||
// of a captured payment.
|
||||
// API used: /v1/payments/capture/<$captureId>
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
/** @var Capture $request */
|
||||
$request = require 'AuthorizationCapture.php';
|
||||
|
||||
use PayPal\Api\Capture;
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\Authorization;
|
||||
|
||||
|
||||
// ### Create a mock Capture
|
||||
try {
|
||||
// create a mock authorization to get authorization Id
|
||||
// createAuthorization is defined in common.php
|
||||
$authId = createAuthorization($apiContext);
|
||||
|
||||
// Lookup the authorization
|
||||
$authorization = Authorization::get($authId, $apiContext);
|
||||
|
||||
### Capture
|
||||
|
||||
$amt = new Amount();
|
||||
$amt->setCurrency("USD")
|
||||
->setTotal("1.00");
|
||||
|
||||
// Create a capture
|
||||
$captureInfo = new Capture();
|
||||
$captureInfo->setId($authId)
|
||||
->setAmount($amt);
|
||||
|
||||
$capture = $authorization->capture($captureInfo, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// ### Retrieve Capture details
|
||||
// You can look up a capture by invoking the Capture::get method
|
||||
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$capture = Capture::get($capture->getId(), $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
$capture = Capture::get($request->getId(), $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Get Captured Payment", "Capture", $request->getId(), null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup a capture</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Capture Id:
|
||||
<?php echo $capture->getId();?>
|
||||
</div>
|
||||
<pre><?php echo $capture->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult("Get Captured Payment", "Capture", $capture->getId(), null, $capture);
|
||||
|
||||
Reference in New Issue
Block a user