From 3c02790138f294b93f973b0842c2865d9e844161 Mon Sep 17 00:00:00 2001 From: japatel Date: Sun, 2 Nov 2014 17:06:58 -0600 Subject: [PATCH] Updates to Sample Code - Updated UI Presentation on samples - Fixed Bugs --- lib/PayPal/Api/Payment.php | 2 +- lib/PayPal/Validation/JsonValidator.php | 10 +- .../Validation/ModelAccessorValidator.php | 4 +- .../CreateBillingAgreementWithCreditCard.php | 5 +- .../CreateBillingAgreementWithPayPal.php | 5 +- sample/billing/CreatePlan.php | 7 +- sample/billing/ExecuteAgreement.php | 5 +- sample/billing/GetBillingAgreement.php | 5 +- sample/billing/GetPlan.php | 5 +- sample/billing/ListPlans.php | 5 +- sample/billing/ReactivateBillingAgreement.php | 5 +- sample/billing/SuspendBillingAgreement.php | 5 +- sample/billing/UpdateBillingAgreement.php | 5 +- sample/billing/UpdatePlan.php | 5 +- sample/common.php | 126 ++++++++---------- sample/doc/assets/behavior.js | 96 ++++++------- .../CreateBillingAgreementWithCreditCard.html | 5 +- .../CreateBillingAgreementWithPayPal.html | 5 +- sample/doc/billing/CreatePlan.html | 7 +- sample/doc/billing/ExecuteAgreement.html | 5 +- sample/doc/billing/GetBillingAgreement.html | 5 +- sample/doc/billing/GetPlan.html | 5 +- sample/doc/billing/ListPlans.html | 5 +- .../billing/ReactivateBillingAgreement.html | 5 +- .../doc/billing/SuspendBillingAgreement.html | 5 +- .../doc/billing/UpdateBillingAgreement.html | 5 +- sample/doc/billing/UpdatePlan.html | 5 +- sample/doc/invoice/CancelInvoice.html | 5 +- sample/doc/invoice/CreateInvoice.html | 5 +- sample/doc/invoice/GetInvoice.html | 5 +- sample/doc/invoice/ListInvoice.html | 5 +- sample/doc/invoice/RemindInvoice.html | 5 +- sample/doc/invoice/SendInvoice.html | 5 +- .../GenerateAccessTokenFromRefreshToken.html | 5 +- sample/doc/lipp/GetUserInfo.html | 5 +- sample/doc/lipp/UserConsentRedirect.html | 5 +- .../payment-experience/CreateWebProfile.html | 10 +- .../payment-experience/DeleteWebProfile.html | 8 +- .../doc/payment-experience/GetWebProfile.html | 8 +- .../payment-experience/ListWebProfiles.html | 8 +- .../PartiallyUpdateWebProfile.html | 6 +- .../payment-experience/UpdateWebProfile.html | 6 +- sample/doc/payments/AuthorizationCapture.html | 46 +++---- sample/doc/payments/AuthorizePayment.html | 66 +++++++++ sample/doc/payments/CreateFuturePayment.html | 24 +--- sample/doc/payments/CreatePayment.html | 28 ++-- .../payments/CreatePaymentUsingPayPal.html | 61 ++++----- .../payments/CreatePaymentUsingSavedCard.html | 66 ++++----- sample/doc/payments/ExecutePayment.html | 8 +- sample/doc/payments/GetAuthorization.html | 35 ++--- sample/doc/payments/GetCapture.html | 47 ++----- sample/doc/payments/GetPayment.html | 29 ++-- sample/doc/payments/ListPayments.html | 27 ++-- sample/doc/payments/Reauthorization.html | 38 ++---- sample/doc/payments/RefundCapture.html | 46 ++----- sample/doc/payments/VoidAuthorization.html | 30 ++--- sample/doc/sale/GetSale.html | 36 +++-- sample/doc/sale/RefundSale.html | 38 +++--- sample/doc/vault/CreateCreditCard.html | 36 ++--- sample/doc/vault/DeleteCreditCard.html | 48 ++----- sample/doc/vault/GetCreditCard.html | 31 ++--- sample/header.html | 13 ++ sample/index.html | 31 +++-- sample/invoice/CancelInvoice.php | 5 +- sample/invoice/CreateInvoice.php | 5 +- sample/invoice/GetInvoice.php | 5 +- sample/invoice/ListInvoice.php | 5 +- sample/invoice/RemindInvoice.php | 5 +- sample/invoice/SendInvoice.php | 5 +- .../GenerateAccessTokenFromRefreshToken.php | 5 +- sample/lipp/GetUserInfo.php | 5 +- sample/lipp/UserConsentRedirect.php | 5 +- .../payment-experience/CreateWebProfile.php | 12 +- .../payment-experience/DeleteWebProfile.php | 8 +- sample/payment-experience/GetWebProfile.php | 8 +- sample/payment-experience/ListWebProfiles.php | 8 +- .../PartiallyUpdateWebProfile.php | 6 +- .../payment-experience/UpdateWebProfile.php | 6 +- sample/payments/AuthorizationCapture.php | 53 +++----- sample/payments/AuthorizePayment.php | 81 +++++++++++ sample/payments/CreateFuturePayment.php | 25 ++-- sample/payments/CreatePayment.php | 29 ++-- sample/payments/CreatePaymentUsingPayPal.php | 64 ++++----- .../payments/CreatePaymentUsingSavedCard.php | 68 +++++----- sample/payments/ExecutePayment.php | 8 +- sample/payments/GetAuthorization.php | 38 ++---- sample/payments/GetCapture.php | 56 ++------ sample/payments/GetPayment.php | 29 ++-- sample/payments/ListPayments.php | 27 ++-- sample/payments/Reauthorization.php | 45 ++----- sample/payments/RefundCapture.php | 58 ++------ sample/payments/VoidAuthorization.php | 38 ++---- sample/sale/GetSale.php | 43 +++--- sample/sale/RefundSale.php | 43 +++--- sample/vault/CreateCreditCard.php | 39 +++--- sample/vault/DeleteCreditCard.php | 57 ++------ sample/vault/GetCreditCard.php | 32 ++--- 97 files changed, 904 insertions(+), 1249 deletions(-) create mode 100644 sample/doc/payments/AuthorizePayment.html create mode 100644 sample/payments/AuthorizePayment.php diff --git a/lib/PayPal/Api/Payment.php b/lib/PayPal/Api/Payment.php index 1217a6c..b290a8d 100644 --- a/lib/PayPal/Api/Payment.php +++ b/lib/PayPal/Api/Payment.php @@ -247,7 +247,7 @@ class Payment extends ResourceModel * A payment can have more than one transaction, with each transaction establishing a contract between the payer and a payee * * - * @param \PayPal\Api\Transaction $transactions + * @param \PayPal\Api\Transaction[] $transactions * * @return $this */ diff --git a/lib/PayPal/Validation/JsonValidator.php b/lib/PayPal/Validation/JsonValidator.php index 9bba938..831c11f 100644 --- a/lib/PayPal/Validation/JsonValidator.php +++ b/lib/PayPal/Validation/JsonValidator.php @@ -14,14 +14,18 @@ class JsonValidator * Helper method for validating if string provided is a valid json. * * @param string $string String representation of Json object + * @param bool $silent Flag to not throw \InvalidArgumentException * @return bool */ - public static function validate($string) + public static function validate($string, $silent = false) { json_decode($string); if (json_last_error() != JSON_ERROR_NONE) { - //Throw an Exception for string or array - throw new \InvalidArgumentException("Invalid JSON String"); + if ($silent == false) { + //Throw an Exception for string or array + throw new \InvalidArgumentException("Invalid JSON String"); + } + return false; } return true; } diff --git a/lib/PayPal/Validation/ModelAccessorValidator.php b/lib/PayPal/Validation/ModelAccessorValidator.php index 6ae2dc9..2810e17 100644 --- a/lib/PayPal/Validation/ModelAccessorValidator.php +++ b/lib/PayPal/Validation/ModelAccessorValidator.php @@ -30,7 +30,7 @@ class ModelAccessorValidator if (!method_exists($class, $methodName)) { //Delegate the error based on the choice $className = is_object($class) ? get_class($class) : (string)$class; - $errorMessage = "Missing Accessor: $className:$methodName. Please let us know by creating an issue at https://github.com/paypal/rest-api-sdk-php/issues"; + $errorMessage = "Missing Accessor: $className:$methodName. Please let us know by creating an issue at https://github.com/paypal/PayPal-PHP-SDK/issues"; PPLoggingManager::getInstance(__CLASS__)->warning($errorMessage); if ($mode == 'strict') { trigger_error($errorMessage, E_USER_NOTICE); @@ -41,4 +41,4 @@ class ModelAccessorValidator } return true; } -} \ No newline at end of file +} diff --git a/sample/billing/CreateBillingAgreementWithCreditCard.php b/sample/billing/CreateBillingAgreementWithCreditCard.php index faab2b4..f60dde9 100644 --- a/sample/billing/CreateBillingAgreementWithCreditCard.php +++ b/sample/billing/CreateBillingAgreementWithCreditCard.php @@ -100,9 +100,8 @@ try { // Please note that as the agreement has not yet activated, we wont be receiving the ID just yet. $agreement = $agreement->create($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Created Billing Agreement.", "Agreement", $agreement->getId(), $request, $ex); exit(1); } diff --git a/sample/billing/CreateBillingAgreementWithPayPal.php b/sample/billing/CreateBillingAgreementWithPayPal.php index 8363df1..6119d2e 100644 --- a/sample/billing/CreateBillingAgreementWithPayPal.php +++ b/sample/billing/CreateBillingAgreementWithPayPal.php @@ -80,9 +80,8 @@ try { } } -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Created Billing Agreement.", "Agreement", null, $request, $ex); exit(1); } diff --git a/sample/billing/CreatePlan.php b/sample/billing/CreatePlan.php index 4248874..f6df53b 100644 --- a/sample/billing/CreatePlan.php +++ b/sample/billing/CreatePlan.php @@ -46,7 +46,7 @@ $merchantPreferences = new MerchantPreferences(); $baseUrl = getBaseUrl(); $merchantPreferences->setReturnUrl("$baseUrl/ExecuteAgreement.php?success=true") ->setCancelUrl("$baseUrl/ExecuteAgreement.php?success=false") - ->setAutoBillAmount("YES") + ->setAutoBillAmount("yes") ->setInitialFailAmountAction("CONTINUE") ->setMaxFailAttempts("0") ->setSetupFee(new Currency(['value' => '1', 'currency' => 'USD'])); @@ -61,9 +61,8 @@ $request = clone $plan; // ### Create Plan try { $output = $plan->create($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Created Plan", "Plan", null, $request, $ex); exit(1); } diff --git a/sample/billing/ExecuteAgreement.php b/sample/billing/ExecuteAgreement.php index 1f3cc71..351e97b 100644 --- a/sample/billing/ExecuteAgreement.php +++ b/sample/billing/ExecuteAgreement.php @@ -10,9 +10,8 @@ if (isset($_GET['success']) && $_GET['success'] == 'true') { try { $agreement->execute($token, $apiContext); - } catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); + } catch (Exception $ex) { + ResultPrinter::printError("Executed an Agreement", "Agreement", $agreement->getId(), $_GET['token'], $ex); exit(1); } ResultPrinter::printResult("Executed an Agreement", "Agreement", $agreement->getId(), $_GET['token'], $agreement); diff --git a/sample/billing/GetBillingAgreement.php b/sample/billing/GetBillingAgreement.php index 336678f..f62ef15 100644 --- a/sample/billing/GetBillingAgreement.php +++ b/sample/billing/GetBillingAgreement.php @@ -14,9 +14,8 @@ use PayPal\Api\Agreement; try { $agreement = Agreement::get($createdAgreement->getId(), $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Retrieved an Agreement", "Agreement", $agreement->getId(), $createdAgreement->getId(), $ex); exit(1); } diff --git a/sample/billing/GetPlan.php b/sample/billing/GetPlan.php index ceeec77..3395461 100644 --- a/sample/billing/GetPlan.php +++ b/sample/billing/GetPlan.php @@ -14,9 +14,8 @@ use PayPal\Api\Plan; try { $plan = Plan::get($createdPlan->getId(), $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Retrieved a Plan", "Plan", $plan->getId(), null, $ex); exit(1); } diff --git a/sample/billing/ListPlans.php b/sample/billing/ListPlans.php index 972ff7f..83d8c75 100644 --- a/sample/billing/ListPlans.php +++ b/sample/billing/ListPlans.php @@ -19,9 +19,8 @@ try { // at https://developer.paypal.com/webapps/developer/docs/api/#list-plans $params = array('page_size' => '2'); $planList = Plan::all($params, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("List of Plans", "Plan", null, $params, $ex); exit(1); } diff --git a/sample/billing/ReactivateBillingAgreement.php b/sample/billing/ReactivateBillingAgreement.php index d56ad35..a5c511d 100644 --- a/sample/billing/ReactivateBillingAgreement.php +++ b/sample/billing/ReactivateBillingAgreement.php @@ -24,9 +24,8 @@ try { // Lets get the updated Agreement Object $agreement = Agreement::get($suspendedAgreement->getId(), $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printResult("Reactivate the Agreement", "Agreement", $agreement->getId(), $suspendedAgreement, $ex); exit(1); } diff --git a/sample/billing/SuspendBillingAgreement.php b/sample/billing/SuspendBillingAgreement.php index e56f289..3d5cef0 100644 --- a/sample/billing/SuspendBillingAgreement.php +++ b/sample/billing/SuspendBillingAgreement.php @@ -24,9 +24,8 @@ try { // Lets get the updated Agreement Object $agreement = Agreement::get($createdAgreement->getId(), $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Suspended the Agreement", "Agreement", null, $agreementStateDescriptor, $ex); exit(1); } diff --git a/sample/billing/UpdateBillingAgreement.php b/sample/billing/UpdateBillingAgreement.php index 7c28fe2..bc8144d 100644 --- a/sample/billing/UpdateBillingAgreement.php +++ b/sample/billing/UpdateBillingAgreement.php @@ -36,9 +36,8 @@ try { // Lets get the updated Agreement Object $agreement = Agreement::get($createdAgreement->getId(), $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Updated the Agreement with new Description and Updated Shipping Address", "Agreement", null, $patchRequest, $ex); exit(1); } diff --git a/sample/billing/UpdatePlan.php b/sample/billing/UpdatePlan.php index 9e2364e..90712db 100644 --- a/sample/billing/UpdatePlan.php +++ b/sample/billing/UpdatePlan.php @@ -34,9 +34,8 @@ try { $plan = Plan::get($createdPlan->getId(), $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Updated the Plan to Active State", "Plan", null, $patchRequest, $ex); exit(1); } diff --git a/sample/common.php b/sample/common.php index ae7db11..0b26849 100644 --- a/sample/common.php +++ b/sample/common.php @@ -17,11 +17,22 @@ use PayPal\Api\FundingInstrument; * * Class ResultPrinter */ -class ResultPrinter { +class ResultPrinter +{ private static $printResultCounter = 0; - public static function printResult($title, $objectName, $objectId = null, $request = null, $response = null) + /** + * Prints HTML Output to web page. + * + * @param string $title + * @param string $objectName + * @param string $objectId + * @param mixed $request + * @param mixed $response + * @param string $error + */ + public static function printOutput($title, $objectName, $objectId = null, $request = null, $response = null, $errorMessage = null) { if (self::$printResultCounter == 0) { include "header.html"; @@ -33,10 +44,10 @@ class ResultPrinter { self::$printResultCounter++; echo '
-
'; @@ -69,14 +80,51 @@ class ResultPrinter { flush(); } - protected static function printObject($object) + /** + * Prints success response HTML Output to web page. + * + * @param string $title + * @param string $objectName + * @param string $objectId + * @param mixed $request + * @param mixed $response + */ + public static function printResult($title, $objectName, $objectId = null, $request = null, $response = null) { + self::printOutput($title, $objectName, $objectId, $request, $response, false); + } + + /** + * Prints Error + * + * @param $title + * @param $objectName + * @param null $objectId + * @param null $request + * @param \Exception $exception + */ + public static function printError($title, $objectName, $objectId = null, $request = null, $exception = null) + { + $data = null; + if ($exception instanceof \PayPal\Exception\PPConnectionException) { + $data = $exception->getData(); + } + self::printOutput($title, $objectName, $objectId, $request, $data, $exception->getMessage()); + } + + protected static function printObject($object, $error = null) + { + if ($error) { + echo '
'. $error . '
'; + } if ($object) { if (is_a($object, 'PayPal\Common\PPModel')) { /** @var $object \PayPal\Common\PPModel */ - echo '
' . $object->toJSON(128) . "
"; + echo '
' . $object->toJSON(128) . "
"; + } elseif (\PayPal\Validation\JsonValidator::validate($object, true)) { + echo '
'. str_replace('\\/', '/', json_encode(json_decode($object), 128)) . "
"; } elseif (is_string($object)) { - echo "
$object
"; + echo '
' . $object . '
'; } else { echo "
";
                 print_r($object);
@@ -111,59 +159,3 @@ function getBaseUrl()
     $request = $_SERVER['PHP_SELF'];
     return dirname($protocol . '://' . $host . ($port == $protocol_port ? '' : ':' . $port) . $request);
 }
-
-/**
- * Creates a new mock 'payment authorization'
- *
- * @param PayPal\Api\ApiContext apiContext
- * @return PayPal\Api\Authorization
- */
-function createAuthorization($apiContext)
-{
-    $addr = new Address();
-    $addr->setLine1("3909 Witmer Road")
-        ->setLine2("Niagara Falls")
-        ->setCity("Niagara Falls")
-        ->setState("NY")
-        ->setPostalCode("14305")
-        ->setCountryCode("US")
-        ->setPhone("716-298-1822");
-
-    $card = new CreditCard();
-    $card->setType("visa")
-        ->setNumber("4417119669820331")
-        ->setExpireMonth("11")
-        ->setExpireYear("2019")
-        ->setCvv2("012")
-        ->setFirstName("Joe")
-        ->setLastName("Shopper")
-        ->setBillingAddress($addr);
-
-    $fi = new FundingInstrument();
-    $fi->setCreditCard($card);
-
-    $payer = new Payer();
-    $payer->setPaymentMethod("credit_card")
-        ->setFundingInstruments(array($fi));
-
-    $amount = new Amount();
-    $amount->setCurrency("USD")
-        ->setTotal("1.00");
-
-    $transaction = new Transaction();
-    $transaction->setAmount($amount)
-        ->setDescription("Payment description.");
-
-    $payment = new Payment();
-
-// Setting intent to authorize creates a payment
-// authorization. Setting it to sale creates actual payment
-    $payment->setIntent("authorize")
-        ->setPayer($payer)
-        ->setTransactions(array($transaction));
-
-    $paymnt = $payment->create($apiContext);
-    $resArray = $paymnt->toArray();
-
-    return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
-}
diff --git a/sample/doc/assets/behavior.js b/sample/doc/assets/behavior.js
index 9cc263e..542f56f 100644
--- a/sample/doc/assets/behavior.js
+++ b/sample/doc/assets/behavior.js
@@ -1107,6 +1107,46 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
               ]
             }
           ]
+        }, {
+          "type": "file",
+          "data": {
+            "language": {
+              "nameMatchers": [{}, ".fbp"],
+              "pygmentsLexer": "php",
+              "singleLineComment": ["//"],
+              "ignorePrefix": "}",
+              "foldPrefix": "^",
+              "name": "PHP"
+            },
+            "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/payments/AuthorizePayment.php",
+            "projectPath": "payments/AuthorizePayment.php",
+            "targetPath": "payments/AuthorizePayment",
+            "pageTitle": "payments/AuthorizePayment",
+            "title": "AuthorizePayment"
+          },
+          "depth": 2,
+          "outline": [
+            {
+              "type": "heading",
+              "data": {
+                "level": 1,
+                "title": "Authorize Payment",
+                "slug": "authorize-payment"
+              },
+              "depth": 1,
+              "children": [
+                {
+                  "type": "heading",
+                  "data": {
+                    "level": 3,
+                    "title": "Create Payment",
+                    "slug": "create-payment"
+                  },
+                  "depth": 3
+                }
+              ]
+            }
+          ]
         }, {
           "type": "file",
           "data": {
@@ -1399,14 +1439,6 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
                     "slug": "get-redirect-url"
                   },
                   "depth": 3
-                }, {
-                  "type": "heading",
-                  "data": {
-                    "level": 3,
-                    "title": "Redirect buyer to PayPal website",
-                    "slug": "redirect-buyer-to-paypal-website"
-                  },
-                  "depth": 3
                 }
               ]
             }
@@ -1613,14 +1645,6 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
               "depth": 1,
               "children": [
                 {
-                  "type": "heading",
-                  "data": {
-                    "level": 3,
-                    "title": "Create a mock Capture",
-                    "slug": "create-a-mock-capture"
-                  },
-                  "depth": 3
-                }, {
                   "type": "heading",
                   "data": {
                     "level": 3,
@@ -1748,14 +1772,6 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
                     "slug": "reauthorization"
                   },
                   "depth": 3
-                }, {
-                  "type": "heading",
-                  "data": {
-                    "level": 3,
-                    "title": "Lookup authorization using the authorization id",
-                    "slug": "lookup-authorization-using-the-authorization-id"
-                  },
-                  "depth": 3
                 }, {
                   "type": "heading",
                   "data": {
@@ -1797,14 +1813,6 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
               "depth": 1,
               "children": [
                 {
-                  "type": "heading",
-                  "data": {
-                    "level": 3,
-                    "title": "Capture",
-                    "slug": "capture"
-                  },
-                  "depth": 3
-                }, {
                   "type": "heading",
                   "data": {
                     "level": 3,
@@ -1895,6 +1903,14 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
               "depth": 1,
               "children": [
                 {
+                  "type": "heading",
+                  "data": {
+                    "level": 3,
+                    "title": "Get Sale From Created Payment",
+                    "slug": "get-sale-from-created-payment"
+                  },
+                  "depth": 3
+                }, {
                   "type": "heading",
                   "data": {
                     "level": 3,
@@ -2049,22 +2065,6 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
               "depth": 1,
               "children": [
                 {
-                  "type": "heading",
-                  "data": {
-                    "level": 3,
-                    "title": "CreditCard",
-                    "slug": "creditcard"
-                  },
-                  "depth": 3
-                }, {
-                  "type": "heading",
-                  "data": {
-                    "level": 3,
-                    "title": "Save card",
-                    "slug": "save-card"
-                  },
-                  "depth": 3
-                }, {
                   "type": "heading",
                   "data": {
                     "level": 3,
diff --git a/sample/doc/billing/CreateBillingAgreementWithCreditCard.html b/sample/doc/billing/CreateBillingAgreementWithCreditCard.html
index dae828c..d6786a3 100644
--- a/sample/doc/billing/CreateBillingAgreementWithCreditCard.html
+++ b/sample/doc/billing/CreateBillingAgreementWithCreditCard.html
@@ -74,9 +74,8 @@ Please note that the plan Id should be only set in this case.

'US'); $agreement->setShippingAddress($shippingAddress);

For Sample Purposes Only.

$request = clone $agreement;

Create Agreement

try {

Please note that as the agreement has not yet activated, we wont be receiving the ID just yet.

$agreement = $agreement->create($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Created Billing Agreement.", "Agreement", $agreement->getId(), $request, $ex); exit(1); } diff --git a/sample/doc/billing/CreateBillingAgreementWithPayPal.html b/sample/doc/billing/CreateBillingAgreementWithPayPal.html index a5c4334..765aadd 100644 --- a/sample/doc/billing/CreateBillingAgreementWithPayPal.html +++ b/sample/doc/billing/CreateBillingAgreementWithPayPal.html @@ -54,9 +54,8 @@ method

catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Created Billing Agreement.", "Agreement", null, $request, $ex); exit(1); } diff --git a/sample/doc/billing/CreatePlan.html b/sample/doc/billing/CreatePlan.html index e22e688..802c519 100644 --- a/sample/doc/billing/CreatePlan.html +++ b/sample/doc/billing/CreatePlan.html @@ -26,7 +26,7 @@ You should be able to see the acceptable values in the comments.

$baseUrl = getBaseUrl(); $merchantPreferences->setReturnUrl("$baseUrl/ExecuteAgreement.php?success=true") ->setCancelUrl("$baseUrl/ExecuteAgreement.php?success=false") - ->setAutoBillAmount("YES") + ->setAutoBillAmount("yes") ->setInitialFailAmountAction("CONTINUE") ->setMaxFailAttempts("0") ->setSetupFee(new Currency(['value' => '1', 'currency' => 'USD'])); @@ -35,9 +35,8 @@ You should be able to see the acceptable values in the comments.

$plan->setPaymentDefinitions(array($paymentDefinition)); $plan->setMerchantPreferences($merchantPreferences);

For Sample Purposes Only.

$request = clone $plan;

Create Plan

try { $output = $plan->create($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Created Plan", "Plan", null, $request, $ex); exit(1); } diff --git a/sample/doc/billing/ExecuteAgreement.html b/sample/doc/billing/ExecuteAgreement.html index c0bf4df..3a0bc3d 100644 --- a/sample/doc/billing/ExecuteAgreement.html +++ b/sample/doc/billing/ExecuteAgreement.html @@ -10,9 +10,8 @@ session_start(); try { $agreement->execute($token, $apiContext); - } catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); + } catch (Exception $ex) { + ResultPrinter::printError("Executed an Agreement", "Agreement", $agreement->getId(), $_GET['token'], $ex); exit(1); } ResultPrinter::printResult("Executed an Agreement", "Agreement", $agreement->getId(), $_GET['token'], $agreement); diff --git a/sample/doc/billing/GetBillingAgreement.html b/sample/doc/billing/GetBillingAgreement.html index 778c5f7..b456c1a 100644 --- a/sample/doc/billing/GetBillingAgreement.html +++ b/sample/doc/billing/GetBillingAgreement.html @@ -8,9 +8,8 @@ API used: /v1/payments/billing-agreements/

try { $agreement = Agreement::get($createdAgreement->getId(), $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Retrieved an Agreement", "Agreement", $agreement->getId(), $createdAgreement->getId(), $ex); exit(1); } diff --git a/sample/doc/billing/GetPlan.html b/sample/doc/billing/GetPlan.html index 68d3460..fefab87 100644 --- a/sample/doc/billing/GetPlan.html +++ b/sample/doc/billing/GetPlan.html @@ -8,9 +8,8 @@ API used: /v1/payments/billing-plans

< try { $plan = Plan::get($createdPlan->getId(), $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Retrieved a Plan", "Plan", $plan->getId(), null, $ex); exit(1); } diff --git a/sample/doc/billing/ListPlans.html b/sample/doc/billing/ListPlans.html index 02c24c3..46901e0 100644 --- a/sample/doc/billing/ListPlans.html +++ b/sample/doc/billing/ListPlans.html @@ -11,9 +11,8 @@ You can modify different params to change the return list. The explanation about each pagination information could be found here at https://developer.paypal.com/webapps/developer/docs/api/#list-plans

$params = array('page_size' => '2'); $planList = Plan::all($params, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("List of Plans", "Plan", null, $params, $ex); exit(1); } diff --git a/sample/doc/billing/ReactivateBillingAgreement.html b/sample/doc/billing/ReactivateBillingAgreement.html index c0753f2..e3895a2 100644 --- a/sample/doc/billing/ReactivateBillingAgreement.html +++ b/sample/doc/billing/ReactivateBillingAgreement.html @@ -15,9 +15,8 @@ API used: /v1/payments/billing-agreements//suspend

$suspendedAgreement->reActivate($agreementStateDescriptor, $apiContext);

Lets get the updated Agreement Object

$agreement = Agreement::get($suspendedAgreement->getId(), $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printResult("Reactivate the Agreement", "Agreement", $agreement->getId(), $suspendedAgreement, $ex); exit(1); } diff --git a/sample/doc/billing/SuspendBillingAgreement.html b/sample/doc/billing/SuspendBillingAgreement.html index 9d6101b..ce39717 100644 --- a/sample/doc/billing/SuspendBillingAgreement.html +++ b/sample/doc/billing/SuspendBillingAgreement.html @@ -15,9 +15,8 @@ API used: /v1/payments/billing-agreements//suspend

$createdAgreement->suspend($agreementStateDescriptor, $apiContext);

Lets get the updated Agreement Object

$agreement = Agreement::get($createdAgreement->getId(), $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Suspended the Agreement", "Agreement", null, $agreementStateDescriptor, $ex); exit(1); } diff --git a/sample/doc/billing/UpdateBillingAgreement.html b/sample/doc/billing/UpdateBillingAgreement.html index 602f0de..cd79371 100644 --- a/sample/doc/billing/UpdateBillingAgreement.html +++ b/sample/doc/billing/UpdateBillingAgreement.html @@ -27,9 +27,8 @@ API used: /v1/payments/billing-agreements/

try { $createdAgreement->update($patchRequest, $apiContext);

Lets get the updated Agreement Object

$agreement = Agreement::get($createdAgreement->getId(), $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Updated the Agreement with new Description and Updated Shipping Address", "Agreement", null, $patchRequest, $ex); exit(1); } diff --git a/sample/doc/billing/UpdatePlan.html b/sample/doc/billing/UpdatePlan.html index be2dff4..6158cfc 100644 --- a/sample/doc/billing/UpdatePlan.html +++ b/sample/doc/billing/UpdatePlan.html @@ -26,9 +26,8 @@ API used: /v1/payments/billing-plans/

$plan = Plan::get($createdPlan->getId(), $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Updated the Plan to Active State", "Plan", null, $patchRequest, $ex); exit(1); } diff --git a/sample/doc/invoice/CancelInvoice.html b/sample/doc/invoice/CancelInvoice.html index 286a67e..1174ee8 100644 --- a/sample/doc/invoice/CancelInvoice.html +++ b/sample/doc/invoice/CancelInvoice.html @@ -24,9 +24,8 @@ static cancel method on the Invoice class by passing a valid notification object (See bootstrap.php for more on ApiContext)

$cancelStatus = $invoice->cancel($notify, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Cancel Invoice", "Invoice", null, $notify, $ex); exit(1); } diff --git a/sample/doc/invoice/CreateInvoice.html b/sample/doc/invoice/CreateInvoice.html index b6aee93..d94ad31 100644 --- a/sample/doc/invoice/CreateInvoice.html +++ b/sample/doc/invoice/CreateInvoice.html @@ -74,9 +74,8 @@ detailed breakdown of invoice

try {

Create Invoice

Create an invoice by calling the invoice->create() method with a valid ApiContext (See bootstrap.php for more on ApiContext)

$invoice->create($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Invoice Creation", "Invoice", null, $request, $ex); exit(1); } diff --git a/sample/doc/invoice/GetInvoice.html b/sample/doc/invoice/GetInvoice.html index 19e0be0..c2f9f5f 100644 --- a/sample/doc/invoice/GetInvoice.html +++ b/sample/doc/invoice/GetInvoice.html @@ -10,9 +10,8 @@ on the Invoice class by passing a valid Invoice ID (See bootstrap.php for more on ApiContext)

try { $invoice = Invoice::get($invoiceId, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception:" . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Get Invoice", "Invoice", $invoice->getId(), $invoiceId, $ex); exit(1); } diff --git a/sample/doc/invoice/ListInvoice.html b/sample/doc/invoice/ListInvoice.html index 4fe074f..2628fa5 100644 --- a/sample/doc/invoice/ListInvoice.html +++ b/sample/doc/invoice/ListInvoice.html @@ -8,9 +8,8 @@ all invoice from history.

static get_all method on the Invoice class. Refer the method doc for valid values for keys (See bootstrap.php for more on ApiContext)

$invoices = Invoice::get_all($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception:" . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Lookup Invoice History", "Invoice", null, null, $ex); exit(1); } ResultPrinter::printResult("Lookup Invoice History", "Invoice", null, null, $invoices);
\ No newline at end of file diff --git a/sample/doc/invoice/RemindInvoice.html b/sample/doc/invoice/RemindInvoice.html index 586d17a..b2180a8 100644 --- a/sample/doc/invoice/RemindInvoice.html +++ b/sample/doc/invoice/RemindInvoice.html @@ -23,9 +23,8 @@ and payer is retrieved from the invoice details

ApiContext)

$remindStatus = $invoice->remind($notify, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Remind Invoice", "Invoice", null, $notify, $ex); exit(1); } diff --git a/sample/doc/invoice/SendInvoice.html b/sample/doc/invoice/SendInvoice.html index 5847408..e17902e 100644 --- a/sample/doc/invoice/SendInvoice.html +++ b/sample/doc/invoice/SendInvoice.html @@ -12,9 +12,8 @@ Invoice ID (See bootstrap.php for more on ApiContext)

$invoice = Invoice::get("INV2-W4LC-6QS9-JZ62-VE4P", $apiContext);

Send Invoice

Send a legitimate invoice to the payer with a valid ApiContext (See bootstrap.php for more on ApiContext)

$sendStatus = $invoice->send($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printResult("Send Invoice", "Invoice", null, null, $ex); exit(1); } diff --git a/sample/doc/lipp/GenerateAccessTokenFromRefreshToken.html b/sample/doc/lipp/GenerateAccessTokenFromRefreshToken.html index 2eb42b0..044cadb 100644 --- a/sample/doc/lipp/GenerateAccessTokenFromRefreshToken.html +++ b/sample/doc/lipp/GenerateAccessTokenFromRefreshToken.html @@ -6,9 +6,8 @@ $tokenInfo = new PPOpenIdTokeninfo(); $tokenInfo = $tokenInfo->createFromRefreshToken(array('refresh_token' => $refreshToken), $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Obtained Access Token From Refresh Token", "Access Token", null, null, $ex); exit(1); } diff --git a/sample/doc/lipp/GetUserInfo.html b/sample/doc/lipp/GetUserInfo.html index 0b01e49..9213d36 100644 --- a/sample/doc/lipp/GetUserInfo.html +++ b/sample/doc/lipp/GetUserInfo.html @@ -16,9 +16,8 @@ to retreive the information. The short lived access token can be retrieved using $params = array('access_token' => $tokenInfo->getAccessToken()); $userInfo = PPOpenIdUserinfo::getUserinfo($params, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("User Information", "User Info", null, $params, $ex); exit(1); } diff --git a/sample/doc/lipp/UserConsentRedirect.html b/sample/doc/lipp/UserConsentRedirect.html index 069101a..5923243 100644 --- a/sample/doc/lipp/UserConsentRedirect.html +++ b/sample/doc/lipp/UserConsentRedirect.html @@ -13,9 +13,8 @@ The user would then able to retrieve the access token by getting the code, which try {

Obtain Authorization Code from Code, Client ID and Client Secret

$accessToken = PPOpenIdTokeninfo::createFromAuthorizationCode(array('code' => $code), null, null, $apiContext); } catch (PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + ResultPrinter::printError("Obtained Access Token", "Access Token", null, $_GET['code'], $ex); + exit(1); } ResultPrinter::printResult("Obtained Access Token", "Access Token", $accessToken->getAccessToken(), $_GET['code'], $accessToken); diff --git a/sample/doc/payment-experience/CreateWebProfile.html b/sample/doc/payment-experience/CreateWebProfile.html index 1a24d5d..50fe53c 100644 --- a/sample/doc/payment-experience/CreateWebProfile.html +++ b/sample/doc/payment-experience/CreateWebProfile.html @@ -3,15 +3,11 @@ require __DIR__ . '/../bootstrap.php';

Create Web Profile

Use the /web-profiles resource to create seamless payment experience profiles. See the payment experience overview for further information about using the /payment resource to create the PayPal payment and pass the experience_profile_id. Documentation available at https://developer.paypal.com/webapps/developer/docs/api/#create-a-web-experience-profile

Lets create an instance of FlowConfig and add -landing page type information

$flowConfig = new \PayPal\Api\FlowConfig();

Type of PayPal page to be displayed when a user lands on the PayPal site for checkout. Allowed values: Billing or Login. When set to Billing, the Non-PayPal account landing page is used. When set to Login, the PayPal account login landing page is used.

$flowConfig->setLandingPageType("Billing");

The URL on the merchant site for transferring to after a bank transfer payment.

$flowConfig->setBankTxnPendingUrl("http://www.yeowza.com/");

Parameters for style and presentation.

$presentation = new \PayPal\Api\Presentation();

A URL to logo image. Allowed vaues: .gif, .jpg, or .png.

$presentation->setLogoImage("http://www.yeowza.com/favico.ico")

A label that overrides the business name in the PayPal account on the PayPal pages.

->setBrandName("YeowZa! Paypal")

Locale of pages displayed by PayPal payment experience.

->setLocaleCode("US");

Parameters for input fields customization.

$inputFields = new \PayPal\Api\InputFields();

Enables the buyer to enter a note to the merchant on the PayPal page during checkout.

$inputFields->setAllowNote(true)

Determines whether or not PayPal displays shipping address fields on the experience pages. Allowed values: 0, 1, or 2. When set to 0, PayPal displays the shipping address on the PayPal pages. When set to 1, PayPal does not display shipping address fields whatsoever. When set to 2, if you do not pass the shipping address, PayPal obtains it from the buyer’s account profile. For digital goods, this field is required, and you must set it to 1.

->setNoShipping(1)

Determines whether or not the PayPal pages should display the shipping address and not the shipping address on file with PayPal for this buyer. Displaying the PayPal street address on file does not allow the buyer to edit that address. Allowed values: 0 or 1. When set to 0, the PayPal pages should not display the shipping address. When set to 1, the PayPal pages should display the shipping address.

->setAddressOverride(0);

Payment Web experience profile resource

$webProfile = new \PayPal\Api\WebProfile();

Name of the web experience profile. Required. Must be unique

$webProfile->setName("YeowZa! T-Shirt Shop" . uniqid())

Parameters for flow configuration.

->setFlowConfig($flowConfig)

Parameters for style and presentation.

->setPresentation($presentation);

For Sample Purposes Only.

$request = clone $webProfile; +landing page type information

$flowConfig = new \PayPal\Api\FlowConfig();

Type of PayPal page to be displayed when a user lands on the PayPal site for checkout. Allowed values: Billing or Login. When set to Billing, the Non-PayPal account landing page is used. When set to Login, the PayPal account login landing page is used.

$flowConfig->setLandingPageType("Billing");

The URL on the merchant site for transferring to after a bank transfer payment.

$flowConfig->setBankTxnPendingUrl("http://www.yeowza.com/");

Parameters for style and presentation.

$presentation = new \PayPal\Api\Presentation();

A URL to logo image. Allowed vaues: .gif, .jpg, or .png.

$presentation->setLogoImage("http://www.yeowza.com/favico.ico")

A label that overrides the business name in the PayPal account on the PayPal pages.

->setBrandName("YeowZa! Paypal")

Locale of pages displayed by PayPal payment experience.

->setLocaleCode("US");

Parameters for input fields customization.

$inputFields = new \PayPal\Api\InputFields();

Enables the buyer to enter a note to the merchant on the PayPal page during checkout.

$inputFields->setAllowNote(true)

Determines whether or not PayPal displays shipping address fields on the experience pages. Allowed values: 0, 1, or 2. When set to 0, PayPal displays the shipping address on the PayPal pages. When set to 1, PayPal does not display shipping address fields whatsoever. When set to 2, if you do not pass the shipping address, PayPal obtains it from the buyer’s account profile. For digital goods, this field is required, and you must set it to 1.

->setNoShipping(1)

Determines whether or not the PayPal pages should display the shipping address and not the shipping address on file with PayPal for this buyer. Displaying the PayPal street address on file does not allow the buyer to edit that address. Allowed values: 0 or 1. When set to 0, the PayPal pages should not display the shipping address. When set to 1, the PayPal pages should display the shipping address.

->setAddressOverride(0);

Payment Web experience profile resource

$webProfile = new \PayPal\Api\WebProfile();

Name of the web experience profile. Required. Must be unique

$webProfile->setName("YeowZa! T-Shirt Shop" . uniqid())

Parameters for flow configuration.

->setFlowConfig($flowConfig)

Parameters for style and presentation.

->setPresentation($presentation)

Parameters for input field customization.

->setInputFields($inputFields);

For Sample Purposes Only.

$request = clone $webProfile; try {

Use this call to create a profile.

$createProfileResponse = $webProfile->create($apiContext); -} catch (\Exception $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - if (is_a($ex, '\PayPal\Exception\PPConnectionException')) { - /** @var $ex \PayPal\Exception\PPConnectionException */ - var_dump($ex->getData()); - } +} catch (\PayPal\Exception\PPConnectionException $ex) { + ResultPrinter::printError("Created Web Profile", "Web Profile", null, $request, $ex); exit(1); } diff --git a/sample/doc/payment-experience/DeleteWebProfile.html b/sample/doc/payment-experience/DeleteWebProfile.html index a5df890..c1cba15 100644 --- a/sample/doc/payment-experience/DeleteWebProfile.html +++ b/sample/doc/payment-experience/DeleteWebProfile.html @@ -8,12 +8,8 @@ that contains the web profile ID.

$webProfile->setId($createProfileResponse->getId()); try {

Execute the delete method

$webProfile->delete($apiContext); -} catch (\Exception $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - if (is_a($ex, '\PayPal\Exception\PPConnectionException')) { - /** @var $ex \PayPal\Exception\PPConnectionException */ - var_dump($ex->getData()); - } +} catch (\PayPal\Exception\PPConnectionException $ex) { + ResultPrinter::printError("Deleted Web Profile", "Web Profile", $createProfileResponse->getId(), null, $ex); exit(1); } diff --git a/sample/doc/payment-experience/GetWebProfile.html b/sample/doc/payment-experience/GetWebProfile.html index 18a240d..e7a1d0f 100644 --- a/sample/doc/payment-experience/GetWebProfile.html +++ b/sample/doc/payment-experience/GetWebProfile.html @@ -7,12 +7,8 @@ that contains the web profile ID.

$createProfileResponse = require 'CreateWebProfile.php'; try {

If your request is successful, the API returns a web_profile object response that contains the profile details.

$webProfile = \PayPal\Api\WebProfile::get($createProfileResponse->getId(), $apiContext); -} catch (\Exception $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - if (is_a($ex, '\PayPal\Exception\PPConnectionException')) { - /** @var $ex \PayPal\Exception\PPConnectionException */ - var_dump($ex->getData()); - } +} catch (\PayPal\Exception\PPConnectionException $ex) { + ResultPrinter::printError("Get Web Profile", "Web Profile", $webProfile->getId(), null, $ex); exit(1); } diff --git a/sample/doc/payment-experience/ListWebProfiles.html b/sample/doc/payment-experience/ListWebProfiles.html index c8398f7..9c95874 100644 --- a/sample/doc/payment-experience/ListWebProfiles.html +++ b/sample/doc/payment-experience/ListWebProfiles.html @@ -5,12 +5,8 @@ static get_list method on the WebProfile class. (See bootstrap.php for more on ApiContext)

try { $list = \PayPal\Api\WebProfile::get_list($apiContext); -} catch (\Exception $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - if (is_a($ex, '\PayPal\Exception\PPConnectionException')) { - /** @var $ex \PayPal\Exception\PPConnectionException */ - var_dump($ex->getData()); - } +} catch (\PayPal\Exception\PPConnectionException $ex) { + ResultPrinter::printError("Get List of All Web Profiles", "Web Profiles", null, null, $ex); exit(1); } $result = ''; diff --git a/sample/doc/payment-experience/PartiallyUpdateWebProfile.html b/sample/doc/payment-experience/PartiallyUpdateWebProfile.html index 4c1b873..1c1ccb5 100644 --- a/sample/doc/payment-experience/PartiallyUpdateWebProfile.html +++ b/sample/doc/payment-experience/PartiallyUpdateWebProfile.html @@ -18,11 +18,7 @@ as shown below

$webProfile = \PayPal\Api\WebProfile::get($webProfile->getId(), $apiContext); } } catch (\Exception $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - if (is_a($ex, '\PayPal\Exception\PPConnectionException')) { - /** @var $ex \PayPal\Exception\PPConnectionException */ - var_dump($ex->getData()); - } + ResultPrinter::printError("Partially Updated Web Profile", "Web Profile", $webProfile->getId(), $patches, $ex); exit(1); } diff --git a/sample/doc/payment-experience/UpdateWebProfile.html b/sample/doc/payment-experience/UpdateWebProfile.html index f5b2000..7cd42b3 100644 --- a/sample/doc/payment-experience/UpdateWebProfile.html +++ b/sample/doc/payment-experience/UpdateWebProfile.html @@ -8,11 +8,7 @@ create a new web profileId for sample, and return the web profile object.

$updatedWebProfile = \PayPal\Api\WebProfile::get($webProfile->getId(), $apiContext); } } catch (\Exception $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - if (is_a($ex, '\PayPal\Exception\PPConnectionException')) { - /** @var $ex \PayPal\Exception\PPConnectionException */ - var_dump($ex->getData()); - } + ResultPrinter::printError("Updated Web Profile", "Web Profile", $webProfile->getId(), $webProfile, $ex); exit(1); } diff --git a/sample/doc/payments/AuthorizationCapture.html b/sample/doc/payments/AuthorizationCapture.html index 34ffbf5..9df4bcb 100644 --- a/sample/doc/payments/AuthorizationCapture.html +++ b/sample/doc/payments/AuthorizationCapture.html @@ -1,39 +1,29 @@ payments/AuthorizationCapture
payments/AuthorizationCapture.php
<?php

AuthorizationCapture

This sample code demonstrates how you can capture a previously authorized payment. -API used: /v1/payments/payment

require __DIR__ . '/../bootstrap.php'; +API used: /v1/payments/payment +https://developer.paypal.com/webapps/developer/docs/api/#capture-an-authorization

/** @var Authorization $authorization */ +$authorization = require 'GetAuthorization.php'; use PayPal\Api\Amount; use PayPal\Api\Capture; use PayPal\Api\Authorization;

Capture Payment

You can capture and process a previously created authorization by invoking the $authorization->capture method -with a valid ApiContext (See bootstrap.php for more on ApiContext)

try {

Create a new authorization to get authorization Id -createAuthorization defined in common.php

$authId = createAuthorization($apiContext); +with a valid ApiContext (See bootstrap.php for more on ApiContext)

try { + $authId = $authorization->getId(); - $amt = new Amount(); - $amt->setCurrency("USD") - ->setTotal("1.00"); + $amt = new Amount(); + $amt->setCurrency("USD") + ->setTotal("1.00"); - ### Capture - $capture = new Capture(); - $capture->setId($authId) - ->setAmount($amt);

Lookup the authorization.

$authorization = Authorization::get($authId, $apiContext);

Perform a capture

$getCapture = $authorization->capture($capture, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + ### Capture + $capture = new Capture(); + $capture->setAmount($amt);

Perform a capture

$getCapture = $authorization->capture($capture, $apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Capture Payment", "Authorization", null, $capture, $ex); + exit(1); } -?> -<html> -<head> - <title>Capturing an authorization</title> -</head> -<body> - <div> - Captured payment <?php echo $getCapture->getParentPayment(); ?>. Capture Id: - <?php echo $getCapture->getId();?> - </div> - <pre><?php echo $getCapture->toJSON(128);?></pre> - <a href='../index.html'>Back</a> -</body> -</html>
\ No newline at end of file + +ResultPrinter::printResult("Capture Payment", "Authorization", $getCapture->getId(), $capture, $getCapture); + +return $getCapture;
\ No newline at end of file diff --git a/sample/doc/payments/AuthorizePayment.html b/sample/doc/payments/AuthorizePayment.html new file mode 100644 index 0000000..53d04f8 --- /dev/null +++ b/sample/doc/payments/AuthorizePayment.html @@ -0,0 +1,66 @@ +payments/AuthorizePayment
payments/AuthorizePayment.php
<?php

Authorize Payment

+

This sample code demonstrates how you can authorize a payment. +API used: /v1/payments/authorization +https://developer.paypal.com/webapps/developer/docs/integration/direct/capture-payment/#authorize-the-payment

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

The biggest difference between creating a payment, and authorizing a payment is to set the intent of payment +to correct setting. In this case, it would be 'authorize'

$addr = new Address(); +$addr->setLine1("3909 Witmer Road") + ->setLine2("Niagara Falls") + ->setCity("Niagara Falls") + ->setState("NY") + ->setPostalCode("14305") + ->setCountryCode("US") + ->setPhone("716-298-1822"); + +$card = new CreditCard(); +$card->setType("visa") + ->setNumber("4417119669820331") + ->setExpireMonth("11") + ->setExpireYear("2019") + ->setCvv2("012") + ->setFirstName("Joe") + ->setLastName("Shopper") + ->setBillingAddress($addr); + +$fi = new FundingInstrument(); +$fi->setCreditCard($card); + +$payer = new Payer(); +$payer->setPaymentMethod("credit_card") + ->setFundingInstruments(array($fi)); + +$amount = new Amount(); +$amount->setCurrency("USD") + ->setTotal("1.00"); + +$transaction = new Transaction(); +$transaction->setAmount($amount) + ->setDescription("Payment description."); + +$payment = new Payment();

Setting intent to authorize creates a payment +authorization. Setting it to sale creates actual payment

$payment->setIntent("authorize") + ->setPayer($payer) + ->setTransactions(array($transaction));

For Sample Purposes Only.

$request = clone $payment;

Create Payment

+

Create a payment by calling the payment->create() method +with a valid ApiContext (See bootstrap.php for more on ApiContext) +The return object contains the state.

try { + $payment->create($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError('Authorize a Payment', 'Authorized Payment', $payment->getId(), $request, $ex); + exit(1); +} + +ResultPrinter::printResult('Authorize a Payment', 'Authorized Payment', $payment->getId(), $request, $payment); + +$transactions = $payment->getTransactions(); +$relatedResources = $transactions[0]->getRelatedResources(); +$authorization = $relatedResources[0]->getAuthorization(); + +return $authorization;
\ No newline at end of file diff --git a/sample/doc/payments/CreateFuturePayment.html b/sample/doc/payments/CreateFuturePayment.html index f8f794f..635f65d 100644 --- a/sample/doc/payments/CreateFuturePayment.html +++ b/sample/doc/payments/CreateFuturePayment.html @@ -36,7 +36,7 @@ the above types and intent set to 'sale'

authorization code from mobile sdk

$authorizationCode = 'EJfRuAqXEE95pdVMmOym_mftTbeJD03RBX-Zjg9pLCAhdLqLeRR6YSKTNsrbQGX7lFoZ3SxwFyxADEZbBOxpn023W9SA0JzSQAy-9eLdON5eDPAyMyKlHyNVS2DqBR2iWVfQGfudbd9MDoRxMEjIZbY';

correlation id from mobile sdk

$correlationId = '123123456'; try {

Exchange authorization_code for long living refresh token. You should store -it in a database for later use

$refreshToken = FuturePayment::getRefreshToken($authorizationCode, $apiContext);

Update the access token in apiContext

$payment->updateAccessToken($refreshToken, $apiContext);

Create Future Payment

+it in a database for later use

$refreshToken = FuturePayment::getRefreshToken($authorizationCode, $apiContext);

Update the access token in apiContext

$payment->updateAccessToken($refreshToken, $apiContext);

For Sample Purposes Only.

$request = clone $payment;

Create Future Payment

Create a payment by calling the 'create' method passing it a valid apiContext. (See bootstrap.php for more on ApiContext) @@ -45,23 +45,11 @@ url to which the buyer must be redirected to for payment approval Please note that currently future payments works only with PayPal as a funding instrument.

$payment->create($apiContext, $correlationId); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Future Payment", "Payment", null, $request, $ex); exit(1); } -?> -<html> -<head> - <title>Future payments</title> -</head> -<body> -<div> - Created payment: - <?php echo $payment->getId();?> -</div> -<pre><?php echo $payment->toJSON(128);?></pre> -<a href='../index.html'>Back</a> -</body> -</html>
\ No newline at end of file +ResultPrinter::printResult("Future Payment", "Payment", $payment->getId(), $request, $payment); + +return $payment; \ No newline at end of file diff --git a/sample/doc/payments/CreatePayment.html b/sample/doc/payments/CreatePayment.html index 7102b35..1db6b89 100644 --- a/sample/doc/payments/CreatePayment.html +++ b/sample/doc/payments/CreatePayment.html @@ -66,32 +66,22 @@ payment - what is the payment for and who is fulfilling it.

$transaction = new Transaction(); $transaction->setAmount($amount) ->setItemList($itemList) - ->setDescription("Payment description");

Payment

+ ->setDescription("Payment description") + ->setInvoiceNumber(uniqid());

Payment

A Payment Resource; create one using the above types and intent set to sale 'sale'

$payment = new Payment(); $payment->setIntent("sale") ->setPayer($payer) - ->setTransactions(array($transaction));

Create Payment

+ ->setTransactions(array($transaction));

For Sample Purposes Only.

$request = clone $payment;

Create Payment

Create a payment by calling the payment->create() method with a valid ApiContext (See bootstrap.php for more on ApiContext) The return object contains the state.

try { $payment->create($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError('Create Payment Using Credit Card', 'Payment', null, $request, $ex); exit(1); } -?> -<html> -<head> - <title>Direct Credit card payments</title> -</head> -<body> - <div> - Created payment: - <?php echo $payment->getId();?> - </div> - <pre><?php echo $payment->toJSON(128);?></pre> - <a href='../index.html'>Back</a> -</body> -</html>
\ No newline at end of file + +ResultPrinter::printResult('Create Payment Using Credit Card', 'Payment', $payment->getId(), $request, $payment); + +return $payment; \ No newline at end of file diff --git a/sample/doc/payments/CreatePaymentUsingPayPal.html b/sample/doc/payments/CreatePaymentUsingPayPal.html index 9b26c77..ffcefae 100644 --- a/sample/doc/payments/CreatePaymentUsingPayPal.html +++ b/sample/doc/payments/CreatePaymentUsingPayPal.html @@ -17,14 +17,14 @@ to 'paypal'.

(Optional) Lets you specify item wise information

$item1 = new Item(); $item1->setName('Ground Coffee 40 oz') - ->setCurrency('USD') - ->setQuantity(1) - ->setPrice('7.50'); + ->setCurrency('USD') + ->setQuantity(1) + ->setPrice('7.50'); $item2 = new Item(); $item2->setName('Granola bars') - ->setCurrency('USD') - ->setQuantity(5) - ->setPrice('2.00'); + ->setCurrency('USD') + ->setQuantity(5) + ->setPrice('2.00'); $itemList = new ItemList(); $itemList->setItems(array($item1, $item2));

Additional payment details

@@ -32,51 +32,52 @@ information

$details = new Details(); $details->setShipping('1.20') - ->setTax('1.30') - ->setSubtotal('17.50');

Amount

+ ->setTax('1.30') + ->setSubtotal('17.50');

Amount

Lets you specify a payment amount. You can also specify additional details such as shipping, tax.

$amount = new Amount(); $amount->setCurrency("USD") - ->setTotal("20.00") - ->setDetails($details);

Transaction

+ ->setTotal("20.00") + ->setDetails($details);

Transaction

A transaction defines the contract of a payment - what is the payment for and who is fulfilling it.

$transaction = new Transaction(); $transaction->setAmount($amount) - ->setItemList($itemList) - ->setDescription("Payment description");

Redirect urls

+ ->setItemList($itemList) + ->setDescription("Payment description") + ->setInvoiceNumber(uniqid());

Redirect urls

Set the urls that the buyer must be redirected to after payment approval/ cancellation.

$baseUrl = getBaseUrl(); $redirectUrls = new RedirectUrls(); $redirectUrls->setReturnUrl("$baseUrl/ExecutePayment.php?success=true") - ->setCancelUrl("$baseUrl/ExecutePayment.php?success=false");

Payment

+ ->setCancelUrl("$baseUrl/ExecutePayment.php?success=false");

Payment

A Payment Resource; create one using the above types and intent set to 'sale'

$payment = new Payment(); $payment->setIntent("sale") - ->setPayer($payer) - ->setRedirectUrls($redirectUrls) - ->setTransactions(array($transaction));

Create Payment

+ ->setPayer($payer) + ->setRedirectUrls($redirectUrls) + ->setTransactions(array($transaction));

For Sample Purposes Only.

$request = clone $payment;

Create Payment

Create a payment by calling the 'create' method passing it a valid apiContext. (See bootstrap.php for more on ApiContext) The return object contains the state and the url to which the buyer must be redirected to for payment approval

try { - $payment->create($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + $payment->create($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex); + exit(1); }

Get redirect url

The API response provides the url that you must redirect the buyer to. Retrieve the url from the $payment->getLinks() -method

foreach($payment->getLinks() as $link) { - if($link->getRel() == 'approval_url') { - $redirectUrl = $link->getHref(); - break; - } -}

Redirect buyer to PayPal website

if(isset($redirectUrl)) { - header("Location: $redirectUrl"); - exit; -}
\ No newline at end of file +method

foreach ($payment->getLinks() as $link) { + if ($link->getRel() == 'approval_url') { + $approvalUrl = $link->getHref(); + break; + } +} + +ResultPrinter::printResult("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $payment); + +return $payment;
\ No newline at end of file diff --git a/sample/doc/payments/CreatePaymentUsingSavedCard.html b/sample/doc/payments/CreatePaymentUsingSavedCard.html index 1929aa4..624f98c 100644 --- a/sample/doc/payments/CreatePaymentUsingSavedCard.html +++ b/sample/doc/payments/CreatePaymentUsingSavedCard.html @@ -1,7 +1,8 @@ payments/CreatePaymentUsingSavedCard
payments/CreatePaymentUsingSavedCard.php
<?php

Create payment using a saved credit card

This sample code demonstrates how you can process a Payment using a previously stored credit card token. -API used: /v1/payments/payment

require __DIR__ . '/../bootstrap.php'; +API used: /v1/payments/payment

/** @var CreditCard $card */ +$card = require __DIR__ . '/../vault/CreateCreditCard.php'; use PayPal\Api\Amount; use PayPal\Api\Details; use PayPal\Api\Item; @@ -10,10 +11,11 @@ API used: /v1/payments/payment

use PayPal\Api\Payer; use PayPal\Api\Payment; use PayPal\Api\FundingInstrument; -use PayPal\Api\Transaction;

Credit card token

+use PayPal\Api\Transaction; +use PayPal\Api\CreditCard;

Credit card token

Saved credit card id from a previous call to CreateCreditCard.php

$creditCardToken = new CreditCardToken(); -$creditCardToken->setCreditCardId('CARD-17M96700G1952584EKRCTV5Y');

FundingInstrument

+$creditCardToken->setCreditCardId($card->getId());

FundingInstrument

A resource representing a Payer's funding instrument. For stored credit card payments, set the CreditCardToken field on this object.

$fi = new FundingInstrument(); @@ -22,18 +24,18 @@ field on this object.

$payer = new Payer(); $payer->setPaymentMethod("credit_card") - ->setFundingInstruments(array($fi));

Itemized information

+ ->setFundingInstruments(array($fi));

Itemized information

(Optional) Lets you specify item wise information

$item1 = new Item(); $item1->setName('Ground Coffee 40 oz') - ->setCurrency('USD') - ->setQuantity(1) - ->setPrice('7.50'); + ->setCurrency('USD') + ->setQuantity(1) + ->setPrice('7.50'); $item2 = new Item(); $item2->setName('Granola bars') - ->setCurrency('USD') - ->setQuantity(5) - ->setPrice('2.00'); + ->setCurrency('USD') + ->setQuantity(5) + ->setPrice('2.00'); $itemList = new ItemList(); $itemList->setItems(array($item1, $item2));

Additional payment details

@@ -41,46 +43,36 @@ information

$details = new Details(); $details->setShipping('1.20') - ->setTax('1.30') - ->setSubtotal('17.50');

Amount

+ ->setTax('1.30') + ->setSubtotal('17.50');

Amount

Lets you specify a payment amount. You can also specify additional details such as shipping, tax.

$amount = new Amount(); $amount->setCurrency("USD") - ->setTotal("20.00") - ->setDetails($details);

Transaction

+ ->setTotal("20.00") + ->setDetails($details);

Transaction

A transaction defines the contract of a payment - what is the payment for and who is fulfilling it.

$transaction = new Transaction(); $transaction->setAmount($amount) - ->setItemList($itemList) - ->setDescription("Payment description");

Payment

+ ->setItemList($itemList) + ->setDescription("Payment description") + ->setInvoiceNumber(uniqid());

Payment

A Payment Resource; create one using the above types and intent set to 'sale'

$payment = new Payment(); $payment->setIntent("sale") - ->setPayer($payer) - ->setTransactions(array($transaction));

Create Payment

+ ->setPayer($payer) + ->setTransactions(array($transaction));

For Sample Purposes Only.

$request = clone $payment;

Create Payment

Create a payment by calling the 'create' method passing it a valid apiContext. (See bootstrap.php for more on ApiContext) The return object contains the state.

try { - $payment->create($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + $payment->create($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Create Payment using Saved Card", "Payment", null, $request, $ex); + exit(1); } -?> -<html> -<head> - <title>Saved Credit card payments</title> -</head> -<body> - <div> - Created payment: - <?php echo $payment->getId();?> - </div> - <pre><?php echo $payment->toJSON(128);?></pre> - <a href='../index.html'>Back</a> -</body> -</html>
\ No newline at end of file + +ResultPrinter::printResult("Create Payment using Saved Card", "Payment", $payment->getId(), $request, $payment); + +return $card;
\ No newline at end of file diff --git a/sample/doc/payments/ExecutePayment.html b/sample/doc/payments/ExecutePayment.html index 45cd116..406850a 100644 --- a/sample/doc/payments/ExecutePayment.html +++ b/sample/doc/payments/ExecutePayment.html @@ -20,12 +20,8 @@ when the user is redirected from paypal back to your site

//Execute the payment

(See bootstrap.php for more on ApiContext)

$result = $payment->execute($execution, $apiContext); - echo "<html><body><pre>"; - echo $result->toJSON(128); - echo "</pre><a href='../index.html'>Back</a></body></html>"; + ResultPrinter::printResult("Executed Payment", "Payment", $payment->getId(), $execution, $result); } else { - echo "<html><body><h1>"; - echo "User cancelled payment."; - echo "</h1><a href='../index.html'>Back</a></body></html>"; + ResultPrinter::printResult("User Cancelled the Approval", null); }
\ No newline at end of file diff --git a/sample/doc/payments/GetAuthorization.html b/sample/doc/payments/GetAuthorization.html index ce43799..ae1c4ab 100644 --- a/sample/doc/payments/GetAuthorization.html +++ b/sample/doc/payments/GetAuthorization.html @@ -1,31 +1,20 @@ payments/GetAuthorization
payments/GetAuthorization.php
<?php

GetAuthorization

This sample code demonstrates how you can get details of an authorized payment. -API used: /v1/payments/authorization/<$authorizationId>

require __DIR__ . '/../bootstrap.php'; +API used: /v1/payments/authorization/<$authorizationId>

/** @var Authorization $authorization */ +$authorization = require 'AuthorizePayment.php'; -use PayPal\Api\Authorization;

GetAuthorization

+use PayPal\Api\Authorization; +use PayPal\Api\Payment;

GetAuthorization

You can retrieve info about an Authorization by invoking the Authorization::get method with a valid ApiContext (See bootstrap.php for more on ApiContext) -The return object contains the authorization state.

try {

create a authorization to get authorization Id -createAuthorization is defined in common.php

$authId = createAuthorization($apiContext); -

Retrieve the authorization

$authorization = Authorization::get($authId, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); +The return object contains the authorization state.

try {

Retrieve the authorization

$result = Authorization::get($authorization->getId(), $apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Get Authorization", "Authorization", null, null, $ex); + exit(1); } -?> -<html> -<head> - <title>Lookup an authorization</title> -</head> -<body> - <div> - Retrieved Authorization: - <?php echo $authorization->getId();?> - </div> - <pre><?php echo $authorization->toJSON(128);?></pre> - <a href='../index.html'>Back</a> -</body> -</html>
\ No newline at end of file + +ResultPrinter::printResult("Get Authorization", "Authorization", $authorization->getId(), null, $result); + +return $authorization; \ No newline at end of file diff --git a/sample/doc/payments/GetCapture.html b/sample/doc/payments/GetCapture.html index d86f09d..cb40818 100644 --- a/sample/doc/payments/GetCapture.html +++ b/sample/doc/payments/GetCapture.html @@ -1,47 +1,18 @@ payments/GetCapture
payments/GetCapture.php
<?php

GetCapture

This sample code demonstrates how you can lookup the details of a captured payment. -API used: /v1/payments/capture/<$captureId>

require __DIR__ . '/../bootstrap.php'; +API used: /v1/payments/capture/<$captureId>

/** @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

+use PayPal\Api\Authorization;

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>
\ No newline at end of file + +ResultPrinter::printResult("Get Captured Payment", "Capture", $capture->getId(), null, $capture); \ No newline at end of file diff --git a/sample/doc/payments/GetPayment.html b/sample/doc/payments/GetPayment.html index c56d14c..faecd4e 100644 --- a/sample/doc/payments/GetPayment.html +++ b/sample/doc/payments/GetPayment.html @@ -5,29 +5,22 @@ you've created using the Payments API. Note various query parameters that you can use to filter, and paginate through the payments list. -API used: GET /v1/payments/payments

require __DIR__ . '/../bootstrap.php'; +API used: GET /v1/payments/payments

/** @var Payment $createdPayment */ +$createdPayment = require 'CreatePayment.php'; use PayPal\Api\Payment; -$paymentId = "PAY-2AH507590P6615624KRCTUSY";

Retrieve payment

+$paymentId = $createdPayment->getId();

Retrieve payment

Retrieve the payment object by calling the static get method on the Payment class by passing a valid Payment ID (See bootstrap.php for more on ApiContext)

try { - $payment = Payment::get($paymentId, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception:" . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + $payment = Payment::get($paymentId, $apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Get Payment", "Payment", null, null, $ex); + exit(1); } -?> -<html> -<head> - <title>Lookup a payment</title> -</head> -<body> - <div>Retrieving Payment ID: <?php echo $paymentId;?></div> - <pre><?php echo $payment->toJSON(128);?></pre> - <a href='../index.html'>Back</a> -</body> -</html>
\ No newline at end of file + +ResultPrinter::printResult("Get Payment", "Payment", $payment->getId(), null, $payment); + +return $payment; \ No newline at end of file diff --git a/sample/doc/payments/ListPayments.html b/sample/doc/payments/ListPayments.html index 5243a5c..0bc2677 100644 --- a/sample/doc/payments/ListPayments.html +++ b/sample/doc/payments/ListPayments.html @@ -5,7 +5,7 @@ you've created using the Payments API. Note various query parameters that you can use to filter, and paginate through the payments list. -API used: GET /v1/payments/payments

require __DIR__ . '/../bootstrap.php'; +API used: GET /v1/payments/payments

require 'CreatePayment.php'; use PayPal\Api\Payment;

Retrieve payment

Retrieve the PaymentHistory object by calling the static get method on the Payment class, @@ -13,20 +13,13 @@ and pass a Map object that contains 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 (PayPal\Exception\PPConnectionException $ex) { - echo "Exception:" . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + + $params = array('count' => 10, 'start_index' => 5); + + $payments = Payment::all($params, $apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("List Payments", "Payment", null, $params, $ex); + exit(1); } -?> -<html> -<head> - <title>Lookup payment history</title> -</head> -<body> - <div>Got <?php echo $payments->getCount(); ?> matching payments </div> - <pre><?php echo $payments->toJSON(128);?></pre> - <a href='../index.html'>Back</a> -</body> -</html>
\ No newline at end of file + +ResultPrinter::printResult("List Payments", "Payment", null, $params, $payments); \ No newline at end of file diff --git a/sample/doc/payments/Reauthorization.html b/sample/doc/payments/Reauthorization.html index a1551ea..9bbc6dd 100644 --- a/sample/doc/payments/Reauthorization.html +++ b/sample/doc/payments/Reauthorization.html @@ -1,37 +1,23 @@ payments/Reauthorization
payments/Reauthorization.php
<?php

Reauthorization Sample

This sample code demonstrates how you can reauthorize a PayPal account payment. -API used: v1/payments/authorization/{authorization_id}/reauthorize

require __DIR__ . '/../bootstrap.php'; +API used: v1/payments/authorization/{authorization_id}/reauthorize

/** @var Authorization $authorization */ +$authorization = require 'AuthorizePayment.php'; use PayPal\Api\Authorization; use PayPal\Api\Amount;

Reauthorization

Reauthorization is available only for PayPal account payments and not for credit card payments.

You can reauthorize a payment only once 4 to 29 days after the 3-day honor period for the original authorization has expired.

try { -

Lookup authorization using the authorization id

$authorization = Authorization::get('7GH53639GA425732B', $apiContext); - $amount = new Amount(); - $amount->setCurrency("USD"); - $amount->setTotal("1.00");

Reauthorize with amount being reauthorized

$authorization->setAmount($amount); - $reauthorization = $authorization->reauthorize($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + $amount = new Amount(); + $amount->setCurrency("USD"); + $amount->setTotal("1.00");

Reauthorize with amount being reauthorized

$authorization->setAmount($amount); + + $reAuthorization = $authorization->reauthorize($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Reauthorize Payment", "Payment", null, null, $ex); + exit(1); } -?> -<html> -<head> - <title>Reauthorize a payment</title> -</head> -<body> - <div> - Reauthorization Id: - <?php echo $reauthorization->getId();?> - </div> - <pre> - <?php echo $reauthorization->toJSON(128);?> - </pre> - <a href='../index.html'>Back</a> -</body> -</html>
\ No newline at end of file + +ResultPrinter::printResult("Reauthorize Payment", "Payment", $authorization->getId(), null, $reAuthorization); \ No newline at end of file diff --git a/sample/doc/payments/RefundCapture.html b/sample/doc/payments/RefundCapture.html index 2daef75..b115eb5 100644 --- a/sample/doc/payments/RefundCapture.html +++ b/sample/doc/payments/RefundCapture.html @@ -1,52 +1,24 @@ payments/RefundCapture
payments/RefundCapture.php
<?php

Refund Capture Sample

This sample code demonstrates how you can process a refund on a Captured transaction. -API used: /v1/payments/capture/{}/refund

require __DIR__ . '/../bootstrap.php'; +API used: /v1/payments/capture/{}/refund

/** @var Capture $capture */ +$capture = require 'AuthorizationCapture.php'; use PayPal\Api\Authorization; use PayPal\Api\Capture; use PayPal\Api\Refund; -use PayPal\Api\Amount; -use PayPal\Rest\ApiContext; - - -try {

Create a mock authorization to get authorization Id

$authId = createAuthorization($apiContext);

Get the authorization

$authorization = Authorization::get($authId, $apiContext); - -

Capture

- $amt = new Amount(); - $amt->setCurrency("USD") - ->setTotal("1.00"); -

Create a capture

$captureInfo = new Capture(); - $captureInfo->setAmount($amt); - - $capture = $authorization->capture($captureInfo, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); -}

Refund

+use PayPal\Api\Amount;

Refund

Create a refund object indicating refund amount and call the refund method

$refund = new Refund(); $refund->setAmount($amt); try {

Create a new apiContext object so we send a new -PayPal-Request-Id (idempotency) header for this resource

$apiContext = getApiContext(); +PayPal-Request-Id (idempotency) header for this resource

$apiContext = getApiContext($clientId, $clientSecret); - $captureRefund = $capture->refund($refund, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + $captureRefund = $capture->refund($refund, $apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Refund Capture", "Capture", null, $refund, $ex); + exit(1); } -?> -<html> -<head> - <title>Refund a captured payment</title> -</head> -<body> - <div>Refund Capture:</div> - <pre><?php echo $captureRefund->toJSON(128);?></pre> - <a href='../index.html'>Back</a> -</body> -</html>
\ No newline at end of file +ResultPrinter::printResult("Refund Capture", "Capture", $captureRefund->getId(), $refund, $captureRefund); \ No newline at end of file diff --git a/sample/doc/payments/VoidAuthorization.html b/sample/doc/payments/VoidAuthorization.html index 57ac7dc..63d97c7 100644 --- a/sample/doc/payments/VoidAuthorization.html +++ b/sample/doc/payments/VoidAuthorization.html @@ -1,28 +1,18 @@ payments/VoidAuthorization
payments/VoidAuthorization.php
<?php

VoidAuthorization

This sample code demonstrates how you can void an authorized payment. -API used: /v1/payments/authorization/<{authorizationid}>/void"

require __DIR__ . '/../bootstrap.php'; +API used: /v1/payments/authorization/<{authorizationid}>/void"

/** @var Authorization $authorization */ +$authorization = require 'AuthorizePayment.php'; use PayPal\Api\Authorization;

VoidAuthorization

You can void a previously authorized payment by invoking the $authorization->void method -with a valid ApiContext (See bootstrap.php for more on ApiContext)

try {

create an authorization to get authorization Id -createAuthorization is defined in common.php

$authId = createAuthorization($apiContext);

Lookup the authorization

$authorization = Authorization::get($authId, $apiContext);

Void the authorization

$voidedAuth = $authorization->void($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); +with a valid ApiContext (See bootstrap.php for more on ApiContext)

try {

Lookup the authorization

$authorization = Authorization::get($authorization->getId(), $apiContext);

Void the authorization

$voidedAuth = $authorization->void($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Void Authorization", "Authorization", null, null, $ex); + exit(1); } -?> -<html> -<head> - <title>Void an authorization</title> -</head> -<body> - <div> - Voided authorization - </div> - <pre><?php echo $voidedAuth->toJSON(128);?></pre> - <a href='../index.html'>Back</a> -</body> -</html>
\ No newline at end of file + +ResultPrinter::printResult("Void Authorization", "Authorization", $voidedAuth->getId(), null, $voidedAuth); + +return $voidedAuth; \ No newline at end of file diff --git a/sample/doc/sale/GetSale.html b/sample/doc/sale/GetSale.html index 4192a3b..36a3de7 100644 --- a/sample/doc/sale/GetSale.html +++ b/sample/doc/sale/GetSale.html @@ -2,27 +2,23 @@

Sale transactions are nothing but completed payments. This sample code demonstrates how you can retrieve details of completed Sale Transaction. -API used: /v1/payments/sale/{sale-id}

require __DIR__ . '/../bootstrap.php'; +API used: /v1/payments/sale/{sale-id}

/** @var Payment $payment */ +$payment = require __DIR__ . '/../payments/CreatePayment.php'; use PayPal\Api\Sale; +use PayPal\Api\Payment;

Get Sale From Created Payment

+

You can retrieve the sale Id from Related Resources for each transactions.

$transactions = $payment->getTransactions(); +$relatedResources = $transactions[0]->getRelatedResources(); +$sale = $relatedResources[0]->getSale(); +$saleId = $sale->getId(); -$saleId = '3RM92092UW5126232'; - -try {

Retrieve the sale object

+try {

Retrieve the sale object

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

$sale = Sale::get($saleId, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception:" . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); +transaction from your payment resource.

$sale = Sale::get($saleId, $apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Look Up A Sale", "Sale", $sale->getId(), null, $ex); + exit(1); } -?> -<html> -<head> - <title>Lookup a sale</title> -</head> -<body> - <div>Retrieving sale id: <?php echo $saleId;?></div> - <pre><?php echo $sale->toJSON(128)?></pre> - <a href='../index.html'>Back</a> -</body> -</html>
\ No newline at end of file + +ResultPrinter::printResult("Look Up A Sale", "Sale", $sale->getId(), null, $sale); + +return $sale; \ No newline at end of file diff --git a/sample/doc/sale/RefundSale.html b/sample/doc/sale/RefundSale.html index 6d23d95..14fd6d7 100644 --- a/sample/doc/sale/RefundSale.html +++ b/sample/doc/sale/RefundSale.html @@ -2,7 +2,10 @@

This sample code demonstrate how you can process a refund on a sale transaction created using the Payments API. -API used: /v1/payments/sale/{sale-id}/refund

require __DIR__ . '/../bootstrap.php'; +API used: /v1/payments/sale/{sale-id}/refund

/** @var Sale $sale */ +$sale = require 'GetSale.php'; +$saleId = $sale->getId(); + use PayPal\Api\Amount; use PayPal\Api\Refund; use PayPal\Api\Sale;

Refund amount

@@ -10,29 +13,20 @@ API used: /v1/payments/sale/{sale-id}/refund

$amt = new Amount(); $amt->setCurrency('USD') - ->setTotal('0.01');

Refund object

$refund = new Refund(); -$refund->setAmount($amt); - -$saleId = '3RM92092UW5126232';

Sale

+ ->setTotal('0.01');

Refund object

$refund = new Refund(); +$refund->setAmount($amt);

Sale

A sale transaction. Create a Sale object with the given sale transaction id.

$sale = new Sale(); $sale->setId($saleId); -try {

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

$sale->refund($refund, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception:" . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); +try {

Create a new apiContext object so we send a new +PayPal-Request-Id (idempotency) header for this resource

$apiContext = getApiContext($clientId, $clientSecret);

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

$refundedSale = $sale->refund($refund, $apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Refund Sale", "Sale", $refundedSale->getId(), $refund, $ex); + exit(1); } -?> -<html> -<head> - <title>Refund a sale</title> -</head> -<body> - <div>Refunding sale id: <?php echo $saleId;?></div> - <pre><?php echo $sale->toJSON(128);?></pre> - <a href='../index.html'>Back</a> -</body> -</html>
\ No newline at end of file + +ResultPrinter::printResult("Refund Sale", "Sale", $refundedSale->getId(), $refund, $refundedSale); + +return $refundedSale; \ No newline at end of file diff --git a/sample/doc/vault/CreateCreditCard.html b/sample/doc/vault/CreateCreditCard.html index 3528ddf..a1f6f37 100644 --- a/sample/doc/vault/CreateCreditCard.html +++ b/sample/doc/vault/CreateCreditCard.html @@ -7,31 +7,23 @@ API used: POST /v1/vault/credit-card

A resource representing a credit card that is to be stored with PayPal.

$card = new CreditCard(); $card->setType("visa") - ->setNumber("4417119669820331") - ->setExpireMonth("11") - ->setExpireYear("2019") - ->setCvv2("012") - ->setFirstName("Joe") - ->setLastName("Shopper");

Save card

+ ->setNumber("4417119669820331") + ->setExpireMonth("11") + ->setExpireYear("2019") + ->setCvv2("012") + ->setFirstName("Joe") + ->setLastName("Shopper");

For Sample Purposes Only.

$request = clone $card;

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 future payments. (See bootstrap.php for more on ApiContext)

try { - $card->create($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception:" . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + $card->create($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Create Credit Card", "Credit Card", null, $request, $ex); + exit(1); } -?> -<html> -<head> - <title>Save a credit card</title> -</head> -<body> - <div>Saved a new credit card with id: <?php echo $card->getId();?></div> - <pre><?php echo $card->toJSON(128);?></pre> - <a href='../index.html'>Back</a> -</body> -</html>
\ No newline at end of file + +ResultPrinter::printResult("Create Credit Card", "Credit Card", $card->getId(), $request, $card); + +return $card; \ No newline at end of file diff --git a/sample/doc/vault/DeleteCreditCard.html b/sample/doc/vault/DeleteCreditCard.html index d5f0578..62b7dca 100644 --- a/sample/doc/vault/DeleteCreditCard.html +++ b/sample/doc/vault/DeleteCreditCard.html @@ -2,44 +2,18 @@

This sample code demonstrate how you can delete a saved credit card. API used: /v1/vault/credit-card/{} -NOTE: HTTP method used here is DELETE

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

Store a mock card that can be deleted later.

-

CreditCard

-

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

$card = new CreditCard(); -$card->setType("visa") - ->setNumber("4417119669820331") - ->setExpireMonth("11") - ->setExpireYear("2019") - ->setCvv2("012") - ->setFirstName("Joe") - ->setLastName("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 later. -(See bootstrap.php for more on ApiContext)

try { - $card = $card->create($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception:" . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); -} +NOTE: HTTP method used here is DELETE

/** @var CreditCard $card */ +$card = require 'CreateCreditCard.php'; +use PayPal\Api\CreditCard; try {

Delete Card

Lookup and delete a saved credit card. -(See bootstrap.php for more on ApiContext)

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

$creditCard = CreditCard::get($card->getId(), $apiContext); + + $creditCard->delete($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Delete Credit Card", "Credit Card", null, null, $ex); + exit(1); } -?> -<html> -<head> - <title>Delete a saved credit card</title> -</head> -<body> - <p> Credit Card deleted Successfully</p> - <a href='../index.html'>Back</a> -</body> -</html>
\ No newline at end of file + +ResultPrinter::printResult("Delete Credit Card", "Credit Card", $card->getId(), null, $creditCard); \ No newline at end of file diff --git a/sample/doc/vault/GetCreditCard.html b/sample/doc/vault/GetCreditCard.html index 1f09c1b..3777777 100644 --- a/sample/doc/vault/GetCreditCard.html +++ b/sample/doc/vault/GetCreditCard.html @@ -3,25 +3,18 @@ retrieve previously saved CreditCards. API called: '/v1/vault/credit-card' The following code takes you through -the process of retrieving a saved CreditCard

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

The cardId can be obtained from a previous save credit -card operation. Use $card->getId()

$cardId = "CARD-44D10970C24287906KRCTWNI"; +the process of retrieving a saved CreditCard

/** @var CreditCard $card */ +$card = require 'CreateCreditCard.php'; + +use PayPal\Api\CreditCard; /// ### Retrieve card

(See bootstrap.php for more on ApiContext)

try { - $card = CreditCard::get($cardId, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + $card = CreditCard::get($card->getId(), $apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Get Credit Card", "Credit Card", $card->getId(), null, $ex); + exit(1); } -?> -<html> -<head> - <title>Lookup a saved credit card</title> -</head> -<body> - <div>Retrieving saved credit card: <?php echo $cardId;?></div> - <pre><?php echo $card->toJSON(128);?></pre> - <a href='../index.html'>Back</a> -</body> -</html>
\ No newline at end of file + +ResultPrinter::printResult("Get Credit Card", "Credit Card", $card->getId(), null, $card); + +return $card; \ No newline at end of file diff --git a/sample/header.html b/sample/header.html index 7e8996a..80c0c49 100644 --- a/sample/header.html +++ b/sample/header.html @@ -22,6 +22,19 @@ overflow-y: auto; overflow-wrap: normal; } + pre.error { + border-color: red; + color: red; + overflow-y: visible; + overflow-wrap: break-word; + } + .panel-default>.panel-heading.error { + background-color: red; + color: white; + } + h1.error, h2.error, h3.error, h4.error, h5.error { + color: red; + } .panel-default>.panel-heading { color: #FFF; background-color: #428bca; diff --git a/sample/index.html b/sample/index.html index 24ea67e..bcf17be 100644 --- a/sample/index.html +++ b/sample/index.html @@ -115,7 +115,7 @@
  • -
    Get sale details
    +
    Get Sale details
    Execute Source @@ -124,7 +124,7 @@
  • -
    Refund a payment
    +
    Refund a Sale
    Execute Source @@ -275,6 +275,15 @@
      +
    • +
      +
      Authorize Payment
      + +
      +
    • Get details of an authorized payment
      @@ -293,6 +302,15 @@
  • +
  • +
    +
    Get details of a captured payment
    + +
    +
  • Void an authorized payment
    @@ -311,15 +329,6 @@
  • -
  • -
    -
    Get details of a captured payment
    - -
    -
  • Refund captured payment
    diff --git a/sample/invoice/CancelInvoice.php b/sample/invoice/CancelInvoice.php index eb6ff79..9d5104c 100644 --- a/sample/invoice/CancelInvoice.php +++ b/sample/invoice/CancelInvoice.php @@ -37,9 +37,8 @@ try { // notification object // (See bootstrap.php for more on `ApiContext`) $cancelStatus = $invoice->cancel($notify, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Cancel Invoice", "Invoice", null, $notify, $ex); exit(1); } diff --git a/sample/invoice/CreateInvoice.php b/sample/invoice/CreateInvoice.php index 69c2592..38a4745 100644 --- a/sample/invoice/CreateInvoice.php +++ b/sample/invoice/CreateInvoice.php @@ -101,9 +101,8 @@ try { // Create an invoice by calling the invoice->create() method // with a valid ApiContext (See bootstrap.php for more on `ApiContext`) $invoice->create($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Invoice Creation", "Invoice", null, $request, $ex); exit(1); } diff --git a/sample/invoice/GetInvoice.php b/sample/invoice/GetInvoice.php index 9a7690d..4d7aa44 100644 --- a/sample/invoice/GetInvoice.php +++ b/sample/invoice/GetInvoice.php @@ -17,9 +17,8 @@ $invoiceId = "INV2-W4LC-6QS9-JZ62-VE4P"; // (See bootstrap.php for more on `ApiContext`) try { $invoice = Invoice::get($invoiceId, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception:" . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Get Invoice", "Invoice", $invoice->getId(), $invoiceId, $ex); exit(1); } diff --git a/sample/invoice/ListInvoice.php b/sample/invoice/ListInvoice.php index 0e52c2f..1d22331 100644 --- a/sample/invoice/ListInvoice.php +++ b/sample/invoice/ListInvoice.php @@ -14,9 +14,8 @@ try { // Refer the method doc for valid values for keys // (See bootstrap.php for more on `ApiContext`) $invoices = Invoice::get_all($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception:" . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Lookup Invoice History", "Invoice", null, null, $ex); exit(1); } ResultPrinter::printResult("Lookup Invoice History", "Invoice", null, null, $invoices); diff --git a/sample/invoice/RemindInvoice.php b/sample/invoice/RemindInvoice.php index 34a36a3..7952af1 100644 --- a/sample/invoice/RemindInvoice.php +++ b/sample/invoice/RemindInvoice.php @@ -35,9 +35,8 @@ try { // notification object // (See bootstrap.php for more on `ApiContext`) $remindStatus = $invoice->remind($notify, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Remind Invoice", "Invoice", null, $notify, $ex); exit(1); } diff --git a/sample/invoice/SendInvoice.php b/sample/invoice/SendInvoice.php index 17db216..16b1cb0 100644 --- a/sample/invoice/SendInvoice.php +++ b/sample/invoice/SendInvoice.php @@ -21,9 +21,8 @@ try { // Send a legitimate invoice to the payer // with a valid ApiContext (See bootstrap.php for more on `ApiContext`) $sendStatus = $invoice->send($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printResult("Send Invoice", "Invoice", null, null, $ex); exit(1); } diff --git a/sample/lipp/GenerateAccessTokenFromRefreshToken.php b/sample/lipp/GenerateAccessTokenFromRefreshToken.php index 44e7b17..711df11 100644 --- a/sample/lipp/GenerateAccessTokenFromRefreshToken.php +++ b/sample/lipp/GenerateAccessTokenFromRefreshToken.php @@ -13,9 +13,8 @@ try { $tokenInfo = new PPOpenIdTokeninfo(); $tokenInfo = $tokenInfo->createFromRefreshToken(array('refresh_token' => $refreshToken), $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Obtained Access Token From Refresh Token", "Access Token", null, null, $ex); exit(1); } diff --git a/sample/lipp/GetUserInfo.php b/sample/lipp/GetUserInfo.php index f79a450..4c98355 100644 --- a/sample/lipp/GetUserInfo.php +++ b/sample/lipp/GetUserInfo.php @@ -28,9 +28,8 @@ try { $params = array('access_token' => $tokenInfo->getAccessToken()); $userInfo = PPOpenIdUserinfo::getUserinfo($params, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("User Information", "User Info", null, $params, $ex); exit(1); } diff --git a/sample/lipp/UserConsentRedirect.php b/sample/lipp/UserConsentRedirect.php index 62e0880..8ff487f 100644 --- a/sample/lipp/UserConsentRedirect.php +++ b/sample/lipp/UserConsentRedirect.php @@ -18,9 +18,8 @@ if (isset($_GET['success']) && $_GET['success'] == 'true') { // Obtain Authorization Code from Code, Client ID and Client Secret $accessToken = PPOpenIdTokeninfo::createFromAuthorizationCode(array('code' => $code), null, null, $apiContext); } catch (PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + ResultPrinter::printError("Obtained Access Token", "Access Token", null, $_GET['code'], $ex); + exit(1); } ResultPrinter::printResult("Obtained Access Token", "Access Token", $accessToken->getAccessToken(), $_GET['code'], $accessToken); diff --git a/sample/payment-experience/CreateWebProfile.php b/sample/payment-experience/CreateWebProfile.php index 07cba83..c2c769b 100644 --- a/sample/payment-experience/CreateWebProfile.php +++ b/sample/payment-experience/CreateWebProfile.php @@ -41,7 +41,9 @@ $webProfile->setName("YeowZa! T-Shirt Shop" . uniqid()) // Parameters for flow configuration. ->setFlowConfig($flowConfig) // Parameters for style and presentation. - ->setPresentation($presentation); + ->setPresentation($presentation) + // Parameters for input field customization. + ->setInputFields($inputFields); // For Sample Purposes Only. $request = clone $webProfile; @@ -49,12 +51,8 @@ $request = clone $webProfile; try { // Use this call to create a profile. $createProfileResponse = $webProfile->create($apiContext); -} catch (\Exception $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - if (is_a($ex, '\PayPal\Exception\PPConnectionException')) { - /** @var $ex \PayPal\Exception\PPConnectionException */ - var_dump($ex->getData()); - } +} catch (\PayPal\Exception\PPConnectionException $ex) { + ResultPrinter::printError("Created Web Profile", "Web Profile", null, $request, $ex); exit(1); } diff --git a/sample/payment-experience/DeleteWebProfile.php b/sample/payment-experience/DeleteWebProfile.php index 847bcc2..f1a3753 100644 --- a/sample/payment-experience/DeleteWebProfile.php +++ b/sample/payment-experience/DeleteWebProfile.php @@ -18,12 +18,8 @@ $webProfile->setId($createProfileResponse->getId()); try { // Execute the delete method $webProfile->delete($apiContext); -} catch (\Exception $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - if (is_a($ex, '\PayPal\Exception\PPConnectionException')) { - /** @var $ex \PayPal\Exception\PPConnectionException */ - var_dump($ex->getData()); - } +} catch (\PayPal\Exception\PPConnectionException $ex) { + ResultPrinter::printError("Deleted Web Profile", "Web Profile", $createProfileResponse->getId(), null, $ex); exit(1); } diff --git a/sample/payment-experience/GetWebProfile.php b/sample/payment-experience/GetWebProfile.php index 77bcda8..23e9f07 100644 --- a/sample/payment-experience/GetWebProfile.php +++ b/sample/payment-experience/GetWebProfile.php @@ -14,12 +14,8 @@ $createProfileResponse = require 'CreateWebProfile.php'; try { // If your request is successful, the API returns a web_profile object response that contains the profile details. $webProfile = \PayPal\Api\WebProfile::get($createProfileResponse->getId(), $apiContext); -} catch (\Exception $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - if (is_a($ex, '\PayPal\Exception\PPConnectionException')) { - /** @var $ex \PayPal\Exception\PPConnectionException */ - var_dump($ex->getData()); - } +} catch (\PayPal\Exception\PPConnectionException $ex) { + ResultPrinter::printError("Get Web Profile", "Web Profile", $webProfile->getId(), null, $ex); exit(1); } diff --git a/sample/payment-experience/ListWebProfiles.php b/sample/payment-experience/ListWebProfiles.php index 1a190a6..eaaa96e 100644 --- a/sample/payment-experience/ListWebProfiles.php +++ b/sample/payment-experience/ListWebProfiles.php @@ -10,12 +10,8 @@ $apiContext = require __DIR__ . '/../bootstrap.php'; // (See bootstrap.php for more on `ApiContext`) try { $list = \PayPal\Api\WebProfile::get_list($apiContext); -} catch (\Exception $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - if (is_a($ex, '\PayPal\Exception\PPConnectionException')) { - /** @var $ex \PayPal\Exception\PPConnectionException */ - var_dump($ex->getData()); - } +} catch (\PayPal\Exception\PPConnectionException $ex) { + ResultPrinter::printError("Get List of All Web Profiles", "Web Profiles", null, null, $ex); exit(1); } $result = ''; diff --git a/sample/payment-experience/PartiallyUpdateWebProfile.php b/sample/payment-experience/PartiallyUpdateWebProfile.php index 1f97c0c..88f4f4b 100644 --- a/sample/payment-experience/PartiallyUpdateWebProfile.php +++ b/sample/payment-experience/PartiallyUpdateWebProfile.php @@ -37,11 +37,7 @@ try { $webProfile = \PayPal\Api\WebProfile::get($webProfile->getId(), $apiContext); } } catch (\Exception $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - if (is_a($ex, '\PayPal\Exception\PPConnectionException')) { - /** @var $ex \PayPal\Exception\PPConnectionException */ - var_dump($ex->getData()); - } + ResultPrinter::printError("Partially Updated Web Profile", "Web Profile", $webProfile->getId(), $patches, $ex); exit(1); } diff --git a/sample/payment-experience/UpdateWebProfile.php b/sample/payment-experience/UpdateWebProfile.php index 12ad366..22b9de8 100644 --- a/sample/payment-experience/UpdateWebProfile.php +++ b/sample/payment-experience/UpdateWebProfile.php @@ -21,11 +21,7 @@ try { $updatedWebProfile = \PayPal\Api\WebProfile::get($webProfile->getId(), $apiContext); } } catch (\Exception $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - if (is_a($ex, '\PayPal\Exception\PPConnectionException')) { - /** @var $ex \PayPal\Exception\PPConnectionException */ - var_dump($ex->getData()); - } + ResultPrinter::printError("Updated Web Profile", "Web Profile", $webProfile->getId(), $webProfile, $ex); exit(1); } diff --git a/sample/payments/AuthorizationCapture.php b/sample/payments/AuthorizationCapture.php index b1e3db2..ca48cd1 100644 --- a/sample/payments/AuthorizationCapture.php +++ b/sample/payments/AuthorizationCapture.php @@ -3,8 +3,10 @@ // This sample code demonstrates how you can capture // a previously authorized payment. // API used: /v1/payments/payment +// https://developer.paypal.com/webapps/developer/docs/api/#capture-an-authorization -require __DIR__ . '/../bootstrap.php'; +/** @var Authorization $authorization */ +$authorization = require 'GetAuthorization.php'; use PayPal\Api\Amount; use PayPal\Api\Capture; use PayPal\Api\Authorization; @@ -15,40 +17,23 @@ use PayPal\Api\Authorization; // by invoking the $authorization->capture method // with a valid ApiContext (See bootstrap.php for more on `ApiContext`) try { - // Create a new authorization to get authorization Id - // createAuthorization defined in common.php - $authId = createAuthorization($apiContext); + $authId = $authorization->getId(); - $amt = new Amount(); - $amt->setCurrency("USD") - ->setTotal("1.00"); + $amt = new Amount(); + $amt->setCurrency("USD") + ->setTotal("1.00"); - ### Capture - $capture = new Capture(); - $capture->setId($authId) - ->setAmount($amt); + ### Capture + $capture = new Capture(); + $capture->setAmount($amt); - // Lookup the authorization. - $authorization = Authorization::get($authId, $apiContext); - - // Perform a capture - $getCapture = $authorization->capture($capture, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + // Perform a capture + $getCapture = $authorization->capture($capture, $apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Capture Payment", "Authorization", null, $capture, $ex); + exit(1); } -?> - - - Capturing an authorization - - -
    - Captured payment getParentPayment(); ?>. Capture Id: - getId();?> -
    -
    toJSON(128);?>
    - Back - - + +ResultPrinter::printResult("Capture Payment", "Authorization", $getCapture->getId(), $capture, $getCapture); + +return $getCapture; diff --git a/sample/payments/AuthorizePayment.php b/sample/payments/AuthorizePayment.php new file mode 100644 index 0000000..3f98cf3 --- /dev/null +++ b/sample/payments/AuthorizePayment.php @@ -0,0 +1,81 @@ +setLine1("3909 Witmer Road") + ->setLine2("Niagara Falls") + ->setCity("Niagara Falls") + ->setState("NY") + ->setPostalCode("14305") + ->setCountryCode("US") + ->setPhone("716-298-1822"); + +$card = new CreditCard(); +$card->setType("visa") + ->setNumber("4417119669820331") + ->setExpireMonth("11") + ->setExpireYear("2019") + ->setCvv2("012") + ->setFirstName("Joe") + ->setLastName("Shopper") + ->setBillingAddress($addr); + +$fi = new FundingInstrument(); +$fi->setCreditCard($card); + +$payer = new Payer(); +$payer->setPaymentMethod("credit_card") + ->setFundingInstruments(array($fi)); + +$amount = new Amount(); +$amount->setCurrency("USD") + ->setTotal("1.00"); + +$transaction = new Transaction(); +$transaction->setAmount($amount) + ->setDescription("Payment description."); + +$payment = new Payment(); + +// Setting intent to authorize creates a payment +// authorization. Setting it to sale creates actual payment +$payment->setIntent("authorize") + ->setPayer($payer) + ->setTransactions(array($transaction)); + +// For Sample Purposes Only. +$request = clone $payment; + +// ### Create Payment +// Create a payment by calling the payment->create() method +// with a valid ApiContext (See bootstrap.php for more on `ApiContext`) +// The return object contains the state. +try { + $payment->create($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError('Authorize a Payment', 'Authorized Payment', $payment->getId(), $request, $ex); + exit(1); +} + +ResultPrinter::printResult('Authorize a Payment', 'Authorized Payment', $payment->getId(), $request, $payment); + +$transactions = $payment->getTransactions(); +$relatedResources = $transactions[0]->getRelatedResources(); +$authorization = $relatedResources[0]->getAuthorization(); + +return $authorization; diff --git a/sample/payments/CreateFuturePayment.php b/sample/payments/CreateFuturePayment.php index c3bfbfd..206e281 100644 --- a/sample/payments/CreateFuturePayment.php +++ b/sample/payments/CreateFuturePayment.php @@ -70,6 +70,9 @@ try { // Update the access token in apiContext $payment->updateAccessToken($refreshToken, $apiContext); + // For Sample Purposes Only. + $request = clone $payment; + // ### Create Future Payment // Create a payment by calling the 'create' method // passing it a valid apiContext. @@ -80,23 +83,11 @@ try { // Please note that currently future payments works only with PayPal as a funding instrument. $payment->create($apiContext, $correlationId); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError("Future Payment", "Payment", null, $request, $ex); exit(1); } -?> - - - Future payments - - -
    - Created payment: - getId();?> -
    -
    toJSON(128);?>
    -Back - - +ResultPrinter::printResult("Future Payment", "Payment", $payment->getId(), $request, $payment); + +return $payment; diff --git a/sample/payments/CreatePayment.php b/sample/payments/CreatePayment.php index 2df81ad..b4bd46f 100644 --- a/sample/payments/CreatePayment.php +++ b/sample/payments/CreatePayment.php @@ -92,7 +92,8 @@ $amount->setCurrency("USD") $transaction = new Transaction(); $transaction->setAmount($amount) ->setItemList($itemList) - ->setDescription("Payment description"); + ->setDescription("Payment description") + ->setInvoiceNumber(uniqid()); // ### Payment // A Payment Resource; create one using @@ -102,28 +103,20 @@ $payment->setIntent("sale") ->setPayer($payer) ->setTransactions(array($transaction)); +// For Sample Purposes Only. +$request = clone $payment; + // ### Create Payment // Create a payment by calling the payment->create() method // with a valid ApiContext (See bootstrap.php for more on `ApiContext`) // The return object contains the state. try { $payment->create($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); +} catch (Exception $ex) { + ResultPrinter::printError('Create Payment Using Credit Card', 'Payment', null, $request, $ex); exit(1); } -?> - - - Direct Credit card payments - - -
    - Created payment: - getId();?> -
    -
    toJSON(128);?>
    - Back - - + +ResultPrinter::printResult('Create Payment Using Credit Card', 'Payment', $payment->getId(), $request, $payment); + +return $payment; diff --git a/sample/payments/CreatePaymentUsingPayPal.php b/sample/payments/CreatePaymentUsingPayPal.php index 7c0c794..0e28f8c 100644 --- a/sample/payments/CreatePaymentUsingPayPal.php +++ b/sample/payments/CreatePaymentUsingPayPal.php @@ -27,14 +27,14 @@ $payer->setPaymentMethod("paypal"); // information $item1 = new Item(); $item1->setName('Ground Coffee 40 oz') - ->setCurrency('USD') - ->setQuantity(1) - ->setPrice('7.50'); + ->setCurrency('USD') + ->setQuantity(1) + ->setPrice('7.50'); $item2 = new Item(); $item2->setName('Granola bars') - ->setCurrency('USD') - ->setQuantity(5) - ->setPrice('2.00'); + ->setCurrency('USD') + ->setQuantity(5) + ->setPrice('2.00'); $itemList = new ItemList(); $itemList->setItems(array($item1, $item2)); @@ -45,8 +45,8 @@ $itemList->setItems(array($item1, $item2)); // charges etc. $details = new Details(); $details->setShipping('1.20') - ->setTax('1.30') - ->setSubtotal('17.50'); + ->setTax('1.30') + ->setSubtotal('17.50'); // ### Amount // Lets you specify a payment amount. @@ -54,8 +54,8 @@ $details->setShipping('1.20') // such as shipping, tax. $amount = new Amount(); $amount->setCurrency("USD") - ->setTotal("20.00") - ->setDetails($details); + ->setTotal("20.00") + ->setDetails($details); // ### Transaction // A transaction defines the contract of a @@ -63,8 +63,9 @@ $amount->setCurrency("USD") // is fulfilling it. $transaction = new Transaction(); $transaction->setAmount($amount) - ->setItemList($itemList) - ->setDescription("Payment description"); + ->setItemList($itemList) + ->setDescription("Payment description") + ->setInvoiceNumber(uniqid()); // ### Redirect urls // Set the urls that the buyer must be redirected to after @@ -72,16 +73,20 @@ $transaction->setAmount($amount) $baseUrl = getBaseUrl(); $redirectUrls = new RedirectUrls(); $redirectUrls->setReturnUrl("$baseUrl/ExecutePayment.php?success=true") - ->setCancelUrl("$baseUrl/ExecutePayment.php?success=false"); + ->setCancelUrl("$baseUrl/ExecutePayment.php?success=false"); // ### Payment // A Payment Resource; create one using // the above types and intent set to 'sale' $payment = new Payment(); $payment->setIntent("sale") - ->setPayer($payer) - ->setRedirectUrls($redirectUrls) - ->setTransactions(array($transaction)); + ->setPayer($payer) + ->setRedirectUrls($redirectUrls) + ->setTransactions(array($transaction)); + + +// For Sample Purposes Only. +$request = clone $payment; // ### Create Payment // Create a payment by calling the 'create' method @@ -91,26 +96,23 @@ $payment->setIntent("sale") // url to which the buyer must be redirected to // for payment approval try { - $payment->create($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + $payment->create($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex); + exit(1); } // ### Get redirect url // The API response provides the url that you must redirect // the buyer to. Retrieve the url from the $payment->getLinks() // method -foreach($payment->getLinks() as $link) { - if($link->getRel() == 'approval_url') { - $redirectUrl = $link->getHref(); - break; - } +foreach ($payment->getLinks() as $link) { + if ($link->getRel() == 'approval_url') { + $approvalUrl = $link->getHref(); + break; + } } -// ### Redirect buyer to PayPal website -if(isset($redirectUrl)) { - header("Location: $redirectUrl"); - exit; -} +ResultPrinter::printResult("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", "$approvalUrl", $request, $payment); + +return $payment; diff --git a/sample/payments/CreatePaymentUsingSavedCard.php b/sample/payments/CreatePaymentUsingSavedCard.php index 556230d..d66f6f1 100644 --- a/sample/payments/CreatePaymentUsingSavedCard.php +++ b/sample/payments/CreatePaymentUsingSavedCard.php @@ -5,7 +5,8 @@ // Payment using a previously stored credit card token. // API used: /v1/payments/payment -require __DIR__ . '/../bootstrap.php'; +/** @var CreditCard $card */ +$card = require __DIR__ . '/../vault/CreateCreditCard.php'; use PayPal\Api\Amount; use PayPal\Api\Details; use PayPal\Api\Item; @@ -15,12 +16,13 @@ use PayPal\Api\Payer; use PayPal\Api\Payment; use PayPal\Api\FundingInstrument; use PayPal\Api\Transaction; +use PayPal\Api\CreditCard; // ### Credit card token // Saved credit card id from a previous call to // CreateCreditCard.php $creditCardToken = new CreditCardToken(); -$creditCardToken->setCreditCardId('CARD-17M96700G1952584EKRCTV5Y'); +$creditCardToken->setCreditCardId($card->getId()); // ### FundingInstrument // A resource representing a Payer's funding instrument. @@ -35,21 +37,21 @@ $fi->setCreditCardToken($creditCardToken); // to 'credit_card'. $payer = new Payer(); $payer->setPaymentMethod("credit_card") - ->setFundingInstruments(array($fi)); + ->setFundingInstruments(array($fi)); // ### Itemized information // (Optional) Lets you specify item wise // information $item1 = new Item(); $item1->setName('Ground Coffee 40 oz') - ->setCurrency('USD') - ->setQuantity(1) - ->setPrice('7.50'); + ->setCurrency('USD') + ->setQuantity(1) + ->setPrice('7.50'); $item2 = new Item(); $item2->setName('Granola bars') - ->setCurrency('USD') - ->setQuantity(5) - ->setPrice('2.00'); + ->setCurrency('USD') + ->setQuantity(5) + ->setPrice('2.00'); $itemList = new ItemList(); $itemList->setItems(array($item1, $item2)); @@ -60,8 +62,8 @@ $itemList->setItems(array($item1, $item2)); // charges etc. $details = new Details(); $details->setShipping('1.20') - ->setTax('1.30') - ->setSubtotal('17.50'); + ->setTax('1.30') + ->setSubtotal('17.50'); // ### Amount // Lets you specify a payment amount. @@ -69,8 +71,8 @@ $details->setShipping('1.20') // such as shipping, tax. $amount = new Amount(); $amount->setCurrency("USD") - ->setTotal("20.00") - ->setDetails($details); + ->setTotal("20.00") + ->setDetails($details); // ### Transaction // A transaction defines the contract of a @@ -78,16 +80,21 @@ $amount->setCurrency("USD") // is fulfilling it. $transaction = new Transaction(); $transaction->setAmount($amount) - ->setItemList($itemList) - ->setDescription("Payment description"); + ->setItemList($itemList) + ->setDescription("Payment description") + ->setInvoiceNumber(uniqid()); // ### Payment // A Payment Resource; create one using // the above types and intent set to 'sale' $payment = new Payment(); $payment->setIntent("sale") - ->setPayer($payer) - ->setTransactions(array($transaction)); + ->setPayer($payer) + ->setTransactions(array($transaction)); + + +// For Sample Purposes Only. +$request = clone $payment; // ###Create Payment // Create a payment by calling the 'create' method @@ -95,23 +102,12 @@ $payment->setIntent("sale") // (See bootstrap.php for more on `ApiContext`) // The return object contains the state. try { - $payment->create($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + $payment->create($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Create Payment using Saved Card", "Payment", null, $request, $ex); + exit(1); } -?> - - - Saved Credit card payments - - -
    - Created payment: - getId();?> -
    -
    toJSON(128);?>
    - Back - - + +ResultPrinter::printResult("Create Payment using Saved Card", "Payment", $payment->getId(), $request, $payment); + +return $card; diff --git a/sample/payments/ExecutePayment.php b/sample/payments/ExecutePayment.php index 031dadb..67080a1 100644 --- a/sample/payments/ExecutePayment.php +++ b/sample/payments/ExecutePayment.php @@ -31,12 +31,8 @@ if (isset($_GET['success']) && $_GET['success'] == 'true') { // (See bootstrap.php for more on `ApiContext`) $result = $payment->execute($execution, $apiContext); - echo "
    ";
    -    echo $result->toJSON(128);
    -    echo "
    Back"; + ResultPrinter::printResult("Executed Payment", "Payment", $payment->getId(), $execution, $result); } else { - echo "

    "; - echo "User cancelled payment."; - echo "

    Back"; + ResultPrinter::printResult("User Cancelled the Approval", null); } diff --git a/sample/payments/GetAuthorization.php b/sample/payments/GetAuthorization.php index bf5c9cf..e2ee117 100644 --- a/sample/payments/GetAuthorization.php +++ b/sample/payments/GetAuthorization.php @@ -4,10 +4,11 @@ // of an authorized payment. // API used: /v1/payments/authorization/<$authorizationId> -require __DIR__ . '/../bootstrap.php'; +/** @var Authorization $authorization */ +$authorization = require 'AuthorizePayment.php'; use PayPal\Api\Authorization; - +use PayPal\Api\Payment; // ### GetAuthorization // You can retrieve info about an Authorization @@ -16,28 +17,13 @@ use PayPal\Api\Authorization; // The return object contains the authorization state. try { - // create a authorization to get authorization Id - // createAuthorization is defined in common.php - $authId = createAuthorization($apiContext); - - // Retrieve the authorization - $authorization = Authorization::get($authId, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + // Retrieve the authorization + $result = Authorization::get($authorization->getId(), $apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Get Authorization", "Authorization", null, null, $ex); + exit(1); } -?> - - - Lookup an authorization - - -
    - Retrieved Authorization: - getId();?> -
    -
    toJSON(128);?>
    - Back - - + +ResultPrinter::printResult("Get Authorization", "Authorization", $authorization->getId(), null, $result); + +return $authorization; diff --git a/sample/payments/GetCapture.php b/sample/payments/GetCapture.php index ed1c9c4..c62f555 100644 --- a/sample/payments/GetCapture.php +++ b/sample/payments/GetCapture.php @@ -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); } -?> - - - Lookup a capture - - -
    - Capture Id: - getId();?> -
    -
    toJSON(128);?>
    - Back - - + +ResultPrinter::printResult("Get Captured Payment", "Capture", $capture->getId(), null, $capture); diff --git a/sample/payments/GetPayment.php b/sample/payments/GetPayment.php index abea03c..67e19d8 100644 --- a/sample/payments/GetPayment.php +++ b/sample/payments/GetPayment.php @@ -8,10 +8,11 @@ // payments list. // API used: GET /v1/payments/payments -require __DIR__ . '/../bootstrap.php'; +/** @var Payment $createdPayment */ +$createdPayment = require 'CreatePayment.php'; use PayPal\Api\Payment; -$paymentId = "PAY-2AH507590P6615624KRCTUSY"; +$paymentId = $createdPayment->getId(); // ### Retrieve payment // Retrieve the payment object by calling the @@ -20,20 +21,12 @@ $paymentId = "PAY-2AH507590P6615624KRCTUSY"; // Payment ID // (See bootstrap.php for more on `ApiContext`) try { - $payment = Payment::get($paymentId, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception:" . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + $payment = Payment::get($paymentId, $apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Get Payment", "Payment", null, null, $ex); + exit(1); } -?> - - - Lookup a payment - - -
    Retrieving Payment ID:
    -
    toJSON(128);?>
    - Back - - + +ResultPrinter::printResult("Get Payment", "Payment", $payment->getId(), null, $payment); + +return $payment; diff --git a/sample/payments/ListPayments.php b/sample/payments/ListPayments.php index 6bcde85..94f9cc8 100644 --- a/sample/payments/ListPayments.php +++ b/sample/payments/ListPayments.php @@ -9,7 +9,7 @@ // payments list. // API used: GET /v1/payments/payments -require __DIR__ . '/../bootstrap.php'; +require 'CreatePayment.php'; use PayPal\Api\Payment; @@ -21,20 +21,13 @@ use PayPal\Api\Payment; // 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 (PayPal\Exception\PPConnectionException $ex) { - echo "Exception:" . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + + $params = array('count' => 10, 'start_index' => 5); + + $payments = Payment::all($params, $apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("List Payments", "Payment", null, $params, $ex); + exit(1); } -?> - - - Lookup payment history - - -
    Got getCount(); ?> matching payments
    -
    toJSON(128);?>
    - Back - - + +ResultPrinter::printResult("List Payments", "Payment", null, $params, $payments); diff --git a/sample/payments/Reauthorization.php b/sample/payments/Reauthorization.php index a0318dc..a6b6982 100644 --- a/sample/payments/Reauthorization.php +++ b/sample/payments/Reauthorization.php @@ -3,8 +3,8 @@ // This sample code demonstrates how you can reauthorize a PayPal // account payment. // API used: v1/payments/authorization/{authorization_id}/reauthorize - -require __DIR__ . '/../bootstrap.php'; +/** @var Authorization $authorization */ +$authorization = require 'AuthorizePayment.php'; use PayPal\Api\Authorization; use PayPal\Api\Amount; @@ -17,35 +17,18 @@ use PayPal\Api\Amount; // has expired. try { - - // ### Lookup authorization using the authorization id - $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"); - // ### Reauthorize with amount being reauthorized - $authorization->setAmount($amount); - $reauthorization = $authorization->reauthorize($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + // ### Reauthorize with amount being reauthorized + $authorization->setAmount($amount); + + $reAuthorization = $authorization->reauthorize($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Reauthorize Payment", "Payment", null, null, $ex); + exit(1); } -?> - - - Reauthorize a payment - - -
    - Reauthorization Id: - getId();?> -
    -
    -		toJSON(128);?>
    -	
    - Back - - + +ResultPrinter::printResult("Reauthorize Payment", "Payment", $authorization->getId(), null, $reAuthorization); diff --git a/sample/payments/RefundCapture.php b/sample/payments/RefundCapture.php index 8dfe4cd..10a8fc9 100644 --- a/sample/payments/RefundCapture.php +++ b/sample/payments/RefundCapture.php @@ -3,40 +3,13 @@ // This sample code demonstrates how you can // process a refund on a Captured transaction. // API used: /v1/payments/capture/{}/refund - -require __DIR__ . '/../bootstrap.php'; +/** @var Capture $capture */ +$capture = require 'AuthorizationCapture.php'; use PayPal\Api\Authorization; use PayPal\Api\Capture; use PayPal\Api\Refund; use PayPal\Api\Amount; -use PayPal\Rest\ApiContext; - - -try { - // Create a mock authorization to get authorization Id - $authId = createAuthorization($apiContext); - - // Get the authorization - $authorization = Authorization::get($authId, $apiContext); - - - // ### Capture - - $amt = new Amount(); - $amt->setCurrency("USD") - ->setTotal("1.00"); - - // Create a capture - $captureInfo = new Capture(); - $captureInfo->setAmount($amt); - - $capture = $authorization->capture($captureInfo, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); -} // ### Refund // Create a refund object indicating @@ -46,25 +19,14 @@ $refund = new Refund(); $refund->setAmount($amt); try { - // Create a new apiContext object so we send a new - // PayPal-Request-Id (idempotency) header for this resource - $apiContext = getApiContext(); + // Create a new apiContext object so we send a new + // PayPal-Request-Id (idempotency) header for this resource + $apiContext = getApiContext($clientId, $clientSecret); - $captureRefund = $capture->refund($refund, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + $captureRefund = $capture->refund($refund, $apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Refund Capture", "Capture", null, $refund, $ex); + exit(1); } -?> - - - Refund a captured payment - - -
    Refund Capture:
    -
    toJSON(128);?>
    - Back - - +ResultPrinter::printResult("Refund Capture", "Capture", $captureRefund->getId(), $refund, $captureRefund); diff --git a/sample/payments/VoidAuthorization.php b/sample/payments/VoidAuthorization.php index 563bf22..04690e9 100644 --- a/sample/payments/VoidAuthorization.php +++ b/sample/payments/VoidAuthorization.php @@ -4,7 +4,8 @@ // void an authorized payment. // API used: /v1/payments/authorization/<{authorizationid}>/void" -require __DIR__ . '/../bootstrap.php'; +/** @var Authorization $authorization */ +$authorization = require 'AuthorizePayment.php'; use PayPal\Api\Authorization; @@ -14,30 +15,17 @@ use PayPal\Api\Authorization; // by invoking the $authorization->void method // with a valid ApiContext (See bootstrap.php for more on `ApiContext`) try { - // create an authorization to get authorization Id - // createAuthorization is defined in common.php - $authId = createAuthorization($apiContext); - // Lookup the authorization - $authorization = Authorization::get($authId, $apiContext); + // Lookup the authorization + $authorization = Authorization::get($authorization->getId(), $apiContext); - // Void the authorization - $voidedAuth = $authorization->void($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + // Void the authorization + $voidedAuth = $authorization->void($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Void Authorization", "Authorization", null, null, $ex); + exit(1); } -?> - - - Void an authorization - - -
    - Voided authorization -
    -
    toJSON(128);?>
    - Back - - + +ResultPrinter::printResult("Void Authorization", "Authorization", $voidedAuth->getId(), null, $voidedAuth); + +return $voidedAuth; diff --git a/sample/sale/GetSale.php b/sample/sale/GetSale.php index 4e0d4d6..ad00990 100644 --- a/sample/sale/GetSale.php +++ b/sample/sale/GetSale.php @@ -6,29 +6,28 @@ // details of completed Sale Transaction. // API used: /v1/payments/sale/{sale-id} -require __DIR__ . '/../bootstrap.php'; +/** @var Payment $payment */ +$payment = require __DIR__ . '/../payments/CreatePayment.php'; use PayPal\Api\Sale; +use PayPal\Api\Payment; -$saleId = '3RM92092UW5126232'; +// ### Get Sale From Created Payment +// You can retrieve the sale Id from Related Resources for each transactions. +$transactions = $payment->getTransactions(); +$relatedResources = $transactions[0]->getRelatedResources(); +$sale = $relatedResources[0]->getSale(); +$saleId = $sale->getId(); -try { - // ### Retrieve the sale object - // Pass the ID of the sale - // transaction from your payment resource. - $sale = Sale::get($saleId, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception:" . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); +try { + // ### Retrieve the sale object + // Pass the ID of the sale + // transaction from your payment resource. + $sale = Sale::get($saleId, $apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Look Up A Sale", "Sale", $sale->getId(), null, $ex); + exit(1); } -?> - - - Lookup a sale - - -
    Retrieving sale id:
    -
    toJSON(128)?>
    - Back - - + +ResultPrinter::printResult("Look Up A Sale", "Sale", $sale->getId(), null, $sale); + +return $sale; diff --git a/sample/sale/RefundSale.php b/sample/sale/RefundSale.php index 93be6fd..dfe674c 100644 --- a/sample/sale/RefundSale.php +++ b/sample/sale/RefundSale.php @@ -6,7 +6,10 @@ // using the Payments API. // API used: /v1/payments/sale/{sale-id}/refund -require __DIR__ . '/../bootstrap.php'; +/** @var Sale $sale */ +$sale = require 'GetSale.php'; +$saleId = $sale->getId(); + use PayPal\Api\Amount; use PayPal\Api\Refund; use PayPal\Api\Sale; @@ -17,37 +20,31 @@ use PayPal\Api\Sale; // field to mention fees refund details. $amt = new Amount(); $amt->setCurrency('USD') - ->setTotal('0.01'); + ->setTotal('0.01'); // ### Refund object $refund = new Refund(); $refund->setAmount($amt); -$saleId = '3RM92092UW5126232'; - // ###Sale // A sale transaction. // Create a Sale object with the // given sale transaction id. $sale = new Sale(); $sale->setId($saleId); -try { - // Refund the sale - // (See bootstrap.php for more on `ApiContext`) - $sale->refund($refund, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception:" . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); +try { + // Create a new apiContext object so we send a new + // PayPal-Request-Id (idempotency) header for this resource + $apiContext = getApiContext($clientId, $clientSecret); + + // Refund the sale + // (See bootstrap.php for more on `ApiContext`) + $refundedSale = $sale->refund($refund, $apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Refund Sale", "Sale", $refundedSale->getId(), $refund, $ex); + exit(1); } -?> - - - Refund a sale - - -
    Refunding sale id:
    -
    toJSON(128);?>
    - Back - - + +ResultPrinter::printResult("Refund Sale", "Sale", $refundedSale->getId(), $refund, $refundedSale); + +return $refundedSale; diff --git a/sample/vault/CreateCreditCard.php b/sample/vault/CreateCreditCard.php index 6c1c358..8a3a4de 100644 --- a/sample/vault/CreateCreditCard.php +++ b/sample/vault/CreateCreditCard.php @@ -15,12 +15,15 @@ use PayPal\Api\CreditCard; // to be stored with PayPal. $card = new CreditCard(); $card->setType("visa") - ->setNumber("4417119669820331") - ->setExpireMonth("11") - ->setExpireYear("2019") - ->setCvv2("012") - ->setFirstName("Joe") - ->setLastName("Shopper"); + ->setNumber("4417119669820331") + ->setExpireMonth("11") + ->setExpireYear("2019") + ->setCvv2("012") + ->setFirstName("Joe") + ->setLastName("Shopper"); + +// For Sample Purposes Only. +$request = clone $card; // ### Save card // Creates the credit card as a resource @@ -29,20 +32,12 @@ $card->setType("visa") // in future payments. // (See bootstrap.php for more on `ApiContext`) try { - $card->create($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception:" . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + $card->create($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Create Credit Card", "Credit Card", null, $request, $ex); + exit(1); } -?> - - - Save a credit card - - -
    Saved a new credit card with id: getId();?>
    -
    toJSON(128);?>
    - Back - - + +ResultPrinter::printResult("Create Credit Card", "Credit Card", $card->getId(), $request, $card); + +return $card; diff --git a/sample/vault/DeleteCreditCard.php b/sample/vault/DeleteCreditCard.php index 3ba6d0d..fd007b9 100644 --- a/sample/vault/DeleteCreditCard.php +++ b/sample/vault/DeleteCreditCard.php @@ -5,53 +5,20 @@ // API used: /v1/vault/credit-card/{} // NOTE: HTTP method used here is DELETE -require __DIR__ . '/../bootstrap.php'; +/** @var CreditCard $card */ +$card = require 'CreateCreditCard.php'; use PayPal\Api\CreditCard; -// Store a mock card that can be deleted later. -// ### CreditCard -// A resource representing a credit card that can be -// used to fund a payment. -$card = new CreditCard(); -$card->setType("visa") - ->setNumber("4417119669820331") - ->setExpireMonth("11") - ->setExpireYear("2019") - ->setCvv2("012") - ->setFirstName("Joe") - ->setLastName("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 later. -// (See bootstrap.php for more on `ApiContext`) try { - $card = $card->create($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception:" . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + // ### Delete Card + // Lookup and delete a saved credit card. + // (See bootstrap.php for more on `ApiContext`) + $creditCard = CreditCard::get($card->getId(), $apiContext); + + $creditCard->delete($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Delete Credit Card", "Credit Card", null, null, $ex); + exit(1); } -try { - // ### Delete Card - // Lookup and delete a saved credit card. - // (See bootstrap.php for more on `ApiContext`) - - $creditCard = CreditCard::get($card->getId(), $apiContext); - $creditCard->delete($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - exit(1); -} -?> - - - Delete a saved credit card - - -

    Credit Card deleted Successfully

    - Back - - +ResultPrinter::printResult("Delete Credit Card", "Credit Card", $card->getId(), null, $creditCard); diff --git a/sample/vault/GetCreditCard.php b/sample/vault/GetCreditCard.php index 3d66c6c..6afe828 100644 --- a/sample/vault/GetCreditCard.php +++ b/sample/vault/GetCreditCard.php @@ -6,30 +6,20 @@ // API called: '/v1/vault/credit-card' // The following code takes you through // the process of retrieving a saved CreditCard -require __DIR__ . '/../bootstrap.php'; -use PayPal\Api\CreditCard; +/** @var CreditCard $card */ +$card = require 'CreateCreditCard.php'; -// The cardId can be obtained from a previous save credit -// card operation. Use $card->getId() -$cardId = "CARD-44D10970C24287906KRCTWNI"; +use PayPal\Api\CreditCard; /// ### Retrieve card // (See bootstrap.php for more on `ApiContext`) try { - $card = CreditCard::get($cardId, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + $card = CreditCard::get($card->getId(), $apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Get Credit Card", "Credit Card", $card->getId(), null, $ex); + exit(1); } -?> - - - Lookup a saved credit card - - -
    Retrieving saved credit card:
    -
    toJSON(128);?>
    - Back - - + +ResultPrinter::printResult("Get Credit Card", "Credit Card", $card->getId(), null, $card); + +return $card;