forked from LiveCarta/PayPal-PHP-SDK
adding auth capture samples
This commit is contained in:
48
sample/payments/AuthorizationCapture.php
Normal file
48
sample/payments/AuthorizationCapture.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
// # AuthorizationCapture
|
||||
// This sample code demonstrate how you can capture the authorized payment
|
||||
// API used: /v1/payments/payment
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\Capture;
|
||||
use PayPal\Api\Authorization;
|
||||
use PayPal\Api\Amount;
|
||||
|
||||
### Amount
|
||||
//Let's you specify a payment amount.
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD");
|
||||
$amount->setTotal("1.00");
|
||||
|
||||
|
||||
### Capture
|
||||
|
||||
$captur = new Capture();
|
||||
$captur->setId('5RA45624N3531924N');
|
||||
$captur->setAmount($amount);
|
||||
|
||||
// get the authorization
|
||||
$authorization = Authorization::get('8UA90289RG279654G', $apiContext);
|
||||
|
||||
// ### Capture Payment
|
||||
// Capture Payment by posting to the APIService
|
||||
// using a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
// The return object contains the status;
|
||||
try {
|
||||
$capt = $authorization->capture($captur, $apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<body>
|
||||
<div>
|
||||
Capture payment:
|
||||
<?php echo $capt->getId();?>
|
||||
</div>
|
||||
<pre><?php var_dump($capt->toArray());?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
31
sample/payments/GetAuthorization.php
Normal file
31
sample/payments/GetAuthorization.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
// # GetAuthorization
|
||||
// This sample code demonstrate how you can get details of an authorized payment
|
||||
// API used: /v1/payments/authorization/<$authorizationId>
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
|
||||
use PayPal\Api\Authorization;
|
||||
|
||||
// ### GetAuthorization
|
||||
// GetAuthorization by posting to the APIService
|
||||
// using a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
// The return object contains the status;
|
||||
try {
|
||||
$authorization = Authorization::get('1FR49283DF589111P', $apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<body>
|
||||
<div>
|
||||
Get Authorization:
|
||||
<?php echo $authorization->getId();?>
|
||||
</div>
|
||||
<pre><?php var_dump($authorization->toArray());?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
30
sample/payments/GetCapture.php
Normal file
30
sample/payments/GetCapture.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
// # GetCapture
|
||||
// This sample code demonstrate how you can get the details of Captured Payment
|
||||
// API used: /v1/payments/capture/<$captureId>
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\Capture;
|
||||
|
||||
// ### Get Capture
|
||||
// Get Capture by posting to the APIService
|
||||
// using a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
// The return object contains the status;
|
||||
try {
|
||||
$capture = Capture::get('7BA08426L46375838', $apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<body>
|
||||
<div>
|
||||
Get Capture :
|
||||
<?php echo $capture->getId();?>
|
||||
</div>
|
||||
<pre><?php var_dump($capture->toArray());?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
45
sample/payments/RefundCapture.php
Normal file
45
sample/payments/RefundCapture.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\Capture;
|
||||
use PayPal\Api\Refund;
|
||||
use PayPal\Api\Amount;
|
||||
|
||||
// # Refund Capture Sample
|
||||
// This sample code demonstrate how you can
|
||||
// process a refund on a Captured transaction created
|
||||
// using the Capture API.
|
||||
// API used: /v1/payments/capture/{<captureID>}/refund
|
||||
|
||||
|
||||
// ### Refund
|
||||
// Create a refund object indicating
|
||||
// refund amount
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD");
|
||||
$amount->setTotal("1.00");
|
||||
|
||||
|
||||
$refund = new Refund();
|
||||
$refund->setId('7BA08426L46375838');
|
||||
$refund->setAmount($amount);
|
||||
|
||||
|
||||
$capture = Capture::get('7BA08426L46375838', $apiContext);
|
||||
try {
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$captureRefund = $capture->refund($refund, $apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
|
||||
<html>
|
||||
<body>
|
||||
<div>Refund Capture:</div>
|
||||
<pre><?php var_dump($captureRefund);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
33
sample/payments/VoidAuthorization.php
Normal file
33
sample/payments/VoidAuthorization.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
// # VoidAuthorization
|
||||
// This sample code demonstrate how you can void an authorized payment
|
||||
// API used: /v1/payments/authorization/<{authorizationid}>/void"
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
|
||||
use PayPal\Api\Authorization;
|
||||
|
||||
$authorization = Authorization::get('87U86133WD4359724', $apiContext);
|
||||
|
||||
|
||||
// ### VoidAuthorization
|
||||
// VoidAuthorization by posting to the APIService
|
||||
// using a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
// The return object contains the status;
|
||||
try {
|
||||
$void = $authorization->void($apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<body>
|
||||
<div>
|
||||
Void Authorization:
|
||||
</div>
|
||||
<pre><?php var_dump($void->toArray());?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user