1

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

guiguie34
  • 33
  • 6
  • possible duplicate https://stackoverflow.com/questions/60413930/fatal-error-uncaught-error-call-to-undefined-function-curl-version-localho – Alberto Sinigaglia Jun 30 '20 at 09:43
  • This generally means your installation of PHP doesn't have the curl extension installed. It does sound like on WAMP you'll want to edit something to reference `php_curl.dll` and restart the server (https://stackoverflow.com/a/9186241/9769731 et al) – karllekko Jun 30 '20 at 10:34
  • In the php.ini "extension=curl" is alreay uncommented and if I use curl outside of my project it works perfectly. But it's only on this PHP project running with WAMP and Apache 2.34 that it doesn't work. I have also tried to move some dll files but no effects. – guiguie34 Jun 30 '20 at 11:12

0 Answers0