Adding Discount to Invoice Samples

This commit is contained in:
Jay Patel
2015-06-26 11:57:22 -05:00
parent 18e4eaaf31
commit ccf9008dfa
3 changed files with 134 additions and 375 deletions

View File

@@ -1,6 +1,7 @@
<!DOCTYPE html><html lang="en"><head><title>invoice/CreateInvoice</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="invoice/CreateInvoice"><meta name="groc-project-path" content="invoice/CreateInvoice.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">invoice/CreateInvoice.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="create-invoice-sample">Create Invoice Sample</h1>
<p>This sample code demonstrate how you can create
an invoice.</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>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Cost</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Invoice</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">MerchantInfo</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">BillingInfo</span>;
@@ -65,10 +66,12 @@ detailed breakdown of invoice</p></div></div><div class="code"><div class="wrapp
-&gt;setValue(<span class="hljs-number">5</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h4 id="tax-item">Tax Item</h4>
<p>You could provide Tax information to each item.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$tax</span> = <span class="hljs-keyword">new</span> \PayPal\Api\Tax();
<span class="hljs-variable">$tax</span>-&gt;setPercent(<span class="hljs-number">1</span>)-&gt;setName(<span class="hljs-string">"Local Tax on Sutures"</span>);
<span class="hljs-variable">$items</span>[<span class="hljs-number">0</span>]-&gt;setTax(<span class="hljs-variable">$tax</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Second Item</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$items</span>[<span class="hljs-number">1</span>] = <span class="hljs-keyword">new</span> InvoiceItem();
<span class="hljs-variable">$items</span>[<span class="hljs-number">0</span>]-&gt;setTax(<span class="hljs-variable">$tax</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Second Item</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$items</span>[<span class="hljs-number">1</span>] = <span class="hljs-keyword">new</span> InvoiceItem();</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Lets add some discount to this item.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$item1discount</span> = <span class="hljs-keyword">new</span> Cost();
<span class="hljs-variable">$item1discount</span>-&gt;setPercent(<span class="hljs-string">"3"</span>);
<span class="hljs-variable">$items</span>[<span class="hljs-number">1</span>]
-&gt;setName(<span class="hljs-string">"Injection"</span>)
-&gt;setQuantity(<span class="hljs-number">5</span>)
-&gt;setDiscount(<span class="hljs-variable">$item1discount</span>)
-&gt;setUnitPrice(<span class="hljs-keyword">new</span> Currency());
<span class="hljs-variable">$items</span>[<span class="hljs-number">1</span>]-&gt;getUnitPrice()
@@ -78,7 +81,10 @@ detailed breakdown of invoice</p></div></div><div class="code"><div class="wrapp
<span class="hljs-variable">$tax2</span>-&gt;setPercent(<span class="hljs-number">3</span>)-&gt;setName(<span class="hljs-string">"Local Tax on Injection"</span>);
<span class="hljs-variable">$items</span>[<span class="hljs-number">1</span>]-&gt;setTax(<span class="hljs-variable">$tax2</span>);
<span class="hljs-variable">$invoice</span>-&gt;setItems(<span class="hljs-variable">$items</span>);
<span class="hljs-variable">$invoice</span>-&gt;setItems(<span class="hljs-variable">$items</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h4 id="final-discount">Final Discount</h4>
<p>You can add final discount to the invoice as shown below. You could either use &quot;percent&quot; or &quot;value&quot; when providing the discount</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$cost</span> = <span class="hljs-keyword">new</span> Cost();
<span class="hljs-variable">$cost</span>-&gt;setPercent(<span class="hljs-string">"2"</span>);
<span class="hljs-variable">$invoice</span>-&gt;setDiscount(<span class="hljs-variable">$cost</span>);
<span class="hljs-variable">$invoice</span>-&gt;getPaymentTerm()
-&gt;setTermType(<span class="hljs-string">"NET_45"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="shipping-information">Shipping Information</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-variable">$invoice</span>-&gt;getShippingInfo()