Migrate billing from Paddle to Lemon Squeezy
This commit is contained in:
@@ -2,9 +2,10 @@
|
||||
|
||||
namespace Tests\Feature\Tenant;
|
||||
|
||||
use App\Services\Paddle\Exceptions\PaddleException;
|
||||
use App\Services\Paddle\PaddleCustomerPortalService;
|
||||
use App\Services\Paddle\PaddleCustomerService;
|
||||
use App\Models\Package;
|
||||
use App\Models\TenantPackage;
|
||||
use App\Services\LemonSqueezy\Exceptions\LemonSqueezyException;
|
||||
use App\Services\LemonSqueezy\LemonSqueezySubscriptionService;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Mockery;
|
||||
|
||||
@@ -17,7 +18,7 @@ class TenantBillingPortalTest extends TenantTestCase
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_portal_logs_paddle_error_context(): void
|
||||
public function test_portal_logs_lemonsqueezy_error_context(): void
|
||||
{
|
||||
$logged = [];
|
||||
Log::listen(function ($event) use (&$logged): void {
|
||||
@@ -28,39 +29,44 @@ class TenantBillingPortalTest extends TenantTestCase
|
||||
];
|
||||
});
|
||||
|
||||
$customerService = Mockery::mock(PaddleCustomerService::class);
|
||||
$customerService->shouldReceive('ensureCustomerId')
|
||||
->once()
|
||||
->withArgs(fn ($tenant) => $tenant->is($this->tenant))
|
||||
->andReturn('ctm_test_123');
|
||||
$this->instance(PaddleCustomerService::class, $customerService);
|
||||
$package = Package::factory()->reseller()->create();
|
||||
TenantPackage::factory()->create([
|
||||
'tenant_id' => $this->tenant->id,
|
||||
'package_id' => $package->id,
|
||||
'lemonsqueezy_subscription_id' => 'sub_123',
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
$portalService = Mockery::mock(PaddleCustomerPortalService::class);
|
||||
$portalService->shouldReceive('createSession')
|
||||
$subscriptions = Mockery::mock(LemonSqueezySubscriptionService::class);
|
||||
$subscriptions->shouldReceive('retrieve')
|
||||
->once()
|
||||
->with('ctm_test_123')
|
||||
->andThrow(new PaddleException('Paddle request failed with status 404', 404, [
|
||||
'error' => [
|
||||
'code' => 'entity_not_found',
|
||||
'message' => 'Not found',
|
||||
->with('sub_123')
|
||||
->andThrow(new LemonSqueezyException('Not found', 404, [
|
||||
'errors' => [
|
||||
[
|
||||
'code' => 'entity_not_found',
|
||||
'detail' => 'Not found',
|
||||
],
|
||||
],
|
||||
'meta' => [
|
||||
'request_id' => 'req_123',
|
||||
],
|
||||
]));
|
||||
$this->instance(PaddleCustomerPortalService::class, $portalService);
|
||||
$this->instance(LemonSqueezySubscriptionService::class, $subscriptions);
|
||||
|
||||
$response = $this->authenticatedRequest('POST', '/api/v1/tenant/billing/portal');
|
||||
|
||||
$response->assertStatus(502)
|
||||
->assertJson([
|
||||
'message' => 'Failed to create Paddle customer portal session.',
|
||||
'message' => 'Failed to fetch Lemon Squeezy subscription portal URL.',
|
||||
]);
|
||||
|
||||
$matched = collect($logged)->contains(function (array $entry): bool {
|
||||
return $entry['level'] === 'warning'
|
||||
&& $entry['message'] === 'Failed to create Paddle customer portal session'
|
||||
&& $entry['message'] === 'Failed to fetch Lemon Squeezy subscription portal URL'
|
||||
&& ($entry['context']['tenant_id'] ?? null) === $this->tenant->id
|
||||
&& ($entry['context']['paddle_customer_id'] ?? null) === 'ctm_test_123'
|
||||
&& ($entry['context']['paddle_status'] ?? null) === 404
|
||||
&& ($entry['context']['paddle_error_code'] ?? null) === 'entity_not_found';
|
||||
&& ($entry['context']['lemonsqueezy_status'] ?? null) === 404
|
||||
&& (($entry['context']['lemonsqueezy_error']['code'] ?? null) === 'entity_not_found');
|
||||
});
|
||||
|
||||
$this->assertTrue($matched);
|
||||
|
||||
Reference in New Issue
Block a user