GetCredits.php
1.26 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
<?php
namespace WPML\TM\ATE\ClonedSites\Endpoints;
use WPML\Ajax\IHandler;
use WPML\Collect\Support\Collection;
use WPML\FP\Either;
use WPML\FP\Lst;
use WPML\LIB\WP\Hooks;
use WPML\LIB\WP\WordPress;
use WPML\TM\API\ATE\Account;
use WPML\TM\ATE\ClonedSites\Endpoints\GetCredits\AMSAPIFactory;
use WPML\TM\ATE\ClonedSites\FingerprintGeneratorForOriginalSite;
use WPML\TM\ATE\ClonedSites\Lock;
use function WPML\Container\make;
class GetCredits implements IHandler {
/** @var AMSAPIFactory */
private $amsAPIFactory;
public function __construct( AMSAPIFactory $amsAPIFactory ) {
$this->amsAPIFactory = $amsAPIFactory;
}
public function run( Collection $data ) {
$getCredit = function () {
try {
$credits = $this->amsAPIFactory->create()->getCredits();
return is_array( $credits )
? Either::right( $credits )
: Either::left( __( 'Communication error', 'sitepress' ) );
} catch ( \Exception $e ) {
return Either::left( __( 'Communication error', 'sitepress' ) );
}
};
$addCreditEndpointToWhitelist = function ( $otherEndpoints ) {
return Lst::append( \WPML_TM_ATE_AMS_Endpoints::ENDPOINTS_CREDITS, $otherEndpoints );
};
return Hooks::callWithFilter( $getCredit, 'wpml_ate_locked_endpoints_whitelist', $addCreditEndpointToWhitelist );
}
}