forked from LiveCarta/PayPal-PHP-SDK
Adding Discount to Invoice Samples
This commit is contained in:
@@ -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"><?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
|
||||
->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>->setPercent(<span class="hljs-number">1</span>)->setName(<span class="hljs-string">"Local Tax on Sutures"</span>);
|
||||
<span class="hljs-variable">$items</span>[<span class="hljs-number">0</span>]->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>]->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>->setPercent(<span class="hljs-string">"3"</span>);
|
||||
<span class="hljs-variable">$items</span>[<span class="hljs-number">1</span>]
|
||||
->setName(<span class="hljs-string">"Injection"</span>)
|
||||
->setQuantity(<span class="hljs-number">5</span>)
|
||||
->setDiscount(<span class="hljs-variable">$item1discount</span>)
|
||||
->setUnitPrice(<span class="hljs-keyword">new</span> Currency());
|
||||
|
||||
<span class="hljs-variable">$items</span>[<span class="hljs-number">1</span>]->getUnitPrice()
|
||||
@@ -78,7 +81,10 @@ detailed breakdown of invoice</p></div></div><div class="code"><div class="wrapp
|
||||
<span class="hljs-variable">$tax2</span>->setPercent(<span class="hljs-number">3</span>)->setName(<span class="hljs-string">"Local Tax on Injection"</span>);
|
||||
<span class="hljs-variable">$items</span>[<span class="hljs-number">1</span>]->setTax(<span class="hljs-variable">$tax2</span>);
|
||||
|
||||
<span class="hljs-variable">$invoice</span>->setItems(<span class="hljs-variable">$items</span>);
|
||||
<span class="hljs-variable">$invoice</span>->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 "percent" or "value" 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>->setPercent(<span class="hljs-string">"2"</span>);
|
||||
<span class="hljs-variable">$invoice</span>->setDiscount(<span class="hljs-variable">$cost</span>);
|
||||
|
||||
<span class="hljs-variable">$invoice</span>->getPaymentTerm()
|
||||
->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>->getShippingInfo()
|
||||
|
||||
Reference in New Issue
Block a user