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