|
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\Payments\PaymentProvider\TransactionCloud; |
|
23
|
|
|
|
|
24
|
|
|
use Parthenon\Payments\Entity\Subscription; |
|
25
|
|
|
use Parthenon\Payments\SubscriptionManagerInterface; |
|
26
|
|
|
use TransactionCloud\Model\PaymentEntry; |
|
|
|
|
|
|
27
|
|
|
use TransactionCloud\TransactionCloud; |
|
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
class SubscriptionManager implements SubscriptionManagerInterface |
|
30
|
|
|
{ |
|
31
|
|
|
public function __construct(private TransactionCloud $transactionCloud) |
|
32
|
|
|
{ |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function cancel(Subscription $subscription) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->transactionCloud->cancelSubscription($subscription->getPaymentId()); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function change(Subscription $subscription) |
|
41
|
|
|
{ |
|
42
|
|
|
// TODO: Implement change() method. |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function syncStatus(Subscription $subscription): Subscription |
|
46
|
|
|
{ |
|
47
|
|
|
$transaction = $this->transactionCloud->getTransactionById($subscription->getPaymentId()); |
|
48
|
|
|
$remoteStatus = $transaction->getTransactionStatus(); |
|
49
|
|
|
|
|
50
|
|
|
switch ($remoteStatus) { |
|
51
|
|
|
case 'SUBSCRIPTION_STATUS_CANCELLED_PENDING': |
|
52
|
|
|
case 'SUBSCRIPTION_STATUS_CANCELLED': |
|
53
|
|
|
$status = Subscription::STATUS_CANCELLED; |
|
54
|
|
|
break; |
|
55
|
|
|
default: |
|
56
|
|
|
$status = Subscription::STATUS_ACTIVE; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$subscription->setStatus($status); |
|
60
|
|
|
|
|
61
|
|
|
return $subscription; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function getInvoiceUrl(Subscription $subscription) |
|
65
|
|
|
{ |
|
66
|
|
|
$transaction = $this->transactionCloud->getTransactionById($subscription->getPaymentId()); |
|
67
|
|
|
/** @var PaymentEntry $payment */ |
|
68
|
|
|
$payment = null; |
|
69
|
|
|
foreach ($transaction->getEntries() as $entry) { |
|
70
|
|
|
if (null === $payment || $payment->getCreateDate() < $entry->getCreateDate()) { |
|
71
|
|
|
$payment = $entry; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
if (null === $payment) { |
|
76
|
|
|
return null; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return $this->transactionCloud->getInvoiceUrlForPayment($entry); |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function getBillingPortal(Subscription $subscription): string |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->transactionCloud->getUrlToManageTransactions($subscription->getCustomerId()); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
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