#jeff-php-error
1 messages ยท Page 1 of 1 (latest)
Hello @south flume
Most of the time this is because you don't run the code you think you are or it's not that part that is erroring.
Can you add a clear log just before the charge creation and confirm you see that log just before the crash?
I don't know what you mean by that question. What would be a Stripe command?
I don't know what you mean by "clear log". That doesn't seem to be a php function so I thought it might be a Stripe call.
they meant log out e.g. using echo or something, before Charge creation in that code snippet to make sure you're actually executing this block of code
@south flume unarchived
Thanks!
I added an echo statement just before the charge creation and that made no difference at all. I can try to post the code before that unless it exceeds the 2000 character limit.
added an echo statement just before the charge creation and that made no difference at al
did that log line log?
like was
"about to enter try / catch block"
logged out?
that 402 should be caught by CardException which you're already catching in your try-catch
๐ Can I ask you to try and write a really simple PHP example that solely uses Stripe (nothing else) and reproduces the error?
right now there's too much in your code that is specific like $_SESSION, your own include path, etc.
Yes, will do that. Hopefully this thread doesn't get archived between now and when I'm finished ๐
It plausibly will, there are a lot of users and we help them in real time so we can't keep threads open for hours unfortunately
Okay, will request an un-archive when I need to post if needed.
@south flume just FYI we usually archive threads after 1 hour of inactivity or less (sometimes if its busy we need to archive quick). I should have already archived this one but I was busy with other threads
@south flume unarchived!
Here's my my much pared-down php code. Still throws the fatal error though.
[Tue Aug 23 19:40:57.312345 2022] [php7:error] [pid 35509] [client 154.27.106.60:58009] PHP Fatal error: Uncaught (Status 402) (Request req_3lSX9nUQHyqcJ9) Your card was declined.\n thrown in /var/www/pear/lib/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php on line 38, referer: https://dev.mt43news.com/subscription.html
That fatal error corresponds correctly with the test card I used 4000000000009979. Still don't see why the exception isn't caught though.
please redact your secret key even though it's a test key
i'd recommend you roll your test secret key at this point
taking a look ๐
Okay, will do. I should state the obvious that this code works as expected when the card is valid and we don't hit the try / catch block.
is there a reason why you're creating a Charge twice in your code?
like what koopajah mentioned earlier, the problem is likely with where the error is being thrown and that you're probably not catching it. You'll likely need to trace through line by line to understand where the issue is in your code
if i run a very simple example - this works as expected
try {
$stripe->paymentIntents->create([
'amount' => 2000,
'currency' => 'usd',
'payment_method_types' => ['card'],
'confirm' => true,
'payment_method' =>'pm_card_visa_chargeDeclined'
]);
error_log("No error.");
} catch(\Stripe\Exception\CardException $e) {
error_log("A payment error occurred: {$e->getError()->message}");
} catch (\Stripe\Exception\InvalidRequestException $e) {
error_log("An invalid request occurred.");
} catch (Exception $e) {
error_log("Another problem occurred, maybe unrelated to Stripe.");
}
i would suggest you pare down your code even further - maybe use my example and then build it back up bit bit. It might make it easier to figure out where the issue is.