Invoicing Template
Inheritance: extends PayPal\Common\PayPalResourceModel
示例#1
0
 /**
  * @depends testSerializationDeserialization
  * @param Template $obj
  */
 public function testGetters($obj)
 {
     $this->assertEquals($obj->getTemplateId(), "TestSample");
     $this->assertEquals($obj->getName(), "TestSample");
     $this->assertEquals($obj->getDefault(), true);
     $this->assertEquals($obj->getTemplateData(), TemplateDataTest::getObject());
     $this->assertEquals($obj->getSettings(), TemplateSettingsTest::getObject());
     $this->assertEquals($obj->getUnitOfMeasure(), "TestSample");
     $this->assertEquals($obj->getCustom(), true);
 }
示例#2
0
 /**
  * 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
  * @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;
 }
<?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;
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": "*****@*****.**" }'));
// ### 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)->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);