webseite funktioniert, pay sdk, blog backend funktioniert

This commit is contained in:
Codex Agent
2025-09-29 22:16:12 +02:00
parent e52a4005aa
commit 21c9391e2c
51 changed files with 2093 additions and 1293 deletions

View File

@@ -10,6 +10,9 @@ use App\Models\PackagePurchase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use Illuminate\Support\Facades\Auth;
use Mockery;
use PayPal\PayPalHttp\Client;
use PayPal\Checkout\Orders\Order;
class PurchaseTest extends TestCase
{
@@ -71,4 +74,67 @@ class PurchaseTest extends TestCase
$response->assertStatus(302); // Redirect to Stripe
$this->assertStringContainsString('checkout.stripe.com', $response->headers->get('Location'));
}
public function test_paypal_checkout_creates_order()
{
$paidPackage = Package::factory()->create(['price' => 10]);
$user = User::factory()->create(['email_verified_at' => now()]);
$tenant = Tenant::factory()->create(['user_id' => $user->id]);
Auth::login($user);
$mockClient = Mockery::mock(\PayPal\PayPalHttp\Client::class);
$mockOrders = Mockery::mock();
$mockOrders->shouldReceive('createOrder')->andReturn(new \stdClass()); // Simplified mock
$mockClient->shouldReceive('orders')->andReturn($mockOrders);
$this->app->instance(\PayPal\PayPalHttp\Client::class, $mockClient);
$response = $this->get(route('buy.packages', $paidPackage->id) . '?provider=paypal');
$response->assertStatus(302);
$this->assertNotNull(session('paypal_order_id'));
}
public function test_paypal_success_captures_and_activates_package()
{
$paidPackage = Package::factory()->create(['price' => 10]);
$user = User::factory()->create(['email_verified_at' => now()]);
$tenant = Tenant::factory()->create(['user_id' => $user->id]);
Auth::login($user);
$metadata = json_encode([
'user_id' => $user->id,
'tenant_id' => $tenant->id,
'package_id' => $paidPackage->id,
'type' => $paidPackage->type,
]);
$mockClient = Mockery::mock(\PayPal\PayPalHttp\Client::class);
$mockOrders = Mockery::mock();
$mockCapture = new \stdClass();
$mockCapture->status = 'COMPLETED';
$mockCapture->purchaseUnits = [(object)['custom_id' => $metadata]];
$mockResponse = new \stdClass();
$mockResponse->result = $mockCapture;
$mockOrders->shouldReceive('captureOrder')->andReturn($mockResponse);
$mockClient->shouldReceive('orders')->andReturn($mockOrders);
$this->app->instance(\PayPal\PayPalHttp\Client::class, $mockClient);
session(['paypal_order_id' => 'test-order-id']);
$response = $this->get(route('marketing.success', $paidPackage->id));
$response->assertRedirect('/admin');
$this->assertDatabaseHas('tenant_packages', [
'tenant_id' => $tenant->id,
'package_id' => $paidPackage->id,
'active' => true,
]);
$this->assertDatabaseHas('package_purchases', [
'tenant_id' => $tenant->id,
'package_id' => $paidPackage->id,
'provider_id' => 'paypal',
]);
$this->assertNull(session('paypal_order_id'));
$this->assertEquals('active', $tenant->fresh()->subscription_status);
}
}