fixed api url for portal sessions

This commit is contained in:
Codex Agent
2025-12-23 15:09:06 +01:00
parent beb36c68ae
commit 6bb159cebb
2 changed files with 10 additions and 7 deletions

View File

@@ -12,9 +12,7 @@ class PaddleCustomerPortalService
*/
public function createSession(string $customerId, array $options = []): array
{
$payload = [
'customer_id' => $customerId,
];
$payload = [];
if (! empty($options['subscription_ids'])) {
$payload['subscription_ids'] = array_values(
@@ -22,6 +20,6 @@ class PaddleCustomerPortalService
);
}
return $this->client->post('/customer-portal-sessions', $payload);
return $this->client->post("/customers/{$customerId}/portal-sessions", $payload);
}
}

View File

@@ -14,7 +14,7 @@ class BillingPortalTest extends TenantTestCase
'*paddle.com/customers' => Http::response([
'data' => ['id' => 'cus_123'],
], 200),
'*paddle.com/customer-portal-sessions' => Http::response([
'*paddle.com/customers/*/portal-sessions' => Http::response([
'data' => [
'urls' => [
'general' => [
@@ -32,7 +32,12 @@ class BillingPortalTest extends TenantTestCase
$response->assertOk();
$response->assertJsonPath('url', 'https://portal.example/overview');
Http::assertSent(fn (Request $request) => $request->hasHeader('Paddle-Version', '1'));
Http::assertSent(function (Request $request): bool {
$path = parse_url($request->url(), PHP_URL_PATH);
return $request->hasHeader('Paddle-Version', '1')
&& $path === '/customers/cus_123/portal-sessions';
});
$this->assertDatabaseHas('tenants', [
'id' => $this->tenant->id,
@@ -63,7 +68,7 @@ class BillingPortalTest extends TenantTestCase
], 200);
}
if ($path === '/customer-portal-sessions' && $request->method() === 'POST') {
if ($path === '/customers/cus_existing/portal-sessions' && $request->method() === 'POST') {
return Http::response([
'data' => [
'urls' => [