The Payment Intent object returned by Stripe is used to handle more complex payment scenarios, such as subscriptions or payments that require additional authentication. It does not necessarily mean that the payment will be rejected. However, it is a good idea to handle any potential errors or exceptions that may occur during the payment process.
As for which ID to store against the order, it depends on your specific use case. If you want to track the payment itself, you can store the Payment Intent ID. If you want to track the specific charge associated with the payment, you can store the Charge ID.
Here's an updated version of the charge method that handles any potential exceptions and stores the Payment Intent ID against the order:
use Stripe\Exception\CardException;
use Stripe\Exception\InvalidRequestException;
public function charge(User $user, $total, $paymentMethodId): string
{
try {
$payment = $user->charge($total * 100, $paymentMethodId);
$paymentIntentId = $payment->payment_intent;
// Store the Payment Intent ID against the order
$order = new Order();
$order->payment_intent_id = $paymentIntentId;
$order->save();
return $paymentIntentId;
} catch (CardException $e) {
// Handle card errors
return $e->getMessage();
} catch (InvalidRequestException $e) {
// Handle invalid request errors
return $e->getMessage();
} catch (\Exception $e) {
// Handle other errors
return $e->getMessage();
}
}