6

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();

?>
Howie
  • 63
  • 1
  • 4
  • This is because eveytime you load the pages payment intent creates. But "client_secret" is needed for working. I am facing same problem, did you find the solution? – Deepak Dholiyan Dec 05 '20 at 13:13

1 Answers1

6

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',
]);
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Thank you, you are awesome, the error message is gone, now there is a new one, it says payment has not been completed, LOL, I will see if I can figure it out myself, if not i will post another question in a couple weeks, thank you. – Howie Dec 28 '19 at 04:44
  • A payment intent is not the same as a charge. – Barmar Dec 29 '19 at 00:50