forked from LiveCarta/PayPal-PHP-SDK
34 lines
5.0 KiB
HTML
34 lines
5.0 KiB
HTML
<!DOCTYPE html><html lang="en"><head><title>billing/UpdateBillingAgreement</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/UpdateBillingAgreement"><meta name="groc-project-path" content="billing/UpdateBillingAgreement.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/UpdateBillingAgreement.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-an-agreement">Update an agreement</h1>
|
|
<p>This sample code demonstrate how you can update a billing agreement, as documented here at:
|
|
<a href="https://developer.paypal.com/docs/api/#update-an-agreement">https://developer.paypal.com/docs/api/#update-an-agreement</a>
|
|
API used: /v1/payments/billing-agreements/<Agreement-Id></p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieving the Agreement object from Create Agreement Sample to demonstrate the List</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/** <span class="hljs-doctag">@var</span> Agreement $createdAgreement */</span>
|
|
<span class="hljs-variable">$createdAgreement</span> = <span class="hljs-string">'your agreement id'</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">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Patch</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-variable">$patch</span> = <span class="hljs-keyword">new</span> Patch();
|
|
|
|
<span class="hljs-variable">$patch</span>->setOp(<span class="hljs-string">'replace'</span>)
|
|
->setPath(<span class="hljs-string">'/'</span>)
|
|
->setValue(json_decode(<span class="hljs-string">'{
|
|
"description": "New Description",
|
|
"shipping_address": {
|
|
"line1": "2065 Hamilton Ave",
|
|
"city": "San Jose",
|
|
"state": "CA",
|
|
"postal_code": "95125",
|
|
"country_code": "US"
|
|
}
|
|
}'</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-keyword">try</span> {
|
|
<span class="hljs-variable">$createdAgreement</span>->update(<span class="hljs-variable">$patchRequest</span>, <span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Lets get the updated Agreement Object</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$agreement</span> = Agreement::get(<span class="hljs-variable">$createdAgreement</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>) {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> ResultPrinter::printError(<span class="hljs-string">"Updated the Agreement with new Description and Updated Shipping Address"</span>, <span class="hljs-string">"Agreement"</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>);
|
|
}</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> ResultPrinter::printResult(<span class="hljs-string">"Updated the Agreement with new Description and Updated Shipping Address"</span>, <span class="hljs-string">"Agreement"</span>, <span class="hljs-variable">$agreement</span>->getId(), <span class="hljs-variable">$patchRequest</span>, <span class="hljs-variable">$agreement</span>);
|
|
|
|
<span class="hljs-keyword">return</span> <span class="hljs-variable">$agreement</span>;</div></div></div></div></body></html>
|