Search code examples
phpstripe-paymentspayment-processing

Why do I keep getting a payment method not entered when processing a credit card transaction via Stripe


I am having some technical difficulties, my programming knowledge is limited so it's probably an easy fix. I am attempting to integrate Stripe credit card transactions into our website, https://cdunion.ca/stripe/. Everything is working, it will connect to Stripe, no error messages, but when I log into my Stripe dashboard, every transaction is listed as 200 ok but also listed as incomplete. The exact error is "The customer has not entered their payment method". I have been Googling and racking my brain out over this for 2 weeks, with no success. I have checked and cards payment method is enabled in my Stripe dashboard. My code is listed below. I am using the Stripe library in Composer on both my home testing server and my live server. Any assistance you can offer is greatly appreciated, merci.

PS The credit card listed is specifically for testing purposes used by all credit card processors, so do not worry, no confidential information has been released.

<?php
/* 
$donation_amount = ($_POST["donation-amount"]) . '00';
$address = (($_POST["unit"]) . '-' . ($_POST["address"]));
$city = ($_POST["city"]);
$province = ($_POST["province"]);
$country = ($_POST["country"]);

echo ($donation_amount . "<br>" . $address . "<br>" . $city . "<br>" . $province . "<br>" . $country);

*/

require_once 'C:/xampp/composer/vendor/autoload.php';

\Stripe\Stripe::setApiKey('*censored*');

\Stripe\PaymentMethod::create([
  'type' => 'card',
  'card' => [
    'number' => '4242424242424242',
    'exp_month' => 12,
    'exp_year' => 2020,
    'cvc' => '314',
  ],
]);

\Stripe\PaymentIntent::create([
    'payment_method_types' => ['card'],
    'amount' => $donation_amount,
    'currency' => 'cad',
]);

die();

?>

Solution

  • You need to pass the ID of the payment method when creating the payment intent.

    $method = \Stripe\PaymentMethod::create([
      'type' => 'card',
      'card' => [
        'number' => '4242424242424242',
        'exp_month' => 12,
        'exp_year' => 2020,
        'cvc' => '314',
      ],
    ]);
    
    \Stripe\PaymentIntent::create([
        'payment_method_types' => ['card'],
        'payment_method' => $method->id,
        'amount' => $donation_amount,
        'currency' => 'cad',
    ]);