Files
fotospiel-app/app/Services/LemonSqueezy/LemonSqueezySubscriptionService.php
Codex Agent 10c99de1e2
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled
Migrate billing from Paddle to Lemon Squeezy
2026-02-03 10:59:54 +01:00

46 lines
1.3 KiB
PHP

<?php
namespace App\Services\LemonSqueezy;
use Illuminate\Support\Arr;
class LemonSqueezySubscriptionService
{
public function __construct(private readonly LemonSqueezyClient $client) {}
/**
* @return array<string, mixed>
*/
public function retrieve(string $subscriptionId): array
{
$response = $this->client->get("/subscriptions/{$subscriptionId}");
return Arr::get($response, 'data', is_array($response) ? $response : []);
}
/**
* @param array<string, mixed> $subscription
* @return array<string, mixed>
*/
public function customData(array $subscription): array
{
$attributes = Arr::get($subscription, 'attributes', []);
$custom = Arr::get($attributes, 'custom_data', Arr::get($attributes, 'custom', []));
return is_array($custom) ? $custom : [];
}
public function portalUrl(array $subscription): ?string
{
return Arr::get($subscription, 'attributes.urls.customer_portal')
?? Arr::get($subscription, 'attributes.urls.customer_portal_url');
}
public function updatePaymentMethodUrl(array $subscription): ?string
{
return Arr::get($subscription, 'attributes.urls.update_payment_method')
?? Arr::get($subscription, 'attributes.urls.update_payment_method_url');
}
}