#xfechx_api
1 messages ยท Page 1 of 1 (latest)
๐ 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.
- xfechx_api, 5 hours ago, 75 messages
This is using PHP stripe library
The request you shared is a PaymentIntent confirmation request.
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
Can you share the screenshot of the error being returned?
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)
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?
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
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.
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
Head over to the event's page in the Dashboard and scroll down to the "Webhook attempts" section.
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?
One sec.
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
The latest call was the confirmation of the PaymentIntent.
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)
๐ stepping in as eze needs to step away
Did you log out the relevant variables used in that request?
yes it's that
because commenting that line makes it work
but why is that making a server error?
No clue. There should be an error on your server if that Stripe request is failing
if I wrap that on try catch, it should display yes?
Yeah it should
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);
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?
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
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
Needs to be a cus_xxxx
I mean it should
and go through?
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
if a customer is null
and you pass it thorugh that function
it should fire an api exception
Yes
and the try catch should catch it
It should.
and display the error, and webhook OK.
but server error
it is strange
can the server have a certain config?
Can you share your full Webhook handler code?
that I am not aware of?
I have no idea how your server is set up, sorry.
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?
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?
in my logs in stripe dashboard?
Yep
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
Are you sure your error_messages($e); is doing what you expect?
Maybe that error_messages() function is your issue?
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
Perhaps something got cached in that case.
$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
Yeah that could be possible but would indeed be a question for your server managers.
Sure thing
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
lol okay yeah well that solves it then for why the exception wasn't getting raised.
sorry I am not that great developer
No worries! Glad it got figured out.
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
The error is that you are trying to call getJsonBody(); on an object that doesn't support that.
uuuu
Yes a Charge will always have amount_captured: https://docs.stripe.com/api/charges/object#charge_object-amount_captured
so I should really fix that because all my try catches in webhook have that
call to the same function
Yep that's what I was indicating before about there being an issue with your error_messages() function
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>";
}```
Take a look at https://docs.stripe.com/error-handling
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
That is how you can specifically handle a CardException
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?
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.
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>";
}```
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.
hmm yes
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."
how can I check where $e comes from ? so that I can disseminate and choose not to use getJsonBody
like in this case