From ff5588bbfe3fdcdda3f46b1d554c6336d560c887 Mon Sep 17 00:00:00 2001
From: japatel
Date: Mon, 1 Dec 2014 13:20:36 -0600
Subject: [PATCH] Updated Billing Plan to have Delete Plan sample code.
- Added helper method in Plan.php to allow deleting a billing plan
- Fixes #171
---
lib/PayPal/Api/Plan.php | 23 ++++++++++++++++
sample/billing/DeletePlan.php | 24 +++++++++++++++++
sample/doc/assets/behavior.js | 29 +++++++++++++++++++++
sample/doc/billing/DeletePlan.html | 18 +++++++++++++
sample/doc/billing/GetBillingAgreement.html | 2 +-
sample/index.php | 13 ++++++++-
6 files changed, 107 insertions(+), 2 deletions(-)
create mode 100644 sample/billing/DeletePlan.php
create mode 100644 sample/doc/billing/DeletePlan.html
diff --git a/lib/PayPal/Api/Plan.php b/lib/PayPal/Api/Plan.php
index 3b46398..9e85ef2 100644
--- a/lib/PayPal/Api/Plan.php
+++ b/lib/PayPal/Api/Plan.php
@@ -2,6 +2,7 @@
namespace PayPal\Api;
+use PayPal\Common\PPModel;
use PayPal\Common\ResourceModel;
use PayPal\Validation\ArgumentValidator;
use PayPal\Api\PlanList;
@@ -543,6 +544,28 @@ class Plan extends ResourceModel
return true;
}
+ /**
+ * Delete a billing plan by passing the ID of the billing plan to the request URI.
+ *
+ * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
+ * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls
+ * @return bool
+ */
+ public function delete($apiContext = null, $restCall = null)
+ {
+ ArgumentValidator::validate($this->getId(), "Id");
+ $patchRequest = new PatchRequest();
+ $patch = new Patch();
+ $value = new PPModel('{
+ "state":"DELETED"
+ }');
+ $patch->setOp('replace')
+ ->setPath('/')
+ ->setValue($value);
+ $patchRequest->addPatch($patch);
+ return $this->update($patchRequest, $apiContext, $restCall);
+ }
+
/**
* List billing plans according to optional query string parameters specified.
*
diff --git a/sample/billing/DeletePlan.php b/sample/billing/DeletePlan.php
new file mode 100644
index 0000000..33901f4
--- /dev/null
+++ b/sample/billing/DeletePlan.php
@@ -0,0 +1,24 @@
+delete($apiContext);
+} catch (Exception $ex) {
+ ResultPrinter::printError("Deleted a Plan", "Plan", $plan->getId(), null, $ex);
+ exit(1);
+}
+
+ResultPrinter::printResult("Deleted a Plan", "Plan", $plan->getId(), null, null);
+
+return $plan;
diff --git a/sample/doc/assets/behavior.js b/sample/doc/assets/behavior.js
index a79fd10..ddd3872 100644
--- a/sample/doc/assets/behavior.js
+++ b/sample/doc/assets/behavior.js
@@ -157,6 +157,35 @@ 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/PayPal-PHP-SDK/sample/billing/DeletePlan.php",
+ "projectPath": "billing/DeletePlan.php",
+ "targetPath": "billing/DeletePlan",
+ "pageTitle": "billing/DeletePlan",
+ "title": "DeletePlan"
+ },
+ "depth": 2,
+ "outline": [
+ {
+ "type": "heading",
+ "data": {
+ "level": 1,
+ "title": "Delete Plan Sample",
+ "slug": "delete-plan-sample"
+ },
+ "depth": 1
+ }
+ ]
}, {
"type": "file",
"data": {
diff --git a/sample/doc/billing/DeletePlan.html b/sample/doc/billing/DeletePlan.html
new file mode 100644
index 0000000..171c90e
--- /dev/null
+++ b/sample/doc/billing/DeletePlan.html
@@ -0,0 +1,18 @@
+billing/DeletePlan
+$createdPlan = require 'CreatePlan.php' ;
+
+use PayPal \Api \Plan ;
+
+try {
+ $result = $createdPlan ->delete($apiContext );
+} catch (Exception $ex ) {
+ ResultPrinter::printError("Deleted a Plan" , "Plan" , $plan ->getId(), null , $ex );
+ exit (1 );
+}
+
+ResultPrinter::printResult("Deleted a Plan" , "Plan" , $plan ->getId(), null , null );
+
+return $plan ;
\ No newline at end of file
diff --git a/sample/doc/billing/GetBillingAgreement.html b/sample/doc/billing/GetBillingAgreement.html
index b456c1a..e4897f6 100644
--- a/sample/doc/billing/GetBillingAgreement.html
+++ b/sample/doc/billing/GetBillingAgreement.html
@@ -7,7 +7,7 @@ API used: /v1/payments/billing-agreements/
use PayPal \Api \Agreement ;
try {
- $agreement = Agreement::get($createdAgreement ->getId(), $apiContext );
+ $agreement = Agreement::get('I-NH3BT1XF0G93' , $apiContext );
} catch (Exception $ex ) {
ResultPrinter::printError("Retrieved an Agreement" , "Agreement" , $agreement ->getId(), $createdAgreement ->getId(), $ex );
exit (1 );
diff --git a/sample/index.php b/sample/index.php
index c1bcb6d..db3858f 100644
--- a/sample/index.php
+++ b/sample/index.php
@@ -4,7 +4,7 @@ if (PHP_SAPI == 'cli') {
// the built in PHP Server
if (version_compare(phpversion(), '5.4.0', '>=') === true) {
//exec('php -S -t ' . __DIR__ . '/');
- $cmd = "php -S localhost:5000 -t " . __DIR__ . '/';
+ $cmd = "php -S localhost:5000 -t " . __DIR__;
$descriptors = array(
0 => array("pipe", "r"),
1 => STDOUT,
@@ -457,6 +457,17 @@ if (PHP_SAPI == 'cli') {
+
+
+
Delete Billing Plan
+
+
+
Delete Plan Sample
+This sample code demonstrate how you can delete a billing plan, as documented here at: +https://developer.paypal.com/webapps/developer/docs/api/#retrieve-a-plan +API used: /v1/payments/billing-plans