1 <?php
2
3 namespace PayPal\Api;
4
5 use PayPal\Common\PayPalResourceModel;
6 use PayPal\Rest\ApiContext;
7 use PayPal\Transport\PayPalRestCall;
8 use PayPal\Validation\ArgumentValidator;
9
10 /**
11 * Class Template
12 *
13 * Invoicing Template
14 *
15 * @package PayPal\Api
16 *
17 * @property string template_id
18 * @property string name
19 * @property bool default
20 * @property \PayPal\Api\TemplateData template_data
21 * @property \PayPal\Api\TemplateSettings[] settings
22 * @property string unit_of_measure
23 * @property bool custom
24 */
25 class Template extends PayPalResourceModel
26 {
27 /**
28 * Unique identifier id of the template.
29 *
30 * @param string $template_id
31 *
32 * @return $this
33 */
34 public function setTemplateId($template_id)
35 {
36 $this->template_id = $template_id;
37 return $this;
38 }
39
40 /**
41 * Unique identifier id of the template.
42 *
43 * @return string
44 */
45 public function getTemplateId()
46 {
47 return $this->template_id;
48 }
49
50 /**
51 * Name of the template.
52 *
53 * @param string $name
54 *
55 * @return $this
56 */
57 public function setName($name)
58 {
59 $this->name = $name;
60 return $this;
61 }
62
63 /**
64 * Name of the template.
65 *
66 * @return string
67 */
68 public function getName()
69 {
70 return $this->name;
71 }
72
73 /**
74 * Indicates that this template is merchant's default. There can be only one template which can be a default.
75 *
76 * @param bool $default
77 *
78 * @return $this
79 */
80 public function setDefault($default)
81 {
82 $this->default = $default;
83 return $this;
84 }
85
86 /**
87 * Indicates that this template is merchant's default. There can be only one template which can be a default.
88 *
89 * @return bool
90 */
91 public function getDefault()
92 {
93 return $this->default;
94 }
95
96 /**
97 * Customized invoice data which is saved as template
98 *
99 * @param \PayPal\Api\TemplateData $template_data
100 *
101 * @return $this
102 */
103 public function setTemplateData($template_data)
104 {
105 $this->template_data = $template_data;
106 return $this;
107 }
108
109 /**
110 * Customized invoice data which is saved as template
111 *
112 * @return \PayPal\Api\TemplateData
113 */
114 public function getTemplateData()
115 {
116 return $this->template_data;
117 }
118
119 /**
120 * Settings for each template
121 *
122 * @param \PayPal\Api\TemplateSettings[] $settings
123 *
124 * @return $this
125 */
126 public function setSettings($settings)
127 {
128 $this->settings = $settings;
129 return $this;
130 }
131
132 /**
133 * Settings for each template
134 *
135 * @return \PayPal\Api\TemplateSettings[]
136 */
137 public function getSettings()
138 {
139 return $this->settings;
140 }
141
142 /**
143 * Append Settings to the list.
144 *
145 * @param \PayPal\Api\TemplateSettings $templateSettings
146 * @return $this
147 */
148 public function addSetting($templateSettings)
149 {
150 if (!$this->getSettings()) {
151 return $this->setSettings(array($templateSettings));
152 } else {
153 return $this->setSettings(
154 array_merge($this->getSettings(), array($templateSettings))
155 );
156 }
157 }
158
159 /**
160 * Remove Settings from the list.
161 *
162 * @param \PayPal\Api\TemplateSettings $templateSettings
163 * @return $this
164 */
165 public function removeSetting($templateSettings)
166 {
167 return $this->setSettings(
168 array_diff($this->getSettings(), array($templateSettings))
169 );
170 }
171
172 /**
173 * Unit of measure for the template, possible values are Quantity, Hours, Amount.
174 *
175 * @param string $unit_of_measure
176 *
177 * @return $this
178 */
179 public function setUnitOfMeasure($unit_of_measure)
180 {
181 $this->unit_of_measure = $unit_of_measure;
182 return $this;
183 }
184
185 /**
186 * Unit of measure for the template, possible values are Quantity, Hours, Amount.
187 *
188 * @return string
189 */
190 public function getUnitOfMeasure()
191 {
192 return $this->unit_of_measure;
193 }
194
195 /**
196 * Indicates whether this is a custom template created by the merchant. Non custom templates are system generated
197 *
198 * @param bool $custom
199 *
200 * @return $this
201 */
202 public function setCustom($custom)
203 {
204 $this->custom = $custom;
205 return $this;
206 }
207
208 /**
209 * Indicates whether this is a custom template created by the merchant. Non custom templates are system generated
210 *
211 * @return bool
212 */
213 public function getCustom()
214 {
215 return $this->custom;
216 }
217
218 /**
219 * Retrieve the details for a particular template by passing the template ID to the request URI.
220 *
221 * @param string $templateId
222 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
223 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
224 * @return Template
225 */
226 public static function get($templateId, $apiContext = null, $restCall = null)
227 {
228 ArgumentValidator::validate($templateId, 'templateId');
229 $payLoad = "";
230 $json = self::executeCall(
231 "/v1/invoicing/templates/$templateId",
232 "GET",
233 $payLoad,
234 null,
235 $apiContext,
236 $restCall
237 );
238 $ret = new Template();
239 $ret->fromJson($json);
240 return $ret;
241 }
242
243 /**
244 * Delete a particular template by passing the template ID to the request URI.
245 *
246 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
247 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
248 * @return bool
249 */
250 public function delete($apiContext = null, $restCall = null)
251 {
252 ArgumentValidator::validate($this->getTemplateId(), "Id");
253 $payLoad = "";
254 self::executeCall(
255 "/v1/invoicing/templates/{$this->getTemplateId()}",
256 "DELETE",
257 $payLoad,
258 null,
259 $apiContext,
260 $restCall
261 );
262 return true;
263 }
264
265 /**
266 * Creates a template.
267 *
268 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
269 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
270 * @return Template
271 */
272 public function create($apiContext = null, $restCall = null)
273 {
274 $json = self::executeCall(
275 "/v1/invoicing/templates",
276 "POST",
277 $this->toJSON(),
278 null,
279 $apiContext,
280 $restCall
281 );
282 $this->fromJson($json);
283 return $this;
284 }
285
286 /**
287 * 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.
288 *
289 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
290 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
291 * @return Template
292 */
293 public function update($apiContext = null, $restCall = null)
294 {
295 ArgumentValidator::validate($this->getTemplateId(), "Id");
296 $payLoad = $this->toJSON();
297 $json = self::executeCall(
298 "/v1/invoicing/templates/{$this->getTemplateId()}",
299 "PUT",
300 $payLoad,
301 null,
302 $apiContext,
303 $restCall
304 );
305 $this->fromJson($json);
306 return $this;
307 }
308
309 }
310