|
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\Obol; |
|
16
|
|
|
|
|
17
|
|
|
use Obol\Model\Events\AbstractCharge; |
|
18
|
|
|
use Obol\Model\PaymentDetails; |
|
19
|
|
|
use Obol\Provider\ProviderInterface; |
|
20
|
|
|
use Parthenon\Billing\CustomerProviderInterface; |
|
21
|
|
|
use Parthenon\Billing\Entity\CustomerInterface; |
|
22
|
|
|
use Parthenon\Billing\Entity\Payment; |
|
23
|
|
|
use Parthenon\Billing\Enum\PaymentStatus; |
|
24
|
|
|
|
|
25
|
|
|
final class PaymentFactory implements PaymentFactoryInterface |
|
26
|
|
|
{ |
|
27
|
|
|
public function __construct( |
|
28
|
|
|
private CustomerProviderInterface $customerProvider, |
|
29
|
|
|
private ProviderInterface $provider, |
|
30
|
|
|
) { |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function fromSubscriptionCreation(PaymentDetails $paymentDetails, ?CustomerInterface $customer = null): Payment |
|
34
|
|
|
{ |
|
35
|
|
|
if (!$customer) { |
|
36
|
|
|
$customer = $this->customerProvider->getCurrentCustomer(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$payment = new Payment(); |
|
40
|
|
|
$payment->setPaymentReference($paymentDetails->getPaymentReference()); |
|
|
|
|
|
|
41
|
|
|
$payment->setPaymentProviderDetailsUrl($paymentDetails->getPaymentReferenceLink()); |
|
42
|
|
|
$payment->setMoneyAmount($paymentDetails->getAmount()); |
|
43
|
|
|
$payment->setCustomer($customer); |
|
44
|
|
|
$payment->setCompleted(true); |
|
45
|
|
|
$payment->setCreatedAt(new \DateTime('now')); |
|
46
|
|
|
$payment->setUpdatedAt(new \DateTime('now')); |
|
47
|
|
|
$payment->setStatus(PaymentStatus::COMPLETED); |
|
48
|
|
|
$payment->setProvider($this->provider->getName()); |
|
49
|
|
|
|
|
50
|
|
|
return $payment; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function fromChargeEvent(AbstractCharge $charge): Payment |
|
54
|
|
|
{ |
|
55
|
|
|
$payment = new Payment(); |
|
56
|
|
|
$payment->setPaymentReference($charge->getPaymentReference()); |
|
57
|
|
|
$payment->setPaymentProviderDetailsUrl($charge->getDetailsLink()); |
|
58
|
|
|
$payment->setAmount($charge->getAmount()); |
|
59
|
|
|
$payment->setCurrency($charge->getCurrency()); |
|
60
|
|
|
$payment->setCreatedAt(new \DateTime('now')); |
|
61
|
|
|
$payment->setUpdatedAt(new \DateTime('now')); |
|
62
|
|
|
$payment->setProvider($this->provider->getName()); |
|
63
|
|
|
|
|
64
|
|
|
return $payment; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|