Skip to content

Commit d6f5ec0

Browse files
[15.x] Catch missing payment intents (#1704)
* Catch missing payment intents * Abort not found payment intent * Update PaymentController.php --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent b9e3baa commit d6f5ec0

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/Http/Controllers/PaymentController.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Laravel\Cashier\Cashier;
88
use Laravel\Cashier\Http\Middleware\VerifyRedirectUrl;
99
use Laravel\Cashier\Payment;
10+
use Stripe\Exception\InvalidRequestException as StripeInvalidRequestException;
1011

1112
class PaymentController extends Controller
1213
{
@@ -28,9 +29,13 @@ public function __construct()
2829
*/
2930
public function show($id)
3031
{
31-
$payment = new Payment(Cashier::stripe()->paymentIntents->retrieve(
32-
$id, ['expand' => ['payment_method']])
33-
);
32+
try {
33+
$payment = new Payment(Cashier::stripe()->paymentIntents->retrieve(
34+
$id, ['expand' => ['payment_method']])
35+
);
36+
} catch (StripeInvalidRequestException $exception) {
37+
abort(404, 'Payment not found.');
38+
}
3439

3540
$paymentIntent = Arr::only($payment->asStripePaymentIntent()->toArray(), [
3641
'id', 'status', 'payment_method_types', 'client_secret', 'payment_method',

0 commit comments

Comments
 (0)