|
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\BillingDetails; |
|
18
|
|
|
use Obol\Model\Subscription; |
|
19
|
|
|
use Parthenon\Billing\Entity\Price; |
|
20
|
|
|
use Parthenon\Billing\Plan\PlanPrice; |
|
21
|
|
|
|
|
22
|
|
|
class SubscriptionFactory implements SubscriptionFactoryInterface |
|
23
|
|
|
{ |
|
24
|
|
|
public function createSubscription( |
|
25
|
|
|
BillingDetails $billingDetails, |
|
26
|
|
|
PlanPrice $planPrice, |
|
27
|
|
|
int $seatNumbers, |
|
28
|
|
|
): Subscription { |
|
29
|
|
|
$obolSubscription = new \Obol\Model\Subscription(); |
|
30
|
|
|
$obolSubscription->setBillingDetails($billingDetails); |
|
31
|
|
|
$obolSubscription->setSeats($seatNumbers); |
|
32
|
|
|
$obolSubscription->setCostPerSeat($planPrice->getPriceAsMoney()); |
|
33
|
|
|
if ($planPrice->hasPriceId()) { |
|
34
|
|
|
$obolSubscription->setPriceId($planPrice->getPriceId()); |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
return $obolSubscription; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function createSubscriptionWithPrice(BillingDetails $billingDetails, Price $price, int $seatNumbers): Subscription |
|
41
|
|
|
{ |
|
42
|
|
|
$obolSubscription = new \Obol\Model\Subscription(); |
|
43
|
|
|
$obolSubscription->setBillingDetails($billingDetails); |
|
44
|
|
|
$obolSubscription->setSeats($seatNumbers); |
|
45
|
|
|
$obolSubscription->setCostPerSeat($price->getAsMoney()); |
|
46
|
|
|
$obolSubscription->setPriceId($price->getExternalReference()); |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
return $obolSubscription; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|