HasMode.php
38 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\PaymentGateways\PayPalCommerce\Repositories\Traits; |
| 4 | |
| 5 | use Give\Framework\Exceptions\Primitives\InvalidArgumentException; |
| 6 | |
| 7 | trait HasMode |
| 8 | { |
| 9 | /** |
| 10 | * The current working mode: live or sandbox |
| 11 | * |
| 12 | * @since 2.9.0 |
| 13 | * |
| 14 | * @var string |
| 15 | */ |
| 16 | protected $mode; |
| 17 | |
| 18 | /** |
| 19 | * Sets the mode for the repository for handling operations |
| 20 | * |
| 21 | * @since 2.9.0 |
| 22 | * |
| 23 | * @param $mode |
| 24 | * |
| 25 | * @return $this |
| 26 | */ |
| 27 | public function setMode($mode) |
| 28 | { |
| 29 | if ( ! in_array($mode, ['live', 'sandbox'], true)) { |
| 30 | throw new InvalidArgumentException("Must be either 'live' or 'sandbox', received: $mode"); |
| 31 | } |
| 32 | |
| 33 | $this->mode = $mode; |
| 34 | |
| 35 | return $this; |
| 36 | } |
| 37 | } |
| 38 |