|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* Copyright Iain Cambridge 2020-2023. |
|
7
|
|
|
* |
|
8
|
|
|
* Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license. |
|
9
|
|
|
* |
|
10
|
|
|
* Change Date: TBD ( 3 years after 2.2.0 release ) |
|
11
|
|
|
* |
|
12
|
|
|
* On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Parthenon\Billing\Refund; |
|
16
|
|
|
|
|
17
|
|
|
use Obol\Model\Refund\IssueRefund; |
|
18
|
|
|
use Obol\Provider\ProviderInterface; |
|
19
|
|
|
use Parthenon\Billing\Entity\BillingAdminInterface; |
|
20
|
|
|
use Parthenon\Billing\Entity\Refund; |
|
21
|
|
|
use Parthenon\Billing\Entity\Subscription; |
|
22
|
|
|
use Parthenon\Billing\Repository\PaymentRepositoryInterface; |
|
23
|
|
|
use Parthenon\Billing\Repository\RefundRepositoryInterface; |
|
24
|
|
|
|
|
25
|
|
|
class RefundManager implements RefundManagerInterface |
|
26
|
|
|
{ |
|
27
|
|
|
public function __construct( |
|
28
|
|
|
private ProviderInterface $provider, |
|
29
|
|
|
private PaymentRepositoryInterface $paymentRepository, |
|
30
|
|
|
private RefundRepositoryInterface $refundRepository, |
|
31
|
|
|
) { |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function issueFullRefundForSubscription(Subscription $subscription, BillingAdminInterface $billingAdmin): void |
|
35
|
|
|
{ |
|
36
|
|
|
$payment = $this->paymentRepository->getLastPaymentForSubscription($subscription); |
|
37
|
|
|
|
|
38
|
|
|
$issueRefund = new IssueRefund(); |
|
39
|
|
|
$issueRefund->setAmount($subscription->getMoneyAmount()); |
|
40
|
|
|
$issueRefund->setPaymentExternalReference($payment->getPaymentReference()); |
|
41
|
|
|
|
|
42
|
|
|
$refund = $this->provider->refunds()->issueRefund($issueRefund); |
|
43
|
|
|
|
|
44
|
|
|
$refundEn = new Refund(); |
|
45
|
|
|
$refundEn->setAmount($refund->getAmount()); |
|
46
|
|
|
$refundEn->setCurrency($refund->getCurrency()); |
|
47
|
|
|
$refundEn->setExternalReference($refund->getId()); |
|
48
|
|
|
$refundEn->setStatus('refunded'); |
|
49
|
|
|
$refundEn->setBillingAdmin($billingAdmin); |
|
50
|
|
|
$refundEn->setPayment($payment); |
|
51
|
|
|
$refundEn->setCustomer($subscription->getCustomer()); |
|
52
|
|
|
|
|
53
|
|
|
$this->refundRepository->save($refundEn); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|