customer_update: auto liess Apple Pay den zuvor synchronisierten Stripe-Customer ueberschreiben (Kartenname + nur Land) — die Rechnung trug den falschen Empfaenger. Mit Profil-Rechnungsadresse bleibt der Customer jetzt unangetastet; nur ohne Adresse erfasst Stripe sie selbst im Checkout (inkl. USt-ID-Abfrage). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
83 lines
2.8 KiB
PHP
83 lines
2.8 KiB
PHP
<?php
|
|
|
|
use App\Models\BillingAddress;
|
|
use App\Models\User;
|
|
use App\Services\Billing\StripeCheckoutService;
|
|
|
|
test('the stripe recipient name prefers the billing company over names', function () {
|
|
$user = User::factory()->create(['name' => 'Login Anzeigename']);
|
|
BillingAddress::factory()->create([
|
|
'user_id' => $user->id,
|
|
'company' => 'Beispiel GmbH',
|
|
'name' => 'Max Mustermann',
|
|
]);
|
|
|
|
expect($user->fresh()->stripeName())->toBe('Beispiel GmbH');
|
|
});
|
|
|
|
test('the stripe recipient name falls back to the billing name, then the display name', function () {
|
|
$user = User::factory()->create(['name' => 'Login Anzeigename']);
|
|
BillingAddress::factory()->create([
|
|
'user_id' => $user->id,
|
|
'company' => null,
|
|
'name' => 'Max Mustermann',
|
|
]);
|
|
|
|
expect($user->fresh()->stripeName())->toBe('Max Mustermann');
|
|
|
|
$withoutAddress = User::factory()->create(['name' => 'Nur Anzeigename']);
|
|
|
|
expect($withoutAddress->stripeName())->toBe('Nur Anzeigename');
|
|
});
|
|
|
|
test('the stripe address mirrors the billing address', function () {
|
|
$user = User::factory()->create();
|
|
BillingAddress::factory()->create([
|
|
'user_id' => $user->id,
|
|
'address1' => 'Rechnungsweg 12',
|
|
'address2' => 'Hinterhaus',
|
|
'postal_code' => '33739',
|
|
'city' => 'Bielefeld',
|
|
'country_code' => 'DE',
|
|
]);
|
|
|
|
expect($user->fresh()->stripeAddress())->toBe([
|
|
'line1' => 'Rechnungsweg 12',
|
|
'line2' => 'Hinterhaus',
|
|
'postal_code' => '33739',
|
|
'city' => 'Bielefeld',
|
|
'country' => 'DE',
|
|
]);
|
|
|
|
expect(User::factory()->create()->stripeAddress())->toBeNull();
|
|
});
|
|
|
|
test('checkout session options leave the stripe customer untouched when a billing address exists', function () {
|
|
$user = User::factory()->create();
|
|
BillingAddress::factory()->create(['user_id' => $user->id]);
|
|
|
|
$options = invokeSessionOptions($user->fresh());
|
|
|
|
expect($options['billing_address_collection'])->toBe('auto')
|
|
->and($options['automatic_tax'])->toBe(['enabled' => true])
|
|
->and($options)->not->toHaveKeys(['customer_update', 'tax_id_collection']);
|
|
});
|
|
|
|
test('checkout session options collect the address in stripe when no billing address exists', function () {
|
|
$options = invokeSessionOptions(User::factory()->create());
|
|
|
|
expect($options['billing_address_collection'])->toBe('required')
|
|
->and($options['tax_id_collection'])->toBe(['enabled' => true])
|
|
->and($options['customer_update'])->toBe(['address' => 'auto', 'name' => 'auto']);
|
|
});
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
function invokeSessionOptions(User $user): array
|
|
{
|
|
$service = app(StripeCheckoutService::class);
|
|
$method = new ReflectionMethod($service, 'sessionOptions');
|
|
|
|
return $method->invoke($service, $user);
|
|
}
|