Create a Payment Intent through Stripe using PHP
January 24, 2024
$stripe_secret_key = '#######################';
$stripe = new \Stripe\StripeClient($stripe_secret_key);
$grand_total = 100;
try {
$intent = $stripe -> paymentIntents -> create(
[
'amount' => $grand_total * 100,
'currency' => 'usd',
'payment_method' => 'Card',
'automatic_payment_methods' => ['enabled' => true],
]);
echo 'Your credit card payment was successful';
} catch (\Stripe\Error\Card $e) {
// The card has been declined
echo 'Your credit card has been declined: ' . $e -> getMessage();
}
echo 'Client Secret: ' . $intent -> client_secret . '< br >';
echo 'Stripe Payment Intent ID: ' . $intent -> id . '< br >';
echo 'Payment Intent Status: ' . $intent -> status . '< br >';