1 <?php
2
3 namespace PayPal\Api;
4
5 use PayPal\Common\PayPalResourceModel;
6 use PayPal\Transport\PayPalRestCall;
7 use PayPal\Validation\ArgumentValidator;
8 use PayPal\Api\Template;
9 use PayPal\Rest\ApiContext;
10
11 /**
12 * Class Templates
13 *
14 * List of templates belonging to merchant.
15 *
16 * @package PayPal\Api
17 *
18 * @property \PayPal\Api\Address[] addresses
19 * @property string[] emails
20 * @property \PayPal\Api\Phone[] phones
21 * @property \PayPal\Api\Template[] templates
22 * @property \PayPal\Api\Links[] links
23 */
24 class Templates extends PayPalResourceModel
25 {
26 /**
27 * List of addresses in merchant's profile.
28 *
29 * @param \PayPal\Api\Address[] $addresses
30 *
31 * @return $this
32 */
33 public function setAddresses($addresses)
34 {
35 $this->addresses = $addresses;
36 return $this;
37 }
38
39 /**
40 * List of addresses in merchant's profile.
41 *
42 * @return \PayPal\Api\Address[]
43 */
44 public function getAddresses()
45 {
46 return $this->addresses;
47 }
48
49 /**
50 * Append Addresses to the list.
51 *
52 * @param \PayPal\Api\Address $address
53 * @return $this
54 */
55 public function addAddress($address)
56 {
57 if (!$this->getAddresses()) {
58 return $this->setAddresses(array($address));
59 } else {
60 return $this->setAddresses(
61 array_merge($this->getAddresses(), array($address))
62 );
63 }
64 }
65
66 /**
67 * Remove Addresses from the list.
68 *
69 * @param \PayPal\Api\Address $address
70 * @return $this
71 */
72 public function removeAddress($address)
73 {
74 return $this->setAddresses(
75 array_diff($this->getAddresses(), array($address))
76 );
77 }
78
79 /**
80 * List of emails in merchant's profile.
81 *
82 * @param string[] $emails
83 *
84 * @return $this
85 */
86 public function setEmails($emails)
87 {
88 $this->emails = $emails;
89 return $this;
90 }
91
92 /**
93 * List of emails in merchant's profile.
94 *
95 * @return string[]
96 */
97 public function getEmails()
98 {
99 return $this->emails;
100 }
101
102 /**
103 * Append Emails to the list.
104 *
105 * @param string $string
106 * @return $this
107 */
108 public function addEmail($string)
109 {
110 if (!$this->getEmails()) {
111 return $this->setEmails(array($string));
112 } else {
113 return $this->setEmails(
114 array_merge($this->getEmails(), array($string))
115 );
116 }
117 }
118
119 /**
120 * Remove Emails from the list.
121 *
122 * @param string $string
123 * @return $this
124 */
125 public function removeEmail($string)
126 {
127 return $this->setEmails(
128 array_diff($this->getEmails(), array($string))
129 );
130 }
131
132 /**
133 * List of phone numbers in merchant's profile.
134 *
135 * @param \PayPal\Api\Phone[] $phones
136 *
137 * @return $this
138 */
139 public function setPhones($phones)
140 {
141 $this->phones = $phones;
142 return $this;
143 }
144
145 /**
146 * List of phone numbers in merchant's profile.
147 *
148 * @return \PayPal\Api\Phone[]
149 */
150 public function getPhones()
151 {
152 return $this->phones;
153 }
154
155 /**
156 * Append Phones to the list.
157 *
158 * @param \PayPal\Api\Phone $phone
159 * @return $this
160 */
161 public function addPhone($phone)
162 {
163 if (!$this->getPhones()) {
164 return $this->setPhones(array($phone));
165 } else {
166 return $this->setPhones(
167 array_merge($this->getPhones(), array($phone))
168 );
169 }
170 }
171
172 /**
173 * Remove Phones from the list.
174 *
175 * @param \PayPal\Api\Phone $phone
176 * @return $this
177 */
178 public function removePhone($phone)
179 {
180 return $this->setPhones(
181 array_diff($this->getPhones(), array($phone))
182 );
183 }
184
185 /**
186 * Array of templates.
187 *
188 * @param \PayPal\Api\Template[] $templates
189 *
190 * @return $this
191 */
192 public function setTemplates($templates)
193 {
194 $this->templates = $templates;
195 return $this;
196 }
197
198 /**
199 * Array of templates.
200 *
201 * @return \PayPal\Api\Template[]
202 */
203 public function getTemplates()
204 {
205 return $this->templates;
206 }
207
208 /**
209 * Append Templates to the list.
210 *
211 * @param \PayPal\Api\Template $template
212 * @return $this
213 */
214 public function addTemplate($template)
215 {
216 if (!$this->getTemplates()) {
217 return $this->setTemplates(array($template));
218 } else {
219 return $this->setTemplates(
220 array_merge($this->getTemplates(), array($template))
221 );
222 }
223 }
224
225 /**
226 * Remove Templates from the list.
227 *
228 * @param \PayPal\Api\Template $template
229 * @return $this
230 */
231 public function removeTemplate($template)
232 {
233 return $this->setTemplates(
234 array_diff($this->getTemplates(), array($template))
235 );
236 }
237
238 /**
239 * Retrieve the details for a particular template by passing the template ID to the request URI.
240 *
241 * @deprecated Please use `Template::get()` instead.
242 * @see Template::get
243 * @param string $templateId
244 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
245 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
246 * @return Template
247 */
248 public static function get($templateId, $apiContext = null, $restCall = null)
249 {
250 ArgumentValidator::validate($templateId, 'templateId');
251 $payLoad = "";
252 $json = self::executeCall(
253 "/v1/invoicing/templates/$templateId",
254 "GET",
255 $payLoad,
256 null,
257 $apiContext,
258 $restCall
259 );
260 $ret = new Template();
261 $ret->fromJson($json);
262 return $ret;
263 }
264
265 /**
266 * Retrieves the template information of the merchant.
267 *
268 * @param array $params
269 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
270 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
271 * @return Templates
272 */
273 public static function getAll($params = array(), $apiContext = null, $restCall = null)
274 {
275 ArgumentValidator::validate($params, 'params');
276 $payLoad = "";
277 $allowedParams = array(
278 'fields' => 1,
279 );
280 $json = self::executeCall(
281 "/v1/invoicing/templates/" . "?" . http_build_query(array_intersect_key($params, $allowedParams)),
282 "GET",
283 $payLoad,
284 null,
285 $apiContext,
286 $restCall
287 );
288 $ret = new Templates();
289 $ret->fromJson($json);
290 return $ret;
291 }
292 }
293