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 - \ No newline at end of file + diff --git a/sample/payments/GetAuthorization.php b/sample/payments/GetAuthorization.php index d27e1ed..18a8a88 100644 --- a/sample/payments/GetAuthorization.php +++ b/sample/payments/GetAuthorization.php @@ -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']; -} \ No newline at end of file +} diff --git a/sample/payments/GetCapture.php b/sample/payments/GetCapture.php index 474fc5e..194de6c 100644 --- a/sample/payments/GetCapture.php +++ b/sample/payments/GetCapture.php @@ -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']; -} \ No newline at end of file +} diff --git a/sample/payments/GetPayment.php b/sample/payments/GetPayment.php index 288d49e..2863af9 100644 --- a/sample/payments/GetPayment.php +++ b/sample/payments/GetPayment.php @@ -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 {
toArray());?>
Back - \ No newline at end of file + diff --git a/sample/payments/ListPayments.php b/sample/payments/ListPayments.php index 4f950c4..ce60abd 100644 --- a/sample/payments/ListPayments.php +++ b/sample/payments/ListPayments.php @@ -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); diff --git a/sample/payments/Reauthorization.php b/sample/payments/Reauthorization.php index c7fe031..8e5f004 100644 --- a/sample/payments/Reauthorization.php +++ b/sample/payments/Reauthorization.php @@ -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{ Back - \ No newline at end of file + diff --git a/sample/payments/RefundCapture.php b/sample/payments/RefundCapture.php index b33dc91..7988a5f 100644 --- a/sample/payments/RefundCapture.php +++ b/sample/payments/RefundCapture.php @@ -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']; -} \ No newline at end of file +} diff --git a/sample/payments/VoidAuthorization.php b/sample/payments/VoidAuthorization.php index dff13be..c5e07e3 100644 --- a/sample/payments/VoidAuthorization.php +++ b/sample/payments/VoidAuthorization.php @@ -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']; -} \ No newline at end of file +} diff --git a/sample/sale/GetSale.php b/sample/sale/GetSale.php index 521f445..14da4bb 100644 --- a/sample/sale/GetSale.php +++ b/sample/sale/GetSale.php @@ -15,7 +15,7 @@ try { // Pass the ID of the sale // transaction from your payment resource. $sale = Sale::get($saleId, $apiContext); -} catch (\PPConnectionException $ex) { +} catch (PayPal\Exception\PPConnectionException $ex) { echo "Exception:" . $ex->getMessage() . PHP_EOL; var_dump($ex->getData()); exit(1); @@ -27,4 +27,4 @@ try {
Back - \ No newline at end of file + diff --git a/sample/sale/RefundSale.php b/sample/sale/RefundSale.php index bcf9df7..1e9bff9 100644 --- a/sample/sale/RefundSale.php +++ b/sample/sale/RefundSale.php @@ -34,7 +34,7 @@ try { // Refund the sale // (See bootstrap.php for more on `ApiContext`) $sale->refund($refund, $apiContext); -} catch (\PPConnectionException $ex) { +} catch (PayPal\Exception\PPConnectionException $ex) { echo "Exception:" . $ex->getMessage() . PHP_EOL; var_dump($ex->getData()); exit(1); @@ -46,4 +46,4 @@ try {
Back - \ No newline at end of file + diff --git a/sample/source/AuthorizationCapture.html b/sample/source/AuthorizationCapture.html index cd22334..5042253 100644 --- a/sample/source/AuthorizationCapture.html +++ b/sample/source/AuthorizationCapture.html @@ -1,92 +1,93 @@ -AuthorizationCaptureBack
<?php

AuthorizationCapture

+AuthorizationCapture
<?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\Address; -use PayPal\Api\Amount; -use PayPal\Api\CreditCard; -use PayPal\Api\Payer; -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

+API used: /v1/payments/payment

require __DIR__ . '/../bootstrap.php'; +use PayPal\Api\Capture; +use PayPal\Api\Authorization; +use PayPal\Api\Address; +use PayPal\Api\Amount; +use PayPal\Api\CreditCard; +use PayPal\Api\Payer; +use PayPal\Api\Payment; +use PayPal\Api\FundingInstrument; +use PayPal\Api\Transaction;

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 { - $getCapture = $authorization->capture($capture, $apiContext); -} catch (\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); -} -?> -<html> -<body> - <div> - Capture payment: - <?php echo $getCapture->getId();?> - </div> - <pre> - <?php var_dump($getCapture->toArray());?> - </pre> - <a href='../index.html'>Back</a> -</body> -</html> -<?php -function createAuthorization($apiContext) -{ - $addr = new Address(); - $addr->setLine1("3909 Witmer Road"); - $addr->setLine2("Niagara Falls"); - $addr->setCity("Niagara Falls"); - $addr->setState("NY"); - $addr->setPostal_code("14305"); - $addr->setCountry_code("US"); - $addr->setPhone("716-298-1822"); - - $card = new CreditCard(); - $card->setType("visa"); - $card->setNumber("4417119669820331"); - $card->setExpire_month("11"); - $card->setExpire_year("2019"); - $card->setCvv2("012"); - $card->setFirst_name("Joe"); - $card->setLast_name("Shopper"); - $card->setBilling_address($addr); - - $fi = new FundingInstrument(); - $fi->setCredit_card($card); - - $payer = new Payer(); - $payer->setPayment_method("credit_card"); - $payer->setFunding_instruments(array($fi)); - - $amount = new Amount(); - $amount->setCurrency("USD"); - $amount->setTotal("1.00"); - - $transaction = new Transaction(); - $transaction->setAmount($amount); - $transaction->setDescription("This is the payment description."); - - $payment = new Payment(); - $payment->setIntent("authorize"); - $payment->setPayer($payer); - $payment->setTransactions(array($transaction)); - - $paymnt = $payment->create($apiContext); - $resArray = $paymnt->toArray(); - - return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id']; -}
\ No newline at end of file +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 (PayPal\Exception\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} +?> +<html> +<body> + <div> + Capture payment: + <?php echo $getCapture->getId();?> + </div> + <pre> + <?php var_dump($getCapture->toArray());?> + </pre> + <a href='../index.html'>Back</a> +</body> +</html> +<?php +function createAuthorization($apiContext) +{ + $addr = new Address(); + $addr->setLine1("3909 Witmer Road"); + $addr->setLine2("Niagara Falls"); + $addr->setCity("Niagara Falls"); + $addr->setState("NY"); + $addr->setPostal_code("14305"); + $addr->setCountry_code("US"); + $addr->setPhone("716-298-1822"); + + $card = new CreditCard(); + $card->setType("visa"); + $card->setNumber("4417119669820331"); + $card->setExpire_month("11"); + $card->setExpire_year("2019"); + $card->setCvv2("012"); + $card->setFirst_name("Joe"); + $card->setLast_name("Shopper"); + $card->setBilling_address($addr); + + $fi = new FundingInstrument(); + $fi->setCredit_card($card); + + $payer = new Payer(); + $payer->setPayment_method("credit_card"); + $payer->setFunding_instruments(array($fi)); + + $amount = new Amount(); + $amount->setCurrency("USD"); + $amount->setTotal("1.00"); + + $transaction = new Transaction(); + $transaction->setAmount($amount); + $transaction->setDescription("This is the payment description."); + + $payment = new Payment(); + $payment->setIntent("authorize"); + $payment->setPayer($payer); + $payment->setTransactions(array($transaction)); + + $paymnt = $payment->create($apiContext); + $resArray = $paymnt->toArray(); + + return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id']; +}
\ No newline at end of file diff --git a/sample/source/CreatePayment.html b/sample/source/CreatePayment.html index bd7e65c..89b6e93 100644 --- a/sample/source/CreatePayment.html +++ b/sample/source/CreatePayment.html @@ -1,4 +1,4 @@ -CreatePaymentBack
<?php

CreatePaymentSample

+CreatePayment
<?php

CreatePaymentSample

This sample code demonstrate how you can process a payment with a credit card. @@ -66,7 +66,7 @@ the above types and intent as 'sale'

ApiContext) 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); @@ -81,4 +81,4 @@ The return object contains the status;

<pre><?php var_dump($payment->toArray());?></pre> <a href='../index.html'>Back</a> </body> -</html>
\ No newline at end of file +</html>
\ No newline at end of file diff --git a/sample/source/CreatePaymentUsingPayPal.html b/sample/source/CreatePaymentUsingPayPal.html index 1cf0ed2..de7b031 100644 --- a/sample/source/CreatePaymentUsingPayPal.html +++ b/sample/source/CreatePaymentUsingPayPal.html @@ -1,4 +1,4 @@ -CreatePaymentUsingPayPalBack
<?php

Create Payment using PayPal as payment method

+CreatePaymentUsingPayPal
<?php

Create Payment using PayPal as payment method

This sample code demonstrates how you can process a PayPal Account based Payment. @@ -48,7 +48,7 @@ The return object contains the status and the url to which the buyer must be redirected to 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); @@ -64,4 +64,4 @@ payment id in a database.

if(isset($redirectUrl)) { header("Location: $redirectUrl"); exit; -}
\ No newline at end of file +}
\ No newline at end of file diff --git a/sample/source/CreatePaymentUsingSavedCard.html b/sample/source/CreatePaymentUsingSavedCard.html index e729795..07417ff 100644 --- a/sample/source/CreatePaymentUsingSavedCard.html +++ b/sample/source/CreatePaymentUsingSavedCard.html @@ -1,4 +1,4 @@ -CreatePaymentUsingSavedCardBack
<?php

Create payment using a saved credit card

+CreatePaymentUsingSavedCard
<?php

Create payment using a saved credit card

This sample code demonstrates how you can process a Payment using a previously saved credit card. @@ -53,7 +53,7 @@ the above types and intent as 'sale'

ApiContext) 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); @@ -68,4 +68,4 @@ The return object contains the status;

<pre><?php var_dump($payment->toArray());?></pre> <a href='../index.html'>Back</a> </body> -</html>
\ No newline at end of file +</html>
\ No newline at end of file diff --git a/sample/source/DeleteCreditCard.html b/sample/source/DeleteCreditCard.html index 6dfd07a..f8e45ed 100644 --- a/sample/source/DeleteCreditCard.html +++ b/sample/source/DeleteCreditCard.html @@ -1,50 +1,50 @@ -DeleteCreditCardBack
<?php

Delete CreditCard Sample

+DeleteCreditCard
<?php

Delete CreditCard Sample

This sample code demonstrate how you can

//delete a saved creditcard

using the delete API. API used: /v1/vault/credit-card/{} -NOTE: HTTP method used here is DELETE

require __DIR__ . '/../bootstrap.php'; -use PayPal\Api\CreditCard; +NOTE: HTTP method used here is DELETE

require __DIR__ . '/../bootstrap.php'; +use PayPal\Api\CreditCard; use PayPal\Api\Address;

save card for demo

CreditCard

A resource representing a credit card that can be -used to fund a payment.

$card = new CreditCard(); -$card->setType("visa"); -$card->setNumber("4417119669820331"); -$card->setExpire_month("11"); -$card->setExpire_year("2019"); -$card->setCvv2("012"); -$card->setFirst_name("Joe"); +used to fund a payment.

$card = new CreditCard(); +$card->setType("visa"); +$card->setNumber("4417119669820331"); +$card->setExpire_month("11"); +$card->setExpire_year("2019"); +$card->setCvv2("012"); +$card->setFirst_name("Joe"); $card->setLast_name("Shopper");

Save card

Creates the credit card as a resource in the PayPal vault. The response contains an 'id' that you can use to refer to it in the future payments. -(See bootstrap.php for more on ApiContext)

try { - $res = $card->create($apiContext); -} catch (\PPConnectionException $ex) { - echo "Exception:" . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); -} - -$creditCard = CreditCard::get($res->getId(), $apiContext); +(See bootstrap.php for more on ApiContext)

try { + $res = $card->create($apiContext); +} catch (\PPConnectionException $ex) { + echo "Exception:" . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} + +$creditCard = CreditCard::get($res->getId(), $apiContext); try {

Delete Card

deletes saved credit card -(See bootstrap.php for more on ApiContext)

$creditCard->delete($apiContext); -} catch (\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - exit(1); -} -?> - -<html> -<body> -<div>Delete CreditCard:</div> - <p> Credit Card deleted Successfully</p> - <a href='../index.html'>Back</a> -</body> -</html>
\ No newline at end of file +(See bootstrap.php for more on ApiContext)

$creditCard->delete($apiContext); +} catch (\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + exit(1); +} +?> + +<html> +<body> +<div>Delete CreditCard:</div> + <p> Credit Card deleted Successfully</p> + <a href='../index.html'>Back</a> +</body> +</html>
\ No newline at end of file diff --git a/sample/source/ExecutePayment.html b/sample/source/ExecutePayment.html index 2bc88b6..ab77e3d 100644 --- a/sample/source/ExecutePayment.html +++ b/sample/source/ExecutePayment.html @@ -1,4 +1,4 @@ -ExecutePaymentBack
<?php

Execute Payment Sample

+ExecutePayment
<?php

Execute Payment Sample

This sample shows how you can complete a payment that has been approved by @@ -29,4 +29,4 @@ when the user is redirected from paypal back to your site

} else { echo "User cancelled payment."; -}
\ No newline at end of file +}
Back
\ No newline at end of file diff --git a/sample/source/GetAuthorization.html b/sample/source/GetAuthorization.html index fa7afcb..0648f9c 100644 --- a/sample/source/GetAuthorization.html +++ b/sample/source/GetAuthorization.html @@ -1,81 +1,82 @@ -GetAuthorizationBack
<?php

GetAuthorization

+GetAuthorization
<?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; -use PayPal\Api\Address; -use PayPal\Api\Amount; -use PayPal\Api\CreditCard; -use PayPal\Api\Payer; -use PayPal\Api\Payment; -use PayPal\Api\FundingInstrument; -use PayPal\Api\Transaction;

create payment to get authorization Id

$authId = createAuthorization($apiContext);

GetAuthorization

+API used: /v1/payments/authorization/<$authorizationId>

require __DIR__ . '/../bootstrap.php'; + +use PayPal\Api\Authorization; +use PayPal\Api\Address; +use PayPal\Api\Amount; +use PayPal\Api\CreditCard; +use PayPal\Api\Payer; +use PayPal\Api\Payment; +use PayPal\Api\FundingInstrument; +use PayPal\Api\Transaction;

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($authId, $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> -<?php -function createAuthorization($apiContext) -{ - $addr = new Address(); - $addr->setLine1("3909 Witmer Road"); - $addr->setLine2("Niagara Falls"); - $addr->setCity("Niagara Falls"); - $addr->setState("NY"); - $addr->setPostal_code("14305"); - $addr->setCountry_code("US"); - $addr->setPhone("716-298-1822"); - - $card = new CreditCard(); - $card->setType("visa"); - $card->setNumber("4417119669820331"); - $card->setExpire_month("11"); - $card->setExpire_year("2019"); - $card->setCvv2("012"); - $card->setFirst_name("Joe"); - $card->setLast_name("Shopper"); - $card->setBilling_address($addr); - - $fi = new FundingInstrument(); - $fi->setCredit_card($card); - - $payer = new Payer(); - $payer->setPayment_method("credit_card"); - $payer->setFunding_instruments(array($fi)); - - $amount = new Amount(); - $amount->setCurrency("USD"); - $amount->setTotal("1.00"); - - $transaction = new Transaction(); - $transaction->setAmount($amount); - $transaction->setDescription("This is the payment description."); - - $payment = new Payment(); - $payment->setIntent("authorize"); - $payment->setPayer($payer); - $payment->setTransactions(array($transaction)); - - $paymnt = $payment->create($apiContext); - $resArray = $paymnt->toArray(); - - return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id']; -}
\ No newline at end of file +The return object contains the status;

try {

create payment to get authorization Id

$authId = createAuthorization($apiContext); + + $authorization = Authorization::get($authId, $apiContext); +} catch (PayPal\Exception\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> +<?php +function createAuthorization($apiContext) +{ + $addr = new Address(); + $addr->setLine1("3909 Witmer Road"); + $addr->setLine2("Niagara Falls"); + $addr->setCity("Niagara Falls"); + $addr->setState("NY"); + $addr->setPostal_code("14305"); + $addr->setCountry_code("US"); + $addr->setPhone("716-298-1822"); + + $card = new CreditCard(); + $card->setType("visa"); + $card->setNumber("4417119669820331"); + $card->setExpire_month("11"); + $card->setExpire_year("2019"); + $card->setCvv2("012"); + $card->setFirst_name("Joe"); + $card->setLast_name("Shopper"); + $card->setBilling_address($addr); + + $fi = new FundingInstrument(); + $fi->setCredit_card($card); + + $payer = new Payer(); + $payer->setPayment_method("credit_card"); + $payer->setFunding_instruments(array($fi)); + + $amount = new Amount(); + $amount->setCurrency("USD"); + $amount->setTotal("1.00"); + + $transaction = new Transaction(); + $transaction->setAmount($amount); + $transaction->setDescription("This is the payment description."); + + $payment = new Payment(); + $payment->setIntent("authorize"); + $payment->setPayer($payer); + $payment->setTransactions(array($transaction)); + + $paymnt = $payment->create($apiContext); + $resArray = $paymnt->toArray(); + + return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id']; +}
\ No newline at end of file diff --git a/sample/source/GetCapture.html b/sample/source/GetCapture.html index 4b647a8..50302d9 100644 --- a/sample/source/GetCapture.html +++ b/sample/source/GetCapture.html @@ -1,99 +1,100 @@ -GetCaptureBack
<?php

GetCapture

+GetCapture
<?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; -use PayPal\Api\Address; -use PayPal\Api\Amount; -use PayPal\Api\CreditCard; -use PayPal\Api\Payer; -use PayPal\Api\Payment; -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

+API used: /v1/payments/capture/<$captureId>

require __DIR__ . '/../bootstrap.php'; +use PayPal\Api\Capture; +use PayPal\Api\Address; +use PayPal\Api\Amount; +use PayPal\Api\CreditCard; +use PayPal\Api\Payer; +use PayPal\Api\Payment; +use PayPal\Api\FundingInstrument; +use PayPal\Api\Transaction; +use PayPal\Api\Authorization;

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); +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 (PayPal\Exception\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); }

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($capt->getId(), $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> -<?php -function createAuthorization($apiContext) -{ - $addr = new Address(); - $addr->setLine1("3909 Witmer Road"); - $addr->setLine2("Niagara Falls"); - $addr->setCity("Niagara Falls"); - $addr->setState("NY"); - $addr->setPostal_code("14305"); - $addr->setCountry_code("US"); - $addr->setPhone("716-298-1822"); - - $card = new CreditCard(); - $card->setType("visa"); - $card->setNumber("4417119669820331"); - $card->setExpire_month("11"); - $card->setExpire_year("2019"); - $card->setCvv2("012"); - $card->setFirst_name("Joe"); - $card->setLast_name("Shopper"); - $card->setBilling_address($addr); - - $fi = new FundingInstrument(); - $fi->setCredit_card($card); - - $payer = new Payer(); - $payer->setPayment_method("credit_card"); - $payer->setFunding_instruments(array($fi)); - - $amount = new Amount(); - $amount->setCurrency("USD"); - $amount->setTotal("1.00"); - - $transaction = new Transaction(); - $transaction->setAmount($amount); - $transaction->setDescription("This is the payment description."); - - $payment = new Payment(); - $payment->setIntent("authorize"); - $payment->setPayer($payer); - $payment->setTransactions(array($transaction)); - - $paymnt = $payment->create($apiContext); - $resArray = $paymnt->toArray(); - - return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id']; -}
\ No newline at end of file +The return object contains the status;

try { + $capture = Capture::get($capt->getId(), $apiContext); +} catch (PayPal\Exception\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> +<?php +function createAuthorization($apiContext) +{ + $addr = new Address(); + $addr->setLine1("3909 Witmer Road"); + $addr->setLine2("Niagara Falls"); + $addr->setCity("Niagara Falls"); + $addr->setState("NY"); + $addr->setPostal_code("14305"); + $addr->setCountry_code("US"); + $addr->setPhone("716-298-1822"); + + $card = new CreditCard(); + $card->setType("visa"); + $card->setNumber("4417119669820331"); + $card->setExpire_month("11"); + $card->setExpire_year("2019"); + $card->setCvv2("012"); + $card->setFirst_name("Joe"); + $card->setLast_name("Shopper"); + $card->setBilling_address($addr); + + $fi = new FundingInstrument(); + $fi->setCredit_card($card); + + $payer = new Payer(); + $payer->setPayment_method("credit_card"); + $payer->setFunding_instruments(array($fi)); + + $amount = new Amount(); + $amount->setCurrency("USD"); + $amount->setTotal("1.00"); + + $transaction = new Transaction(); + $transaction->setAmount($amount); + $transaction->setDescription("This is the payment description."); + + $payment = new Payment(); + $payment->setIntent("authorize"); + $payment->setPayer($payer); + $payment->setTransactions(array($transaction)); + + $paymnt = $payment->create($apiContext); + $resArray = $paymnt->toArray(); + + return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id']; +}
\ No newline at end of file diff --git a/sample/source/GetPayment.html b/sample/source/GetPayment.html index c59c1c8..ddbcd9b 100644 --- a/sample/source/GetPayment.html +++ b/sample/source/GetPayment.html @@ -1,4 +1,4 @@ -GetPaymentBack
<?php

GetPaymentSample

+GetPayment
<?php

GetPaymentSample

This sample code demonstrate how you can retrieve a list of all Payment resources @@ -17,7 +17,7 @@ on the Payment class by passing a valid Payment ID (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); @@ -29,4 +29,4 @@ Payment ID <pre><?php var_dump($payment->toArray());?></pre> <a href='../index.html'>Back</a> </body> -</html>
\ No newline at end of file +</html>
\ No newline at end of file diff --git a/sample/source/GetSale.html b/sample/source/GetSale.html index fd2c9ff..5330fac 100644 --- a/sample/source/GetSale.html +++ b/sample/source/GetSale.html @@ -11,7 +11,7 @@ API used: /v1/payments/sale/{sale-id}

Pass the ID of the sale transaction from your payment resource.

$sale = Sale::get($saleId, $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/source/ListPayments.html b/sample/source/ListPayments.html index b4050b3..b420ec8 100644 --- a/sample/source/ListPayments.html +++ b/sample/source/ListPayments.html @@ -1,4 +1,4 @@ -ListPaymentsBack
<?php

GetPaymentList

+ListPayments
<?php

GetPaymentList

This sample code demonstrate how you can retrieve a list of all Payment resources @@ -16,7 +16,7 @@ query parameters for paginations and filtering. Refer the method doc for valid values for keys (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); @@ -28,4 +28,4 @@ Refer the method doc for valid values for keys <pre><?php var_dump($payments->toArray());?></pre> <a href='../index.html'>Back</a> </body> -</html>
\ No newline at end of file +</html>
\ No newline at end of file diff --git a/sample/source/Reauthorization.html b/sample/source/Reauthorization.html index a8a15fe..a42eb16 100644 --- a/sample/source/Reauthorization.html +++ b/sample/source/Reauthorization.html @@ -1,39 +1,40 @@ -ReauthorizationBack
<?php

Reauthorization Sample

+Reauthorization
<?php

Reauthorization Sample

Sample showing how to do a reauthorization -API used: v1/payments/authorization/{authorization_id}/reauthorize

require __DIR__ . '/../bootstrap.php'; -use PayPal\Api\Authorization; -use PayPal\Api\Amount; -use PayPal\Exception\PPConnectionException;

Reauthorization

+API used: v1/payments/authorization/{authorization_id}/reauthorize

require __DIR__ . '/../bootstrap.php'; +use PayPal\Api\Authorization; +use PayPal\Api\Amount; + +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"); - -$authorization->setAmount($amount); -try{ - $reauthorization = $authorization->reauthorize($apiContext); -}catch (\PPConnectionException $ex){ - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); -} -?> -<html> -<body> - <div> - Reauthorize: - <?php echo $reauthorization->getId();?> - </div> - <pre> - <?php var_dump($reauthorization->toArray());?> - </pre> - <a href='../index.html'>Back</a> -</body> -</html>
\ No newline at end of file +expires.

$authorization = Authorization::get('7GH53639GA425732B', $apiContext); + + $amount = new Amount(); + $amount->setCurrency("USD"); + $amount->setTotal("1.00"); + + $authorization->setAmount($amount); + + $reauthorization = $authorization->reauthorize($apiContext); +}catch (PayPal\Exception\PPConnectionException $ex){ + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} +?> +<html> +<body> + <div> + Reauthorize: + <?php echo $reauthorization->getId();?> + </div> + <pre> + <?php var_dump($reauthorization->toArray());?> + </pre> + <a href='../index.html'>Back</a> +</body> +</html>
\ No newline at end of file diff --git a/sample/source/RefundCapture.html b/sample/source/RefundCapture.html index 2b48d65..c53b095 100644 --- a/sample/source/RefundCapture.html +++ b/sample/source/RefundCapture.html @@ -1,106 +1,108 @@ -RefundCaptureBack
<?php

Refund Capture Sample

+RefundCapture
<?php

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/{}/refund

require __DIR__ . '/../bootstrap.php'; -use PayPal\Api\Authorization; -use PayPal\Api\Capture; -use PayPal\Api\Refund; -use PayPal\Api\Address; -use PayPal\Api\Amount; -use PayPal\Api\CreditCard; -use PayPal\Api\Payer; -use PayPal\Api\Payment; -use PayPal\Api\FundingInstrument; -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

+API used: /v1/payments/capture/{}/refund

require __DIR__ . '/../bootstrap.php'; +use PayPal\Api\Authorization; +use PayPal\Api\Capture; +use PayPal\Api\Refund; +use PayPal\Api\Address; +use PayPal\Api\Amount; +use PayPal\Api\CreditCard; +use PayPal\Api\Payer; +use PayPal\Api\Payment; +use PayPal\Api\FundingInstrument; +use PayPal\Api\Transaction; +use PayPal\Rest\ApiContext; +use PayPal\Auth\OAuthTokenCredential;

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); +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 (PayPal\Exception\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); }

Refund

Create a refund object indicating -refund amount

$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) { - 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> -<?php -function createAuthorization($apiContext) -{ - $addr = new Address(); - $addr->setLine1("3909 Witmer Road"); - $addr->setLine2("Niagara Falls"); - $addr->setCity("Niagara Falls"); - $addr->setState("NY"); - $addr->setPostal_code("14305"); - $addr->setCountry_code("US"); - $addr->setPhone("716-298-1822"); - - $card = new CreditCard(); - $card->setType("visa"); - $card->setNumber("4417119669820331"); - $card->setExpire_month("11"); - $card->setExpire_year("2019"); - $card->setCvv2("012"); - $card->setFirst_name("Joe"); - $card->setLast_name("Shopper"); - $card->setBilling_address($addr); - - $fi = new FundingInstrument(); - $fi->setCredit_card($card); - - $payer = new Payer(); - $payer->setPayment_method("credit_card"); - $payer->setFunding_instruments(array($fi)); - - $amount = new Amount(); - $amount->setCurrency("USD"); - $amount->setTotal("10.00"); - - $transaction = new Transaction(); - $transaction->setAmount($amount); - $transaction->setDescription("This is the payment description."); - - $payment = new Payment(); - $payment->setIntent("authorize"); - $payment->setPayer($payer); - $payment->setTransactions(array($transaction)); - - $paymnt = $payment->create($apiContext); - $resArray = $paymnt->toArray(); - - return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id']; -}
\ No newline at end of file +refund amount

$refund = new Refund(); +$refund->setAmount($amt); + + +try { + $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); +} +?> + +<html> +<body> + <div>Refund Capture:</div> + <pre><?php var_dump($captureRefund);?></pre> + <a href='../index.html'>Back</a> +</body> +</html> +<?php +function createAuthorization($apiContext) +{ + $addr = new Address(); + $addr->setLine1("3909 Witmer Road"); + $addr->setLine2("Niagara Falls"); + $addr->setCity("Niagara Falls"); + $addr->setState("NY"); + $addr->setPostal_code("14305"); + $addr->setCountry_code("US"); + $addr->setPhone("716-298-1822"); + + $card = new CreditCard(); + $card->setType("visa"); + $card->setNumber("4417119669820331"); + $card->setExpire_month("11"); + $card->setExpire_year("2019"); + $card->setCvv2("012"); + $card->setFirst_name("Joe"); + $card->setLast_name("Shopper"); + $card->setBilling_address($addr); + + $fi = new FundingInstrument(); + $fi->setCredit_card($card); + + $payer = new Payer(); + $payer->setPayment_method("credit_card"); + $payer->setFunding_instruments(array($fi)); + + $amount = new Amount(); + $amount->setCurrency("USD"); + $amount->setTotal("10.00"); + + $transaction = new Transaction(); + $transaction->setAmount($amount); + $transaction->setDescription("This is the payment description."); + + $payment = new Payment(); + $payment->setIntent("authorize"); + $payment->setPayer($payer); + $payment->setTransactions(array($transaction)); + + $paymnt = $payment->create($apiContext); + $resArray = $paymnt->toArray(); + + return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id']; +}
\ No newline at end of file diff --git a/sample/source/RefundSale.html b/sample/source/RefundSale.html index 3b8375d..3c18b91 100644 --- a/sample/source/RefundSale.html +++ b/sample/source/RefundSale.html @@ -25,7 +25,7 @@ given sale transaction id.

try {

Refund the sale (See bootstrap.php for more on ApiContext)

$sale->refund($refund, $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/source/VoidAuthorization.html b/sample/source/VoidAuthorization.html index f3de626..bf9b900 100644 --- a/sample/source/VoidAuthorization.html +++ b/sample/source/VoidAuthorization.html @@ -1,82 +1,82 @@ -VoidAuthorizationBack
<?php

VoidAuthorization

+VoidAuthorization
<?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; -use PayPal\Api\Address; -use PayPal\Api\Amount; -use PayPal\Api\CreditCard; -use PayPal\Api\Payer; -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

+API used: /v1/payments/authorization/<{authorizationid}>/void"

require __DIR__ . '/../bootstrap.php'; + +use PayPal\Api\Authorization; +use PayPal\Api\Address; +use PayPal\Api\Amount; +use PayPal\Api\CreditCard; +use PayPal\Api\Payer; +use PayPal\Api\Payment; +use PayPal\Api\FundingInstrument; +use PayPal\Api\Transaction;

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> -<?php -function createAuthorization($apiContext) -{ - $addr = new Address(); - $addr->setLine1("3909 Witmer Road"); - $addr->setLine2("Niagara Falls"); - $addr->setCity("Niagara Falls"); - $addr->setState("NY"); - $addr->setPostal_code("14305"); - $addr->setCountry_code("US"); - $addr->setPhone("716-298-1822"); - - $card = new CreditCard(); - $card->setType("visa"); - $card->setNumber("4417119669820331"); - $card->setExpire_month("11"); - $card->setExpire_year("2019"); - $card->setCvv2("012"); - $card->setFirst_name("Joe"); - $card->setLast_name("Shopper"); - $card->setBilling_address($addr); - - $fi = new FundingInstrument(); - $fi->setCredit_card($card); - - $payer = new Payer(); - $payer->setPayment_method("credit_card"); - $payer->setFunding_instruments(array($fi)); - - $amount = new Amount(); - $amount->setCurrency("USD"); - $amount->setTotal("1.00"); - - $transaction = new Transaction(); - $transaction->setAmount($amount); - $transaction->setDescription("This is the payment description."); - - $payment = new Payment(); - $payment->setIntent("authorize"); - $payment->setPayer($payer); - $payment->setTransactions(array($transaction)); - - $paymnt = $payment->create($apiContext); - $resArray = $paymnt->toArray(); - - return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id']; -}
\ No newline at end of file +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 (PayPal\Exception\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> +<?php +function createAuthorization($apiContext) +{ + $addr = new Address(); + $addr->setLine1("3909 Witmer Road"); + $addr->setLine2("Niagara Falls"); + $addr->setCity("Niagara Falls"); + $addr->setState("NY"); + $addr->setPostal_code("14305"); + $addr->setCountry_code("US"); + $addr->setPhone("716-298-1822"); + + $card = new CreditCard(); + $card->setType("visa"); + $card->setNumber("4417119669820331"); + $card->setExpire_month("11"); + $card->setExpire_year("2019"); + $card->setCvv2("012"); + $card->setFirst_name("Joe"); + $card->setLast_name("Shopper"); + $card->setBilling_address($addr); + + $fi = new FundingInstrument(); + $fi->setCredit_card($card); + + $payer = new Payer(); + $payer->setPayment_method("credit_card"); + $payer->setFunding_instruments(array($fi)); + + $amount = new Amount(); + $amount->setCurrency("USD"); + $amount->setTotal("1.00"); + + $transaction = new Transaction(); + $transaction->setAmount($amount); + $transaction->setDescription("This is the payment description."); + + $payment = new Payment(); + $payment->setIntent("authorize"); + $payment->setPayer($payer); + $payment->setTransactions(array($transaction)); + + $paymnt = $payment->create($apiContext); + $resArray = $paymnt->toArray(); + + return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id']; +}
\ No newline at end of file