1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* Copyright (C) 2020-2025 Iain Cambridge |
7
|
|
|
* |
8
|
|
|
* This program is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by |
10
|
|
|
* the Free Software Foundation, either version 2.1 of the License, or |
11
|
|
|
* (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU Lesser General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU General Public License |
19
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace Parthenon\Billing\BillaBear\Subscription; |
23
|
|
|
|
24
|
|
|
use Parthenon\Billing\BillaBear\SdkFactory; |
25
|
|
|
use Parthenon\Billing\Entity\CustomerInterface; |
26
|
|
|
use Parthenon\Billing\Entity\Subscription; |
27
|
|
|
use Parthenon\Billing\Enum\SubscriptionStatus; |
28
|
|
|
use Parthenon\Billing\Factory\EntityFactoryInterface; |
29
|
|
|
use Parthenon\Billing\Subscription\SubscriptionProviderInterface; |
30
|
|
|
|
31
|
|
|
class SubscriptionProvider implements SubscriptionProviderInterface |
32
|
|
|
{ |
33
|
|
|
public function __construct( |
34
|
|
|
private SdkFactory $sdkFactory, |
35
|
|
|
private EntityFactoryInterface $entityFactory, |
36
|
|
|
) { |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function getSubscriptionsForCustomer(CustomerInterface $customer): array |
40
|
|
|
{ |
41
|
|
|
$response = $this->sdkFactory->createSubscriptionsApi()->getActiveForCustomer($customer->getExternalCustomerReference()); |
42
|
|
|
$output = []; |
43
|
|
|
foreach ($response->getData() as $subscription) { |
44
|
|
|
$output[] = $this->buildSubscription($subscription); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $output; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function buildSubscription(\BillaBear\Model\Subscription $subscription): Subscription |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$entity = $this->entityFactory->getSubscriptionEntity(); |
53
|
|
|
$entity->setId($subscription->getId()); |
54
|
|
|
$entity->setActive(true); |
55
|
|
|
$entity->setPaymentSchedule($subscription->getSchedule()); |
56
|
|
|
$entity->setSeats($subscription->getSeatNumber()); |
57
|
|
|
$entity->setPlanName($subscription->getPlan()?->getName()); |
58
|
|
|
$entity->setValidUntil(new \DateTime($subscription->getValidUntil())); |
59
|
|
|
$entity->setCreatedAt(new \DateTime($subscription->getCreatedAt())); |
60
|
|
|
$entity->setUpdatedAt(new \DateTime($subscription->getUpdatedAt())); |
61
|
|
|
$entity->setCurrency($subscription->getPrice()?->getCurrency()); |
62
|
|
|
$entity->setStatus(SubscriptionStatus::from($subscription->getStatus())); |
63
|
|
|
|
64
|
|
|
if ($subscription->getPrice()) { |
65
|
|
|
$price = $this->entityFactory->getPriceEntity(); |
66
|
|
|
$price->setCurrency($subscription->getPrice()?->getCurrency()); |
67
|
|
|
$price->setAmount($subscription->getPrice()?->getAmount()); |
68
|
|
|
$price->setSchedule($subscription->getPrice()?->getSchedule()); |
69
|
|
|
$entity->setPrice($price); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $entity; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function getSubscription(string $id): Subscription |
76
|
|
|
{ |
77
|
|
|
$response = $this->sdkFactory->createSubscriptionsApi()->showSubscriptionById($id); |
78
|
|
|
|
79
|
|
|
return $this->buildSubscription($response); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths