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 Payout
12 *
13 * This object represents a set of payouts that includes status data for the payouts. This object enables you to create a payout using a POST request.
14 *
15 * @package PayPal\Api
16 *
17 * @property \PayPal\Api\PayoutSenderBatchHeader sender_batch_header
18 * @property \PayPal\Api\PayoutItem[] items
19 * @property \PayPal\Api\Links[] links
20 */
21 class Payout extends PayPalResourceModel
22 {
23 /**
24 * The original batch header as provided by the payment sender.
25 *
26 * @param \PayPal\Api\PayoutSenderBatchHeader $sender_batch_header
27 *
28 * @return $this
29 */
30 public function setSenderBatchHeader($sender_batch_header)
31 {
32 $this->sender_batch_header = $sender_batch_header;
33 return $this;
34 }
35
36 /**
37 * The original batch header as provided by the payment sender.
38 *
39 * @return \PayPal\Api\PayoutSenderBatchHeader
40 */
41 public function getSenderBatchHeader()
42 {
43 return $this->sender_batch_header;
44 }
45
46 /**
47 * An array of payout items (that is, a set of individual payouts).
48 *
49 * @param \PayPal\Api\PayoutItem[] $items
50 *
51 * @return $this
52 */
53 public function setItems($items)
54 {
55 $this->items = $items;
56 return $this;
57 }
58
59 /**
60 * An array of payout items (that is, a set of individual payouts).
61 *
62 * @return \PayPal\Api\PayoutItem[]
63 */
64 public function getItems()
65 {
66 return $this->items;
67 }
68
69 /**
70 * Append Items to the list.
71 *
72 * @param \PayPal\Api\PayoutItem $payoutItem
73 * @return $this
74 */
75 public function addItem($payoutItem)
76 {
77 if (!$this->getItems()) {
78 return $this->setItems(array($payoutItem));
79 } else {
80 return $this->setItems(
81 array_merge($this->getItems(), array($payoutItem))
82 );
83 }
84 }
85
86 /**
87 * Remove Items from the list.
88 *
89 * @param \PayPal\Api\PayoutItem $payoutItem
90 * @return $this
91 */
92 public function removeItem($payoutItem)
93 {
94 return $this->setItems(
95 array_diff($this->getItems(), array($payoutItem))
96 );
97 }
98
99 /**
100 * Create a payout batch resource by passing a sender_batch_header and an items array to the request URI. The sender_batch_header contains payout parameters that describe the handling of a batch resource while the items array conatins payout items.
101 *
102 * @param array $params
103 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
104 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
105 * @return PayoutBatch
106 */
107 public function create($params = array(), $apiContext = null, $restCall = null)
108 {
109 $params = $params ? $params : array();
110 ArgumentValidator::validate($params, 'params');
111 $payLoad = $this->toJSON();
112 $allowedParams = array(
113 'sync_mode' => 1,
114 );
115 $json = self::executeCall(
116 "/v1/payments/payouts" . "?" . http_build_query(array_intersect_key($params, $allowedParams)),
117 "POST",
118 $payLoad,
119 null,
120 $apiContext,
121 $restCall
122 );
123 $ret = new PayoutBatch();
124 $ret->fromJson($json);
125 return $ret;
126 }
127
128 /**
129 * You can submit a payout with a synchronous API call, which immediately returns the results of a PayPal payment.
130 *
131 * @param ApiContext $apiContext
132 * @param PayPalRestCall $restCall
133 * @return PayoutBatch
134 */
135 public function createSynchronous($apiContext = null, $restCall = null)
136 {
137 $params = array('sync_mode' => 'true');
138 return $this->create($params, $apiContext, $restCall);
139 }
140
141 /**
142 * Obtain the status of a specific batch resource by passing the payout batch ID to the request URI. You can issue this call multiple times to get the current status.
143 *
144 * @param string $payoutBatchId
145 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
146 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
147 * @return PayoutBatch
148 */
149 public static function get($payoutBatchId, $apiContext = null, $restCall = null)
150 {
151 ArgumentValidator::validate($payoutBatchId, 'payoutBatchId');
152 $payLoad = "";
153 $json = self::executeCall(
154 "/v1/payments/payouts/$payoutBatchId",
155 "GET",
156 $payLoad,
157 null,
158 $apiContext,
159 $restCall
160 );
161 $ret = new PayoutBatch();
162 $ret->fromJson($json);
163 return $ret;
164 }
165
166 }
167