- Wired the checkout wizard for Google “comfort login”: added Socialite controller + dependency, new Google env
hooks in config/services.php/.env.example, and updated wizard steps/controllers to store session payloads, attach packages, and surface localized success/error states. - Retooled payment handling for both Stripe and PayPal, adding richer status management in CheckoutController/ PayPalController, fallback flows in the wizard’s PaymentStep.tsx, and fresh feature tests for intent creation, webhooks, and the wizard CTA. - Introduced a consent-aware Matomo analytics stack: new consent context, cookie-banner UI, useAnalytics/ useCtaExperiment hooks, and MatomoTracker component, then instrumented marketing pages (Home, Packages, Checkout) with localized copy and experiment tracking. - Polished package presentation across marketing UIs by centralizing formatting in PresentsPackages, surfacing localized description tables/placeholders, tuning badges/layouts, and syncing guest/marketing translations. - Expanded docs & reference material (docs/prp/*, TODOs, public gallery overview) and added a Playwright smoke test for the hero CTA while reconciling outstanding checklist items.
This commit is contained in:
132
tests/Feature/CheckoutPaymentIntentTest.php
Normal file
132
tests/Feature/CheckoutPaymentIntentTest.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Package;
|
||||
use App\Models\Tenant;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
|
||||
|
||||
#[RunTestsInSeparateProcesses]
|
||||
class CheckoutPaymentIntentTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Mockery::close();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
private function actingAsTenantUser(): User
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
Tenant::factory()->create(['user_id' => $user->id]);
|
||||
Auth::login($user);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function test_returns_null_client_secret_for_free_package(): void
|
||||
{
|
||||
$this->actingAsTenantUser();
|
||||
$package = Package::factory()->create([
|
||||
'price' => 0,
|
||||
]);
|
||||
|
||||
if (Schema::hasColumn('packages', 'is_free')) {
|
||||
\DB::table('packages')->where('id', $package->id)->update(['is_free' => true]);
|
||||
}
|
||||
|
||||
$response = $this->postJson('/stripe/create-payment-intent', [
|
||||
'package_id' => $package->id,
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
if (Schema::hasColumn('packages', 'is_free')) {
|
||||
$response->assertJson([
|
||||
'client_secret' => null,
|
||||
'free_package' => true,
|
||||
]);
|
||||
} else {
|
||||
$response->assertJson([
|
||||
'client_secret' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function mockStripePaymentIntent(object $payload): void
|
||||
{
|
||||
if (class_exists(\Stripe\PaymentIntent::class, false)) {
|
||||
$this->fail('Stripe\\PaymentIntent already loaded; unable to mock static methods.');
|
||||
}
|
||||
|
||||
$mock = Mockery::mock('alias:Stripe\PaymentIntent');
|
||||
$mock->shouldReceive('create')
|
||||
->once()
|
||||
->andReturn($payload);
|
||||
}
|
||||
|
||||
private function mockStripePaymentIntentFailure(\Throwable $exception): void
|
||||
{
|
||||
if (class_exists(\Stripe\PaymentIntent::class, false)) {
|
||||
$this->fail('Stripe\\PaymentIntent already loaded; unable to mock static methods.');
|
||||
}
|
||||
|
||||
$mock = Mockery::mock('alias:Stripe\PaymentIntent');
|
||||
$mock->shouldReceive('create')
|
||||
->once()
|
||||
->andThrow($exception);
|
||||
}
|
||||
|
||||
public function test_creates_payment_intent_and_returns_client_secret(): void
|
||||
{
|
||||
config(['services.stripe.secret' => 'sk_test_dummy']);
|
||||
|
||||
$this->actingAsTenantUser();
|
||||
$package = Package::factory()->create([
|
||||
'price' => 129,
|
||||
]);
|
||||
|
||||
$this->mockStripePaymentIntent((object) [
|
||||
'id' => 'pi_test_123',
|
||||
'client_secret' => 'secret_test_456',
|
||||
]);
|
||||
|
||||
$response = $this->postJson('/stripe/create-payment-intent', [
|
||||
'package_id' => $package->id,
|
||||
]);
|
||||
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'client_secret' => 'secret_test_456',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_returns_error_when_payment_intent_creation_fails(): void
|
||||
{
|
||||
config(['services.stripe.secret' => 'sk_test_dummy']);
|
||||
|
||||
$this->actingAsTenantUser();
|
||||
$package = Package::factory()->create([
|
||||
'price' => 59,
|
||||
]);
|
||||
|
||||
$this->mockStripePaymentIntentFailure(new \RuntimeException('Stripe failure'));
|
||||
|
||||
$response = $this->postJson('/stripe/create-payment-intent', [
|
||||
'package_id' => $package->id,
|
||||
]);
|
||||
|
||||
$response->assertStatus(500)
|
||||
->assertJson([
|
||||
'error' => 'Fehler beim Erstellen der Zahlungsdaten: Stripe failure',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user