#karls-exception
1 messages · Page 1 of 1 (latest)
@analog vessel yes you should. Really our API can return a wide range of errors and your code needs to catch and handle all potential errors as documented in https://stripe.com/docs/api/errors
What is funny, I accidentally tested first with LIVE api keys using the 0002 CC number and my code handled the exception just fine (user prompted with CC failed).
maybe you handle error in some cases and not others?
yep, looking now. Not a PHP developer though! Supporting this app for a client.
Just a thought, but...
I see in code that we call chargeAmountFromCard and it gets a response. In code we test for "fail" and then echo the response to the user. So no CATCH of an exception in this case.
wouldn't a "declined" CC pass back an appropriate failure message, therefore I'm not catching any exception?
no, declines raise an exception
ok! good to know.
so, just tried the test with live mode creds using test CC and (for whatever reason, still investigating) this object is passed back to the client, which I think is what i want, where a user friendly "card declined" dialog appears.
{
"error": {
"code": "card_declined",
"decline_code": "live_mode_test_card",
"doc_url": "https://stripe.com/docs/error-codes/card-declined",
"message": "Your card was declined. Your request was in live mode, but used a known test card.",
"param": "",
"type": "card_error"
}
}
you cannot use the test cards in live mode
they only work in test mode
what are you trying to test?
declined CC.
I understand that, i'm just trying to determine how my code is working in one case and not the other.
which test card are you using?
I understand the difference now. The object I shared with you is caught client-side, thus my code responds correctly, but I need to trap the (402) exception serverside and pass that back.
card ending in 0002
To be clear: the call to stripe /Tokens fails in live mode for test CC but in test mode my server side code in invoked and there I don't handle the exception properly.
Right, you can't even create the token for the test card in live mode
yep yep
this is expected - use your test mode PK to get the token, then try the payment
do you have a link to any PHP sample code for calling chargeAmountFromCard? I'm a hack PHP developer
what is chargeAmountFromCard here? where do you see that?
This is the point in my back-end code where I call to charge the card (PHP mind you) and my code fails "unhandled exception"
what does that code look like now?
I have a couple of TEMP statements in here to help trace the exception. My code reaches TEMP_0000, then call chargeAmountFromCard, then fails, but never reaches TEMP_0002 in my exception handler.
try
{
error_log("TEMP_0000");
$stripeResponse = $stripePayment->chargeAmountFromCard($registrationInfo);
error_log("TEMP_0001");
}
catch(exception $e)
{
error_log("TEMP_0002");
error_log($e->getMessage());
}
original code (no trace staments)
$stripePayment = new StripePayment();
$stripeResponse = $stripePayment->chargeAmountFromCard($registrationInfo);
if ($stripeResponse['amount_refunded'] == 0 && empty($stripeResponse['failure_code']) && $stripeResponse['paid'] == 1 && $stripeResponse['captured'] == 1 && $stripeResponse['status'] == 'succeeded') {
$registrationInfo['tx_ID'] = $stripeResponse["balance_transaction"];
completeRegistrationWithPaymentDetails($registrationInfo);
} else {
echo "Payment Failed";
}
are you still able to help?
no matter what I do, my code is not catching any exception.
yes sorry, many threads
i think i got it. in PHP Exception is required, so capital E
I was using exception in my handler
ah nice! does it get the expected error now?
actually, this is catching my exception
catch(\Stripe\Exception\CardException $e) {
yep, I can handle it from here. thank you.
perfect!