Skip to content

Commit

Permalink
[Billing] Have billabear subscription provider use entity factory
Browse files Browse the repository at this point in the history
  • Loading branch information
that-guy-iain committed Oct 31, 2024
1 parent 24e3a3d commit 4934135
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@

use Parthenon\Billing\BillaBear\SdkFactory;
use Parthenon\Billing\Entity\CustomerInterface;
use Parthenon\Billing\Entity\Price;
use Parthenon\Billing\Entity\Subscription;
use Parthenon\Billing\Enum\SubscriptionStatus;
use Parthenon\Billing\Factory\EntityFactoryInterface;
use Parthenon\Billing\Subscription\SubscriptionProviderInterface;

class SubscriptionProvider implements SubscriptionProviderInterface
{
public function __construct(private SdkFactory $sdkFactory)
{
public function __construct(
private SdkFactory $sdkFactory,
private EntityFactoryInterface $entityFactory,
) {
}

public function getSubscriptionsForCustomer(CustomerInterface $customer): array
Expand All @@ -47,7 +49,7 @@ public function getSubscriptionsForCustomer(CustomerInterface $customer): array

public function buildSubscription(\BillaBear\Model\Subscription $subscription): Subscription
{
$entity = new Subscription();
$entity = $this->entityFactory->getSubscriptionEntity();
$entity->setId($subscription->getId());
$entity->setActive(true);
$entity->setPaymentSchedule($subscription->getSchedule());
Expand All @@ -60,7 +62,7 @@ public function buildSubscription(\BillaBear\Model\Subscription $subscription):
$entity->setStatus(SubscriptionStatus::from($subscription->getStatus()));

if ($subscription->getPrice()) {
$price = new Price();
$price = $this->entityFactory->getPriceEntity();
$price->setCurrency($subscription->getPrice()?->getCurrency());
$price->setAmount($subscription->getPrice()?->getAmount());
$price->setSchedule($subscription->getPrice()?->getSchedule());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

<service id="Parthenon\Billing\BillaBear\Subscription\SubscriptionProvider" class="Parthenon\Billing\BillaBear\Subscription\SubscriptionProvider">
<argument type="service" id="Parthenon\Billing\BillaBear\SdkFactory" />
<argument type="service" id="Parthenon\Billing\Factory\EntityFactoryInterface" />
</service>

<service id="Parthenon\Billing\Subscription\CachedSubscriptionProvider" class="Parthenon\Billing\Subscription\CachedSubscriptionProvider">
Expand Down

0 comments on commit 4934135

Please sign in to comment.