| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Square\Legacy\Models; |
| 6 |
|
| 7 |
use stdClass; |
| 8 |
|
| 9 |
/** |
| 10 |
* A request to create a loyalty reward. |
| 11 |
*/ |
| 12 |
class CreateLoyaltyRewardRequest implements \JsonSerializable |
| 13 |
{ |
| 14 |
/** |
| 15 |
* @var LoyaltyReward |
| 16 |
*/ |
| 17 |
private $reward; |
| 18 |
|
| 19 |
/** |
| 20 |
* @var string |
| 21 |
*/ |
| 22 |
private $idempotencyKey; |
| 23 |
|
| 24 |
/** |
| 25 |
* @param LoyaltyReward $reward |
| 26 |
* @param string $idempotencyKey |
| 27 |
*/ |
| 28 |
public function __construct(LoyaltyReward $reward, string $idempotencyKey) |
| 29 |
{ |
| 30 |
$this->reward = $reward; |
| 31 |
$this->idempotencyKey = $idempotencyKey; |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Returns Reward. |
| 36 |
* Represents a contract to redeem loyalty points for a [reward tier]($m/LoyaltyProgramRewardTier) |
| 37 |
* discount. Loyalty rewards can be in an ISSUED, REDEEMED, or DELETED state. |
| 38 |
* For more information, see [Manage loyalty rewards](https://developer.squareup.com/docs/loyalty- |
| 39 |
* api/loyalty-rewards). |
| 40 |
*/ |
| 41 |
public function getReward(): LoyaltyReward |
| 42 |
{ |
| 43 |
return $this->reward; |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Sets Reward. |
| 48 |
* Represents a contract to redeem loyalty points for a [reward tier]($m/LoyaltyProgramRewardTier) |
| 49 |
* discount. Loyalty rewards can be in an ISSUED, REDEEMED, or DELETED state. |
| 50 |
* For more information, see [Manage loyalty rewards](https://developer.squareup.com/docs/loyalty- |
| 51 |
* api/loyalty-rewards). |
| 52 |
* |
| 53 |
* @required |
| 54 |
* @maps reward |
| 55 |
*/ |
| 56 |
public function setReward(LoyaltyReward $reward): void |
| 57 |
{ |
| 58 |
$this->reward = $reward; |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Returns Idempotency Key. |
| 63 |
* A unique string that identifies this `CreateLoyaltyReward` request. |
| 64 |
* Keys can be any valid string, but must be unique for every request. |
| 65 |
*/ |
| 66 |
public function getIdempotencyKey(): string |
| 67 |
{ |
| 68 |
return $this->idempotencyKey; |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Sets Idempotency Key. |
| 73 |
* A unique string that identifies this `CreateLoyaltyReward` request. |
| 74 |
* Keys can be any valid string, but must be unique for every request. |
| 75 |
* |
| 76 |
* @required |
| 77 |
* @maps idempotency_key |
| 78 |
*/ |
| 79 |
public function setIdempotencyKey(string $idempotencyKey): void |
| 80 |
{ |
| 81 |
$this->idempotencyKey = $idempotencyKey; |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Encode this object to JSON |
| 86 |
* |
| 87 |
* @param bool $asArrayWhenEmpty Whether to serialize this model as an array whenever no fields |
| 88 |
* are set. (default: false) |
| 89 |
* |
| 90 |
* @return array|stdClass |
| 91 |
*/ |
| 92 |
#[\ReturnTypeWillChange] // @phan-suppress-current-line PhanUndeclaredClassAttribute for (php < 8.1) |
| 93 |
public function jsonSerialize(bool $asArrayWhenEmpty = false) |
| 94 |
{ |
| 95 |
$json = []; |
| 96 |
$json['reward'] = $this->reward; |
| 97 |
$json['idempotency_key'] = $this->idempotencyKey; |
| 98 |
$json = array_filter($json, function ($val) { |
| 99 |
return $val !== null; |
| 100 |
}); |
| 101 |
|
| 102 |
return (!$asArrayWhenEmpty && empty($json)) ? new stdClass() : $json; |
| 103 |
} |
| 104 |
} |
| 105 |
|