Migrate billing from Paddle to Lemon Squeezy
This commit is contained in:
@@ -5,7 +5,7 @@ namespace Tests\Feature;
|
||||
use App\Models\Package;
|
||||
use App\Models\Tenant;
|
||||
use App\Models\User;
|
||||
use App\Services\Paddle\PaddleCheckoutService;
|
||||
use App\Services\LemonSqueezy\LemonSqueezyCheckoutService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
@@ -20,12 +20,12 @@ class PurchaseTest extends TestCase
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_create_paddle_checkout_requires_paddle_price(): void
|
||||
public function test_create_lemonsqueezy_checkout_requires_variant(): void
|
||||
{
|
||||
[$tenant, $package] = $this->seedTenantWithPackage(includePaddlePrice: false);
|
||||
[$tenant, $package] = $this->seedTenantWithPackage(includeVariant: false);
|
||||
$this->actingAs($tenant->user);
|
||||
|
||||
$response = $this->postJson('/paddle/create-checkout', [
|
||||
$response = $this->postJson('/lemonsqueezy/create-checkout', [
|
||||
'package_id' => $package->id,
|
||||
'accepted_terms' => true,
|
||||
]);
|
||||
@@ -34,12 +34,12 @@ class PurchaseTest extends TestCase
|
||||
->assertJsonValidationErrors('package_id');
|
||||
}
|
||||
|
||||
public function test_create_paddle_checkout_returns_checkout_url(): void
|
||||
public function test_create_lemonsqueezy_checkout_returns_checkout_url(): void
|
||||
{
|
||||
[$tenant, $package] = $this->seedTenantWithPackage(includePaddlePrice: true);
|
||||
[$tenant, $package] = $this->seedTenantWithPackage(includeVariant: true);
|
||||
$this->actingAs($tenant->user);
|
||||
|
||||
$service = Mockery::mock(PaddleCheckoutService::class);
|
||||
$service = Mockery::mock(LemonSqueezyCheckoutService::class);
|
||||
$service->shouldReceive('createCheckout')
|
||||
->once()
|
||||
->with(
|
||||
@@ -52,55 +52,41 @@ class PurchaseTest extends TestCase
|
||||
})
|
||||
)
|
||||
->andReturn([
|
||||
'checkout_url' => 'https://paddle.test/checkout/abc',
|
||||
'checkout_url' => 'https://checkout.lemonsqueezy.test/checkout/abc',
|
||||
]);
|
||||
|
||||
$this->app->instance(PaddleCheckoutService::class, $service);
|
||||
$this->app->instance(LemonSqueezyCheckoutService::class, $service);
|
||||
|
||||
$response = $this->postJson('/paddle/create-checkout', [
|
||||
$response = $this->postJson('/lemonsqueezy/create-checkout', [
|
||||
'package_id' => $package->id,
|
||||
'accepted_terms' => true,
|
||||
]);
|
||||
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'checkout_url' => 'https://paddle.test/checkout/abc',
|
||||
'checkout_url' => 'https://checkout.lemonsqueezy.test/checkout/abc',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_create_paddle_checkout_inline_returns_items(): void
|
||||
public function test_create_lemonsqueezy_checkout_requires_terms(): void
|
||||
{
|
||||
[$tenant, $package] = $this->seedTenantWithPackage(includePaddlePrice: true);
|
||||
[$tenant, $package] = $this->seedTenantWithPackage(includeVariant: true);
|
||||
$this->actingAs($tenant->user);
|
||||
|
||||
$service = Mockery::mock(PaddleCheckoutService::class);
|
||||
$service = Mockery::mock(LemonSqueezyCheckoutService::class);
|
||||
$service->shouldNotReceive('createCheckout');
|
||||
$this->app->instance(PaddleCheckoutService::class, $service);
|
||||
$this->app->instance(LemonSqueezyCheckoutService::class, $service);
|
||||
|
||||
$response = $this->postJson('/paddle/create-checkout', [
|
||||
$response = $this->postJson('/lemonsqueezy/create-checkout', [
|
||||
'package_id' => $package->id,
|
||||
'inline' => true,
|
||||
'accepted_terms' => true,
|
||||
'accepted_terms' => false,
|
||||
]);
|
||||
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'mode' => 'inline',
|
||||
])
|
||||
->assertJsonStructure([
|
||||
'mode',
|
||||
'items' => [
|
||||
['priceId', 'quantity'],
|
||||
],
|
||||
'custom_data' => ['tenant_id', 'package_id', 'checkout_session_id'],
|
||||
]);
|
||||
|
||||
$payload = $response->json();
|
||||
$this->assertSame($package->paddle_price_id, $payload['items'][0]['priceId']);
|
||||
$this->assertSame(1, $payload['items'][0]['quantity']);
|
||||
$response->assertStatus(422)
|
||||
->assertJsonValidationErrors('accepted_terms');
|
||||
}
|
||||
|
||||
private function seedTenantWithPackage(int $price = 10, string $type = 'endcustomer', bool $includePaddlePrice = true): array
|
||||
private function seedTenantWithPackage(int $price = 10, string $type = 'endcustomer', bool $includeVariant = true): array
|
||||
{
|
||||
$user = User::factory()->create(['email_verified_at' => now()]);
|
||||
$tenant = Tenant::factory()->create(['user_id' => $user->id]);
|
||||
@@ -110,7 +96,7 @@ class PurchaseTest extends TestCase
|
||||
$package = Package::factory()->create([
|
||||
'price' => $price,
|
||||
'type' => $type,
|
||||
'paddle_price_id' => $includePaddlePrice ? 'price_123' : null,
|
||||
'lemonsqueezy_variant_id' => $includeVariant ? 'variant_123' : null,
|
||||
]);
|
||||
|
||||
return [$tenant, $package];
|
||||
|
||||
Reference in New Issue
Block a user