#jeff-php-error

1 messages ยท Page 1 of 1 (latest)

obtuse burrow
#

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?

south flume
#

Yes--will do.

#

Um--is that stripe command? Not finding anything in php named that.

obtuse burrow
#

I don't know what you mean by that question. What would be a Stripe command?

south flume
#

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.

obtuse carbon
#

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

obtuse carbon
#

@south flume unarchived

south flume
#

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.

obtuse carbon
#

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

obtuse burrow
#

๐Ÿ‘‹ 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.

south flume
#

Yes, will do that. Hopefully this thread doesn't get archived between now and when I'm finished ๐Ÿ˜‰

obtuse burrow
#

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

south flume
#

Okay, will request an un-archive when I need to post if needed.

livid carbon
#

@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

devout vale
#

@south flume unarchived!

south flume
#

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.

devout vale
#

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 ๐Ÿ‘€

south flume
#

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.

devout vale
#

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.