Schreibe Begründung und Parameter einer abgelehnten Stripe-Anfrage ins Protokoll
CI Feature / test (push) Successful in 2m0s
CI Feature / test (push) Successful in 2m0s
Der Fehler 400 invalid_request_error war ohne Begründung nicht zu deuten. Das Protokoll nennt jetzt zusätzlich den betroffenen Parameter und die gekürzte Begründung von Stripe. Schlüssel und Kundendaten bleiben draußen (Test). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
94eda30298
commit
7ef58e0e6e
2 files changed
+12
-2
No files matched your search
@@ -133,11 +133,14 @@ private function assertOk(Response $response, string $what): void
|
||||
return;
|
||||
}
|
||||
|
||||
// Nur Statuscode und Fehlertyp ins Log, nie Schlüssel oder Kundendaten.
|
||||
// Statuscode, Fehlertyp, Code, betroffener Parameter und Begründung von Stripe, damit die Ursache lesbar ist.
|
||||
// Nie Schlüssel oder Kundendaten; die Begründung wird gekürzt.
|
||||
Log::warning('Stripe-Anfrage fehlgeschlagen', [
|
||||
'status' => $response->status(),
|
||||
'type' => $response->json('error.type'),
|
||||
'code' => $response->json('error.code'),
|
||||
'param' => $response->json('error.param'),
|
||||
'message' => mb_substr((string) $response->json('error.message'), 0, 300),
|
||||
]);
|
||||
|
||||
throw new DomainRuleException('Die Zahlung konnte bei Stripe nicht '.$what.' werden. Bitte versuche es später noch einmal.');
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\Client\Request as HttpRequest;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Testing\TestResponse;
|
||||
use Tests\Support\BuildsShop;
|
||||
use Tests\TestCase;
|
||||
@@ -137,12 +138,18 @@ public function test_only_test_keys_reach_stripe(): void
|
||||
public function test_a_stripe_error_leaves_the_order_open_and_shows_a_plain_message(): void
|
||||
{
|
||||
$order = $this->orderOf($this->tina(), [$this->privateKonflikte()]);
|
||||
Http::fake(['stripe.test/*' => Http::response(['error' => ['type' => 'api_error']], 500)]);
|
||||
Log::spy();
|
||||
Http::fake(['stripe.test/*' => Http::response(['error' => ['type' => 'invalid_request_error', 'param' => 'success_url', 'message' => 'Not a valid URL']], 400)]);
|
||||
|
||||
$this->actingAs($this->tina())->post(route('member.order.pay', $order))
|
||||
->assertSessionHasErrors(['payment' => 'Die Zahlung konnte bei Stripe nicht angelegt werden. Bitte versuche es später noch einmal.']);
|
||||
$this->assertSame('offen', $order->fresh()->status);
|
||||
$this->assertSame(0, $order->payments()->count());
|
||||
Log::shouldHaveReceived('warning')->withArgs(fn (string $message, array $context): bool => $message === 'Stripe-Anfrage fehlgeschlagen'
|
||||
&& $context['status'] === 400
|
||||
&& $context['param'] === 'success_url'
|
||||
&& $context['message'] === 'Not a valid URL'
|
||||
&& ! str_contains(json_encode($context), 'sk_test'))->once();
|
||||
}
|
||||
|
||||
public function test_a_signed_paid_event_grants_every_line_once_even_when_repeated(): void
|
||||
|
||||
Reference in new issue
Block a user