46 lines
1.3 KiB
PHP
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');
|
|
}
|
|
}
|