| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\Framework\FieldsAPI\Concerns; |
| 4 |
|
| 5 |
use Closure; |
| 6 |
|
| 7 |
/** |
| 8 |
* @since 2.10.2 |
| 9 |
*/ |
| 10 |
trait ShowInReceipt |
| 11 |
{ |
| 12 |
|
| 13 |
/** |
| 14 |
* @since 2.10.2 |
| 15 |
*/ |
| 16 |
protected $showInReceipt = false; |
| 17 |
|
| 18 |
/** |
| 19 |
* @var string |
| 20 |
*/ |
| 21 |
protected $receiptLabel; |
| 22 |
|
| 23 |
/** |
| 24 |
* @var Closure |
| 25 |
*/ |
| 26 |
protected $receiptValueCallback; |
| 27 |
|
| 28 |
/** |
| 29 |
* @since 2.10.2 |
| 30 |
*/ |
| 31 |
public function showInReceipt($showInReceipt = true): self |
| 32 |
{ |
| 33 |
$this->showInReceipt = $showInReceipt; |
| 34 |
|
| 35 |
return $this; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* @since 2.10.2 |
| 40 |
*/ |
| 41 |
public function shouldShowInReceipt(): bool |
| 42 |
{ |
| 43 |
return $this->showInReceipt; |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* @since 3.3.0 |
| 48 |
*/ |
| 49 |
public function receiptLabel(string $label): self |
| 50 |
{ |
| 51 |
$this->receiptLabel = $label; |
| 52 |
|
| 53 |
return $this; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* @since 3.3.0 |
| 58 |
*/ |
| 59 |
public function hasReceiptLabel(): bool |
| 60 |
{ |
| 61 |
return !empty($this->receiptLabel); |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* @since 3.3.0 |
| 66 |
*/ |
| 67 |
public function getReceiptLabel(): string |
| 68 |
{ |
| 69 |
return $this->receiptLabel; |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* @since 3.3.0 |
| 74 |
*/ |
| 75 |
public function hasReceiptValue(): bool |
| 76 |
{ |
| 77 |
return !empty($this->receiptValueCallback); |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* @since 3.3.0 |
| 82 |
*/ |
| 83 |
public function isReceiptValueCallback(): bool |
| 84 |
{ |
| 85 |
return is_callable($this->receiptValueCallback); |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* @since 3.3.0 |
| 90 |
*/ |
| 91 |
public function getReceiptValue(): Closure |
| 92 |
{ |
| 93 |
return $this->receiptValueCallback; |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* @since 3.3.0 |
| 98 |
*/ |
| 99 |
public function receiptValue(Closure $value): self |
| 100 |
{ |
| 101 |
$this->receiptValueCallback = $value; |
| 102 |
|
| 103 |
return $this; |
| 104 |
} |
| 105 |
} |
| 106 |
|