#xfechx_api

1 messages ยท Page 1 of 1 (latest)

flat warrenBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1365390030612332545

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

abstract prism
#

This is using PHP stripe library

opaque walrus
#

The request you shared is a PaymentIntent confirmation request.

abstract prism
#

yes

#

I am having issues with this exact line:

#

$payment_intent_object = \Stripe\PaymentIntent::retrieve($payment_intent_id

#

I am having a server error when reaching that line

opaque walrus
#

Can you share the screenshot of the error being returned?

abstract prism
#

sure

#

--- filling metadata now ------ API being used is: ------ Test Mode: ------ Stripe Source: ---event id: evt_3RGhstIVVhxSAz7H2JJfUxlN ---connected_account: ---origin: https://app.marlarecords.com ------ Origin: app.marlarecords.com ------ Destination: app.marlarecords.com ------ Internal Application ------ EVENT: CHARGE.SUCCEDED ------ payment intent not empty --- payment_intent = pi_3RGhstIVVhxSAz7H2ThCwLcU{"code":"internal_server_error","message":"<p>There has been a critical error on this website.</p><p><a href="https://wordpress.org/support/article/faq-troubleshooting/">Learn more about troubleshooting WordPress.</a></p>","data":{"status":500},"additional_errors":[]}

#

this is the log

#

this is the code:

#

you can ignore $connected_account, it is empty, and I also try without it and I use it all over the code like that for many many years.

#

it is the array for the connected account (if exists, otherwise it is empty)

opaque walrus
#

It looks like you're talking about two different things here:

  • Retrieving the PaymentIntent ID from the PaymentIntent object
  • Failed webhook deliveries
#

What's the specific issue you need assistance with?

abstract prism
#

yes, I think the problem is on the line where the $charge->metadata = $payment_intent_object->metadata

#

because if I do var_dump($payment_intent_object I can see it is properly retrieved

opaque walrus
#

Not sure that's the case. I'm looking at the event associated with the log line you shared and we successfully delivered the charge.succeeded event to multiple webhook endpoints with exception to one.

abstract prism
#

for what I can see, because I wrote this many years ago, this is trying to update the charge description based on the payment intent description

opaque walrus
#

Head over to the event's page in the Dashboard and scroll down to the "Webhook attempts" section.

abstract prism
#

something related to admin, for sure. But it is giving me an error

#

sure, I also can see it has successfully been sent to other places, but those are irrelevant actually

#

those don't even read the webhook, they discard it

#

that is why it has successfully delivered

#

because it doesn't belong to them

#

I remember now:
for example in this case, the charge description is:
"description": "(2) Used Custom Vinyl - โ‚ฌ20.00\n(1) Used Custom Vinyl - โ‚ฌ5.00\n",

#

how to copy this description so that the payment intent also has it?

#

so that it appears on the dashborard under transactions, for example

#

or is that not the problem?

opaque walrus
#

One sec.

abstract prism
#

Ok, I can explain better

#

My app, takes application transfers whenever there is a successful charge

#

and lately it has been failing, and I am trying to figure out where exactly is the error

#

under my logs (that appear on stripe's webhook response) I can see the server error

#

but I cannot pinpoint where exactly is coming from

#

so perhaps if I could know what is the latest successful stripe call

opaque walrus
#

The latest call was the confirmation of the PaymentIntent.

flat warrenBOT
abstract prism
#

I think it might be this line:

$customer =\Stripe\Customer::retrieve($charge->customer, $connected_account);
#

because I can print all the way till there

#

but I cannot var_dump($customer)

loud oar
#

๐Ÿ‘‹ stepping in as eze needs to step away

#

Did you log out the relevant variables used in that request?

abstract prism
#

yes it's that

#

because commenting that line makes it work

#

but why is that making a server error?

loud oar
#

No clue. There should be an error on your server if that Stripe request is failing

abstract prism
#

if I wrap that on try catch, it should display yes?

loud oar
#

Yeah it should

flat warrenBOT
abstract prism
#

it's very weird, it doesn't

#

with a wrap try catch, just gives me an internal server error

#

if I comment the line, webhook is delivered succesfully

#

$customer =\Stripe\Customer::retrieve($charge->customer, $connected_account);

loud oar
#

Have you logged out $charge -> customer and $connected_account prior to that line?

#

To make sure those variables are properly initialized

#

Also what is the actual error on your server?

abstract prism
#

yes, connected account is empty, and always works, that I am 100% sure is not the problem.

$charge - > customer is null, according to the stripe log

loud oar
#

You keep saying it gives you "internal server error" but that is what you are seeing client-side, right?

#

Well $charge -> customer can't be null here to retrieve a Customer....

#

Can you hard code in a Customer ID

#

And test that way

abstract prism
#

$customer = 'customerdemo123';

#

same error

loud oar
#

Needs to be a cus_xxxx

abstract prism
#

but wouldn't that message appear?

#

like an api error?

loud oar
#

I mean it should

abstract prism
#

and go through?

loud oar
#

But I have no idea what your server is doing

#

I'm flying blind here

#

So suggesting making a real request that should work

#

And going from there

abstract prism
#

if a customer is null

#

and you pass it thorugh that function

#

it should fire an api exception

loud oar
#

Yes

abstract prism
#

and the try catch should catch it

loud oar
#

It should.

abstract prism
#

and display the error, and webhook OK.

#

but server error

#

it is strange

#

can the server have a certain config?

loud oar
#

Can you share your full Webhook handler code?

abstract prism
#

that I am not aware of?

loud oar
#

I have no idea how your server is set up, sorry.

abstract prism
#

I know you don't but also I don't. I changed lately to a managed server, but I am unaware if things like this can be configured.

#

like to not enable try catch

#

or something.

#
                            try{
                            $customer = \Stripe\Customer::retrieve($charge_customer, $connected_account);
                            } catch (\Stripe\Exception\ApiErrorException $e) {
                                // Handle Stripe API errors
                                error_messages("Stripe API Error: " . $e->getMessage());
                            } catch(\Stripe\Error\InvalidRequest $e){
                                error_messages($e);
                            } catch (\Stripe\Error\Card $e){
                                error_messages($e);
                            } catch (Exception $e){
                                error_messages($e);
                            } ```
#

That try catch just like that has work through the years. (i.e error messages is a function that works)

#

*error_messages($e)

#

i don't want to use a real customer because then it will just make the webhook work, i want the webhook to work but to throw me an api exception error so that i can see the stripe error.

#

what about this:

$customer = \Stripe\Customer::retrieve($charge->customer, $connected_account);
} catch(Exception $e){
  $customer = null;
}```

would that work?
loud oar
#

Sorry I really don't know what to suggest here. Overall there is something unique going on with your server. It feels to me like the Stripe request isn't the issue at all. I would recommend finding out if the request is even being made here at all -- do you see a failing request in your logs?

abstract prism
#

in my logs in stripe dashboard?

loud oar
#

Yep

abstract prism
#

OK, so that makes it work.

#

This:

#

try{
$customer = \Stripe\Customer::retrieve($charge->customer, $connected_account);
} catch(Exception $e){
$customer = null;
}

#

that is all i needed

loud oar
#

Are you sure your error_messages($e); is doing what you expect?

#

Maybe that error_messages() function is your issue?

abstract prism
#

yes...

#
function error_messages($e){
  $body = $e->getJsonBody();
  $err  = $body['error'];

  echo "<h4>We are sorry</h4>";

  echo "<p><strong>There was a problem with your transaction";
  echo "<br>" . $err['message'] . "</strong></p>";

}```
#

not sure why suddenly this is happening tho

loud oar
#

Perhaps something got cached in that case.

abstract prism
#

$body = $e->getJsonBody();

#

this is the problem i am almost sure now, but it has been working for years, so I am confused

#

can the server dissallow getJsonBody() ?

#

like a secure flag?

#

i will ask server developers (it is a manged server now)

#

i used to run my own servers before, but too much work

loud oar
#

Yeah that could be possible but would indeed be a question for your server managers.

abstract prism
#

thanks for your help

#

a lot

#

cheers

loud oar
#

Sure thing

abstract prism
#

last question

#

if($event->type == 'charge.succeeded' && $event->data->object->amount_captured > 0) do you see any possible problem with this?

#

or am I safe to use it

#

because I only had this in this app, and I just did git pull to it and this line of code i did not have it elsewhere or on repository, so want to know if this COULD be a cause of a lot of problems

#

and better just leave it as charge.succeeded and omit the check for amount_captured

#

PHP Fatal error: Uncaught Error: Call to undefined method Stripe\\Exception\\UnexpectedValueException::getJsonBody() in /home/894259.cloudwaysapps.com/rtwnabpnwq/public_html/wp-content/themes/sigourney/includes/stripe/stripe-functions.php:1820

#

sorry, this is actual error on the server

loud oar
#

lol okay yeah well that solves it then for why the exception wasn't getting raised.

abstract prism
#

sorry I am not that great developer

loud oar
#

No worries! Glad it got figured out.

abstract prism
#

๐Ÿ™‚

#

but what is it?

loud oar
#

In terms of your first question, that should be fine.

#

What is the error?

abstract prism
#

ok, i will leave it there

#

so will it ALWAYS be there no matter the event when charge.successfull? $event->data->object->amount_captured > 0

loud oar
#

The error is that you are trying to call getJsonBody(); on an object that doesn't support that.

abstract prism
#

uuuu

loud oar
abstract prism
#

so I should really fix that because all my try catches in webhook have that

#

call to the same function

loud oar
#

Yep that's what I was indicating before about there being an issue with your error_messages() function

abstract prism
#

how should I modify it then?

#

here is error_messages($e):

  $body = $e->getJsonBody();
  $err  = $body['error'];

  echo "<h4>We are sorry</h4>";

  echo "<p><strong>There was a problem with your transaction";
  echo "<br>" . $err['message'] . "</strong></p>";

}```
loud oar
#

That has some suggestions

#

But overall you want to just record the error directly without calling any method on it

#

To figure this out you could log out the entire $e here and see which properties you care about

#

And then log them

abstract prism
#

like this:
$e->getError()->message

#

only

#

not getJsonBody

loud oar
#

That is how you can specifically handle a CardException

abstract prism
#

simpler:

#
  echo "<h4>We are sorry</h4>";
  echo "<p><strong>There was a problem with your transaction";
  echo "<br>" . $e->getError()->message . "</strong></p>";
}```
#

will this cover me for now?

loud oar
#

For CardErrors yes. But if you had an actual server-side error because of a bug in your code then I don't believe so.

#

You need to just handle the generic Exception in that case.

#

I'm not a PHP dev so I don't know exactly what this looks like.

#

You can trigger a general exception and just log the entire $e object to see what it will look like.

abstract prism
#

so my try catches are mostly like this:

#
catch (\Stripe\Exception\ApiErrorException $e) {
                    // Handle Stripe API errors
                    error_messages("Stripe API Error: " . $e->getMessage());
                } catch(\Stripe\Error\InvalidRequest $e){
                    error_messages($e);
                } catch (\Stripe\Error\Card $e){
                    error_messages($e);
                } catch (Exception $e){
                    error_messages($e);
                } ```
#

I suppose a safer approach would be to then make error_messages($e) like:

  echo "<h4>We are sorry</h4>";
  echo "<p><strong>There was a problem with your transaction";
  echo "<br>" . $e . "</strong></p>";
}```
loud oar
#

I mean yeah but you don't want to show the whole error object client-side as it will contain a lot of jargon and things that don't make any sense to a customer.

abstract prism
#

hmm yes

loud oar
#

Most times when folks catch a general Exception they just return their own error message

#

And you log the entire error object for yourself to analyze later

#

So you just echo back something like "Sorry, something went wrong."

flat warrenBOT
abstract prism
#

how can I check where $e comes from ? so that I can disseminate and choose not to use getJsonBody

#

like in this case

loud oar
#

You can't check that

#

Your last catch is just a catch-all

#

So it shouldn't try to do anything to the exception

abstract prism
#

so your recommended approach, would be to use a generic catch (Exception $e){ error_messages($e); }

#

and log the error to see on my end