From 6bb159cebb473df1e4810f46aa24c216d9416bbb Mon Sep 17 00:00:00 2001 From: Codex Agent Date: Tue, 23 Dec 2025 15:09:06 +0100 Subject: [PATCH] fixed api url for portal sessions --- app/Services/Paddle/PaddleCustomerPortalService.php | 6 ++---- tests/Feature/Api/Tenant/BillingPortalTest.php | 11 ++++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/Services/Paddle/PaddleCustomerPortalService.php b/app/Services/Paddle/PaddleCustomerPortalService.php index 75df782..934592f 100644 --- a/app/Services/Paddle/PaddleCustomerPortalService.php +++ b/app/Services/Paddle/PaddleCustomerPortalService.php @@ -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); } } diff --git a/tests/Feature/Api/Tenant/BillingPortalTest.php b/tests/Feature/Api/Tenant/BillingPortalTest.php index dc36146..d082aa6 100644 --- a/tests/Feature/Api/Tenant/BillingPortalTest.php +++ b/tests/Feature/Api/Tenant/BillingPortalTest.php @@ -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' => [