More Vault API Samples

- Updated Samples for Vault APIs
- Updated Payment Execute to be more verbose
- Delete Plan Sample Update
- Fixes #168
This commit is contained in:
japatel
2014-12-01 16:52:44 -06:00
parent ff5588bbfe
commit 6cf15ab4bf
22 changed files with 527 additions and 60 deletions

View File

@@ -9,10 +9,10 @@ API used: /v1/payments/billing-plans</p></div></div></div><div class="segment"><
<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>);
ResultPrinter::printError(<span class="hljs-string">"Deleted a Plan"</span>, <span class="hljs-string">"Plan"</span>, <span class="hljs-variable">$createdPlan</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>);
ResultPrinter::printResult(<span class="hljs-string">"Deleted a Plan"</span>, <span class="hljs-string">"Plan"</span>, <span class="hljs-variable">$createdPlan</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>
<span class="hljs-keyword">return</span> <span class="hljs-variable">$createdPlan</span>;</div></div></div></div></body></html>

View File

@@ -1,15 +1,12 @@
<!DOCTYPE html><html lang="en"><head><title>billing/ExecuteAgreement</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/ExecuteAgreement"><meta name="groc-project-path" content="billing/ExecuteAgreement.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/ExecuteAgreement.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span>
<span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
session_start();
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$_GET</span>[<span class="hljs-string">'success'</span>]) &amp;&amp; <span class="hljs-variable">$_GET</span>[<span class="hljs-string">'success'</span>] == <span class="hljs-string">'true'</span>) {
<!DOCTYPE html><html lang="en"><head><title>billing/ExecuteAgreement</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/ExecuteAgreement"><meta name="groc-project-path" content="billing/ExecuteAgreement.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/ExecuteAgreement.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="execute-agreement">Execute Agreement</h1>
<p>This is the second part of CreateAgreement Sample.
Use this call to execute an agreement after the buyer approves it</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"><h2 id="approval-status">Approval Status</h2>
<p>Determine if the user accepted or denied the request</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">if</span> (<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$_GET</span>[<span class="hljs-string">'success'</span>]) &amp;&amp; <span class="hljs-variable">$_GET</span>[<span class="hljs-string">'success'</span>] == <span class="hljs-string">'true'</span>) {
<span class="hljs-variable">$token</span> = <span class="hljs-variable">$_GET</span>[<span class="hljs-string">'token'</span>];
<span class="hljs-variable">$agreement</span> = <span class="hljs-keyword">new</span> \PayPal\Api\Agreement();
<span class="hljs-keyword">try</span> {
<span class="hljs-variable">$agreement</span>-&gt;execute(<span class="hljs-variable">$token</span>, <span class="hljs-variable">$apiContext</span>);
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h2 id="execute-agreement">Execute Agreement</h2>
<p>Execute the agreement by passing in the token</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$agreement</span>-&gt;execute(<span class="hljs-variable">$token</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>) {
ResultPrinter::printError(<span class="hljs-string">"Executed an Agreement"</span>, <span class="hljs-string">"Agreement"</span>, <span class="hljs-variable">$agreement</span>-&gt;getId(), <span class="hljs-variable">$_GET</span>[<span class="hljs-string">'token'</span>], <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);

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">try</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-variable">$agreement</span> = Agreement::get(<span class="hljs-variable">$createdAgreement</span>-&gt;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">"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>);