AccountDetail.php
83 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\PaymentGateways\Stripe\Models; |
| 4 | |
| 5 | use Give\Helpers\ArrayDataSet; |
| 6 | use InvalidArgumentException; |
| 7 | |
| 8 | /** |
| 9 | * Class AccountDetail |
| 10 | * |
| 11 | * @package Give\PaymentGateways\Stripe\Models |
| 12 | * @since 2.10.2 |
| 13 | * |
| 14 | * @property-read string $type |
| 15 | * @property-read string $accountName |
| 16 | * @property-read string $accountSlug |
| 17 | * @property-read string $accountEmail |
| 18 | * @property-read string $accountCountry |
| 19 | * @property-read string $accountId |
| 20 | * @property-read string $liveSecretKey |
| 21 | * @property-read string $livePublishableKey |
| 22 | * @property-read string $testSecretKey |
| 23 | * @property-read string $testPublishableKey |
| 24 | */ |
| 25 | class AccountDetail { |
| 26 | protected $args; |
| 27 | protected $propertiesArgs; |
| 28 | protected $requiredArgs = [ |
| 29 | 'type', |
| 30 | 'account_name', |
| 31 | 'account_slug', |
| 32 | 'account_email', |
| 33 | 'account_country', |
| 34 | 'account_id', |
| 35 | 'live_secret_key', |
| 36 | 'live_publishable_key', |
| 37 | 'test_secret_key', |
| 38 | 'test_publishable_key', |
| 39 | ]; |
| 40 | |
| 41 | /** |
| 42 | * AccountDetail constructor. |
| 43 | * |
| 44 | * @since 2.10.2 |
| 45 | * @param array $args |
| 46 | */ |
| 47 | public function __construct( array $args ) { |
| 48 | $this->args = $args; |
| 49 | $this->propertiesArgs = ArrayDataSet::camelCaseKeys( $args ); |
| 50 | $this->validate( $args ); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * @since 2.10.2 |
| 55 | * @param string $key |
| 56 | * |
| 57 | * @return mixed |
| 58 | */ |
| 59 | public function __get( $key ) { |
| 60 | return $this->propertiesArgs[ $key ]; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Validate array format. |
| 65 | * |
| 66 | * @since 2.10.2 |
| 67 | * @param array $array |
| 68 | * |
| 69 | * @throws InvalidArgumentException |
| 70 | */ |
| 71 | private function validate( $array ) { |
| 72 | if ( array_diff( $this->requiredArgs, array_keys( $array ) ) ) { |
| 73 | throw new InvalidArgumentException( |
| 74 | sprintf( |
| 75 | esc_html__( 'To create a %1$s object, please provide valid: %2$s', 'give' ), |
| 76 | __CLASS__, |
| 77 | implode( ' , ', $this->requiredArgs ) |
| 78 | ) |
| 79 | ); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 |