DisconnectStripeAccountController.php
4 years ago
GetStripeAccountDetailsController.php
4 years ago
NewStripeAccountOnBoardingController.php
2 years ago
SetDefaultStripeAccountController.php
4 years ago
GetStripeAccountDetailsController.php
61 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 | /** |
| 18 | * @var AccountDetail |
| 19 | */ |
| 20 | private $accountDetailServiceProvider; |
| 21 | |
| 22 | /** |
| 23 | * @since 2.13.3 |
| 24 | * |
| 25 | * @param AccountDetail $accountDetailServiceProvider |
| 26 | */ |
| 27 | public function __construct(AccountDetail $accountDetailServiceProvider) |
| 28 | { |
| 29 | $this->accountDetailServiceProvider = $accountDetailServiceProvider; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * @since 2.13.3 |
| 34 | */ |
| 35 | public function __invoke() |
| 36 | { |
| 37 | $this->validateRequest(); |
| 38 | $requestedData = GetStripeAccountDetailsDto::fromArray(give_clean($_POST)); |
| 39 | |
| 40 | try { |
| 41 | wp_send_json_success( |
| 42 | $this->accountDetailServiceProvider |
| 43 | ->getAccountDetailBySlug($requestedData->accountSlug) |
| 44 | ->toArray() |
| 45 | ); |
| 46 | } catch (InvalidArgumentException $e) { |
| 47 | wp_send_json_error(); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @since 2.13.0 |
| 53 | */ |
| 54 | private function validateRequest() |
| 55 | { |
| 56 | if ( ! current_user_can('manage_give_settings')) { |
| 57 | die(); |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 |