diff --git a/sample/bootstrap.php b/sample/bootstrap.php index 5095a03..d930b4f 100644 --- a/sample/bootstrap.php +++ b/sample/bootstrap.php @@ -22,6 +22,7 @@ use PayPal\Auth\OAuthTokenCredential; $apiContext = new ApiContext(new OAuthTokenCredential( 'EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM', 'EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM')); + // Uncomment this step if you want to use per request // dynamic configuration instead of using sdk_config.ini /* @@ -34,6 +35,7 @@ $apiContext->setConfig(array( )); */ + /** * ### getBaseUrl function * // utility function that returns base url for diff --git a/sample/payments/AuthorizationCapture.php b/sample/payments/AuthorizationCapture.php index 52345fa..6b064b9 100644 --- a/sample/payments/AuthorizationCapture.php +++ b/sample/payments/AuthorizationCapture.php @@ -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']; -} \ No newline at end of file +} diff --git a/sample/payments/CreatePayment.php b/sample/payments/CreatePayment.php index 258629f..7c34bb8 100644 --- a/sample/payments/CreatePayment.php +++ b/sample/payments/CreatePayment.php @@ -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); diff --git a/sample/payments/CreatePaymentUsingPayPal.php b/sample/payments/CreatePaymentUsingPayPal.php index e4cf904..0f4163c 100644 --- a/sample/payments/CreatePaymentUsingPayPal.php +++ b/sample/payments/CreatePaymentUsingPayPal.php @@ -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); diff --git a/sample/payments/CreatePaymentUsingSavedCard.php b/sample/payments/CreatePaymentUsingSavedCard.php index 40c9bf6..18fa312 100644 --- a/sample/payments/CreatePaymentUsingSavedCard.php +++ b/sample/payments/CreatePaymentUsingSavedCard.php @@ -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 {
toArray());?>Back