I'm trying to integrate Stripe payment in my PHP Project (PHP 7.4.5 with WAMP on Windows).
I use the structure from the official documentation (https://stripe.com/docs/payments/integration-builder) but I obtain the following error when I check the console in my browser:
POST 500 (Internal Server Error) and in the network section the response to the POST(for create.php) request is
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
{"error":"Call to undefined function curl_version()"}
Here is my code: create.php
require_once('../stripe-php-7.37.1/init.php'); //my others require are not printed
\Stripe\Stripe::setApiKey('my_key');
header('Content-Type: application/json');
try {
// retrieve JSON from POST body
$json_str = file_get_contents('php://input');
$json_obj = json_decode($json_str);
$paymentIntent = \Stripe\PaymentIntent::create([
'amount' => calculateOrderAmount(), //amount calculator
'currency' => 'eur',
]);
$output = [
'clientSecret' => $paymentIntent->client_secret,
];
echo json_encode($output);
} catch (Error $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}
checkout.php
...
<script src="https://js.stripe.com/v3/"></script>
...
<form id="payment-form">
<div id="card-element"><!--Stripe.js injects the Card Element--></div>
<button id="submit">
<div class="spinner hidden" id="spinner"></div>
<span id="button-text">Pay</span>
</button>
<p id="card-errors" role="alert"></p>
<p class="result-message hidden">
Payment succeeded, see the result in your
<a href="" target="_blank">Stripe dashboard.</a> Refresh the page to pay again.
</p>
</form>
...
<script>
var stripe = Stripe("my_key");
// Disable the button until we have Stripe set up on the page
document.querySelector("button").disabled = true;
fetch("/Stripe/create.php", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(purchase)
})
.then(function(result) {
result.json();
})
.then(function(data) {
var elements = stripe.elements();
...
</script>
I have checked on WAMP, the curl extension is enabled in PHP.ini
I have the following file architecture:
├───stripe-php-7.37.1
├───Stripe
│ ├───checkout.php
│ ├───create.php
Thanks for the help