charitable
/
vendor
/
square
/
square
/
src
/
Legacy
/
Models
/
LoyaltyPromotionAvailableTimeData.php
LoyaltyPromotionAvailableTimeData.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.13, at vendor/square/square/src/Legacy/Models/LoyaltyPromotionAvailableTimeData.php
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Square\Legacy\Models; |
| 6 | |
| 7 | use stdClass; |
| 8 | |
| 9 | /** |
| 10 | * Represents scheduling information that determines when purchases can qualify to earn points |
| 11 | * from a [loyalty promotion]($m/LoyaltyPromotion). |
| 12 | */ |
| 13 | class LoyaltyPromotionAvailableTimeData implements \JsonSerializable |
| 14 | { |
| 15 | /** |
| 16 | * @var string|null |
| 17 | */ |
| 18 | private $startDate; |
| 19 | |
| 20 | /** |
| 21 | * @var string|null |
| 22 | */ |
| 23 | private $endDate; |
| 24 | |
| 25 | /** |
| 26 | * @var string[] |
| 27 | */ |
| 28 | private $timePeriods; |
| 29 | |
| 30 | /** |
| 31 | * @param string[] $timePeriods |
| 32 | */ |
| 33 | public function __construct(array $timePeriods) |
| 34 | { |
| 35 | $this->timePeriods = $timePeriods; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Returns Start Date. |
| 40 | * The date that the promotion starts, in `YYYY-MM-DD` format. Square populates this field |
| 41 | * based on the provided `time_periods`. |
| 42 | */ |
| 43 | public function getStartDate(): ?string |
| 44 | { |
| 45 | return $this->startDate; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Sets Start Date. |
| 50 | * The date that the promotion starts, in `YYYY-MM-DD` format. Square populates this field |
| 51 | * based on the provided `time_periods`. |
| 52 | * |
| 53 | * @maps start_date |
| 54 | */ |
| 55 | public function setStartDate(?string $startDate): void |
| 56 | { |
| 57 | $this->startDate = $startDate; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Returns End Date. |
| 62 | * The date that the promotion ends, in `YYYY-MM-DD` format. Square populates this field |
| 63 | * based on the provided `time_periods`. If an end date is not specified, an `ACTIVE` promotion |
| 64 | * remains available until it is canceled. |
| 65 | */ |
| 66 | public function getEndDate(): ?string |
| 67 | { |
| 68 | return $this->endDate; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Sets End Date. |
| 73 | * The date that the promotion ends, in `YYYY-MM-DD` format. Square populates this field |
| 74 | * based on the provided `time_periods`. If an end date is not specified, an `ACTIVE` promotion |
| 75 | * remains available until it is canceled. |
| 76 | * |
| 77 | * @maps end_date |
| 78 | */ |
| 79 | public function setEndDate(?string $endDate): void |
| 80 | { |
| 81 | $this->endDate = $endDate; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Returns Time Periods. |
| 86 | * A list of [iCalendar (RFC 5545) events](https://tools.ietf.org/html/rfc5545#section-3.6.1) |
| 87 | * (`VEVENT`). Each event represents an available time period per day or days of the week. |
| 88 | * A day can have a maximum of one available time period. |
| 89 | * |
| 90 | * Only `DTSTART`, `DURATION`, and `RRULE` are supported. `DTSTART` and `DURATION` are required and |
| 91 | * timestamps must be in local (unzoned) time format. Include `RRULE` to specify recurring promotions, |
| 92 | * an end date (using the `UNTIL` keyword), or both. For more information, see |
| 93 | * [Available time](https://developer.squareup.com/docs/loyalty-api/loyalty-promotions#available-time). |
| 94 | * |
| 95 | * Note that `BEGIN:VEVENT` and `END:VEVENT` are optional in a `CreateLoyaltyPromotion` request |
| 96 | * but are always included in the response. |
| 97 | * |
| 98 | * @return string[] |
| 99 | */ |
| 100 | public function getTimePeriods(): array |
| 101 | { |
| 102 | return $this->timePeriods; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Sets Time Periods. |
| 107 | * A list of [iCalendar (RFC 5545) events](https://tools.ietf.org/html/rfc5545#section-3.6.1) |
| 108 | * (`VEVENT`). Each event represents an available time period per day or days of the week. |
| 109 | * A day can have a maximum of one available time period. |
| 110 | * |
| 111 | * Only `DTSTART`, `DURATION`, and `RRULE` are supported. `DTSTART` and `DURATION` are required and |
| 112 | * timestamps must be in local (unzoned) time format. Include `RRULE` to specify recurring promotions, |
| 113 | * an end date (using the `UNTIL` keyword), or both. For more information, see |
| 114 | * [Available time](https://developer.squareup.com/docs/loyalty-api/loyalty-promotions#available-time). |
| 115 | * |
| 116 | * Note that `BEGIN:VEVENT` and `END:VEVENT` are optional in a `CreateLoyaltyPromotion` request |
| 117 | * but are always included in the response. |
| 118 | * |
| 119 | * @required |
| 120 | * @maps time_periods |
| 121 | * |
| 122 | * @param string[] $timePeriods |
| 123 | */ |
| 124 | public function setTimePeriods(array $timePeriods): void |
| 125 | { |
| 126 | $this->timePeriods = $timePeriods; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Encode this object to JSON |
| 131 | * |
| 132 | * @param bool $asArrayWhenEmpty Whether to serialize this model as an array whenever no fields |
| 133 | * are set. (default: false) |
| 134 | * |
| 135 | * @return array|stdClass |
| 136 | */ |
| 137 | #[\ReturnTypeWillChange] // @phan-suppress-current-line PhanUndeclaredClassAttribute for (php < 8.1) |
| 138 | public function jsonSerialize(bool $asArrayWhenEmpty = false) |
| 139 | { |
| 140 | $json = []; |
| 141 | if (isset($this->startDate)) { |
| 142 | $json['start_date'] = $this->startDate; |
| 143 | } |
| 144 | if (isset($this->endDate)) { |
| 145 | $json['end_date'] = $this->endDate; |
| 146 | } |
| 147 | $json['time_periods'] = $this->timePeriods; |
| 148 | $json = array_filter($json, function ($val) { |
| 149 | return $val !== null; |
| 150 | }); |
| 151 | |
| 152 | return (!$asArrayWhenEmpty && empty($json)) ? new stdClass() : $json; |
| 153 | } |
| 154 | } |
| 155 |