| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Square\Legacy\Models; |
| 6 |
|
| 7 |
use stdClass; |
| 8 |
|
| 9 |
/** |
| 10 |
* Represents a Square loyalty program. Loyalty programs define how buyers can earn points and redeem |
| 11 |
* points for rewards. |
| 12 |
* Square sellers can have only one loyalty program, which is created and managed from the Seller |
| 13 |
* Dashboard. |
| 14 |
* For more information, see [Loyalty Program Overview](https://developer.squareup. |
| 15 |
* com/docs/loyalty/overview). |
| 16 |
*/ |
| 17 |
class LoyaltyProgram implements \JsonSerializable |
| 18 |
{ |
| 19 |
/** |
| 20 |
* @var string|null |
| 21 |
*/ |
| 22 |
private $id; |
| 23 |
|
| 24 |
/** |
| 25 |
* @var string|null |
| 26 |
*/ |
| 27 |
private $status; |
| 28 |
|
| 29 |
/** |
| 30 |
* @var array |
| 31 |
*/ |
| 32 |
private $rewardTiers = []; |
| 33 |
|
| 34 |
/** |
| 35 |
* @var LoyaltyProgramExpirationPolicy|null |
| 36 |
*/ |
| 37 |
private $expirationPolicy; |
| 38 |
|
| 39 |
/** |
| 40 |
* @var LoyaltyProgramTerminology|null |
| 41 |
*/ |
| 42 |
private $terminology; |
| 43 |
|
| 44 |
/** |
| 45 |
* @var array |
| 46 |
*/ |
| 47 |
private $locationIds = []; |
| 48 |
|
| 49 |
/** |
| 50 |
* @var string|null |
| 51 |
*/ |
| 52 |
private $createdAt; |
| 53 |
|
| 54 |
/** |
| 55 |
* @var string|null |
| 56 |
*/ |
| 57 |
private $updatedAt; |
| 58 |
|
| 59 |
/** |
| 60 |
* @var array |
| 61 |
*/ |
| 62 |
private $accrualRules = []; |
| 63 |
|
| 64 |
/** |
| 65 |
* Returns Id. |
| 66 |
* The Square-assigned ID of the loyalty program. Updates to |
| 67 |
* the loyalty program do not modify the identifier. |
| 68 |
*/ |
| 69 |
public function getId(): ?string |
| 70 |
{ |
| 71 |
return $this->id; |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Sets Id. |
| 76 |
* The Square-assigned ID of the loyalty program. Updates to |
| 77 |
* the loyalty program do not modify the identifier. |
| 78 |
* |
| 79 |
* @maps id |
| 80 |
*/ |
| 81 |
public function setId(?string $id): void |
| 82 |
{ |
| 83 |
$this->id = $id; |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Returns Status. |
| 88 |
* Indicates whether the program is currently active. |
| 89 |
*/ |
| 90 |
public function getStatus(): ?string |
| 91 |
{ |
| 92 |
return $this->status; |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Sets Status. |
| 97 |
* Indicates whether the program is currently active. |
| 98 |
* |
| 99 |
* @maps status |
| 100 |
*/ |
| 101 |
public function setStatus(?string $status): void |
| 102 |
{ |
| 103 |
$this->status = $status; |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* Returns Reward Tiers. |
| 108 |
* The list of rewards for buyers, sorted by ascending points. |
| 109 |
* |
| 110 |
* @return LoyaltyProgramRewardTier[]|null |
| 111 |
*/ |
| 112 |
public function getRewardTiers(): ?array |
| 113 |
{ |
| 114 |
if (count($this->rewardTiers) == 0) { |
| 115 |
return null; |
| 116 |
} |
| 117 |
return $this->rewardTiers['value']; |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Sets Reward Tiers. |
| 122 |
* The list of rewards for buyers, sorted by ascending points. |
| 123 |
* |
| 124 |
* @maps reward_tiers |
| 125 |
* |
| 126 |
* @param LoyaltyProgramRewardTier[]|null $rewardTiers |
| 127 |
*/ |
| 128 |
public function setRewardTiers(?array $rewardTiers): void |
| 129 |
{ |
| 130 |
$this->rewardTiers['value'] = $rewardTiers; |
| 131 |
} |
| 132 |
|
| 133 |
/** |
| 134 |
* Unsets Reward Tiers. |
| 135 |
* The list of rewards for buyers, sorted by ascending points. |
| 136 |
*/ |
| 137 |
public function unsetRewardTiers(): void |
| 138 |
{ |
| 139 |
$this->rewardTiers = []; |
| 140 |
} |
| 141 |
|
| 142 |
/** |
| 143 |
* Returns Expiration Policy. |
| 144 |
* Describes when the loyalty program expires. |
| 145 |
*/ |
| 146 |
public function getExpirationPolicy(): ?LoyaltyProgramExpirationPolicy |
| 147 |
{ |
| 148 |
return $this->expirationPolicy; |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* Sets Expiration Policy. |
| 153 |
* Describes when the loyalty program expires. |
| 154 |
* |
| 155 |
* @maps expiration_policy |
| 156 |
*/ |
| 157 |
public function setExpirationPolicy(?LoyaltyProgramExpirationPolicy $expirationPolicy): void |
| 158 |
{ |
| 159 |
$this->expirationPolicy = $expirationPolicy; |
| 160 |
} |
| 161 |
|
| 162 |
/** |
| 163 |
* Returns Terminology. |
| 164 |
* Represents the naming used for loyalty points. |
| 165 |
*/ |
| 166 |
public function getTerminology(): ?LoyaltyProgramTerminology |
| 167 |
{ |
| 168 |
return $this->terminology; |
| 169 |
} |
| 170 |
|
| 171 |
/** |
| 172 |
* Sets Terminology. |
| 173 |
* Represents the naming used for loyalty points. |
| 174 |
* |
| 175 |
* @maps terminology |
| 176 |
*/ |
| 177 |
public function setTerminology(?LoyaltyProgramTerminology $terminology): void |
| 178 |
{ |
| 179 |
$this->terminology = $terminology; |
| 180 |
} |
| 181 |
|
| 182 |
/** |
| 183 |
* Returns Location Ids. |
| 184 |
* The [locations](entity:Location) at which the program is active. |
| 185 |
* |
| 186 |
* @return string[]|null |
| 187 |
*/ |
| 188 |
public function getLocationIds(): ?array |
| 189 |
{ |
| 190 |
if (count($this->locationIds) == 0) { |
| 191 |
return null; |
| 192 |
} |
| 193 |
return $this->locationIds['value']; |
| 194 |
} |
| 195 |
|
| 196 |
/** |
| 197 |
* Sets Location Ids. |
| 198 |
* The [locations](entity:Location) at which the program is active. |
| 199 |
* |
| 200 |
* @maps location_ids |
| 201 |
* |
| 202 |
* @param string[]|null $locationIds |
| 203 |
*/ |
| 204 |
public function setLocationIds(?array $locationIds): void |
| 205 |
{ |
| 206 |
$this->locationIds['value'] = $locationIds; |
| 207 |
} |
| 208 |
|
| 209 |
/** |
| 210 |
* Unsets Location Ids. |
| 211 |
* The [locations](entity:Location) at which the program is active. |
| 212 |
*/ |
| 213 |
public function unsetLocationIds(): void |
| 214 |
{ |
| 215 |
$this->locationIds = []; |
| 216 |
} |
| 217 |
|
| 218 |
/** |
| 219 |
* Returns Created At. |
| 220 |
* The timestamp when the program was created, in RFC 3339 format. |
| 221 |
*/ |
| 222 |
public function getCreatedAt(): ?string |
| 223 |
{ |
| 224 |
return $this->createdAt; |
| 225 |
} |
| 226 |
|
| 227 |
/** |
| 228 |
* Sets Created At. |
| 229 |
* The timestamp when the program was created, in RFC 3339 format. |
| 230 |
* |
| 231 |
* @maps created_at |
| 232 |
*/ |
| 233 |
public function setCreatedAt(?string $createdAt): void |
| 234 |
{ |
| 235 |
$this->createdAt = $createdAt; |
| 236 |
} |
| 237 |
|
| 238 |
/** |
| 239 |
* Returns Updated At. |
| 240 |
* The timestamp when the reward was last updated, in RFC 3339 format. |
| 241 |
*/ |
| 242 |
public function getUpdatedAt(): ?string |
| 243 |
{ |
| 244 |
return $this->updatedAt; |
| 245 |
} |
| 246 |
|
| 247 |
/** |
| 248 |
* Sets Updated At. |
| 249 |
* The timestamp when the reward was last updated, in RFC 3339 format. |
| 250 |
* |
| 251 |
* @maps updated_at |
| 252 |
*/ |
| 253 |
public function setUpdatedAt(?string $updatedAt): void |
| 254 |
{ |
| 255 |
$this->updatedAt = $updatedAt; |
| 256 |
} |
| 257 |
|
| 258 |
/** |
| 259 |
* Returns Accrual Rules. |
| 260 |
* Defines how buyers can earn loyalty points from the base loyalty program. |
| 261 |
* To check for associated [loyalty promotions](entity:LoyaltyPromotion) that enable |
| 262 |
* buyers to earn extra points, call [ListLoyaltyPromotions](api-endpoint:Loyalty- |
| 263 |
* ListLoyaltyPromotions). |
| 264 |
* |
| 265 |
* @return LoyaltyProgramAccrualRule[]|null |
| 266 |
*/ |
| 267 |
public function getAccrualRules(): ?array |
| 268 |
{ |
| 269 |
if (count($this->accrualRules) == 0) { |
| 270 |
return null; |
| 271 |
} |
| 272 |
return $this->accrualRules['value']; |
| 273 |
} |
| 274 |
|
| 275 |
/** |
| 276 |
* Sets Accrual Rules. |
| 277 |
* Defines how buyers can earn loyalty points from the base loyalty program. |
| 278 |
* To check for associated [loyalty promotions](entity:LoyaltyPromotion) that enable |
| 279 |
* buyers to earn extra points, call [ListLoyaltyPromotions](api-endpoint:Loyalty- |
| 280 |
* ListLoyaltyPromotions). |
| 281 |
* |
| 282 |
* @maps accrual_rules |
| 283 |
* |
| 284 |
* @param LoyaltyProgramAccrualRule[]|null $accrualRules |
| 285 |
*/ |
| 286 |
public function setAccrualRules(?array $accrualRules): void |
| 287 |
{ |
| 288 |
$this->accrualRules['value'] = $accrualRules; |
| 289 |
} |
| 290 |
|
| 291 |
/** |
| 292 |
* Unsets Accrual Rules. |
| 293 |
* Defines how buyers can earn loyalty points from the base loyalty program. |
| 294 |
* To check for associated [loyalty promotions](entity:LoyaltyPromotion) that enable |
| 295 |
* buyers to earn extra points, call [ListLoyaltyPromotions](api-endpoint:Loyalty- |
| 296 |
* ListLoyaltyPromotions). |
| 297 |
*/ |
| 298 |
public function unsetAccrualRules(): void |
| 299 |
{ |
| 300 |
$this->accrualRules = []; |
| 301 |
} |
| 302 |
|
| 303 |
/** |
| 304 |
* Encode this object to JSON |
| 305 |
* |
| 306 |
* @param bool $asArrayWhenEmpty Whether to serialize this model as an array whenever no fields |
| 307 |
* are set. (default: false) |
| 308 |
* |
| 309 |
* @return array|stdClass |
| 310 |
*/ |
| 311 |
#[\ReturnTypeWillChange] // @phan-suppress-current-line PhanUndeclaredClassAttribute for (php < 8.1) |
| 312 |
public function jsonSerialize(bool $asArrayWhenEmpty = false) |
| 313 |
{ |
| 314 |
$json = []; |
| 315 |
if (isset($this->id)) { |
| 316 |
$json['id'] = $this->id; |
| 317 |
} |
| 318 |
if (isset($this->status)) { |
| 319 |
$json['status'] = $this->status; |
| 320 |
} |
| 321 |
if (!empty($this->rewardTiers)) { |
| 322 |
$json['reward_tiers'] = $this->rewardTiers['value']; |
| 323 |
} |
| 324 |
if (isset($this->expirationPolicy)) { |
| 325 |
$json['expiration_policy'] = $this->expirationPolicy; |
| 326 |
} |
| 327 |
if (isset($this->terminology)) { |
| 328 |
$json['terminology'] = $this->terminology; |
| 329 |
} |
| 330 |
if (!empty($this->locationIds)) { |
| 331 |
$json['location_ids'] = $this->locationIds['value']; |
| 332 |
} |
| 333 |
if (isset($this->createdAt)) { |
| 334 |
$json['created_at'] = $this->createdAt; |
| 335 |
} |
| 336 |
if (isset($this->updatedAt)) { |
| 337 |
$json['updated_at'] = $this->updatedAt; |
| 338 |
} |
| 339 |
if (!empty($this->accrualRules)) { |
| 340 |
$json['accrual_rules'] = $this->accrualRules['value']; |
| 341 |
} |
| 342 |
$json = array_filter($json, function ($val) { |
| 343 |
return $val !== null; |
| 344 |
}); |
| 345 |
|
| 346 |
return (!$asArrayWhenEmpty && empty($json)) ? new stdClass() : $json; |
| 347 |
} |
| 348 |
} |
| 349 |
|