Skip to content

Commit

Permalink
Catch missing payment intents
Browse files Browse the repository at this point in the history
  • Loading branch information
shatterproof committed Aug 12, 2024
1 parent 0349c66 commit c327208
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Http/Controllers/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Laravel\Cashier\Cashier;
use Laravel\Cashier\Http\Middleware\VerifyRedirectUrl;
use Laravel\Cashier\Payment;
use Stripe\Exception\InvalidRequestException as StripeInvalidRequestException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class PaymentController extends Controller
{
Expand All @@ -25,12 +27,18 @@ public function __construct()
*
* @param string $id
* @return \Illuminate\Contracts\View\View
*
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function show($id)
{
$payment = new Payment(Cashier::stripe()->paymentIntents->retrieve(
$id, ['expand' => ['payment_method']])
);
try {
$payment = new Payment(Cashier::stripe()->paymentIntents->retrieve(
$id, ['expand' => ['payment_method']])
);
} catch (StripeInvalidRequestException $exception) {
throw new NotFoundHttpException;
}

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

0 comments on commit c327208

Please sign in to comment.