PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.7
GiveWP – Donation Plugin and Fundraising Platform v4.16.7
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / PaymentGateways / Stripe / Controllers / SetDefaultStripeAccountController.php
SetDefaultStripeAccountController.php
76 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\PaymentGateways\Stripe\Controllers;
4
5 use Give\PaymentGateways\Stripe\DataTransferObjects\SetDefaultStripeAccountDto;
6 use Give\PaymentGateways\Stripe\Repositories\Settings;
7
8 /**
9 * Class SetDefaultStripeAccountController
10 * @package Give\PaymentGateways\Stripe\Controllers
11 *
12 * @since 2.13.0
13 */
14 class SetDefaultStripeAccountController
15 {
16 /**
17 * @var Settings
18 */
19 private $settingsRepository;
20
21 /**
22 * @param Settings $settingsRepository
23 */
24 public function __construct(Settings $settingsRepository)
25 {
26 $this->settingsRepository = $settingsRepository;
27 }
28
29 /**
30 * @since 2.13.0
31 */
32 public function __invoke()
33 {
34 $this->validateRequest();
35
36 $requestData = SetDefaultStripeAccountDto::fromArray(give_clean($_POST));
37
38 try {
39 if ($requestData->formId) {
40 $this->settingsRepository
41 ->setDefaultStripeAccountSlugForDonationForm(
42 $requestData->formId,
43 $requestData->accountSlug
44 );
45
46 give()->form_meta->update_meta(
47 $requestData->formId,
48 'give_stripe_per_form_accounts',
49 'enabled'
50 );
51
52 wp_send_json_success();
53 }
54
55 $this->settingsRepository->setDefaultGlobalStripeAccountSlug($requestData->accountSlug);
56 wp_send_json_success();
57 } catch (\Exception $e) {
58 wp_send_json_error(
59 [
60 'error' => $e->getMessage(),
61 ]
62 );
63 }
64 }
65
66 /**
67 * @since 2.13.0
68 */
69 private function validateRequest()
70 {
71 if ( ! current_user_can('manage_give_settings')) {
72 die();
73 }
74 }
75 }
76