| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Square\Legacy\Models; |
| 6 |
|
| 7 |
use stdClass; |
| 8 |
|
| 9 |
/** |
| 10 |
* Represents the Square processing fee. |
| 11 |
*/ |
| 12 |
class ProcessingFee implements \JsonSerializable |
| 13 |
{ |
| 14 |
/** |
| 15 |
* @var array |
| 16 |
*/ |
| 17 |
private $effectiveAt = []; |
| 18 |
|
| 19 |
/** |
| 20 |
* @var array |
| 21 |
*/ |
| 22 |
private $type = []; |
| 23 |
|
| 24 |
/** |
| 25 |
* @var Money|null |
| 26 |
*/ |
| 27 |
private $amountMoney; |
| 28 |
|
| 29 |
/** |
| 30 |
* Returns Effective At. |
| 31 |
* The timestamp of when the fee takes effect, in RFC 3339 format. |
| 32 |
*/ |
| 33 |
public function getEffectiveAt(): ?string |
| 34 |
{ |
| 35 |
if (count($this->effectiveAt) == 0) { |
| 36 |
return null; |
| 37 |
} |
| 38 |
return $this->effectiveAt['value']; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Sets Effective At. |
| 43 |
* The timestamp of when the fee takes effect, in RFC 3339 format. |
| 44 |
* |
| 45 |
* @maps effective_at |
| 46 |
*/ |
| 47 |
public function setEffectiveAt(?string $effectiveAt): void |
| 48 |
{ |
| 49 |
$this->effectiveAt['value'] = $effectiveAt; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Unsets Effective At. |
| 54 |
* The timestamp of when the fee takes effect, in RFC 3339 format. |
| 55 |
*/ |
| 56 |
public function unsetEffectiveAt(): void |
| 57 |
{ |
| 58 |
$this->effectiveAt = []; |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Returns Type. |
| 63 |
* The type of fee assessed or adjusted. The fee type can be `INITIAL` or `ADJUSTMENT`. |
| 64 |
*/ |
| 65 |
public function getType(): ?string |
| 66 |
{ |
| 67 |
if (count($this->type) == 0) { |
| 68 |
return null; |
| 69 |
} |
| 70 |
return $this->type['value']; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Sets Type. |
| 75 |
* The type of fee assessed or adjusted. The fee type can be `INITIAL` or `ADJUSTMENT`. |
| 76 |
* |
| 77 |
* @maps type |
| 78 |
*/ |
| 79 |
public function setType(?string $type): void |
| 80 |
{ |
| 81 |
$this->type['value'] = $type; |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Unsets Type. |
| 86 |
* The type of fee assessed or adjusted. The fee type can be `INITIAL` or `ADJUSTMENT`. |
| 87 |
*/ |
| 88 |
public function unsetType(): void |
| 89 |
{ |
| 90 |
$this->type = []; |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Returns Amount Money. |
| 95 |
* Represents an amount of money. `Money` fields can be signed or unsigned. |
| 96 |
* Fields that do not explicitly define whether they are signed or unsigned are |
| 97 |
* considered unsigned and can only hold positive amounts. For signed fields, the |
| 98 |
* sign of the value indicates the purpose of the money transfer. See |
| 99 |
* [Working with Monetary Amounts](https://developer.squareup.com/docs/build-basics/working-with- |
| 100 |
* monetary-amounts) |
| 101 |
* for more information. |
| 102 |
*/ |
| 103 |
public function getAmountMoney(): ?Money |
| 104 |
{ |
| 105 |
return $this->amountMoney; |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* Sets Amount Money. |
| 110 |
* Represents an amount of money. `Money` fields can be signed or unsigned. |
| 111 |
* Fields that do not explicitly define whether they are signed or unsigned are |
| 112 |
* considered unsigned and can only hold positive amounts. For signed fields, the |
| 113 |
* sign of the value indicates the purpose of the money transfer. See |
| 114 |
* [Working with Monetary Amounts](https://developer.squareup.com/docs/build-basics/working-with- |
| 115 |
* monetary-amounts) |
| 116 |
* for more information. |
| 117 |
* |
| 118 |
* @maps amount_money |
| 119 |
*/ |
| 120 |
public function setAmountMoney(?Money $amountMoney): void |
| 121 |
{ |
| 122 |
$this->amountMoney = $amountMoney; |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* Encode this object to JSON |
| 127 |
* |
| 128 |
* @param bool $asArrayWhenEmpty Whether to serialize this model as an array whenever no fields |
| 129 |
* are set. (default: false) |
| 130 |
* |
| 131 |
* @return array|stdClass |
| 132 |
*/ |
| 133 |
#[\ReturnTypeWillChange] // @phan-suppress-current-line PhanUndeclaredClassAttribute for (php < 8.1) |
| 134 |
public function jsonSerialize(bool $asArrayWhenEmpty = false) |
| 135 |
{ |
| 136 |
$json = []; |
| 137 |
if (!empty($this->effectiveAt)) { |
| 138 |
$json['effective_at'] = $this->effectiveAt['value']; |
| 139 |
} |
| 140 |
if (!empty($this->type)) { |
| 141 |
$json['type'] = $this->type['value']; |
| 142 |
} |
| 143 |
if (isset($this->amountMoney)) { |
| 144 |
$json['amount_money'] = $this->amountMoney; |
| 145 |
} |
| 146 |
$json = array_filter($json, function ($val) { |
| 147 |
return $val !== null; |
| 148 |
}); |
| 149 |
|
| 150 |
return (!$asArrayWhenEmpty && empty($json)) ? new stdClass() : $json; |
| 151 |
} |
| 152 |
} |
| 153 |
|