Updated Billing Plan to have Delete Plan sample code.

- Added helper method in Plan.php to allow deleting a billing plan
- Fixes #171
This commit is contained in:
japatel
2014-12-01 13:20:36 -06:00
parent 493c6f8531
commit ff5588bbfe
6 changed files with 107 additions and 2 deletions

View File

@@ -2,6 +2,7 @@
namespace PayPal\Api; namespace PayPal\Api;
use PayPal\Common\PPModel;
use PayPal\Common\ResourceModel; use PayPal\Common\ResourceModel;
use PayPal\Validation\ArgumentValidator; use PayPal\Validation\ArgumentValidator;
use PayPal\Api\PlanList; use PayPal\Api\PlanList;
@@ -543,6 +544,28 @@ class Plan extends ResourceModel
return true; 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. * List billing plans according to optional query string parameters specified.
* *

View File

@@ -0,0 +1,24 @@
<?php
// # 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
// Retrieving the Plan object from Create Plan Sample
/** @var Plan $createdPlan */
$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;

View File

@@ -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", "type": "file",
"data": { "data": {

View File

@@ -0,0 +1,18 @@
<!DOCTYPE html><html lang="en"><head><title>billing/DeletePlan</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content="../"><meta name="groc-document-path" content="billing/DeletePlan"><meta name="groc-project-path" content="billing/DeletePlan.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">billing/DeletePlan.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="delete-plan-sample">Delete Plan Sample</h1>
<p>This sample code demonstrate how you can delete a billing plan, as documented here at:
<a href="https://developer.paypal.com/webapps/developer/docs/api/#retrieve-a-plan">https://developer.paypal.com/webapps/developer/docs/api/#retrieve-a-plan</a>
API used: /v1/payments/billing-plans</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieving the Plan object from Create Plan Sample</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> Plan $createdPlan */</span>
<span class="hljs-variable">$createdPlan</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreatePlan.php'</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Plan</span>;
<span class="hljs-keyword">try</span> {
<span class="hljs-variable">$result</span> = <span class="hljs-variable">$createdPlan</span>-&gt;delete(<span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
ResultPrinter::printError(<span class="hljs-string">"Deleted a Plan"</span>, <span class="hljs-string">"Plan"</span>, <span class="hljs-variable">$plan</span>-&gt;getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}
ResultPrinter::printResult(<span class="hljs-string">"Deleted a Plan"</span>, <span class="hljs-string">"Plan"</span>, <span class="hljs-variable">$plan</span>-&gt;getId(), <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$plan</span>;</div></div></div></div></body></html>

View File

@@ -7,7 +7,7 @@ API used: /v1/payments/billing-agreements/<Agreement-Id></p></div></div></div><d
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Agreement</span>; <span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Agreement</span>;
<span class="hljs-keyword">try</span> { <span class="hljs-keyword">try</span> {
<span class="hljs-variable">$agreement</span> = Agreement::get(<span class="hljs-variable">$createdAgreement</span>-&gt;getId(), <span class="hljs-variable">$apiContext</span>); <span class="hljs-variable">$agreement</span> = Agreement::get(<span class="hljs-string">'I-NH3BT1XF0G93'</span>, <span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) { } <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
ResultPrinter::printError(<span class="hljs-string">"Retrieved an Agreement"</span>, <span class="hljs-string">"Agreement"</span>, <span class="hljs-variable">$agreement</span>-&gt;getId(), <span class="hljs-variable">$createdAgreement</span>-&gt;getId(), <span class="hljs-variable">$ex</span>); ResultPrinter::printError(<span class="hljs-string">"Retrieved an Agreement"</span>, <span class="hljs-string">"Agreement"</span>, <span class="hljs-variable">$agreement</span>-&gt;getId(), <span class="hljs-variable">$createdAgreement</span>-&gt;getId(), <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>); <span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);

View File

@@ -4,7 +4,7 @@ if (PHP_SAPI == 'cli') {
// the built in PHP Server // the built in PHP Server
if (version_compare(phpversion(), '5.4.0', '>=') === true) { if (version_compare(phpversion(), '5.4.0', '>=') === true) {
//exec('php -S -t ' . __DIR__ . '/'); //exec('php -S -t ' . __DIR__ . '/');
$cmd = "php -S localhost:5000 -t " . __DIR__ . '/'; $cmd = "php -S localhost:5000 -t " . __DIR__;
$descriptors = array( $descriptors = array(
0 => array("pipe", "r"), 0 => array("pipe", "r"),
1 => STDOUT, 1 => STDOUT,
@@ -457,6 +457,17 @@ if (PHP_SAPI == 'cli') {
</div> </div>
</div> </div>
</li> </li>
<li class="list-group-item">
<div class="row">
<div class="col-md-8"><h5>Delete Billing Plan</h5></div>
<div class="col-md-4">
<a href="billing/DeletePlan.php" class="btn btn-primary pull-left execute"> Try It <i
class="fa fa-play-circle-o"></i></a>
<a href="doc/billing/DeletePlan.html" class="btn btn-default pull-right">Source <i
class="fa fa-file-code-o"></i></a>
</div>
</div>
</li>
<li class="list-group-item"> <li class="list-group-item">
<div class="row"> <div class="row">
<div class="col-md-8"><h5>List Billing Plans</h5></div> <div class="col-md-8"><h5>List Billing Plans</h5></div>