| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Square\Legacy\Models; |
| 6 |
|
| 7 |
use stdClass; |
| 8 |
|
| 9 |
/** |
| 10 |
* A response that contains a `GiftCard`. The response might contain a set of `Error` objects if the |
| 11 |
* request |
| 12 |
* resulted in errors. |
| 13 |
*/ |
| 14 |
class CreateGiftCardResponse implements \JsonSerializable |
| 15 |
{ |
| 16 |
/** |
| 17 |
* @var Error[]|null |
| 18 |
*/ |
| 19 |
private $errors; |
| 20 |
|
| 21 |
/** |
| 22 |
* @var GiftCard|null |
| 23 |
*/ |
| 24 |
private $giftCard; |
| 25 |
|
| 26 |
/** |
| 27 |
* Returns Errors. |
| 28 |
* Any errors that occurred during the request. |
| 29 |
* |
| 30 |
* @return Error[]|null |
| 31 |
*/ |
| 32 |
public function getErrors(): ?array |
| 33 |
{ |
| 34 |
return $this->errors; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Sets Errors. |
| 39 |
* Any errors that occurred during the request. |
| 40 |
* |
| 41 |
* @maps errors |
| 42 |
* |
| 43 |
* @param Error[]|null $errors |
| 44 |
*/ |
| 45 |
public function setErrors(?array $errors): void |
| 46 |
{ |
| 47 |
$this->errors = $errors; |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Returns Gift Card. |
| 52 |
* Represents a Square gift card. |
| 53 |
*/ |
| 54 |
public function getGiftCard(): ?GiftCard |
| 55 |
{ |
| 56 |
return $this->giftCard; |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Sets Gift Card. |
| 61 |
* Represents a Square gift card. |
| 62 |
* |
| 63 |
* @maps gift_card |
| 64 |
*/ |
| 65 |
public function setGiftCard(?GiftCard $giftCard): void |
| 66 |
{ |
| 67 |
$this->giftCard = $giftCard; |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Encode this object to JSON |
| 72 |
* |
| 73 |
* @param bool $asArrayWhenEmpty Whether to serialize this model as an array whenever no fields |
| 74 |
* are set. (default: false) |
| 75 |
* |
| 76 |
* @return array|stdClass |
| 77 |
*/ |
| 78 |
#[\ReturnTypeWillChange] // @phan-suppress-current-line PhanUndeclaredClassAttribute for (php < 8.1) |
| 79 |
public function jsonSerialize(bool $asArrayWhenEmpty = false) |
| 80 |
{ |
| 81 |
$json = []; |
| 82 |
if (isset($this->errors)) { |
| 83 |
$json['errors'] = $this->errors; |
| 84 |
} |
| 85 |
if (isset($this->giftCard)) { |
| 86 |
$json['gift_card'] = $this->giftCard; |
| 87 |
} |
| 88 |
$json = array_filter($json, function ($val) { |
| 89 |
return $val !== null; |
| 90 |
}); |
| 91 |
|
| 92 |
return (!$asArrayWhenEmpty && empty($json)) ? new stdClass() : $json; |
| 93 |
} |
| 94 |
} |
| 95 |
|