Fix PayPal billing flow and mobile admin UX
This commit is contained in:
27
tests/Feature/Api/Tenant/BillingReceiptTest.php
Normal file
27
tests/Feature/Api/Tenant/BillingReceiptTest.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\Tenant;
|
||||
|
||||
use App\Models\Package;
|
||||
use App\Models\PackagePurchase;
|
||||
use Tests\Feature\Tenant\TenantTestCase;
|
||||
|
||||
class BillingReceiptTest extends TenantTestCase
|
||||
{
|
||||
public function test_receipt_endpoint_returns_pdf(): void
|
||||
{
|
||||
$package = Package::factory()->create(['name' => 'Starter']);
|
||||
$purchase = PackagePurchase::factory()->create([
|
||||
'tenant_id' => $this->tenant->id,
|
||||
'package_id' => $package->id,
|
||||
'provider' => 'paypal',
|
||||
'provider_id' => 'ORDER-123',
|
||||
'price' => 49.0,
|
||||
]);
|
||||
|
||||
$response = $this->authenticatedRequest('GET', '/api/v1/tenant/billing/transactions/'.$purchase->id.'/receipt');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertHeader('Content-Type', 'application/pdf');
|
||||
}
|
||||
}
|
||||
@@ -2,49 +2,30 @@
|
||||
|
||||
namespace Tests\Feature\Api\Tenant;
|
||||
|
||||
use Illuminate\Http\Client\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Models\Package;
|
||||
use App\Models\PackagePurchase;
|
||||
use Tests\Feature\Tenant\TenantTestCase;
|
||||
|
||||
class BillingTransactionsTest extends TenantTestCase
|
||||
{
|
||||
public function test_transactions_endpoint_creates_missing_lemonsqueezy_customer_id(): void
|
||||
public function test_transactions_endpoint_returns_package_purchases(): void
|
||||
{
|
||||
Http::fake(function (Request $request) {
|
||||
$path = parse_url($request->url(), PHP_URL_PATH);
|
||||
|
||||
if ($path === '/customers' && $request->method() === 'POST') {
|
||||
return Http::response([
|
||||
'data' => ['id' => 'cus_456'],
|
||||
], 200);
|
||||
}
|
||||
|
||||
if ($path === '/transactions' && $request->method() === 'GET') {
|
||||
return Http::response([
|
||||
'data' => [],
|
||||
'meta' => [
|
||||
'pagination' => [
|
||||
'next' => null,
|
||||
'previous' => null,
|
||||
'has_more' => false,
|
||||
],
|
||||
],
|
||||
], 200);
|
||||
}
|
||||
|
||||
return Http::response([], 404);
|
||||
});
|
||||
|
||||
$this->tenant->forceFill(['lemonsqueezy_customer_id' => null])->save();
|
||||
$package = Package::factory()->create(['name' => 'Starter']);
|
||||
$purchase = PackagePurchase::factory()->create([
|
||||
'tenant_id' => $this->tenant->id,
|
||||
'package_id' => $package->id,
|
||||
'provider' => 'paypal',
|
||||
'provider_id' => 'ORDER-123',
|
||||
'price' => 49.0,
|
||||
]);
|
||||
|
||||
$response = $this->authenticatedRequest('GET', '/api/v1/tenant/billing/transactions');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('data', []);
|
||||
|
||||
$this->assertDatabaseHas('tenants', [
|
||||
'id' => $this->tenant->id,
|
||||
'lemonsqueezy_customer_id' => 'cus_456',
|
||||
$response->assertJsonFragment([
|
||||
'id' => $purchase->id,
|
||||
'provider' => 'paypal',
|
||||
'provider_id' => 'ORDER-123',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,5 +93,6 @@ class TenantPackageOverviewTest extends TenantTestCase
|
||||
|
||||
$this->assertSame($package->id, $payload['active_package']['package_id']);
|
||||
$this->assertSame(['custom_branding'], $payload['active_package']['package_limits']['features']);
|
||||
$this->assertSame(1, $payload['active_package']['remaining_events']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user