| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Square\Legacy\Models; |
| 6 |
|
| 7 |
use stdClass; |
| 8 |
|
| 9 |
/** |
| 10 |
* Represents a [CalculateLoyaltyPoints]($e/Loyalty/CalculateLoyaltyPoints) request. |
| 11 |
*/ |
| 12 |
class CalculateLoyaltyPointsRequest implements \JsonSerializable |
| 13 |
{ |
| 14 |
/** |
| 15 |
* @var array |
| 16 |
*/ |
| 17 |
private $orderId = []; |
| 18 |
|
| 19 |
/** |
| 20 |
* @var Money|null |
| 21 |
*/ |
| 22 |
private $transactionAmountMoney; |
| 23 |
|
| 24 |
/** |
| 25 |
* @var array |
| 26 |
*/ |
| 27 |
private $loyaltyAccountId = []; |
| 28 |
|
| 29 |
/** |
| 30 |
* Returns Order Id. |
| 31 |
* The [order](entity:Order) ID for which to calculate the points. |
| 32 |
* Specify this field if your application uses the Orders API to process orders. |
| 33 |
* Otherwise, specify the `transaction_amount_money`. |
| 34 |
*/ |
| 35 |
public function getOrderId(): ?string |
| 36 |
{ |
| 37 |
if (count($this->orderId) == 0) { |
| 38 |
return null; |
| 39 |
} |
| 40 |
return $this->orderId['value']; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Sets Order Id. |
| 45 |
* The [order](entity:Order) ID for which to calculate the points. |
| 46 |
* Specify this field if your application uses the Orders API to process orders. |
| 47 |
* Otherwise, specify the `transaction_amount_money`. |
| 48 |
* |
| 49 |
* @maps order_id |
| 50 |
*/ |
| 51 |
public function setOrderId(?string $orderId): void |
| 52 |
{ |
| 53 |
$this->orderId['value'] = $orderId; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Unsets Order Id. |
| 58 |
* The [order](entity:Order) ID for which to calculate the points. |
| 59 |
* Specify this field if your application uses the Orders API to process orders. |
| 60 |
* Otherwise, specify the `transaction_amount_money`. |
| 61 |
*/ |
| 62 |
public function unsetOrderId(): void |
| 63 |
{ |
| 64 |
$this->orderId = []; |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Returns Transaction Amount Money. |
| 69 |
* Represents an amount of money. `Money` fields can be signed or unsigned. |
| 70 |
* Fields that do not explicitly define whether they are signed or unsigned are |
| 71 |
* considered unsigned and can only hold positive amounts. For signed fields, the |
| 72 |
* sign of the value indicates the purpose of the money transfer. See |
| 73 |
* [Working with Monetary Amounts](https://developer.squareup.com/docs/build-basics/working-with- |
| 74 |
* monetary-amounts) |
| 75 |
* for more information. |
| 76 |
*/ |
| 77 |
public function getTransactionAmountMoney(): ?Money |
| 78 |
{ |
| 79 |
return $this->transactionAmountMoney; |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Sets Transaction Amount Money. |
| 84 |
* Represents an amount of money. `Money` fields can be signed or unsigned. |
| 85 |
* Fields that do not explicitly define whether they are signed or unsigned are |
| 86 |
* considered unsigned and can only hold positive amounts. For signed fields, the |
| 87 |
* sign of the value indicates the purpose of the money transfer. See |
| 88 |
* [Working with Monetary Amounts](https://developer.squareup.com/docs/build-basics/working-with- |
| 89 |
* monetary-amounts) |
| 90 |
* for more information. |
| 91 |
* |
| 92 |
* @maps transaction_amount_money |
| 93 |
*/ |
| 94 |
public function setTransactionAmountMoney(?Money $transactionAmountMoney): void |
| 95 |
{ |
| 96 |
$this->transactionAmountMoney = $transactionAmountMoney; |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Returns Loyalty Account Id. |
| 101 |
* The ID of the target [loyalty account](entity:LoyaltyAccount). Optionally specify this field |
| 102 |
* if your application uses the Orders API to process orders. |
| 103 |
* |
| 104 |
* If specified, the `promotion_points` field in the response shows the number of points the buyer |
| 105 |
* would |
| 106 |
* earn from the purchase. In this case, Square uses the account ID to determine whether the |
| 107 |
* promotion's |
| 108 |
* `trigger_limit` (the maximum number of times that a buyer can trigger the promotion) has been |
| 109 |
* reached. |
| 110 |
* If not specified, the `promotion_points` field shows the number of points the purchase qualifies |
| 111 |
* for regardless of the trigger limit. |
| 112 |
*/ |
| 113 |
public function getLoyaltyAccountId(): ?string |
| 114 |
{ |
| 115 |
if (count($this->loyaltyAccountId) == 0) { |
| 116 |
return null; |
| 117 |
} |
| 118 |
return $this->loyaltyAccountId['value']; |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* Sets Loyalty Account Id. |
| 123 |
* The ID of the target [loyalty account](entity:LoyaltyAccount). Optionally specify this field |
| 124 |
* if your application uses the Orders API to process orders. |
| 125 |
* |
| 126 |
* If specified, the `promotion_points` field in the response shows the number of points the buyer |
| 127 |
* would |
| 128 |
* earn from the purchase. In this case, Square uses the account ID to determine whether the |
| 129 |
* promotion's |
| 130 |
* `trigger_limit` (the maximum number of times that a buyer can trigger the promotion) has been |
| 131 |
* reached. |
| 132 |
* If not specified, the `promotion_points` field shows the number of points the purchase qualifies |
| 133 |
* for regardless of the trigger limit. |
| 134 |
* |
| 135 |
* @maps loyalty_account_id |
| 136 |
*/ |
| 137 |
public function setLoyaltyAccountId(?string $loyaltyAccountId): void |
| 138 |
{ |
| 139 |
$this->loyaltyAccountId['value'] = $loyaltyAccountId; |
| 140 |
} |
| 141 |
|
| 142 |
/** |
| 143 |
* Unsets Loyalty Account Id. |
| 144 |
* The ID of the target [loyalty account](entity:LoyaltyAccount). Optionally specify this field |
| 145 |
* if your application uses the Orders API to process orders. |
| 146 |
* |
| 147 |
* If specified, the `promotion_points` field in the response shows the number of points the buyer |
| 148 |
* would |
| 149 |
* earn from the purchase. In this case, Square uses the account ID to determine whether the |
| 150 |
* promotion's |
| 151 |
* `trigger_limit` (the maximum number of times that a buyer can trigger the promotion) has been |
| 152 |
* reached. |
| 153 |
* If not specified, the `promotion_points` field shows the number of points the purchase qualifies |
| 154 |
* for regardless of the trigger limit. |
| 155 |
*/ |
| 156 |
public function unsetLoyaltyAccountId(): void |
| 157 |
{ |
| 158 |
$this->loyaltyAccountId = []; |
| 159 |
} |
| 160 |
|
| 161 |
/** |
| 162 |
* Encode this object to JSON |
| 163 |
* |
| 164 |
* @param bool $asArrayWhenEmpty Whether to serialize this model as an array whenever no fields |
| 165 |
* are set. (default: false) |
| 166 |
* |
| 167 |
* @return array|stdClass |
| 168 |
*/ |
| 169 |
#[\ReturnTypeWillChange] // @phan-suppress-current-line PhanUndeclaredClassAttribute for (php < 8.1) |
| 170 |
public function jsonSerialize(bool $asArrayWhenEmpty = false) |
| 171 |
{ |
| 172 |
$json = []; |
| 173 |
if (!empty($this->orderId)) { |
| 174 |
$json['order_id'] = $this->orderId['value']; |
| 175 |
} |
| 176 |
if (isset($this->transactionAmountMoney)) { |
| 177 |
$json['transaction_amount_money'] = $this->transactionAmountMoney; |
| 178 |
} |
| 179 |
if (!empty($this->loyaltyAccountId)) { |
| 180 |
$json['loyalty_account_id'] = $this->loyaltyAccountId['value']; |
| 181 |
} |
| 182 |
$json = array_filter($json, function ($val) { |
| 183 |
return $val !== null; |
| 184 |
}); |
| 185 |
|
| 186 |
return (!$asArrayWhenEmpty && empty($json)) ? new stdClass() : $json; |
| 187 |
} |
| 188 |
} |
| 189 |
|