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 use PayPal\Validation\UrlValidator;
10
11 /**
12 * Class Invoice
13 *
14 * Detailed invoice information.
15 *
16 * @package PayPal\Api
17 *
18 * @property string id
19 * @property string number
20 * @property string template_id
21 * @property string uri
22 * @property string status
23 * @property \PayPal\Api\MerchantInfo merchant_info
24 * @property \PayPal\Api\BillingInfo[] billing_info
25 * @property \PayPal\Api\Participant[] cc_info
26 * @property \PayPal\Api\ShippingInfo shipping_info
27 * @property \PayPal\Api\InvoiceItem[] items
28 * @property string invoice_date
29 * @property \PayPal\Api\PaymentTerm payment_term
30 * @property string reference
31 * @property \PayPal\Api\Cost discount
32 * @property \PayPal\Api\ShippingCost shipping_cost
33 * @property \PayPal\Api\CustomAmount custom
34 * @property bool allow_partial_payment
35 * @property \PayPal\Api\Currency minimum_amount_due
36 * @property bool tax_calculated_after_discount
37 * @property bool tax_inclusive
38 * @property string terms
39 * @property string note
40 * @property string merchant_memo
41 * @property string logo_url
42 * @property \PayPal\Api\Currency total_amount
43 * @property \PayPal\Api\PaymentDetail[] payments
44 * @property \PayPal\Api\RefundDetail[] refunds
45 * @property \PayPal\Api\Metadata metadata
46 * @property \PayPal\Api\PaymentSummary paid_amount
47 * @property \PayPal\Api\PaymentSummary refunded_amount
48 * @property \PayPal\Api\FileAttachment[] attachments
49 */
50 class Invoice extends PayPalResourceModel
51 {
52 /**
53 * The unique invoice resource identifier.
54 *
55 * @param string $id
56 *
57 * @return $this
58 */
59 public function setId($id)
60 {
61 $this->id = $id;
62 return $this;
63 }
64
65 /**
66 * The unique invoice resource identifier.
67 *
68 * @return string
69 */
70 public function getId()
71 {
72 return $this->id;
73 }
74
75 /**
76 * Unique number that appears on the invoice. If left blank will be auto-incremented from the last number. 25 characters max.
77 *
78 * @param string $number
79 *
80 * @return $this
81 */
82 public function setNumber($number)
83 {
84 $this->number = $number;
85 return $this;
86 }
87
88 /**
89 * Unique number that appears on the invoice. If left blank will be auto-incremented from the last number. 25 characters max.
90 *
91 * @return string
92 */
93 public function getNumber()
94 {
95 return $this->number;
96 }
97
98 /**
99 * The template ID used for the invoice. Useful for copy functionality.
100 *
101 * @param string $template_id
102 *
103 * @return $this
104 */
105 public function setTemplateId($template_id)
106 {
107 $this->template_id = $template_id;
108 return $this;
109 }
110
111 /**
112 * The template ID used for the invoice. Useful for copy functionality.
113 *
114 * @return string
115 */
116 public function getTemplateId()
117 {
118 return $this->template_id;
119 }
120
121 /**
122 * URI of the invoice resource.
123 *
124 * @param string $uri
125 *
126 * @return $this
127 */
128 public function setUri($uri)
129 {
130 $this->uri = $uri;
131 return $this;
132 }
133
134 /**
135 * URI of the invoice resource.
136 *
137 * @return string
138 */
139 public function getUri()
140 {
141 return $this->uri;
142 }
143
144 /**
145 * Status of the invoice.
146 * Valid Values: ["DRAFT", "SENT", "PAID", "MARKED_AS_PAID", "CANCELLED", "REFUNDED", "PARTIALLY_REFUNDED", "MARKED_AS_REFUNDED", "UNPAID", "PAYMENT_PENDING"]
147 *
148 * @param string $status
149 *
150 * @return $this
151 */
152 public function setStatus($status)
153 {
154 $this->status = $status;
155 return $this;
156 }
157
158 /**
159 * Status of the invoice.
160 *
161 * @return string
162 */
163 public function getStatus()
164 {
165 return $this->status;
166 }
167
168 /**
169 * Information about the merchant who is sending the invoice.
170 *
171 * @param \PayPal\Api\MerchantInfo $merchant_info
172 *
173 * @return $this
174 */
175 public function setMerchantInfo($merchant_info)
176 {
177 $this->merchant_info = $merchant_info;
178 return $this;
179 }
180
181 /**
182 * Information about the merchant who is sending the invoice.
183 *
184 * @return \PayPal\Api\MerchantInfo
185 */
186 public function getMerchantInfo()
187 {
188 return $this->merchant_info;
189 }
190
191 /**
192 * The required invoice recipient email address and any optional billing information. One recipient is supported.
193 *
194 * @param \PayPal\Api\BillingInfo[] $billing_info
195 *
196 * @return $this
197 */
198 public function setBillingInfo($billing_info)
199 {
200 $this->billing_info = $billing_info;
201 return $this;
202 }
203
204 /**
205 * The required invoice recipient email address and any optional billing information. One recipient is supported.
206 *
207 * @return \PayPal\Api\BillingInfo[]
208 */
209 public function getBillingInfo()
210 {
211 return $this->billing_info;
212 }
213
214 /**
215 * Append BillingInfo to the list.
216 *
217 * @param \PayPal\Api\BillingInfo $billingInfo
218 * @return $this
219 */
220 public function addBillingInfo($billingInfo)
221 {
222 if (!$this->getBillingInfo()) {
223 return $this->setBillingInfo(array($billingInfo));
224 } else {
225 return $this->setBillingInfo(
226 array_merge($this->getBillingInfo(), array($billingInfo))
227 );
228 }
229 }
230
231 /**
232 * Remove BillingInfo from the list.
233 *
234 * @param \PayPal\Api\BillingInfo $billingInfo
235 * @return $this
236 */
237 public function removeBillingInfo($billingInfo)
238 {
239 return $this->setBillingInfo(
240 array_diff($this->getBillingInfo(), array($billingInfo))
241 );
242 }
243
244 /**
245 * 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.
246 *
247 * @param \PayPal\Api\Participant[] $cc_info
248 *
249 * @return $this
250 */
251 public function setCcInfo($cc_info)
252 {
253 $this->cc_info = $cc_info;
254 return $this;
255 }
256
257 /**
258 * 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.
259 *
260 * @return \PayPal\Api\Participant[]
261 */
262 public function getCcInfo()
263 {
264 return $this->cc_info;
265 }
266
267 /**
268 * Append CcInfo to the list.
269 *
270 * @param \PayPal\Api\Participant $participant
271 * @return $this
272 */
273 public function addCcInfo($participant)
274 {
275 if (!$this->getCcInfo()) {
276 return $this->setCcInfo(array($participant));
277 } else {
278 return $this->setCcInfo(
279 array_merge($this->getCcInfo(), array($participant))
280 );
281 }
282 }
283
284 /**
285 * Remove CcInfo from the list.
286 *
287 * @param \PayPal\Api\Participant $participant
288 * @return $this
289 */
290 public function removeCcInfo($participant)
291 {
292 return $this->setCcInfo(
293 array_diff($this->getCcInfo(), array($participant))
294 );
295 }
296
297 /**
298 * The shipping information for entities to whom items are being shipped.
299 *
300 * @param \PayPal\Api\ShippingInfo $shipping_info
301 *
302 * @return $this
303 */
304 public function setShippingInfo($shipping_info)
305 {
306 $this->shipping_info = $shipping_info;
307 return $this;
308 }
309
310 /**
311 * The shipping information for entities to whom items are being shipped.
312 *
313 * @return \PayPal\Api\ShippingInfo
314 */
315 public function getShippingInfo()
316 {
317 return $this->shipping_info;
318 }
319
320 /**
321 * The list of items to include in the invoice. Maximum value is 100 items per invoice.
322 *
323 * @param \PayPal\Api\InvoiceItem[] $items
324 *
325 * @return $this
326 */
327 public function setItems($items)
328 {
329 $this->items = $items;
330 return $this;
331 }
332
333 /**
334 * The list of items to include in the invoice. Maximum value is 100 items per invoice.
335 *
336 * @return \PayPal\Api\InvoiceItem[]
337 */
338 public function getItems()
339 {
340 return $this->items;
341 }
342
343 /**
344 * Append Items to the list.
345 *
346 * @param \PayPal\Api\InvoiceItem $invoiceItem
347 * @return $this
348 */
349 public function addItem($invoiceItem)
350 {
351 if (!$this->getItems()) {
352 return $this->setItems(array($invoiceItem));
353 } else {
354 return $this->setItems(
355 array_merge($this->getItems(), array($invoiceItem))
356 );
357 }
358 }
359
360 /**
361 * Remove Items from the list.
362 *
363 * @param \PayPal\Api\InvoiceItem $invoiceItem
364 * @return $this
365 */
366 public function removeItem($invoiceItem)
367 {
368 return $this->setItems(
369 array_diff($this->getItems(), array($invoiceItem))
370 );
371 }
372
373 /**
374 * The date when the invoice was enabled. The date format is *yyyy*-*MM*-*dd* *z* as defined in [Internet Date/Time Format](http://tools.ietf.org/html/rfc3339#section-5.6).
375 *
376 * @param string $invoice_date
377 *
378 * @return $this
379 */
380 public function setInvoiceDate($invoice_date)
381 {
382 $this->invoice_date = $invoice_date;
383 return $this;
384 }
385
386 /**
387 * The date when the invoice was enabled. The date format is *yyyy*-*MM*-*dd* *z* as defined in [Internet Date/Time Format](http://tools.ietf.org/html/rfc3339#section-5.6).
388 *
389 * @return string
390 */
391 public function getInvoiceDate()
392 {
393 return $this->invoice_date;
394 }
395
396 /**
397 * Optional. The payment deadline for the invoice. Value is either `term_type` or `due_date` but not both.
398 *
399 * @param \PayPal\Api\PaymentTerm $payment_term
400 *
401 * @return $this
402 */
403 public function setPaymentTerm($payment_term)
404 {
405 $this->payment_term = $payment_term;
406 return $this;
407 }
408
409 /**
410 * Optional. The payment deadline for the invoice. Value is either `term_type` or `due_date` but not both.
411 *
412 * @return \PayPal\Api\PaymentTerm
413 */
414 public function getPaymentTerm()
415 {
416 return $this->payment_term;
417 }
418
419 /**
420 * Reference data, such as PO number, to add to the invoice. Maximum length is 60 characters.
421 *
422 * @param string $reference
423 *
424 * @return $this
425 */
426 public function setReference($reference)
427 {
428 $this->reference = $reference;
429 return $this;
430 }
431
432 /**
433 * Reference data, such as PO number, to add to the invoice. Maximum length is 60 characters.
434 *
435 * @return string
436 */
437 public function getReference()
438 {
439 return $this->reference;
440 }
441
442 /**
443 * The invoice level discount, as a percent or an amount value.
444 *
445 * @param \PayPal\Api\Cost $discount
446 *
447 * @return $this
448 */
449 public function setDiscount($discount)
450 {
451 $this->discount = $discount;
452 return $this;
453 }
454
455 /**
456 * The invoice level discount, as a percent or an amount value.
457 *
458 * @return \PayPal\Api\Cost
459 */
460 public function getDiscount()
461 {
462 return $this->discount;
463 }
464
465 /**
466 * The shipping cost, as a percent or an amount value.
467 *
468 * @param \PayPal\Api\ShippingCost $shipping_cost
469 *
470 * @return $this
471 */
472 public function setShippingCost($shipping_cost)
473 {
474 $this->shipping_cost = $shipping_cost;
475 return $this;
476 }
477
478 /**
479 * The shipping cost, as a percent or an amount value.
480 *
481 * @return \PayPal\Api\ShippingCost
482 */
483 public function getShippingCost()
484 {
485 return $this->shipping_cost;
486 }
487
488 /**
489 * The custom amount to apply on an invoice. If you include a label, the amount cannot be empty.
490 *
491 * @param \PayPal\Api\CustomAmount $custom
492 *
493 * @return $this
494 */
495 public function setCustom($custom)
496 {
497 $this->custom = $custom;
498 return $this;
499 }
500
501 /**
502 * The custom amount to apply on an invoice. If you include a label, the amount cannot be empty.
503 *
504 * @return \PayPal\Api\CustomAmount
505 */
506 public function getCustom()
507 {
508 return $this->custom;
509 }
510
511 /**
512 * Indicates whether the invoice allows a partial payment. If set to `false`, invoice must be paid in full. If set to `true`, the invoice allows partial payments. Default is `false`.
513 *
514 * @param bool $allow_partial_payment
515 *
516 * @return $this
517 */
518 public function setAllowPartialPayment($allow_partial_payment)
519 {
520 $this->allow_partial_payment = $allow_partial_payment;
521 return $this;
522 }
523
524 /**
525 * Indicates whether the invoice allows a partial payment. If set to `false`, invoice must be paid in full. If set to `true`, the invoice allows partial payments. Default is `false`.
526 *
527 * @return bool
528 */
529 public function getAllowPartialPayment()
530 {
531 return $this->allow_partial_payment;
532 }
533
534 /**
535 * If `allow_partial_payment` is set to `true`, the minimum amount allowed for a partial payment.
536 *
537 * @param \PayPal\Api\Currency $minimum_amount_due
538 *
539 * @return $this
540 */
541 public function setMinimumAmountDue($minimum_amount_due)
542 {
543 $this->minimum_amount_due = $minimum_amount_due;
544 return $this;
545 }
546
547 /**
548 * If `allow_partial_payment` is set to `true`, the minimum amount allowed for a partial payment.
549 *
550 * @return \PayPal\Api\Currency
551 */
552 public function getMinimumAmountDue()
553 {
554 return $this->minimum_amount_due;
555 }
556
557 /**
558 * Indicates whether tax is calculated before or after a discount. If set to `false`, the tax is calculated before a discount. If set to `true`, the tax is calculated after a discount. Default is `false`.
559 *
560 * @param bool $tax_calculated_after_discount
561 *
562 * @return $this
563 */
564 public function setTaxCalculatedAfterDiscount($tax_calculated_after_discount)
565 {
566 $this->tax_calculated_after_discount = $tax_calculated_after_discount;
567 return $this;
568 }
569
570 /**
571 * Indicates whether tax is calculated before or after a discount. If set to `false`, the tax is calculated before a discount. If set to `true`, the tax is calculated after a discount. Default is `false`.
572 *
573 * @return bool
574 */
575 public function getTaxCalculatedAfterDiscount()
576 {
577 return $this->tax_calculated_after_discount;
578 }
579
580 /**
581 * Indicates whether the unit price includes tax. Default is `false`.
582 *
583 * @param bool $tax_inclusive
584 *
585 * @return $this
586 */
587 public function setTaxInclusive($tax_inclusive)
588 {
589 $this->tax_inclusive = $tax_inclusive;
590 return $this;
591 }
592
593 /**
594 * Indicates whether the unit price includes tax. Default is `false`.
595 *
596 * @return bool
597 */
598 public function getTaxInclusive()
599 {
600 return $this->tax_inclusive;
601 }
602
603 /**
604 * General terms of the invoice. 4000 characters max.
605 *
606 * @param string $terms
607 *
608 * @return $this
609 */
610 public function setTerms($terms)
611 {
612 $this->terms = $terms;
613 return $this;
614 }
615
616 /**
617 * General terms of the invoice. 4000 characters max.
618 *
619 * @return string
620 */
621 public function getTerms()
622 {
623 return $this->terms;
624 }
625
626 /**
627 * Note to the payer. 4000 characters max.
628 *
629 * @param string $note
630 *
631 * @return $this
632 */
633 public function setNote($note)
634 {
635 $this->note = $note;
636 return $this;
637 }
638
639 /**
640 * Note to the payer. 4000 characters max.
641 *
642 * @return string
643 */
644 public function getNote()
645 {
646 return $this->note;
647 }
648
649 /**
650 * A private bookkeeping memo for the merchant. Maximum length is 150 characters.
651 *
652 * @param string $merchant_memo
653 *
654 * @return $this
655 */
656 public function setMerchantMemo($merchant_memo)
657 {
658 $this->merchant_memo = $merchant_memo;
659 return $this;
660 }
661
662 /**
663 * A private bookkeeping memo for the merchant. Maximum length is 150 characters.
664 *
665 * @return string
666 */
667 public function getMerchantMemo()
668 {
669 return $this->merchant_memo;
670 }
671
672 /**
673 * Full URL of an external image to use as the logo. Maximum length is 4000 characters.
674 *
675 * @param string $logo_url
676 * @throws \InvalidArgumentException
677 * @return $this
678 */
679 public function setLogoUrl($logo_url)
680 {
681 UrlValidator::validate($logo_url, "LogoUrl");
682 $this->logo_url = $logo_url;
683 return $this;
684 }
685
686 /**
687 * Full URL of an external image to use as the logo. Maximum length is 4000 characters.
688 *
689 * @return string
690 */
691 public function getLogoUrl()
692 {
693 return $this->logo_url;
694 }
695
696 /**
697 * The total amount of the invoice.
698 *
699 * @param \PayPal\Api\Currency $total_amount
700 *
701 * @return $this
702 */
703 public function setTotalAmount($total_amount)
704 {
705 $this->total_amount = $total_amount;
706 return $this;
707 }
708
709 /**
710 * The total amount of the invoice.
711 *
712 * @return \PayPal\Api\Currency
713 */
714 public function getTotalAmount()
715 {
716 return $this->total_amount;
717 }
718
719 /**
720 * List of payment details for the invoice.
721 *
722 * @param \PayPal\Api\PaymentDetail[] $payments
723 *
724 * @return $this
725 */
726 public function setPayments($payments)
727 {
728 $this->payments = $payments;
729 return $this;
730 }
731
732 /**
733 * List of payment details for the invoice.
734 *
735 * @return \PayPal\Api\PaymentDetail[]
736 */
737 public function getPayments()
738 {
739 return $this->payments;
740 }
741
742 /**
743 * Append Payments to the list.
744 *
745 * @param \PayPal\Api\PaymentDetail $paymentDetail
746 * @return $this
747 */
748 public function addPayment($paymentDetail)
749 {
750 if (!$this->getPayments()) {
751 return $this->setPayments(array($paymentDetail));
752 } else {
753 return $this->setPayments(
754 array_merge($this->getPayments(), array($paymentDetail))
755 );
756 }
757 }
758
759 /**
760 * Remove Payments from the list.
761 *
762 * @param \PayPal\Api\PaymentDetail $paymentDetail
763 * @return $this
764 */
765 public function removePayment($paymentDetail)
766 {
767 return $this->setPayments(
768 array_diff($this->getPayments(), array($paymentDetail))
769 );
770 }
771
772 /**
773 * List of refund details for the invoice.
774 *
775 * @param \PayPal\Api\RefundDetail[] $refunds
776 *
777 * @return $this
778 */
779 public function setRefunds($refunds)
780 {
781 $this->refunds = $refunds;
782 return $this;
783 }
784
785 /**
786 * List of refund details for the invoice.
787 *
788 * @return \PayPal\Api\RefundDetail[]
789 */
790 public function getRefunds()
791 {
792 return $this->refunds;
793 }
794
795 /**
796 * Append Refunds to the list.
797 *
798 * @param \PayPal\Api\RefundDetail $refundDetail
799 * @return $this
800 */
801 public function addRefund($refundDetail)
802 {
803 if (!$this->getRefunds()) {
804 return $this->setRefunds(array($refundDetail));
805 } else {
806 return $this->setRefunds(
807 array_merge($this->getRefunds(), array($refundDetail))
808 );
809 }
810 }
811
812 /**
813 * Remove Refunds from the list.
814 *
815 * @param \PayPal\Api\RefundDetail $refundDetail
816 * @return $this
817 */
818 public function removeRefund($refundDetail)
819 {
820 return $this->setRefunds(
821 array_diff($this->getRefunds(), array($refundDetail))
822 );
823 }
824
825 /**
826 * Audit information for the invoice.
827 *
828 * @param \PayPal\Api\Metadata $metadata
829 *
830 * @return $this
831 */
832 public function setMetadata($metadata)
833 {
834 $this->metadata = $metadata;
835 return $this;
836 }
837
838 /**
839 * Audit information for the invoice.
840 *
841 * @return \PayPal\Api\Metadata
842 */
843 public function getMetadata()
844 {
845 return $this->metadata;
846 }
847
848 /**
849 * Any miscellaneous invoice data. Maximum length is 4000 characters.
850 * @deprecated Not publicly available
851 * @param string $additional_data
852 *
853 * @return $this
854 */
855 public function setAdditionalData($additional_data)
856 {
857 $this->additional_data = $additional_data;
858 return $this;
859 }
860
861 /**
862 * Any miscellaneous invoice data. Maximum length is 4000 characters.
863 * @deprecated Not publicly available
864 * @return string
865 */
866 public function getAdditionalData()
867 {
868 return $this->additional_data;
869 }
870
871 /**
872 * Payment summary of the invoice including amount paid through PayPal and other sources.
873 *
874 * @param \PayPal\Api\PaymentSummary $paid_amount
875 *
876 * @return $this
877 */
878 public function setPaidAmount($paid_amount)
879 {
880 $this->paid_amount = $paid_amount;
881 return $this;
882 }
883
884 /**
885 * Payment summary of the invoice including amount paid through PayPal and other sources.
886 *
887 * @return \PayPal\Api\PaymentSummary
888 */
889 public function getPaidAmount()
890 {
891 return $this->paid_amount;
892 }
893
894 /**
895 * Payment summary of the invoice including amount refunded through PayPal and other sources.
896 *
897 * @param \PayPal\Api\PaymentSummary $refunded_amount
898 *
899 * @return $this
900 */
901 public function setRefundedAmount($refunded_amount)
902 {
903 $this->refunded_amount = $refunded_amount;
904 return $this;
905 }
906
907 /**
908 * Payment summary of the invoice including amount refunded through PayPal and other sources.
909 *
910 * @return \PayPal\Api\PaymentSummary
911 */
912 public function getRefundedAmount()
913 {
914 return $this->refunded_amount;
915 }
916
917 /**
918 * List of files attached to the invoice.
919 *
920 * @param \PayPal\Api\FileAttachment[] $attachments
921 *
922 * @return $this
923 */
924 public function setAttachments($attachments)
925 {
926 $this->attachments = $attachments;
927 return $this;
928 }
929
930 /**
931 * List of files attached to the invoice.
932 *
933 * @return \PayPal\Api\FileAttachment[]
934 */
935 public function getAttachments()
936 {
937 return $this->attachments;
938 }
939
940 /**
941 * Append Attachments to the list.
942 *
943 * @param \PayPal\Api\FileAttachment $fileAttachment
944 * @return $this
945 */
946 public function addAttachment($fileAttachment)
947 {
948 if (!$this->getAttachments()) {
949 return $this->setAttachments(array($fileAttachment));
950 } else {
951 return $this->setAttachments(
952 array_merge($this->getAttachments(), array($fileAttachment))
953 );
954 }
955 }
956
957 /**
958 * Remove Attachments from the list.
959 *
960 * @param \PayPal\Api\FileAttachment $fileAttachment
961 * @return $this
962 */
963 public function removeAttachment($fileAttachment)
964 {
965 return $this->setAttachments(
966 array_diff($this->getAttachments(), array($fileAttachment))
967 );
968 }
969
970 /**
971 * Creates an invoice. Include invoice details including merchant information in the request.
972 *
973 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
974 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
975 * @return Invoice
976 */
977 public function create($apiContext = null, $restCall = null)
978 {
979 $payLoad = $this->toJSON();
980 $json = self::executeCall(
981 "/v1/invoicing/invoices",
982 "POST",
983 $payLoad,
984 null,
985 $apiContext,
986 $restCall
987 );
988 $this->fromJson($json);
989 return $this;
990 }
991
992 /**
993 * Searches for an invoice or invoices. Include a search object that specifies your search criteria in the request.
994 *
995 * @param Search $search
996 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
997 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
998 * @return InvoiceSearchResponse
999 */
1000 public static function search($search, $apiContext = null, $restCall = null)
1001 {
1002 ArgumentValidator::validate($search, 'search');
1003 $payLoad = $search->toJSON();
1004 $json = self::executeCall(
1005 "/v1/invoicing/search",
1006 "POST",
1007 $payLoad,
1008 null,
1009 $apiContext,
1010 $restCall
1011 );
1012 $ret = new InvoiceSearchResponse();
1013 $ret->fromJson($json);
1014 return $ret;
1015 }
1016
1017 /**
1018 * Sends an invoice, by ID, to a recipient. Optionally, set the `notify_merchant` query parameter to send the merchant an invoice update notification. By default, `notify_merchant` is `true`.
1019 *
1020 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
1021 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
1022 * @return bool
1023 */
1024 public function send($apiContext = null, $restCall = null)
1025 {
1026 ArgumentValidator::validate($this->getId(), "Id");
1027 $payLoad = "";
1028 self::executeCall(
1029 "/v1/invoicing/invoices/{$this->getId()}/send",
1030 "POST",
1031 $payLoad,
1032 null,
1033 $apiContext,
1034 $restCall
1035 );
1036 return true;
1037 }
1038
1039 /**
1040 * Sends a reminder about a specific invoice, by ID, to a recipient. Include a notification object that defines the reminder subject and other details in the JSON request body.
1041 *
1042 * @param Notification $notification
1043 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
1044 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
1045 * @return bool
1046 */
1047 public function remind($notification, $apiContext = null, $restCall = null)
1048 {
1049 ArgumentValidator::validate($this->getId(), "Id");
1050 ArgumentValidator::validate($notification, 'notification');
1051 $payLoad = $notification->toJSON();
1052 self::executeCall(
1053 "/v1/invoicing/invoices/{$this->getId()}/remind",
1054 "POST",
1055 $payLoad,
1056 null,
1057 $apiContext,
1058 $restCall
1059 );
1060 return true;
1061 }
1062
1063 /**
1064 * Cancels an invoice, by ID.
1065 *
1066 * @param CancelNotification $cancelNotification
1067 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
1068 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
1069 * @return bool
1070 */
1071 public function cancel($cancelNotification, $apiContext = null, $restCall = null)
1072 {
1073 ArgumentValidator::validate($this->getId(), "Id");
1074 ArgumentValidator::validate($cancelNotification, 'cancelNotification');
1075 $payLoad = $cancelNotification->toJSON();
1076 self::executeCall(
1077 "/v1/invoicing/invoices/{$this->getId()}/cancel",
1078 "POST",
1079 $payLoad,
1080 null,
1081 $apiContext,
1082 $restCall
1083 );
1084 return true;
1085 }
1086
1087 /**
1088 * Marks the status of a specified invoice, by ID, as paid. Include a payment detail object that defines the payment method and other details in the JSON request body.
1089 *
1090 * @param PaymentDetail $paymentDetail
1091 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
1092 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
1093 * @return bool
1094 */
1095 public function recordPayment($paymentDetail, $apiContext = null, $restCall = null)
1096 {
1097 ArgumentValidator::validate($this->getId(), "Id");
1098 ArgumentValidator::validate($paymentDetail, 'paymentDetail');
1099 $payLoad = $paymentDetail->toJSON();
1100 self::executeCall(
1101 "/v1/invoicing/invoices/{$this->getId()}/record-payment",
1102 "POST",
1103 $payLoad,
1104 null,
1105 $apiContext,
1106 $restCall
1107 );
1108 return true;
1109 }
1110
1111 /**
1112 * Marks the status of a specified invoice, by ID, as refunded. Include a refund detail object that defines the refund type and other details in the JSON request body.
1113 *
1114 * @param RefundDetail $refundDetail
1115 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
1116 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
1117 * @return bool
1118 */
1119 public function recordRefund($refundDetail, $apiContext = null, $restCall = null)
1120 {
1121 ArgumentValidator::validate($this->getId(), "Id");
1122 ArgumentValidator::validate($refundDetail, 'refundDetail');
1123 $payLoad = $refundDetail->toJSON();
1124 self::executeCall(
1125 "/v1/invoicing/invoices/{$this->getId()}/record-refund",
1126 "POST",
1127 $payLoad,
1128 null,
1129 $apiContext,
1130 $restCall
1131 );
1132 return true;
1133 }
1134
1135 /**
1136 * Gets the details for a specified invoice, by ID.
1137 *
1138 * @param string $invoiceId
1139 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
1140 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
1141 * @return Invoice
1142 */
1143 public static function get($invoiceId, $apiContext = null, $restCall = null)
1144 {
1145 ArgumentValidator::validate($invoiceId, 'invoiceId');
1146 $payLoad = "";
1147 $json = self::executeCall(
1148 "/v1/invoicing/invoices/$invoiceId",
1149 "GET",
1150 $payLoad,
1151 null,
1152 $apiContext,
1153 $restCall
1154 );
1155 $ret = new Invoice();
1156 $ret->fromJson($json);
1157 return $ret;
1158 }
1159
1160 /**
1161 * Lists some or all merchant invoices. Filters the response by any specified optional query string parameters.
1162 *
1163 * @param array $params
1164 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
1165 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
1166 * @return InvoiceSearchResponse
1167 */
1168 public static function getAll($params = array(), $apiContext = null, $restCall = null)
1169 {
1170 ArgumentValidator::validate($params, 'params');
1171
1172 $allowedParams = array(
1173 'page' => 1,
1174 'page_size' => 1,
1175 'total_count_required' => 1
1176 );
1177
1178 $payLoad = "";
1179 $json = self::executeCall(
1180 "/v1/invoicing/invoices/?" . http_build_query(array_intersect_key($params, $allowedParams)),
1181 "GET",
1182 $payLoad,
1183 null,
1184 $apiContext,
1185 $restCall
1186 );
1187 $ret = new InvoiceSearchResponse();
1188 $ret->fromJson($json);
1189 return $ret;
1190 }
1191
1192 /**
1193 * 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.
1194 *
1195 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
1196 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
1197 * @return Invoice
1198 */
1199 public function update($apiContext = null, $restCall = null)
1200 {
1201 ArgumentValidator::validate($this->getId(), "Id");
1202 $payLoad = $this->toJSON();
1203 $json = self::executeCall(
1204 "/v1/invoicing/invoices/{$this->getId()}",
1205 "PUT",
1206 $payLoad,
1207 null,
1208 $apiContext,
1209 $restCall
1210 );
1211 $this->fromJson($json);
1212 return $this;
1213 }
1214
1215 /**
1216 * Delete a particular invoice by passing the invoice ID to the request URI.
1217 *
1218 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
1219 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
1220 * @return bool
1221 */
1222 public function delete($apiContext = null, $restCall = null)
1223 {
1224 ArgumentValidator::validate($this->getId(), "Id");
1225 $payLoad = "";
1226 self::executeCall(
1227 "/v1/invoicing/invoices/{$this->getId()}",
1228 "DELETE",
1229 $payLoad,
1230 null,
1231 $apiContext,
1232 $restCall
1233 );
1234 return true;
1235 }
1236
1237 /**
1238 * Delete external payment.
1239 *
1240 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
1241 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
1242 * @return bool
1243 */
1244 public function deleteExternalPayment($transactionId, $apiContext = null, $restCall = null)
1245 {
1246 ArgumentValidator::validate($this->getId(), "Id");
1247 ArgumentValidator::validate($transactionId, "TransactionId");
1248 $payLoad = "";
1249 self::executeCall(
1250 "/v1/invoicing/invoices/{$this->getId()}/payment-records/{$transactionId}",
1251 "DELETE",
1252 $payLoad,
1253 null,
1254 $apiContext,
1255 $restCall
1256 );
1257 return true;
1258 }
1259
1260 /**
1261 * Delete external refund.
1262 *
1263 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
1264 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
1265 * @return bool
1266 */
1267 public function deleteExternalRefund($transactionId, $apiContext = null, $restCall = null)
1268 {
1269 ArgumentValidator::validate($this->getId(), "Id");
1270 ArgumentValidator::validate($transactionId, "TransactionId");
1271 $payLoad = "";
1272 self::executeCall(
1273 "/v1/invoicing/invoices/{$this->getId()}/refund-records/{$transactionId}",
1274 "DELETE",
1275 $payLoad,
1276 null,
1277 $apiContext,
1278 $restCall
1279 );
1280 return true;
1281 }
1282
1283 /**
1284 * 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.
1285 *
1286 * @param array $params
1287 * @param string $invoiceId
1288 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
1289 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
1290 * @return Image
1291 */
1292 public static function qrCode($invoiceId, $params = array(), $apiContext = null, $restCall = null)
1293 {
1294 ArgumentValidator::validate($invoiceId, 'invoiceId');
1295 ArgumentValidator::validate($params, 'params');
1296
1297 $allowedParams = array(
1298 'width' => 1,
1299 'height' => 1,
1300 'action' => 1
1301 );
1302
1303 $payLoad = "";
1304 $json = self::executeCall(
1305 "/v1/invoicing/invoices/$invoiceId/qr-code?" . http_build_query(array_intersect_key($params, $allowedParams)),
1306 "GET",
1307 $payLoad,
1308 null,
1309 $apiContext,
1310 $restCall
1311 );
1312 $ret = new Image();
1313 $ret->fromJson($json);
1314 return $ret;
1315 }
1316
1317 /**
1318 * Generates the successive invoice number.
1319 *
1320 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
1321 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
1322 * @return InvoiceNumber
1323 */
1324 public static function generateNumber($apiContext = null, $restCall = null)
1325 {
1326 $payLoad = "";
1327 $json = self::executeCall(
1328 "/v1/invoicing/invoices/next-invoice-number",
1329 "POST",
1330 $payLoad,
1331 null,
1332 $apiContext,
1333 $restCall
1334 );
1335 $ret = new InvoiceNumber();
1336 $ret->fromJson($json);
1337 return $ret;
1338 }
1339
1340 }
1341