PluginProbe
AliNext – WooCommerce Dropshipping Plugin for AliExpress / trunk
AliNext – WooCommerce Dropshipping Plugin for AliExpress vtrunk
ali2woo-lite / includes / classes / service / PurchaseCodeInfoService.php

PurchaseCodeInfoService.php in AliNext – WooCommerce Dropshipping Plugin for AliExpress trunk, at includes/classes/service/PurchaseCodeInfoService.php

75 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Description of PurchaseCodeInfoService
5 *
6 * @author Ali2Woo Team
7 */
8
9 namespace AliNext_Lite;;
10
11 class PurchaseCodeInfoService
12 {
13 protected PurchaseCodeInfoFactory $PurchaseCodeInfoFactory;
14 protected PlatformClient $PlatformClient;
15 protected PurchaseCodeInfoRepository $PurchaseCodeInfoRepository;
16
17
18 public function __construct(
19 PurchaseCodeInfoFactory $PurchaseCodeInfoFactory,
20 PlatformClient $PlatformClient,
21 PurchaseCodeInfoRepository $PurchaseCodeInfoRepository
22 ) {
23 $this->PurchaseCodeInfoFactory = $PurchaseCodeInfoFactory;
24 $this->PlatformClient = $PlatformClient;
25 $this->PurchaseCodeInfoRepository = $PurchaseCodeInfoRepository;
26 }
27
28 /**
29 * @throws PlatformException
30 */
31 public function getFromApi(): PurchaseCodeInfo
32 {
33 $ApiResponse = $this->PlatformClient->serverPing();
34
35 if ($ApiResponse->isStateOk()) {
36
37 $PurchaseCodeInfo = $this->PurchaseCodeInfoFactory->buildFromData(
38 $ApiResponse->getData()
39 );
40
41 $this->PurchaseCodeInfoRepository->save($PurchaseCodeInfo);
42
43 return $PurchaseCodeInfo;
44 }
45
46 throw new PlatformException($ApiResponse->getMessage());
47 }
48
49 public function getFromCache(): PurchaseCodeInfo
50 {
51 return $this->PurchaseCodeInfoRepository->get();
52 }
53
54 public function checkAutoUpdateMaxQuota(?PurchaseCodeInfo $PurchaseCodeInfo = null): bool
55 {
56 if (!A2WL()->isAnPlugin()) {
57 return true;
58 }
59
60 if (is_null($PurchaseCodeInfo)) {
61 $PurchaseCodeInfo = $this->getFromCache();
62 }
63
64 $PackageUsageInPercent = $PurchaseCodeInfo->getPackageUsageInPercent();
65
66 if (is_null($PackageUsageInPercent)) {
67 return true;
68 }
69
70 $autoUpdateMaxQuota = intval(get_setting(Settings::SETTING_AUTO_UPDATE_MAX_QUOTA));
71
72 return $PackageUsageInPercent <= $autoUpdateMaxQuota;
73 }
74 }
75