cf223f05fa6071c887059901be85d7c574a3cc7b
[WP-Plugins/glm-member-db-registrations.git] /
1 <?php
2 namespace PayPal\Api;
3
4 use PayPal\Common\PPModel;
5 use PayPal\Rest\IResource;
6 use PayPal\Rest\Call;
7 use PayPal\Rest\ApiContext;
8 use PayPal\Api\Payment;
9 use PayPal\Api\PaymentHistory;
10 use PayPal\Transport\PPRestCall;
11
12 class Payment extends PPModel implements IResource {
13
14         private static $credential;
15
16         /**
17          *
18          * @deprecated. Pass ApiContext to create/get methods instead
19          */
20         public static function setCredential($credential) {
21                 self::$credential = $credential;
22         }
23
24         /**
25          * Identifier of the payment resource created.
26          * @param string $id
27          */
28         public function setId($id) {
29                 $this->id = $id;
30                 return $this;
31         }
32
33         /**
34          * Identifier of the payment resource created.
35          * @return string
36          */
37         public function getId() {
38                 return $this->id;
39         }
40
41
42         /**
43          * Time the resource was created.
44          * @param string $create_time
45          */
46         public function setCreateTime($create_time) {
47                 $this->create_time = $create_time;
48                 return $this;
49         }
50
51         /**
52          * Time the resource was created.
53          * @return string
54          */
55         public function getCreateTime() {
56                 return $this->create_time;
57         }
58
59         /**
60          * Time the resource was created.
61          * @param string $create_time
62          * @deprecated. Instead use setCreateTime
63          */
64         public function setCreate_time($create_time) {
65                 $this->create_time = $create_time;
66                 return $this;
67         }
68         /**
69          * Time the resource was created.
70          * @return string
71          * @deprecated. Instead use getCreateTime
72          */
73         public function getCreate_time() {
74                 return $this->create_time;
75         }
76
77         /**
78          * Time the resource was last updated.
79          * @param string $update_time
80          */
81         public function setUpdateTime($update_time) {
82                 $this->update_time = $update_time;
83                 return $this;
84         }
85
86         /**
87          * Time the resource was last updated.
88          * @return string
89          */
90         public function getUpdateTime() {
91                 return $this->update_time;
92         }
93
94         /**
95          * Time the resource was last updated.
96          * @param string $update_time
97          * @deprecated. Instead use setUpdateTime
98          */
99         public function setUpdate_time($update_time) {
100                 $this->update_time = $update_time;
101                 return $this;
102         }
103         /**
104          * Time the resource was last updated.
105          * @return string
106          * @deprecated. Instead use getUpdateTime
107          */
108         public function getUpdate_time() {
109                 return $this->update_time;
110         }
111
112         /**
113          * Intent of the payment - Sale or Authorization or Order.
114          * @param string $intent
115          */
116         public function setIntent($intent) {
117                 $this->intent = $intent;
118                 return $this;
119         }
120
121         /**
122          * Intent of the payment - Sale or Authorization or Order.
123          * @return string
124          */
125         public function getIntent() {
126                 return $this->intent;
127         }
128
129
130         /**
131          * Source of the funds for this payment represented by a PayPal account or a direct credit card.
132          * @param PayPal\Api\Payer $payer
133          */
134         public function setPayer($payer) {
135                 $this->payer = $payer;
136                 return $this;
137         }
138
139         /**
140          * Source of the funds for this payment represented by a PayPal account or a direct credit card.
141          * @return PayPal\Api\Payer
142          */
143         public function getPayer() {
144                 return $this->payer;
145         }
146
147
148         /**
149          * A payment can have more than one transaction, with each transaction establishing a contract between the payer and a payee
150          * @array
151          * @param PayPal\Api\Transaction $transactions
152          */
153         public function setTransactions($transactions) {
154                 $this->transactions = $transactions;
155                 return $this;
156         }
157
158         /**
159          * A payment can have more than one transaction, with each transaction establishing a contract between the payer and a payee
160          * @return PayPal\Api\Transaction
161          */
162         public function getTransactions() {
163                 return $this->transactions;
164         }
165
166
167         /**
168          * state of the payment
169          * @param string $state
170          */
171         public function setState($state) {
172                 $this->state = $state;
173                 return $this;
174         }
175
176         /**
177          * state of the payment
178          * @return string
179          */
180         public function getState() {
181                 return $this->state;
182         }
183
184
185         /**
186          * Redirect urls required only when using payment_method as PayPal - the only settings supported are return and cancel urls.
187          * @param PayPal\Api\RedirectUrls $redirect_urls
188          */
189         public function setRedirectUrls($redirect_urls) {
190                 $this->redirect_urls = $redirect_urls;
191                 return $this;
192         }
193
194         /**
195          * Redirect urls required only when using payment_method as PayPal - the only settings supported are return and cancel urls.
196          * @return PayPal\Api\RedirectUrls
197          */
198         public function getRedirectUrls() {
199                 return $this->redirect_urls;
200         }
201
202         /**
203          * Redirect urls required only when using payment_method as PayPal - the only settings supported are return and cancel urls.
204          * @param PayPal\Api\RedirectUrls $redirect_urls
205          * @deprecated. Instead use setRedirectUrls
206          */
207         public function setRedirect_urls($redirect_urls) {
208                 $this->redirect_urls = $redirect_urls;
209                 return $this;
210         }
211         /**
212          * Redirect urls required only when using payment_method as PayPal - the only settings supported are return and cancel urls.
213          * @return PayPal\Api\RedirectUrls
214          * @deprecated. Instead use getRedirectUrls
215          */
216         public function getRedirect_urls() {
217                 return $this->redirect_urls;
218         }
219
220         /**
221          * 
222          * @array
223          * @param PayPal\Api\Links $links
224          */
225         public function setLinks($links) {
226                 $this->links = $links;
227                 return $this;
228         }
229
230         /**
231          * 
232          * @return PayPal\Api\Links
233          */
234         public function getLinks() {
235                 return $this->links;
236         }
237
238
239
240         public function create($apiContext = null) {
241                 $payLoad = $this->toJSON();
242                 if ($apiContext == null) {
243                         $apiContext = new ApiContext(self::$credential);
244                 }
245                 $call = new PPRestCall($apiContext);
246                 $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payments/payment", "POST", $payLoad);
247                 $this->fromJson($json);
248                 return $this;
249         }
250
251         public static function get($paymentId, $apiContext = null) {
252                 if (($paymentId == null) || (strlen($paymentId) <= 0)) {
253                         throw new \InvalidArgumentException("paymentId cannot be null or empty");
254                 }
255                 $payLoad = "";
256                 if ($apiContext == null) {
257                         $apiContext = new ApiContext(self::$credential);
258                 }
259                 $call = new PPRestCall($apiContext);
260                 $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payments/payment/$paymentId", "GET", $payLoad);
261                 $ret = new Payment();
262                 $ret->fromJson($json);
263                 return $ret;
264         }
265
266         public function execute($paymentExecution, $apiContext = null) {
267                 if ($this->getId() == null) {
268                         throw new \InvalidArgumentException("Id cannot be null");
269                 }
270                 if (($paymentExecution == null)) {
271                         throw new \InvalidArgumentException("paymentExecution cannot be null or empty");
272                 }
273                 $payLoad = $paymentExecution->toJSON();
274                 if ($apiContext == null) {
275                         $apiContext = new ApiContext(self::$credential);
276                 }
277                 $call = new PPRestCall($apiContext);
278                 $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payments/payment/{$this->getId()}/execute", "POST", $payLoad);
279                 $ret = new Payment();
280                 $ret->fromJson($json);
281                 return $ret;
282         }
283
284         public static function all($params, $apiContext = null) {
285                 if (($params == null)) {
286                         throw new \InvalidArgumentException("params cannot be null or empty");
287                 }
288                 $payLoad = "";
289                 $allowedParams = array('count' => 1, 'start_id' => 1, 'start_index' => 1, 'start_time' => 1, 'end_time' => 1, 'payee_id' => 1, 'sort_by' => 1, 'sort_order' => 1, );
290                 if ($apiContext == null) {
291                         $apiContext = new ApiContext(self::$credential);
292                 }
293                 $call = new PPRestCall($apiContext);
294                 $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payments/payment?" . http_build_query(array_intersect_key($params, $allowedParams)), "GET", $payLoad);
295                 $ret = new PaymentHistory();
296                 $ret->fromJson($json);
297                 return $ret;
298         }
299 }