Skip to content

Commit

Permalink
[OBOL] Populate tiers
Browse files Browse the repository at this point in the history
Automatic commit for getparthenon/monorepo@24770ae
  • Loading branch information
that-guy-iain committed Sep 25, 2024
1 parent 503b143 commit b50020a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Model/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class Price

private ?UsageType $usageType = null;

private array $tiers = [];

public function isIncludingTax(): bool
{
return $this->includingTax;
Expand Down Expand Up @@ -171,4 +173,14 @@ public function setUsageType(?UsageType $usageType): void
{
$this->usageType = $usageType;
}

public function getTiers(): array
{
return $this->tiers;
}

public function setTiers(array $tiers): void
{
$this->tiers = $tiers;
}
}
17 changes: 17 additions & 0 deletions src/Provider/Stripe/PriceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
use Obol\Model\Enum\UsageType;
use Obol\Model\Price;
use Obol\Model\PriceCreation;
use Obol\Model\Tier;
use Obol\PriceServiceInterface;
use Obol\Provider\ProviderInterface;
use Psr\Log\LoggerAwareTrait;
use Stripe\StripeClient;
use Stripe\StripeObject;

class PriceService implements PriceServiceInterface
{
Expand Down Expand Up @@ -129,7 +131,22 @@ public function populatePrice(\Stripe\Price $stripePrice): Price
$price->setTierMode(TierMode::fromString($stripePrice->tiers_mode));
$price->setBillingType(BillingType::fromStripe($stripePrice->billing_scheme));
$price->setUsageType(UsageType::fromStripe($stripePrice->recurring?->usage_type));
$tiers = [];
foreach ($stripePrice->tiers ?? [] as $tier) {
$tiers[] = $this->populatTier($tier);
}
$price->setTiers($tiers);

return $price;
}

public function populatTier(StripeObject $data): Tier
{
$tier = new Tier();
$tier->setUpTo($data->up_to);
$tier->setFlatAmount($data->flat_amount);
$tier->setUnitAmount($data->unit_amount);

return $tier;
}
}

0 comments on commit b50020a

Please sign in to comment.