Merge pull request #649 from paypal/invoicing-update

Updated Invoice API
This commit is contained in:
Jay
2016-09-21 14:55:12 -05:00
committed by GitHub
21 changed files with 535 additions and 15 deletions

View File

@@ -140,7 +140,7 @@ class BillingInfo extends PayPalModel
/**
* The language in which the email was sent to the payer. Used only when the payer does not have a PayPal account.
* Valid Values: ["da_DK", "de_DE", "en_AU", "en_GB", "en_US", "es_ES", "es_XC", "fr_CA", "fr_FR", "fr_XC", "he_IL", "id_ID", "it_IT", "ja_JP", "nl_NL", "no_NO", "pl_PL", "pt_BR", "pt_PT", "ru_RU", "sv_SE", "th_TH", "zh_CN", "zh_HK", "zh_TW", "zh_XC"]
* Valid Values: ["da_DK", "de_DE", "en_AU", "en_GB", "en_US", "es_ES", "es_XC", "fr_CA", "fr_FR", "fr_XC", "he_IL", "id_ID", "it_IT", "ja_JP", "nl_NL", "no_NO", "pl_PL", "pt_BR", "pt_PT", "ru_RU", "sv_SE", "th_TH", "tr_TR", "zh_CN", "zh_HK", "zh_TW", "zh_XC"]
*
* @param string $language
*

View File

@@ -1190,7 +1190,7 @@ class Invoice extends PayPalResourceModel
}
/**
* Fully updates an invoice by passing the invoice ID to the request URI. In addition, pass a complete invoice object in the request JSON. Does not support partial updates.
* Fully updates an invoice by passing the invoice ID to the request URI. In addition, pass a complete invoice object in the request JSON. Partial updates are not supported.
*
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
@@ -1213,7 +1213,7 @@ class Invoice extends PayPalResourceModel
}
/**
* Deletes an invoice, by ID.
* Delete a particular invoice by passing the invoice ID to the request URI.
*
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
@@ -1234,6 +1234,52 @@ class Invoice extends PayPalResourceModel
return true;
}
/**
* Delete external payment.
*
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return bool
*/
public function deleteExternalPayment($transactionId, $apiContext = null, $restCall = null)
{
ArgumentValidator::validate($this->getId(), "Id");
ArgumentValidator::validate($transactionId, "TransactionId");
$payLoad = "";
self::executeCall(
"/v1/invoicing/invoices/{$this->getId()}/payment-records/{$transactionId}",
"DELETE",
$payLoad,
null,
$apiContext,
$restCall
);
return true;
}
/**
* Delete external refund.
*
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return bool
*/
public function deleteExternalRefund($transactionId, $apiContext = null, $restCall = null)
{
ArgumentValidator::validate($this->getId(), "Id");
ArgumentValidator::validate($transactionId, "TransactionId");
$payLoad = "";
self::executeCall(
"/v1/invoicing/invoices/{$this->getId()}/refund-records/{$transactionId}",
"DELETE",
$payLoad,
null,
$apiContext,
$restCall
);
return true;
}
/**
* Generate a QR code for an invoice by passing the invoice ID to the request URI. The request generates a QR code that is 500 pixels in width and height. You can change the dimensions of the returned code by specifying optional query parameters.
*
@@ -1269,7 +1315,7 @@ class Invoice extends PayPalResourceModel
}
/**
* Generate the successive invoice number for the merchant.
* Generates the successive invoice number.
*
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls

View File

@@ -80,7 +80,7 @@ class InvoiceItem extends PayPalModel
*/
public function setQuantity($quantity)
{
NumericValidator::validate($quantity, "Percent");
NumericValidator::validate($quantity, "Quantity");
$quantity = FormatConverter::formatToPrice($quantity);
$this->quantity = $quantity;
return $this;

View File

@@ -12,6 +12,7 @@ use PayPal\Common\PayPalModel;
* @package PayPal\Api
*
* @property string type
* @property string transaction_id
* @property string date
* @property string note
* @property \PayPal\Api\Currency amount
@@ -42,6 +43,29 @@ class RefundDetail extends PayPalModel
return $this->type;
}
/**
* The PayPal refund transaction ID. Required with the `PAYPAL` refund type.
*
* @param string $transaction_id
*
* @return $this
*/
public function setTransactionId($transaction_id)
{
$this->transaction_id = $transaction_id;
return $this;
}
/**
* The PayPal refund transaction ID. Required with the `PAYPAL` refund type.
*
* @return string
*/
public function getTransactionId()
{
return $this->transaction_id;
}
/**
* Date on which the invoice was refunded. Date format: yyyy-MM-dd z. For example, 2014-02-27 PST.
*

View File

@@ -111,7 +111,7 @@ class ShippingInfo extends PayPalModel
}
/**
*
* @deprecated Not used anymore
*
* @param string $email
* @return $this
@@ -123,7 +123,7 @@ class ShippingInfo extends PayPalModel
}
/**
*
* @deprecated Not used anymore
*
* @return string
*/

View File

@@ -2,7 +2,10 @@
namespace PayPal\Api;
use PayPal\Common\PayPalModel;
use PayPal\Common\PayPalResourceModel;
use PayPal\Rest\ApiContext;
use PayPal\Transport\PayPalRestCall;
use PayPal\Validation\ArgumentValidator;
/**
* Class Template
@@ -19,7 +22,7 @@ use PayPal\Common\PayPalModel;
* @property string unit_of_measure
* @property bool custom
*/
class Template extends PayPalModel
class Template extends PayPalResourceModel
{
/**
* Unique identifier id of the template.
@@ -212,4 +215,95 @@ class Template extends PayPalModel
return $this->custom;
}
/**
* Retrieve the details for a particular template by passing the template ID to the request URI.
*
* @param string $templateId
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return Template
*/
public static function get($templateId, $apiContext = null, $restCall = null)
{
ArgumentValidator::validate($templateId, 'templateId');
$payLoad = "";
$json = self::executeCall(
"/v1/invoicing/templates/$templateId",
"GET",
$payLoad,
null,
$apiContext,
$restCall
);
$ret = new Template();
$ret->fromJson($json);
return $ret;
}
/**
* Delete a particular template by passing the template ID to the request URI.
*
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return bool
*/
public function delete($apiContext = null, $restCall = null)
{
ArgumentValidator::validate($this->getTemplateId(), "Id");
$payLoad = "";
self::executeCall(
"/v1/invoicing/templates/{$this->getTemplateId()}",
"DELETE",
$payLoad,
null,
$apiContext,
$restCall
);
return true;
}
/**
* Creates a template.
*
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return Template
*/
public function create($apiContext = null, $restCall = null)
{
$json = self::executeCall(
"/v1/invoicing/templates",
"POST",
$this->toJSON(),
null,
$apiContext,
$restCall
);
$this->fromJson($json);
return $this;
}
/**
* Update an existing template by passing the template ID to the request URI. In addition, pass a complete template object in the request JSON. Partial updates are not supported.
*
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return Template
*/
public function update($apiContext = null, $restCall = null)
{
ArgumentValidator::validate($this->getTemplateId(), "Id");
$payLoad = $this->toJSON();
$json = self::executeCall(
"/v1/invoicing/templates/{$this->getTemplateId()}",
"PUT",
$payLoad,
null,
$apiContext,
$restCall
);
$this->fromJson($json);
return $this;
}
}

View File

@@ -114,7 +114,7 @@ class TemplateData extends PayPalModel
/**
* For invoices sent by email, one or more email addresses to which to send a Cc: copy of the notification. Supports only email addresses under participant.
*
* @param string $cc_info
* @param string[] $cc_info
*
* @return $this
*/

View File

@@ -3,6 +3,7 @@
namespace PayPal\Api;
use PayPal\Common\PayPalResourceModel;
use PayPal\Transport\PayPalRestCall;
use PayPal\Validation\ArgumentValidator;
use PayPal\Api\Template;
use PayPal\Rest\ApiContext;
@@ -235,8 +236,10 @@ class Templates extends PayPalResourceModel
}
/**
* Shows the details for a template, by ID.
* Retrieve the details for a particular template by passing the template ID to the request URI.
*
* @deprecated Please use `Template::get()` instead.
* @see Template::get
* @param string $templateId
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
@@ -260,14 +263,14 @@ class Templates extends PayPalResourceModel
}
/**
* Lists all templates for the merchant.
* Retrieves the template information of the merchant.
*
* @param array $params
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return Templates
*/
public static function getAll($params, $apiContext = null, $restCall = null)
public static function getAll($params = array(), $apiContext = null, $restCall = null)
{
ArgumentValidator::validate($params, 'params');
$payLoad = "";
@@ -286,5 +289,4 @@ class Templates extends PayPalResourceModel
$ret->fromJson($json);
return $ret;
}
}

View File

@@ -0,0 +1,43 @@
<!DOCTYPE html><html lang="en"><head><title>invoice-templates/CreateInvoiceTemplate</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-templates/CreateInvoiceTemplate"><meta name="groc-project-path" content="invoice-templates/CreateInvoiceTemplate.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-templates/CreateInvoiceTemplate.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-template-sample">Create Invoice Template Sample</h1>
<p>This sample code demonstrate how you can create
an invoice template.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Currency</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">InvoiceItem</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">Template</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">TemplateData</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">TemplateSettings</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">TemplateSettingsMetadata</span>;
<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"><h3 id="invoice-template-item">Invoice Template Item</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-variable">$invoiceTemplateDataItem</span> = <span class="hljs-keyword">new</span> InvoiceItem();
<span class="hljs-variable">$invoiceTemplateDataItem</span>
-&gt;setName(<span class="hljs-string">"Nutri Bullet"</span>)
-&gt;setQuantity(<span class="hljs-number">1</span>)
-&gt;setUnitPrice(<span class="hljs-keyword">new</span> Currency(<span class="hljs-string">'{ "currency": "USD", "value": "50.00" }'</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="invoice-template-data">Invoice Template Data</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-variable">$invoiceTemplateData</span> = <span class="hljs-keyword">new</span> TemplateData();
<span class="hljs-variable">$invoiceTemplateData</span>
-&gt;setTaxCalculatedAfterDiscount(<span class="hljs-keyword">false</span>)
-&gt;setTaxInclusive(<span class="hljs-keyword">false</span>)
-&gt;setNote(<span class="hljs-string">"Thank you for your business"</span>)
-&gt;setLogoUrl(<span class="hljs-string">"https://pics.paypal.com/v1/images/redDot.jpeg"</span>)
-&gt;addItem(<span class="hljs-variable">$invoiceTemplateDataItem</span>)
-&gt;setMerchantInfo(<span class="hljs-keyword">new</span> MerchantInfo(<span class="hljs-string">'{ "email": "jaypatel512-facilitator@hotmail.com" }'</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="template-settings">Template Settings</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-variable">$displayPreferences</span> = <span class="hljs-keyword">new</span> TemplateSettingsMetadata();
<span class="hljs-variable">$displayPreferences</span>-&gt;setHidden(<span class="hljs-keyword">true</span>);
<span class="hljs-variable">$settingDate</span> = <span class="hljs-keyword">new</span> TemplateSettings();
<span class="hljs-variable">$settingDate</span>
-&gt;setFieldName(<span class="hljs-string">"items.date"</span>)
-&gt;setDisplayPreference(<span class="hljs-variable">$displayPreferences</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="template">Template</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-variable">$invoiceTemplate</span> = <span class="hljs-keyword">new</span> Template();
<span class="hljs-variable">$invoiceTemplate</span>
-&gt;setName(<span class="hljs-string">"Hours Template"</span> . rand())
-&gt;setDefault(<span class="hljs-keyword">true</span>)
-&gt;setUnitOfMeasure(<span class="hljs-string">"HOURS"</span>)
-&gt;setTemplateData(<span class="hljs-variable">$invoiceTemplateData</span>)</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>This is another way of initializing the object.</p></div></div><div class="code"><div class="wrapper"> -&gt;addSetting(<span class="hljs-keyword">new</span> TemplateSettings(<span class="hljs-string">'{ "field_name": "custom", "display_preference": { "hidden": true } }'</span>))
-&gt;addSetting(<span class="hljs-variable">$settingDate</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>For Sample Purposes Only.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$request</span> = <span class="hljs-keyword">clone</span> <span class="hljs-variable">$invoiceTemplate</span>;
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-invoice-template">Create Invoice Template</h3>
<p>Create an invoice by calling the invoice-&gt;create() method
with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$invoiceTemplate</span>-&gt;create(<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">"Create Invoice Template"</span>, <span class="hljs-string">"Template"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$request</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">"Create Invoice Template"</span>, <span class="hljs-string">"Template"</span>, <span class="hljs-variable">$invoiceTemplate</span>-&gt;getTemplateId(), <span class="hljs-variable">$request</span>, <span class="hljs-variable">$invoiceTemplate</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$invoiceTemplate</span>;</div></div></div></div></body></html>

View File

@@ -0,0 +1,16 @@
<!DOCTYPE html><html lang="en"><head><title>invoice-templates/DeleteInvoiceTemplate</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-templates/DeleteInvoiceTemplate"><meta name="groc-project-path" content="invoice-templates/DeleteInvoiceTemplate.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-templates/DeleteInvoiceTemplate.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="delete-invoice-template-sample">Delete Invoice Template Sample</h1>
<p>This sample code demonstrate how you can delete
an invoice template</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/** <span class="hljs-doctag">@var</span> Template $template */</span>
<span class="hljs-variable">$template</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateInvoiceTemplate.php'</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Template</span>;
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="delete-invoice-template">Delete Invoice Template</h3>
<p>Delete invoice object by calling the
<code>delete</code> method
on the Invoice Template class by passing a valid
notification object
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$deleteStatus</span> = <span class="hljs-variable">$template</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>) {</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">"Delete Invoice Template"</span>, <span class="hljs-string">"Template"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$deleteStatus</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">"Delete Invoice Template"</span>, <span class="hljs-string">"Template"</span>, <span class="hljs-variable">$template</span>-&gt;getTemplateId(), <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>);</div></div></div></div></body></html>

View File

@@ -0,0 +1,13 @@
<!DOCTYPE html><html lang="en"><head><title>invoice-templates/GetAllInvoiceTemplates</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-templates/GetAllInvoiceTemplates"><meta name="groc-project-path" content="invoice-templates/GetAllInvoiceTemplates.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-templates/GetAllInvoiceTemplates.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">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Templates</span>;
<span class="hljs-keyword">require</span> <span class="hljs-string">'CreateInvoiceTemplate.php'</span>;
<span class="hljs-keyword">try</span> {
<span class="hljs-variable">$templates</span> = Templates::getAll(<span class="hljs-keyword">array</span>(<span class="hljs-string">"fields"</span> =&gt; <span class="hljs-string">"all"</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>) {</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">"Get all Templates"</span>, <span class="hljs-string">"Templates"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</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">"Get all Templates"</span>, <span class="hljs-string">"Templates"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$templates</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$templates</span>;</div></div></div></div></body></html>

View File

@@ -0,0 +1,19 @@
<!DOCTYPE html><html lang="en"><head><title>invoice-templates/GetInvoiceTemplate</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-templates/GetInvoiceTemplate"><meta name="groc-project-path" content="invoice-templates/GetInvoiceTemplate.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-templates/GetInvoiceTemplate.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="retrieve-invoice-template-sample">Retrieve Invoice Template Sample</h1>
<p>This sample code demonstrate how you can get
an invoice template using templateId.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Template</span>;
<span class="hljs-variable">$invoiceTemplate</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateInvoiceTemplate.php'</span>;
<span class="hljs-comment">/** <span class="hljs-doctag">@var</span> Template $invoiceTemplate */</span>
<span class="hljs-variable">$templateId</span> = <span class="hljs-variable">$invoiceTemplate</span>-&gt;getTemplateId();</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="retrieve-invoice-template">Retrieve Invoice Template</h3>
<p>Retrieve the invoice template object by calling the
static <code>get</code> method
on the Template class by passing a valid
Template ID
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
<span class="hljs-variable">$template</span> = Template::get(<span class="hljs-variable">$templateId</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>) {</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">"Get Invoice Template"</span>, <span class="hljs-string">"Template"</span>, <span class="hljs-variable">$template</span>-&gt;getTemplateId(), <span class="hljs-variable">$templateId</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">"Get Invoice Template"</span>, <span class="hljs-string">"Template"</span>, <span class="hljs-variable">$template</span>-&gt;getTemplateId(), <span class="hljs-variable">$templateId</span>, <span class="hljs-variable">$template</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$template</span>;</div></div></div></div></body></html>

View File

@@ -0,0 +1,12 @@
<!DOCTYPE html><html lang="en"><head><title>invoice-templates/UpdateInvoiceTemplate</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-templates/UpdateInvoiceTemplate"><meta name="groc-project-path" content="invoice-templates/UpdateInvoiceTemplate.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-templates/UpdateInvoiceTemplate.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="update-invoice-sample">Update Invoice Sample</h1>
<p>This sample code demonstrate how you can update
an invoice.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/** <span class="hljs-doctag">@var</span> Template $template */</span>
<span class="hljs-variable">$template</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'GetInvoiceTemplate.php'</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Template</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="update-invoice">Update Invoice</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-variable">$template</span>-&gt;setUnitOfMeasure(<span class="hljs-string">"QUANTITY"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="note-these-are-the-work-around-added-to-the">NOTE: These are the work-around added to the</h3>
<p>sample, to get past the bug in PayPal APIs.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$template</span>-&gt;setCustom(<span class="hljs-keyword">null</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>For Sample Purposes Only.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$request</span> = <span class="hljs-keyword">clone</span> <span class="hljs-variable">$template</span>;
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="update-invoice-template">Update Invoice Template</h3>
<p>Update an invoice by calling the invoice-&gt;update() method
with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$template</span>-&gt;update(<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">"Invoice Template Updated"</span>, <span class="hljs-string">"Invoice"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$request</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">"Invoice Template Updated"</span>, <span class="hljs-string">"Invoice"</span>, <span class="hljs-variable">$template</span>-&gt;getTemplateId(), <span class="hljs-variable">$request</span>, <span class="hljs-variable">$template</span>);</div></div></div></div></body></html>

View File

@@ -225,6 +225,7 @@ if (PHP_SAPI == 'cli') {
<li><a href="#experience">Payment Experience</a></li>
<li><a href="#notifications">Notifications</a></li>
<li><a href="#invoice">Invoice</a></li>
<li><a href="#invoice-templates">Invoice Templates</a></li>
<li><a href="#identity">Identity (LIPP)</a></li>
</ul>
@@ -1343,6 +1344,73 @@ if (PHP_SAPI == 'cli') {
</ul>
</div>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 id="invoice-templates" class="panel-title"><a
href="https://developer.paypal.com/docs/api/invoicing/#templates"
target="_blank">Invoice Templates</a></h3>
</div>
<!-- List group -->
<ul class="list-group">
<li class="list-group-item">
<div class="row">
<div class="col-md-8"><h5>Create Invoice Template</h5></div>
<div class="col-md-4">
<a href="invoice-templates/CreateInvoiceTemplate.php" class="btn btn-primary pull-left execute"> Try It <i
class="fa fa-play-circle-o"></i></a>
<a href="doc/invoice-templates/CreateInvoiceTemplate.html" class="btn btn-default pull-right">Source <i
class="fa fa-file-code-o"></i></a>
</div>
</div>
</li>
<li class="list-group-item">
<div class="row">
<div class="col-md-8"><h5>Get Invoice Template</h5></div>
<div class="col-md-4">
<a href="invoice-templates/GetInvoiceTemplate.php" class="btn btn-primary pull-left execute"> Try It <i
class="fa fa-play-circle-o"></i></a>
<a href="doc/invoice-templates/GetInvoiceTemplate.html" class="btn btn-default pull-right">Source <i
class="fa fa-file-code-o"></i></a>
</div>
</div>
</li>
<li class="list-group-item">
<div class="row">
<div class="col-md-8"><h5>Update Invoice Template</h5></div>
<div class="col-md-4">
<a href="invoice-templates/UpdateInvoiceTemplate.php" class="btn btn-primary pull-left execute"> Try It <i
class="fa fa-play-circle-o"></i></a>
<a href="doc/invoice-templates/UpdateInvoiceTemplate.html" class="btn btn-default pull-right">Source <i
class="fa fa-file-code-o"></i></a>
</div>
</div>
</li>
<li class="list-group-item">
<div class="row">
<div class="col-md-8"><h5>Delete an Invoice Template</h5></div>
<div class="col-md-4">
<a href="invoice-templates/DeleteInvoiceTemplate.php" class="btn btn-primary pull-left execute"> Try It <i
class="fa fa-play-circle-o"></i></a>
<a href="doc/invoice-templates/DeleteInvoiceTemplate.html" class="btn btn-default pull-right">Source <i
class="fa fa-file-code-o"></i></a>
</div>
</div>
</li>
<li class="list-group-item">
<div class="row">
<div class="col-md-8"><h5>Get All Invoice Templates</h5></div>
<div class="col-md-4">
<a href="invoice-templates/GetAllInvoiceTemplates.php" class="btn btn-primary pull-left execute"> Try It <i
class="fa fa-play-circle-o"></i></a>
<a href="doc/invoice-templates/GetAllInvoiceTemplates.html" class="btn btn-default pull-right">Source <i
class="fa fa-file-code-o"></i></a>
</div>
</div>
</li>
</ul>
</div>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 id="identity" class="panel-title"><a

View File

@@ -0,0 +1,72 @@
<?php
// # Create Invoice Template Sample
// This sample code demonstrate how you can create
// an invoice template.
use PayPal\Api\Currency;
use PayPal\Api\InvoiceItem;
use PayPal\Api\MerchantInfo;
use PayPal\Api\Template;
use PayPal\Api\TemplateData;
use PayPal\Api\TemplateSettings;
use PayPal\Api\TemplateSettingsMetadata;
require __DIR__ . '/../bootstrap.php';
// ### Invoice Template Item
$invoiceTemplateDataItem = new InvoiceItem();
$invoiceTemplateDataItem
->setName("Nutri Bullet")
->setQuantity(1)
->setUnitPrice(new Currency('{ "currency": "USD", "value": "50.00" }'));
// ### Invoice Template Data
$invoiceTemplateData = new TemplateData();
$invoiceTemplateData
->setTaxCalculatedAfterDiscount(false)
->setTaxInclusive(false)
->setNote("Thank you for your business")
->setLogoUrl("https://pics.paypal.com/v1/images/redDot.jpeg")
->addItem($invoiceTemplateDataItem)
->setMerchantInfo(new MerchantInfo('{ "email": "jaypatel512-facilitator@hotmail.com" }'));
// ### Template Settings
$displayPreferences = new TemplateSettingsMetadata();
$displayPreferences->setHidden(true);
$settingDate = new TemplateSettings();
$settingDate
->setFieldName("items.date")
->setDisplayPreference($displayPreferences);
// ### Template
$invoiceTemplate = new Template();
$invoiceTemplate
->setName("Hours Template" . rand())
->setDefault(true)
->setUnitOfMeasure("HOURS")
->setTemplateData($invoiceTemplateData)
// This is another way of initializing the object.
->addSetting(new TemplateSettings('{ "field_name": "custom", "display_preference": { "hidden": true } }'))
->addSetting($settingDate);
// For Sample Purposes Only.
$request = clone $invoiceTemplate;
try {
// ### Create Invoice Template
// Create an invoice by calling the invoice->create() method
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
$invoiceTemplate->create($apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Create Invoice Template", "Template", null, $request, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Create Invoice Template", "Template", $invoiceTemplate->getTemplateId(), $request, $invoiceTemplate);
return $invoiceTemplate;

View File

@@ -0,0 +1,28 @@
<?php
// # Delete Invoice Template Sample
// This sample code demonstrate how you can delete
// an invoice template
/** @var Template $template */
$template = require 'CreateInvoiceTemplate.php';
use PayPal\Api\Template;
try {
// ### Delete Invoice Template
// Delete invoice object by calling the
// `delete` method
// on the Invoice Template class by passing a valid
// notification object
// (See bootstrap.php for more on `ApiContext`)
$deleteStatus = $template->delete($apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Delete Invoice Template", "Template", null, $deleteStatus, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Delete Invoice Template", "Template", $template->getTemplateId(), null, null);

View File

@@ -0,0 +1,18 @@
<?php
use PayPal\Api\Templates;
require 'CreateInvoiceTemplate.php';
try {
$templates = Templates::getAll(array("fields" => "all"), $apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Get all Templates", "Templates", null, null, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Get all Templates", "Templates", null, null, $templates);
return $templates;

View File

@@ -0,0 +1,31 @@
<?php
// # Retrieve Invoice Template Sample
// This sample code demonstrate how you can get
// an invoice template using templateId.
use PayPal\Api\Template;
$invoiceTemplate = require 'CreateInvoiceTemplate.php';
/** @var Template $invoiceTemplate */
$templateId = $invoiceTemplate->getTemplateId();
// ### Retrieve Invoice Template
// Retrieve the invoice template object by calling the
// static `get` method
// on the Template class by passing a valid
// Template ID
// (See bootstrap.php for more on `ApiContext`)
try {
$template = Template::get($templateId, $apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Get Invoice Template", "Template", $template->getTemplateId(), $templateId, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Get Invoice Template", "Template", $template->getTemplateId(), $templateId, $template);
return $template;

View File

@@ -0,0 +1,33 @@
<?php
// # Update Invoice Sample
// This sample code demonstrate how you can update
// an invoice.
/** @var Template $template */
$template = require 'GetInvoiceTemplate.php';
use PayPal\Api\Template;
// ### Update Invoice
$template->setUnitOfMeasure("QUANTITY");
// ### NOTE: These are the work-around added to the
// sample, to get past the bug in PayPal APIs.
$template->setCustom(null);
// For Sample Purposes Only.
$request = clone $template;
try {
// ### Update Invoice Template
// Update an invoice by calling the invoice->update() method
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
$template->update($apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Invoice Template Updated", "Invoice", null, $request, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Invoice Template Updated", "Invoice", $template->getTemplateId(), $request, $template);

View File

@@ -39,6 +39,7 @@ class RefundDetailTest extends \PHPUnit_Framework_TestCase
$obj = new RefundDetail(self::getJson());
$this->assertNotNull($obj);
$this->assertNotNull($obj->getType());
$this->assertNotNull($obj->getTransactionId());
$this->assertNotNull($obj->getDate());
$this->assertNotNull($obj->getNote());
$this->assertNotNull($obj->getAmount());
@@ -53,6 +54,7 @@ class RefundDetailTest extends \PHPUnit_Framework_TestCase
public function testGetters($obj)
{
$this->assertEquals($obj->getType(), "TestSample");
$this->assertEquals($obj->getTransactionId(), "TestSample");
$this->assertEquals($obj->getDate(), "TestSample");
$this->assertEquals($obj->getNote(), "TestSample");
$this->assertEquals($obj->getAmount(), CurrencyTest::getObject());

View File

@@ -2,7 +2,6 @@
namespace PayPal\Test\Api;
use PayPal\Common\PayPalModel;
use PayPal\Api\TemplateData;
/**