1 <?php
2
3 namespace PayPal\Api;
4
5 use PayPal\Common\PayPalResourceModel;
6 use PayPal\Validation\ArgumentValidator;
7 use PayPal\Rest\ApiContext;
8
9 /**
10 * Class Order
11 *
12 * An order transaction.
13 *
14 * @package PayPal\Api
15 *
16 * @property string id
17 * @property string reference_id
18 * @property \PayPal\Api\Amount amount
19 * @property string payment_mode
20 * @property string state
21 * @property string reason_code
22 * @property string pending_reason
23 * @property string protection_eligibility
24 * @property string protection_eligibility_type
25 * @property string parent_payment
26 * @property \PayPal\Api\FmfDetails fmf_details
27 * @property string create_time
28 * @property string update_time
29 * @property \PayPal\Api\Links[] links
30 */
31 class Order extends PayPalResourceModel
32 {
33 /**
34 * Identifier of the order transaction.
35 *
36 * @param string $id
37 *
38 * @return $this
39 */
40 public function setId($id)
41 {
42 $this->id = $id;
43 return $this;
44 }
45
46 /**
47 * Identifier of the order transaction.
48 *
49 * @return string
50 */
51 public function getId()
52 {
53 return $this->id;
54 }
55
56 /**
57 * Identifier to the purchase unit associated with this object. Obsolete. Use one in cart_base.
58 *
59 * @deprecated Use #setReferenceId instead
60 *
61 * @param string $purchase_unit_reference_id
62 *
63 * @return $this
64 */
65 public function setPurchaseUnitReferenceId($purchase_unit_reference_id)
66 {
67 $this->purchase_unit_reference_id = $purchase_unit_reference_id;
68 return $this;
69 }
70
71 /**
72 * Identifier to the purchase unit associated with this object. Obsolete. Use one in cart_base.
73 * @deprecated Use #getReferenceId instead
74 *
75 * @return string
76 */
77 public function getPurchaseUnitReferenceId()
78 {
79 return $this->purchase_unit_reference_id;
80 }
81
82 /**
83 * Identifier to the purchase unit associated with this object. Obsolete. Use one in cart_base.
84 *
85 * @param string $reference_id
86 *
87 * @return $this
88 */
89 public function setReferenceId($reference_id)
90 {
91 $this->reference_id = $reference_id;
92 return $this;
93 }
94
95 /**
96 * Identifier to the purchase unit associated with this object. Obsolete. Use one in cart_base.
97 *
98 * @return string
99 */
100 public function getReferenceId()
101 {
102 return $this->reference_id;
103 }
104
105 /**
106 * Amount being collected.
107 *
108 * @param \PayPal\Api\Amount $amount
109 *
110 * @return $this
111 */
112 public function setAmount($amount)
113 {
114 $this->amount = $amount;
115 return $this;
116 }
117
118 /**
119 * Amount being collected.
120 *
121 * @return \PayPal\Api\Amount
122 */
123 public function getAmount()
124 {
125 return $this->amount;
126 }
127
128 /**
129 * specifies payment mode of the transaction
130 * Valid Values: ["INSTANT_TRANSFER", "MANUAL_BANK_TRANSFER", "DELAYED_TRANSFER", "ECHECK"]
131 *
132 * @param string $payment_mode
133 *
134 * @return $this
135 */
136 public function setPaymentMode($payment_mode)
137 {
138 $this->payment_mode = $payment_mode;
139 return $this;
140 }
141
142 /**
143 * specifies payment mode of the transaction
144 *
145 * @return string
146 */
147 public function getPaymentMode()
148 {
149 return $this->payment_mode;
150 }
151
152 /**
153 * State of the order transaction.
154 * Valid Values: ["pending", "completed", "voided", "authorized", "captured"]
155 *
156 * @param string $state
157 *
158 * @return $this
159 */
160 public function setState($state)
161 {
162 $this->state = $state;
163 return $this;
164 }
165
166 /**
167 * State of the order transaction.
168 *
169 * @return string
170 */
171 public function getState()
172 {
173 return $this->state;
174 }
175
176 /**
177 * Reason code for the transaction state being Pending or Reversed. This field will replace pending_reason field eventually. Only supported when the `payment_method` is set to `paypal`.
178 * Valid Values: ["PAYER_SHIPPING_UNCONFIRMED", "MULTI_CURRENCY", "RISK_REVIEW", "REGULATORY_REVIEW", "VERIFICATION_REQUIRED", "ORDER", "OTHER"]
179 *
180 * @param string $reason_code
181 *
182 * @return $this
183 */
184 public function setReasonCode($reason_code)
185 {
186 $this->reason_code = $reason_code;
187 return $this;
188 }
189
190 /**
191 * Reason code for the transaction state being Pending or Reversed. This field will replace pending_reason field eventually. Only supported when the `payment_method` is set to `paypal`.
192 *
193 * @return string
194 */
195 public function getReasonCode()
196 {
197 return $this->reason_code;
198 }
199
200 /**
201 * [DEPRECATED] Reason code for the transaction state being Pending. Obsolete. Retained for backward compatability. Use reason_code field above instead.
202 * Valid Values: ["payer_shipping_unconfirmed", "multi_currency", "risk_review", "regulatory_review", "verification_required", "order", "other"]
203 *
204 * @param string $pending_reason
205 *
206 * @return $this
207 */
208 public function setPendingReason($pending_reason)
209 {
210 $this->pending_reason = $pending_reason;
211 return $this;
212 }
213
214 /**
215 * @deprecated [DEPRECATED] Reason code for the transaction state being Pending. Obsolete. Retained for backward compatability. Use reason_code field above instead.
216 *
217 * @return string
218 */
219 public function getPendingReason()
220 {
221 return $this->pending_reason;
222 }
223
224 /**
225 * The level of seller protection in force for the transaction.
226 * Valid Values: ["ELIGIBLE", "PARTIALLY_ELIGIBLE", "INELIGIBLE"]
227 *
228 * @param string $protection_eligibility
229 *
230 * @return $this
231 */
232 public function setProtectionEligibility($protection_eligibility)
233 {
234 $this->protection_eligibility = $protection_eligibility;
235 return $this;
236 }
237
238 /**
239 * The level of seller protection in force for the transaction.
240 *
241 * @return string
242 */
243 public function getProtectionEligibility()
244 {
245 return $this->protection_eligibility;
246 }
247
248 /**
249 * The kind of seller protection in force for the transaction. This property is returned only when the `protection_eligibility` property is set to `ELIGIBLE`or `PARTIALLY_ELIGIBLE`. Only supported when the `payment_method` is set to `paypal`. Allowed values:<br> `ITEM_NOT_RECEIVED_ELIGIBLE`- Sellers are protected against claims for items not received.<br> `UNAUTHORIZED_PAYMENT_ELIGIBLE`- Sellers are protected against claims for unauthorized payments.<br> One or both of the allowed values can be returned.
250 * Valid Values: ["ITEM_NOT_RECEIVED_ELIGIBLE", "UNAUTHORIZED_PAYMENT_ELIGIBLE", "ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE"]
251 *
252 * @param string $protection_eligibility_type
253 *
254 * @return $this
255 */
256 public function setProtectionEligibilityType($protection_eligibility_type)
257 {
258 $this->protection_eligibility_type = $protection_eligibility_type;
259 return $this;
260 }
261
262 /**
263 * The kind of seller protection in force for the transaction. This property is returned only when the `protection_eligibility` property is set to `ELIGIBLE`or `PARTIALLY_ELIGIBLE`. Only supported when the `payment_method` is set to `paypal`. Allowed values:<br> `ITEM_NOT_RECEIVED_ELIGIBLE`- Sellers are protected against claims for items not received.<br> `UNAUTHORIZED_PAYMENT_ELIGIBLE`- Sellers are protected against claims for unauthorized payments.<br> One or both of the allowed values can be returned.
264 *
265 * @return string
266 */
267 public function getProtectionEligibilityType()
268 {
269 return $this->protection_eligibility_type;
270 }
271
272 /**
273 * ID of the Payment resource that this transaction is based on.
274 *
275 * @param string $parent_payment
276 *
277 * @return $this
278 */
279 public function setParentPayment($parent_payment)
280 {
281 $this->parent_payment = $parent_payment;
282 return $this;
283 }
284
285 /**
286 * ID of the Payment resource that this transaction is based on.
287 *
288 * @return string
289 */
290 public function getParentPayment()
291 {
292 return $this->parent_payment;
293 }
294
295 /**
296 * Fraud Management Filter (FMF) details applied for the payment that could result in accept/deny/pending action.
297 *
298 * @param \PayPal\Api\FmfDetails $fmf_details
299 *
300 * @return $this
301 */
302 public function setFmfDetails($fmf_details)
303 {
304 $this->fmf_details = $fmf_details;
305 return $this;
306 }
307
308 /**
309 * Fraud Management Filter (FMF) details applied for the payment that could result in accept/deny/pending action.
310 *
311 * @return \PayPal\Api\FmfDetails
312 */
313 public function getFmfDetails()
314 {
315 return $this->fmf_details;
316 }
317
318 /**
319 * Time the resource was created in UTC ISO8601 format.
320 *
321 * @param string $create_time
322 *
323 * @return $this
324 */
325 public function setCreateTime($create_time)
326 {
327 $this->create_time = $create_time;
328 return $this;
329 }
330
331 /**
332 * Time the resource was created in UTC ISO8601 format.
333 *
334 * @return string
335 */
336 public function getCreateTime()
337 {
338 return $this->create_time;
339 }
340
341 /**
342 * Time the resource was last updated in UTC ISO8601 format.
343 *
344 * @param string $update_time
345 *
346 * @return $this
347 */
348 public function setUpdateTime($update_time)
349 {
350 $this->update_time = $update_time;
351 return $this;
352 }
353
354 /**
355 * Time the resource was last updated in UTC ISO8601 format.
356 *
357 * @return string
358 */
359 public function getUpdateTime()
360 {
361 return $this->update_time;
362 }
363
364 /**
365 * Shows details for an order, by ID.
366 *
367 * @param string $orderId
368 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
369 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
370 * @return Order
371 */
372 public static function get($orderId, $apiContext = null, $restCall = null)
373 {
374 ArgumentValidator::validate($orderId, 'orderId');
375 $payLoad = "";
376 $json = self::executeCall(
377 "/v1/payments/orders/$orderId",
378 "GET",
379 $payLoad,
380 null,
381 $apiContext,
382 $restCall
383 );
384 $ret = new Order();
385 $ret->fromJson($json);
386 return $ret;
387 }
388
389 /**
390 * Captures a payment for an order, by ID. To use this call, the original payment call must specify an intent of `order`. In the JSON request body, include the payment amount and indicate whether this capture is the final capture for the authorization.
391 *
392 * @param Capture $capture
393 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
394 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
395 * @return Capture
396 */
397 public function capture($capture, $apiContext = null, $restCall = null)
398 {
399 ArgumentValidator::validate($this->getId(), "Id");
400 ArgumentValidator::validate($capture, 'capture');
401 $payLoad = $capture->toJSON();
402 $json = self::executeCall(
403 "/v1/payments/orders/{$this->getId()}/capture",
404 "POST",
405 $payLoad,
406 null,
407 $apiContext,
408 $restCall
409 );
410 $ret = new Capture();
411 $ret->fromJson($json);
412 return $ret;
413 }
414
415 /**
416 * Voids, or cancels, an order, by ID. You cannot void an order if a payment has already been partially or fully captured.
417 *
418 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
419 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
420 * @return Order
421 */
422 public function void($apiContext = null, $restCall = null)
423 {
424 ArgumentValidator::validate($this->getId(), "Id");
425 $payLoad = "";
426 $json = self::executeCall(
427 "/v1/payments/orders/{$this->getId()}/do-void",
428 "POST",
429 $payLoad,
430 null,
431 $apiContext,
432 $restCall
433 );
434 $this->fromJson($json);
435 return $this;
436 }
437
438 /**
439 * Authorizes an order, by ID. Include an `amount` object in the JSON request body.
440 *
441 * @param Authorization $authorization Authorization Object with Amount value to be authorized
442 * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
443 * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
444 * @return Authorization
445 */
446 public function authorize($authorization, $apiContext = null, $restCall = null)
447 {
448 ArgumentValidator::validate($this->getId(), "Id");
449 ArgumentValidator::validate($authorization, 'Authorization');
450 $payLoad = $authorization->toJSON();
451 $json = self::executeCall(
452 "/v1/payments/orders/{$this->getId()}/authorize",
453 "POST",
454 $payLoad,
455 null,
456 $apiContext,
457 $restCall
458 );
459 $ret = new Authorization();
460 $ret->fromJson($json);
461 return $ret;
462 }
463
464 }
465