forked from LiveCarta/PayPal-PHP-SDK
Fixing handling of PPConnectionException in sample code
This commit is contained in:
@@ -14,28 +14,29 @@ use PayPal\Api\Payment;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
use PayPal\Api\Transaction;
|
||||
|
||||
// create payment to get authorization Id
|
||||
$authId = createAuthorization($apiContext);
|
||||
|
||||
$amt = new Amount();
|
||||
$amt->setCurrency("USD");
|
||||
$amt->setTotal("1.00");
|
||||
|
||||
### Capture
|
||||
$capture = new Capture();
|
||||
$capture->setId($authId);
|
||||
$capture->setAmount($amt);
|
||||
|
||||
// get the authorization
|
||||
$authorization = Authorization::get($authId, $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 {
|
||||
// create payment to get authorization Id
|
||||
$authId = createAuthorization($apiContext);
|
||||
|
||||
$amt = new Amount();
|
||||
$amt->setCurrency("USD");
|
||||
$amt->setTotal("1.00");
|
||||
|
||||
### Capture
|
||||
$capture = new Capture();
|
||||
$capture->setId($authId);
|
||||
$capture->setAmount($amt);
|
||||
|
||||
// get the authorization
|
||||
$authorization = Authorization::get($authId, $apiContext);
|
||||
|
||||
$getCapture = $authorization->capture($capture, $apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
@@ -99,4 +100,4 @@ function createAuthorization($apiContext)
|
||||
$resArray = $paymnt->toArray();
|
||||
|
||||
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ $payment->setTransactions(array($transaction));
|
||||
// The return object contains the status;
|
||||
try {
|
||||
$payment->create($apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
|
||||
@@ -63,7 +63,7 @@ $payment->setTransactions(array($transaction));
|
||||
// for payment approval
|
||||
try {
|
||||
$payment->create($apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
|
||||
@@ -70,7 +70,7 @@ $payment->setTransactions(array($transaction));
|
||||
// The return object contains the status;
|
||||
try {
|
||||
$payment->create($apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
} catch (PayPal\ExceptionPayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
@@ -85,4 +85,4 @@ try {
|
||||
<pre><?php var_dump($payment->toArray());?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@@ -14,16 +14,17 @@ use PayPal\Api\Payment;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
use PayPal\Api\Transaction;
|
||||
|
||||
// create payment to get authorization Id
|
||||
$authId = createAuthorization($apiContext);
|
||||
|
||||
// ### 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 {
|
||||
// create payment to get authorization Id
|
||||
$authId = createAuthorization($apiContext);
|
||||
|
||||
$authorization = Authorization::get($authId, $apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
@@ -85,4 +86,4 @@ function createAuthorization($apiContext)
|
||||
$resArray = $paymnt->toArray();
|
||||
|
||||
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,27 +14,28 @@ use PayPal\Api\FundingInstrument;
|
||||
use PayPal\Api\Transaction;
|
||||
use PayPal\Api\Authorization;
|
||||
|
||||
// create payment to get authorization Id
|
||||
$authId = createAuthorization($apiContext);
|
||||
$amt = new Amount();
|
||||
$amt->setCurrency("USD");
|
||||
$amt->setTotal("1.00");
|
||||
|
||||
### Capture
|
||||
$captur = new Capture();
|
||||
$captur->setId($authId);
|
||||
$captur->setAmount($amt);
|
||||
|
||||
// get the authorization
|
||||
$authorization = Authorization::get($authId, $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 {
|
||||
// create payment to get authorization Id
|
||||
$authId = createAuthorization($apiContext);
|
||||
$amt = new Amount();
|
||||
$amt->setCurrency("USD");
|
||||
$amt->setTotal("1.00");
|
||||
|
||||
### Capture
|
||||
$captur = new Capture();
|
||||
$captur->setId($authId);
|
||||
$captur->setAmount($amt);
|
||||
|
||||
// get the authorization
|
||||
$authorization = Authorization::get($authId, $apiContext);
|
||||
|
||||
$capt = $authorization->capture($captur, $apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
@@ -46,7 +47,7 @@ try {
|
||||
// The return object contains the status;
|
||||
try {
|
||||
$capture = Capture::get($capt->getId(), $apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
@@ -108,4 +109,4 @@ function createAuthorization($apiContext)
|
||||
$resArray = $paymnt->toArray();
|
||||
|
||||
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ $paymentId = "PAY-0XL713371A312273YKE2GCNI";
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$payment = Payment::get($paymentId, $apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
@@ -33,4 +33,4 @@ try {
|
||||
<pre><?php var_dump($payment->toArray());?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@@ -22,7 +22,7 @@ use PayPal\Api\Payment;
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$payments = Payment::all(array('count' => 10, 'start_index' => 5), $apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
|
||||
@@ -5,24 +5,24 @@
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\Authorization;
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Exception\PPConnectionException;
|
||||
|
||||
// ###Reauthorization
|
||||
// Retrieve a authorization id from authorization object
|
||||
// by making a `Payment Using PayPal` with intent
|
||||
// as `authorize`. You can reauthorize a payment only once 4 to 29
|
||||
// days after 3-day honor period for the original authorization
|
||||
// expires.
|
||||
$authorization = Authorization::get('7GH53639GA425732B', $apiContext);
|
||||
try {
|
||||
// ###Reauthorization
|
||||
// Retrieve a authorization id from authorization object
|
||||
// by making a `Payment Using PayPal` with intent
|
||||
// as `authorize`. You can reauthorize a payment only once 4 to 29
|
||||
// days after 3-day honor period for the original authorization
|
||||
// expires.
|
||||
$authorization = Authorization::get('7GH53639GA425732B', $apiContext);
|
||||
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD");
|
||||
$amount->setTotal("1.00");
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD");
|
||||
$amount->setTotal("1.00");
|
||||
|
||||
$authorization->setAmount($amount);
|
||||
try{
|
||||
$authorization->setAmount($amount);
|
||||
|
||||
$reauthorization = $authorization->reauthorize($apiContext);
|
||||
}catch (PPConnectionException $ex){
|
||||
}catch (PayPal\Exception\PPConnectionException $ex){
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
@@ -39,4 +39,4 @@ try{
|
||||
</pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@@ -18,27 +18,28 @@ use PayPal\Api\Transaction;
|
||||
use PayPal\Rest\ApiContext;
|
||||
use PayPal\Auth\OAuthTokenCredential;
|
||||
|
||||
// create payment to get authorization Id
|
||||
$authId = createAuthorization($apiContext);
|
||||
|
||||
$amt = new Amount();
|
||||
$amt->setCurrency("USD");
|
||||
$amt->setTotal("1.00");
|
||||
|
||||
### Capture
|
||||
$captur = new Capture();
|
||||
$captur->setAmount($amt);
|
||||
|
||||
// get the authorization
|
||||
$authorization = Authorization::get($authId, $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 {
|
||||
// create payment to get authorization Id
|
||||
$authId = createAuthorization($apiContext);
|
||||
|
||||
$amt = new Amount();
|
||||
$amt->setCurrency("USD");
|
||||
$amt->setTotal("1.00");
|
||||
|
||||
### Capture
|
||||
$captur = new Capture();
|
||||
$captur->setAmount($amt);
|
||||
|
||||
// get the authorization
|
||||
$authorization = Authorization::get($authId, $apiContext);
|
||||
|
||||
$capt = $authorization->capture($captur, $apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
@@ -52,16 +53,15 @@ try {
|
||||
$refund = new Refund();
|
||||
$refund->setAmount($amt);
|
||||
|
||||
$capture = Capture::get($capt->getId(), $apiContext);
|
||||
|
||||
// create new API context
|
||||
$context = new ApiContext(new OAuthTokenCredential(
|
||||
'EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM',
|
||||
'EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM'));
|
||||
try {
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$captureRefund = $capture->refund($refund, $context);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
$capture = Capture::get($capt->getId(), $apiContext);
|
||||
|
||||
// Create a new apiContext object so we send a new
|
||||
// PayPal-Request-Id (idempotency) header for this resource
|
||||
$apiContext = new ApiContext($apiContext->getCredential());
|
||||
$captureRefund = $capture->refund($refund, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
@@ -121,4 +121,4 @@ function createAuthorization($apiContext)
|
||||
$resArray = $paymnt->toArray();
|
||||
|
||||
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,6 @@ use PayPal\Api\Payment;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
use PayPal\Api\Transaction;
|
||||
|
||||
// create payment to get authorization Id
|
||||
$authId = createAuthorization($apiContext);
|
||||
|
||||
$authorization = Authorization::get($authId, $apiContext);
|
||||
|
||||
|
||||
// ### VoidAuthorization
|
||||
@@ -25,8 +21,12 @@ $authorization = Authorization::get($authId, $apiContext);
|
||||
// using a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
// The return object contains the status;
|
||||
try {
|
||||
// create payment to get authorization Id
|
||||
$authId = createAuthorization($apiContext);
|
||||
$authorization = Authorization::get($authId, $apiContext);
|
||||
|
||||
$void = $authorization->void($apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
@@ -87,4 +87,4 @@ function createAuthorization($apiContext)
|
||||
$resArray = $paymnt->toArray();
|
||||
|
||||
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user