DisconnectStripeAccountController.php
4 years ago
GetStripeAccountDetailsController.php
4 years ago
NewStripeAccountOnBoardingController.php
4 years ago
SetDefaultStripeAccountController.php
4 years ago
GetStripeAccountDetailsController.php
56 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\PaymentGateways\Stripe\Controllers; |
| 4 | |
| 5 | use Give\Framework\Exceptions\Primitives\InvalidArgumentException; |
| 6 | use Give\PaymentGateways\Stripe\DataTransferObjects\GetStripeAccountDetailsDto; |
| 7 | use Give\PaymentGateways\Stripe\Repositories\AccountDetail; |
| 8 | |
| 9 | /** |
| 10 | * Class GetStripeAccountDetailsController |
| 11 | * @package Give\PaymentGateways\Stripe\Controllers |
| 12 | * |
| 13 | * @since 2.13.0 |
| 14 | */ |
| 15 | class GetStripeAccountDetailsController { |
| 16 | /** |
| 17 | * @var AccountDetail |
| 18 | */ |
| 19 | private $accountDetailServiceProvider; |
| 20 | |
| 21 | /** |
| 22 | * @since 2.13.3 |
| 23 | * @param AccountDetail $accountDetailServiceProvider |
| 24 | */ |
| 25 | public function __construct( AccountDetail $accountDetailServiceProvider ) { |
| 26 | $this->accountDetailServiceProvider = $accountDetailServiceProvider; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @since 2.13.3 |
| 31 | */ |
| 32 | public function __invoke() { |
| 33 | $this->validateRequest(); |
| 34 | $requestedData = GetStripeAccountDetailsDto::fromArray( give_clean( $_POST ) ); |
| 35 | |
| 36 | try { |
| 37 | wp_send_json_success( |
| 38 | $this->accountDetailServiceProvider |
| 39 | ->getAccountDetailBySlug( $requestedData->accountSlug ) |
| 40 | ->toArray() |
| 41 | ); |
| 42 | } catch ( InvalidArgumentException $e ) { |
| 43 | wp_send_json_error(); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @since 2.13.0 |
| 49 | */ |
| 50 | private function validateRequest() { |
| 51 | if ( ! current_user_can( 'manage_give_settings' ) ) { |
| 52 | die(); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 |