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 '
-
+
@@ -44,13 +55,13 @@ class ResultPrinter {
';
if ($objectId) {
- echo '
' . ($objectName ? $objectName : "Object") . " with ID: $objectId
";
+ echo "
" . ($objectName ? $objectName : "Object") . " with ID: $objectId
";
}
echo '
Request Object
';
self::printObject($request);
- echo 'Response Object
';
- self::printObject($response);
+ echo 'Response Object
';
+ self::printObject($response, $errorMessage);
echo '';
echo '
@@ -61,7 +72,7 @@ class ResultPrinter {
Request Object
';
self::printObject($request) ;
echo 'Response Object
';
- self::printObject($response);
+ self::printObject($response, $errorMessage);
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);$request = clone $agreement;
$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);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); $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);
$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); $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
$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);
For Sample Purposes Only.