Update PayPal references and tests
This commit is contained in:
@@ -7,6 +7,7 @@ use Illuminate\Http\Client\Factory as HttpFactory;
|
||||
use Illuminate\Http\Client\PendingRequest;
|
||||
use Illuminate\Http\Client\RequestException;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class LemonSqueezyClient
|
||||
{
|
||||
@@ -68,7 +69,7 @@ class LemonSqueezyClient
|
||||
throw new LemonSqueezyException('Lemon Squeezy API key is not configured.');
|
||||
}
|
||||
|
||||
$baseUrl = rtrim((string) config('lemonsqueezy.base_url'), '/');
|
||||
$baseUrl = $this->normalizeBaseUrl((string) config('lemonsqueezy.base_url'));
|
||||
|
||||
return $this->http
|
||||
->baseUrl($baseUrl)
|
||||
@@ -81,4 +82,30 @@ class LemonSqueezyClient
|
||||
->acceptJson()
|
||||
->asJson();
|
||||
}
|
||||
|
||||
protected function normalizeBaseUrl(string $baseUrl): string
|
||||
{
|
||||
$baseUrl = trim($baseUrl);
|
||||
|
||||
if ($baseUrl === '') {
|
||||
$baseUrl = 'https://api.lemonsqueezy.com/v1';
|
||||
}
|
||||
|
||||
if (! Str::startsWith($baseUrl, ['http://', 'https://'])) {
|
||||
$baseUrl = 'https://api.lemonsqueezy.com/'.ltrim($baseUrl, '/');
|
||||
}
|
||||
|
||||
$parsedHost = parse_url($baseUrl, PHP_URL_HOST);
|
||||
if (! is_string($parsedHost) || $parsedHost === '' || ! Str::endsWith($parsedHost, 'lemonsqueezy.com')) {
|
||||
$baseUrl = 'https://api.lemonsqueezy.com/v1';
|
||||
}
|
||||
|
||||
$baseUrl = rtrim($baseUrl, '/');
|
||||
|
||||
if (! Str::endsWith($baseUrl, '/v1')) {
|
||||
$baseUrl .= '/v1';
|
||||
}
|
||||
|
||||
return $baseUrl;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user