34 lines
819 B
PHP
34 lines
819 B
PHP
<?php
|
|
|
|
namespace App\Services\Paddle;
|
|
|
|
use Illuminate\Support\Arr;
|
|
|
|
class PaddleSubscriptionService
|
|
{
|
|
public function __construct(private readonly PaddleClient $client) {}
|
|
|
|
/**
|
|
* Retrieve a subscription record directly from Paddle.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function retrieve(string $subscriptionId): array
|
|
{
|
|
$response = $this->client->get("/subscriptions/{$subscriptionId}");
|
|
|
|
return is_array($response) ? $response : [];
|
|
}
|
|
|
|
/**
|
|
* Convenience helper to extract metadata from the subscription response.
|
|
*
|
|
* @param array<string, mixed> $subscription
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function metadata(array $subscription): array
|
|
{
|
|
return Arr::get($subscription, 'data.metadata', []);
|
|
}
|
|
}
|