SubscriptionUpdate.php
2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace ACP\RequestHandler\Ajax;
use AC;
use AC\Capabilities;
use AC\Nonce;
use ACP\Access\ActivationKeyStorage;
use ACP\Access\ActivationStorage;
use ACP\Access\ActivationUpdater;
use ACP\Access\PermissionChecker;
use ACP\ActivationTokenFactory;
use ACP\LicenseKeyRepository;
use ACP\PluginRepository;
use ACP\RequestAjaxHandler;
use ACP\RequestDispatcher;
use ACP\Type\SiteUrl;
class SubscriptionUpdate implements RequestAjaxHandler {
/**
* @var ActivationStorage
*/
private $activation_storage;
/**
* @var ActivationKeyStorage
*/
private $activation_key_storage;
/**
* @var LicenseKeyRepository
*/
private $license_key_repository;
/**
* @var PermissionChecker
*/
private $permission_checker;
/**
* @var RequestDispatcher
*/
private $api;
/**
* @var SiteUrl
*/
private $activation_url;
/**
* @var ActivationTokenFactory
*/
private $token_factory;
/**
* @var PluginRepository
*/
private $plugin_repository;
public function __construct( ActivationStorage $activation_storage, ActivationKeyStorage $activation_key_storage, LicenseKeyRepository $license_key_repository, PermissionChecker $permission_checker, RequestDispatcher $api, SiteUrl $activation_url, ActivationTokenFactory $token_factory, PluginRepository $plugin_repository ) {
$this->activation_storage = $activation_storage;
$this->activation_key_storage = $activation_key_storage;
$this->license_key_repository = $license_key_repository;
$this->permission_checker = $permission_checker;
$this->api = $api;
$this->activation_url = $activation_url;
$this->token_factory = $token_factory;
$this->plugin_repository = $plugin_repository;
}
public function handle(): void {
if ( ! current_user_can( Capabilities::MANAGE ) ) {
return;
}
$request = new AC\Request();
if ( ! ( new Nonce\Ajax() )->verify( $request ) ) {
wp_send_json_error();
}
$activation_token = $this->token_factory->create();
if ( ! $activation_token ) {
wp_send_json_error();
}
$updater = new ActivationUpdater(
$this->activation_key_storage,
$this->activation_storage,
$this->license_key_repository,
$this->api,
$this->activation_url,
$this->plugin_repository,
$this->permission_checker
);
$api_response = $updater->update( $activation_token );
if ( $api_response->has_error() ) {
wp_send_json_error( $api_response->get_error()->get_error_message() );
}
wp_send_json_success();
}
}