forked from LiveCarta/PayPal-PHP-SDK
Updated User Agent & More Samples for Billing Plans
- Fixed versioning in User Agent. - Updated Billing Plan sample to update Payment definitions - Docs & Tests
This commit is contained in:
43
sample/doc/billing/UpdatePlanPaymentDefinitions.html
Normal file
43
sample/doc/billing/UpdatePlanPaymentDefinitions.html
Normal file
@@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>billing/UpdatePlanPaymentDefinitions</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/UpdatePlanPaymentDefinitions"><meta name="groc-project-path" content="billing/UpdatePlanPaymentDefinitions.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/UpdatePlanPaymentDefinitions.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor"><?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="update-a-plan">Update a plan</h1>
|
||||
<p>This sample code demonstrate how you can update a billing plan, as documented here at:
|
||||
<a href="https://developer.paypal.com/webapps/developer/docs/api/#update-a-plan">https://developer.paypal.com/webapps/developer/docs/api/#update-a-plan</a>
|
||||
API used: /v1/payments/billing-plans/<Plan-Id></p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="changing-plan-amount">Changing Plan Amount</h3>
|
||||
<p>This example demonstrate how you could change the plan amount</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieving the Plan object from Create Plan Sample to demonstrate the List</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">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">PatchRequest</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Patch</span>;
|
||||
|
||||
<span class="hljs-keyword">try</span> {
|
||||
<span class="hljs-variable">$patch</span> = <span class="hljs-keyword">new</span> Patch();
|
||||
|
||||
<span class="hljs-variable">$paymentDefinitions</span> = <span class="hljs-variable">$createdPlan</span>->getPaymentDefinitions();
|
||||
<span class="hljs-variable">$paymentDefinitionId</span> = <span class="hljs-variable">$paymentDefinitions</span>[<span class="hljs-number">0</span>]->getId();
|
||||
<span class="hljs-variable">$patch</span>->setOp(<span class="hljs-string">'replace'</span>)
|
||||
->setPath(<span class="hljs-string">'/payment-definitions/'</span> . <span class="hljs-variable">$paymentDefinitionId</span>)
|
||||
->setValue(json_decode(
|
||||
<span class="hljs-string">'{
|
||||
"name": "Updated Payment Definition",
|
||||
"frequency": "Day",
|
||||
"amount": {
|
||||
"currency": "USD",
|
||||
"value": "50"
|
||||
}
|
||||
}'</span>
|
||||
));
|
||||
<span class="hljs-variable">$patchRequest</span> = <span class="hljs-keyword">new</span> PatchRequest();
|
||||
<span class="hljs-variable">$patchRequest</span>->addPatch(<span class="hljs-variable">$patch</span>);
|
||||
|
||||
<span class="hljs-variable">$createdPlan</span>->update(<span class="hljs-variable">$patchRequest</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
|
||||
<span class="hljs-variable">$plan</span> = Plan::get(<span class="hljs-variable">$createdPlan</span>->getId(), <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">"Updated the Plan Payment Definition"</span>, <span class="hljs-string">"Plan"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$patchRequest</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">"Updated the Plan Payment Definition"</span>, <span class="hljs-string">"Plan"</span>, <span class="hljs-variable">$plan</span>->getId(), <span class="hljs-variable">$patchRequest</span>, <span class="hljs-variable">$plan</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$plan</span>;</div></div></div></div></body></html>
|
||||
Reference in New Issue
Block a user