forked from LiveCarta/PayPal-PHP-SDK
Add samples for Invoice Template API
This commit is contained in:
@@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
namespace PayPal\Api;
|
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
|
* Class Template
|
||||||
@@ -18,9 +21,8 @@ use PayPal\Common\PayPalModel;
|
|||||||
* @property \PayPal\Api\TemplateSettings[] settings
|
* @property \PayPal\Api\TemplateSettings[] settings
|
||||||
* @property string unit_of_measure
|
* @property string unit_of_measure
|
||||||
* @property bool custom
|
* @property bool custom
|
||||||
* @property \PayPal\Api\Links[] links
|
|
||||||
*/
|
*/
|
||||||
class Template extends PayPalModel
|
class Template extends PayPalResourceModel
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Unique identifier id of the template.
|
* Unique identifier id of the template.
|
||||||
@@ -214,56 +216,94 @@ class Template extends PayPalModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets Links
|
* Retrieve the details for a particular template by passing the template ID to the request URI.
|
||||||
*
|
*
|
||||||
* @param \PayPal\Api\Links[] $links
|
* @param string $templateId
|
||||||
*
|
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
|
||||||
* @return $this
|
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
|
||||||
|
* @return Template
|
||||||
*/
|
*/
|
||||||
public function setLinks($links)
|
public static function get($templateId, $apiContext = null, $restCall = null)
|
||||||
{
|
{
|
||||||
$this->links = $links;
|
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;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets Links
|
* 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.
|
||||||
*
|
*
|
||||||
* @return \PayPal\Api\Links[]
|
* @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 getLinks()
|
public function update($apiContext = null, $restCall = null)
|
||||||
{
|
{
|
||||||
return $this->links;
|
ArgumentValidator::validate($this->getTemplateId(), "Id");
|
||||||
}
|
$payLoad = $this->toJSON();
|
||||||
|
$json = self::executeCall(
|
||||||
/**
|
"/v1/invoicing/templates/{$this->getTemplateId()}",
|
||||||
* Append Links to the list.
|
"PUT",
|
||||||
*
|
$payLoad,
|
||||||
* @param \PayPal\Api\Links $links
|
null,
|
||||||
* @return $this
|
$apiContext,
|
||||||
*/
|
$restCall
|
||||||
public function addLink($links)
|
|
||||||
{
|
|
||||||
if (!$this->getLinks()) {
|
|
||||||
return $this->setLinks(array($links));
|
|
||||||
} else {
|
|
||||||
return $this->setLinks(
|
|
||||||
array_merge($this->getLinks(), array($links))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove Links from the list.
|
|
||||||
*
|
|
||||||
* @param \PayPal\Api\Links $links
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function removeLink($links)
|
|
||||||
{
|
|
||||||
return $this->setLinks(
|
|
||||||
array_diff($this->getLinks(), array($links))
|
|
||||||
);
|
);
|
||||||
|
$this->fromJson($json);
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace PayPal\Api;
|
namespace PayPal\Api;
|
||||||
|
|
||||||
use PayPal\Common\PayPalResourceModel;
|
use PayPal\Common\PayPalResourceModel;
|
||||||
|
use PayPal\Transport\PayPalRestCall;
|
||||||
use PayPal\Validation\ArgumentValidator;
|
use PayPal\Validation\ArgumentValidator;
|
||||||
use PayPal\Api\Template;
|
use PayPal\Api\Template;
|
||||||
use PayPal\Rest\ApiContext;
|
use PayPal\Rest\ApiContext;
|
||||||
@@ -237,6 +238,8 @@ class Templates extends PayPalResourceModel
|
|||||||
/**
|
/**
|
||||||
* Retrieve the details for a particular template by passing the template ID to the request URI.
|
* 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 string $templateId
|
||||||
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
|
* @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
|
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
|
||||||
@@ -267,7 +270,7 @@ class Templates extends PayPalResourceModel
|
|||||||
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
|
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
|
||||||
* @return Templates
|
* @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');
|
ArgumentValidator::validate($params, 'params');
|
||||||
$payLoad = "";
|
$payLoad = "";
|
||||||
@@ -286,78 +289,4 @@ class Templates extends PayPalResourceModel
|
|||||||
$ret->fromJson($json);
|
$ret->fromJson($json);
|
||||||
return $ret;
|
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->getId(), "Id");
|
|
||||||
$payLoad = "";
|
|
||||||
self::executeCall(
|
|
||||||
"/v1/invoicing/templates/{$this->getId()}",
|
|
||||||
"DELETE",
|
|
||||||
$payLoad,
|
|
||||||
null,
|
|
||||||
$apiContext,
|
|
||||||
$restCall
|
|
||||||
);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a template.
|
|
||||||
*
|
|
||||||
* @param Template $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($template, $apiContext = null, $restCall = null)
|
|
||||||
{
|
|
||||||
ArgumentValidator::validate($template, 'template');
|
|
||||||
$payLoad = $template->toJSON();
|
|
||||||
$json = self::executeCall(
|
|
||||||
"/v1/invoicing/templates",
|
|
||||||
"POST",
|
|
||||||
$payLoad,
|
|
||||||
null,
|
|
||||||
$apiContext,
|
|
||||||
$restCall
|
|
||||||
);
|
|
||||||
$ret = new Template();
|
|
||||||
$ret->fromJson($json);
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 Template $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 update($template, $apiContext = null, $restCall = null)
|
|
||||||
{
|
|
||||||
ArgumentValidator::validate($this->getId(), "Id");
|
|
||||||
ArgumentValidator::validate($template, 'template');
|
|
||||||
$payLoad = $template->toJSON();
|
|
||||||
$json = self::executeCall(
|
|
||||||
"/v1/invoicing/templates/{$this->getId()}",
|
|
||||||
"PUT",
|
|
||||||
$payLoad,
|
|
||||||
null,
|
|
||||||
$apiContext,
|
|
||||||
$restCall
|
|
||||||
);
|
|
||||||
$ret = new Template();
|
|
||||||
$ret->fromJson($json);
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -225,6 +225,7 @@ if (PHP_SAPI == 'cli') {
|
|||||||
<li><a href="#experience">Payment Experience</a></li>
|
<li><a href="#experience">Payment Experience</a></li>
|
||||||
<li><a href="#notifications">Notifications</a></li>
|
<li><a href="#notifications">Notifications</a></li>
|
||||||
<li><a href="#invoice">Invoice</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>
|
<li><a href="#identity">Identity (LIPP)</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
@@ -1343,6 +1344,73 @@ if (PHP_SAPI == 'cli') {
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</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/GetNextInvoiceNumber.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/CreateInvoice.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/CreateThirdPartyInvoice.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/SendInvoice.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/UpdateInvoice.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 panel-primary">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<h3 id="identity" class="panel-title"><a
|
<h3 id="identity" class="panel-title"><a
|
||||||
|
|||||||
72
sample/invoice-templates/CreateInvoiceTemplate.php
Normal file
72
sample/invoice-templates/CreateInvoiceTemplate.php
Normal 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;
|
||||||
28
sample/invoice-templates/DeleteInvoiceTemplate.php
Normal file
28
sample/invoice-templates/DeleteInvoiceTemplate.php
Normal 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);
|
||||||
18
sample/invoice-templates/GetAllInvoiceTemplates.php
Normal file
18
sample/invoice-templates/GetAllInvoiceTemplates.php
Normal 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;
|
||||||
31
sample/invoice-templates/GetInvoiceTemplate.php
Normal file
31
sample/invoice-templates/GetInvoiceTemplate.php
Normal 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;
|
||||||
33
sample/invoice-templates/UpdateInvoiceTemplate.php
Normal file
33
sample/invoice-templates/UpdateInvoiceTemplate.php
Normal 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);
|
||||||
Reference in New Issue
Block a user