| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Square\Legacy\Models; |
| 6 |
|
| 7 |
use stdClass; |
| 8 |
|
| 9 |
class CreateOrderRequest implements \JsonSerializable |
| 10 |
{ |
| 11 |
/** |
| 12 |
* @var Order|null |
| 13 |
*/ |
| 14 |
private $order; |
| 15 |
|
| 16 |
/** |
| 17 |
* @var string|null |
| 18 |
*/ |
| 19 |
private $idempotencyKey; |
| 20 |
|
| 21 |
/** |
| 22 |
* Returns Order. |
| 23 |
* Contains all information related to a single order to process with Square, |
| 24 |
* including line items that specify the products to purchase. `Order` objects also |
| 25 |
* include information about any associated tenders, refunds, and returns. |
| 26 |
* |
| 27 |
* All Connect V2 Transactions have all been converted to Orders including all associated |
| 28 |
* itemization data. |
| 29 |
*/ |
| 30 |
public function getOrder(): ?Order |
| 31 |
{ |
| 32 |
return $this->order; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Sets Order. |
| 37 |
* Contains all information related to a single order to process with Square, |
| 38 |
* including line items that specify the products to purchase. `Order` objects also |
| 39 |
* include information about any associated tenders, refunds, and returns. |
| 40 |
* |
| 41 |
* All Connect V2 Transactions have all been converted to Orders including all associated |
| 42 |
* itemization data. |
| 43 |
* |
| 44 |
* @maps order |
| 45 |
*/ |
| 46 |
public function setOrder(?Order $order): void |
| 47 |
{ |
| 48 |
$this->order = $order; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Returns Idempotency Key. |
| 53 |
* A value you specify that uniquely identifies this |
| 54 |
* order among orders you have created. |
| 55 |
* |
| 56 |
* If you are unsure whether a particular order was created successfully, |
| 57 |
* you can try it again with the same idempotency key without |
| 58 |
* worrying about creating duplicate orders. |
| 59 |
* |
| 60 |
* For more information, see [Idempotency](https://developer.squareup.com/docs/build-basics/common-api- |
| 61 |
* patterns/idempotency). |
| 62 |
*/ |
| 63 |
public function getIdempotencyKey(): ?string |
| 64 |
{ |
| 65 |
return $this->idempotencyKey; |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Sets Idempotency Key. |
| 70 |
* A value you specify that uniquely identifies this |
| 71 |
* order among orders you have created. |
| 72 |
* |
| 73 |
* If you are unsure whether a particular order was created successfully, |
| 74 |
* you can try it again with the same idempotency key without |
| 75 |
* worrying about creating duplicate orders. |
| 76 |
* |
| 77 |
* For more information, see [Idempotency](https://developer.squareup.com/docs/build-basics/common-api- |
| 78 |
* patterns/idempotency). |
| 79 |
* |
| 80 |
* @maps idempotency_key |
| 81 |
*/ |
| 82 |
public function setIdempotencyKey(?string $idempotencyKey): void |
| 83 |
{ |
| 84 |
$this->idempotencyKey = $idempotencyKey; |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Encode this object to JSON |
| 89 |
* |
| 90 |
* @param bool $asArrayWhenEmpty Whether to serialize this model as an array whenever no fields |
| 91 |
* are set. (default: false) |
| 92 |
* |
| 93 |
* @return array|stdClass |
| 94 |
*/ |
| 95 |
#[\ReturnTypeWillChange] // @phan-suppress-current-line PhanUndeclaredClassAttribute for (php < 8.1) |
| 96 |
public function jsonSerialize(bool $asArrayWhenEmpty = false) |
| 97 |
{ |
| 98 |
$json = []; |
| 99 |
if (isset($this->order)) { |
| 100 |
$json['order'] = $this->order; |
| 101 |
} |
| 102 |
if (isset($this->idempotencyKey)) { |
| 103 |
$json['idempotency_key'] = $this->idempotencyKey; |
| 104 |
} |
| 105 |
$json = array_filter($json, function ($val) { |
| 106 |
return $val !== null; |
| 107 |
}); |
| 108 |
|
| 109 |
return (!$asArrayWhenEmpty && empty($json)) ? new stdClass() : $json; |
| 110 |
} |
| 111 |
} |
| 112 |
|