#JeffRoss-help
1 messages · Page 1 of 1 (latest)
Hi there, I can't unarchive but I'd be happy to help if you would summarize your issue here?
Apparently copy/paste doesn't work in Discord? So give me a minute to put it all together.
I assume you can access that thread above. I continue to get this error message while testing invalid cards even after switching to PaymentIntents:
PHP Fatal error: Uncaught (Status 402) (Request req_1fxsjnf2iaEYQf) Your card has insufficient funds.\n thrown in /var/www/pear/lib/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php
I added some debugging to the Stripe supplied vendor/strip-php/lib/Exception/ApiErrorException.php so now when I get the fatal error I also see the following:
[Mon Aug 29 11:03:47.768881 2022] [php7:notice] [pid 96052] [client 154.27.106.60:58235] message: Your card has insufficient funds., referer: https://dev.mt43news.com/subscription.html
[Mon Aug 29 11:03:47.768919 2022] [php7:notice] [pid 96052] [client 154.27.106.60:58235] httpStatus 402, referer: https://dev.mt43news.com/subscription.html
[Mon Aug 29 11:03:47.768947 2022] [php7:notice] [pid 96052] [client 154.27.106.60:58235] httpBody: {\n "error": {\n "code": "card_declined",\n "decline_code": "insufficient_funds",\n "doc_url": "https://stripe.com/docs/error-codes/card-declined",\n "message": "Your card has insufficient funds.",\n "param": "",\n "type": "card_error"\n }\n}\n, referer: https://dev.mt43news.com/subscription.html
[Mon Aug 29 11:03:47.768973 2022] [php7:notice] [pid 96052] [client 154.27.106.60:58235] jsonBody: Array\n(\n [error] => Array\n (\n [code] => card_declined\n [decline_code] => insufficient_funds\n [doc_url] => https://stripe.com/docs/error-codes/card-declined\n [message] => Your card has insufficient funds.\n [param] => \n [type] => card_error\n )\n\n)\n, referer: https://dev.mt43news.com/subscription.html
[Mon Aug 29 11:03:47.768998 2022] [php7:notice] [pid 96052] [client 154.27.106.60:58235] httpHeaders: Stripe\Util\CaseInsensitiveArray Object\n(\n [container:Stripe\Util\CaseInsensitiveArray:private] => Array\n (\n [server] => nginx\n [date] => Mon, 29 Aug 2022 17:04:14 GMT\n [content-type] => application/json\n [content-length] => 254\n [access-control-allow-credentials] => true\n [access-control-allow-methods] => GET, POST, HEAD, OPTIONS,\nDELETE\n [access-control-allow-origin] => *\n [access-control-expose-headers] => Request-Id,\nStripe-Manage-Version, X-Stripe-External-Auth-Required,\nX-Stripe-Privileged-Session-Required\n [access-control-max-age] => 300\n [cache-control] => no-cache, no-store\n [idempotency-key] => 5283464d-e9ce-4a1b-b4d1-a74b5ed2df06\n [original-request] => req_1fxsjnf2iaEYQf\n [request-id] => req_1fxsjnf2iaEYQf\n [stripe-should-retry] => false\n [stripe-version] => 2020-08-27\n [strict-transport-security] => max-age=63072000;\nincludeSubDomains; preload\n )\n\n)\n, referer: https://dev.mt43news.com/subscription.html
[Mon Aug 29 11:03:47.769034 2022] [php7:notice] [pid 96052] [client 154.27.106.60:58235] stripeCode: card_declined, referer: https://dev.mt43news.com/subscription.html
[Mon Aug 29 11:03:47.777093 2022] [php7:error] [pid 96052] [client 154.27.106.60:58235] PHP Fatal error: Uncaught (Status 402) (Request req_1fxsjnf2iaEYQf) Your card has insufficient funds.\n thrown in /var/www/pear/lib/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php on line 46, referer: https://dev.mt43news.com/subscription.html
Thanks for any input! I still don't understand why that 402 is not handled by the Stripe code.
So you are using the 4000000000009995 test card
That test card specifically declines for insufficient funds
When you attach a card to a customer, we do a card authorization. See: https://support.stripe.com/questions/check-if-a-card-is-valid-without-a-charge
So all of this is expected here
The php Fatal Error is expected?
Yes the 402 is expected here since the attachment was declined for insufficient funds
Yes, I know the 402 is expected but I can't imagine then why php throws a Fatal error--that absolutely prevents me from even attempting to handle that and throws a blank page in apache with no chance to even warn my user that there is a problem with their card.
Aren't you wrapping in a try/catch?
Yes--my code is posted in that thread but here is the relevant part:
try {
$charge = \Stripe\PaymentIntents::create(
array(
'customer' => $stripe_id,
'amount' => $_SESSION['stripe_billing_amount'],
'currency' => 'usd',
'receipt_email' => $_SESSION['email'],
'payment_method_types' => ['card'],
'statement_descriptor' => 'MT43News Subscription'
)
);
$_SESSION['charge_id'] = $charge->id;
stripe_logging($db,$charge,$_SESSION['charge_id']);
stripe_logging($db,$charge,'success!');
header('Location: https://' . $_SERVER['SERVER_NAME'] . '/subscription_payment_success.html');
} catch(\Stripe\Exception\CardException $e) {
stripe_logging($db,$charge,$e);
$_SESSION['e'] = $e;
error_log("A payment error occurred: {$e->getError()->message}");
header('Location: https://' . $_SERVER['SERVER_NAME'] . '/subscription_payment_error.html');
} catch (\Stripe\Exception\InvalidRequestException $e) {
stripe_logging($db,$charge,$e);
error_log("An invalid request occurred.");
header('Location: https://' . $_SERVER['SERVER_NAME'] . '/subscription_payment_error.html');
} catch (\Exception $e) {
stripe_logging($db,$charge,$e);
error_log("Another problem occurred, maybe unrelated to Stripe.");
header('Location: https://' . $_SERVER['SERVER_NAME'] . '/subscription_payment_error.html');
}
That isn't the relevant code, though, right? That is for a PaymentIntent creation?
The failure above is on your Customer creation
I was using "$charge = \Stripe\Charge::create(" but I was told that was deprecated and I should use PaymentIntents instead.
That's correct. However this is a different part of the flow from that.
You first accept the card details client-side and create a token. Then you pass that token to your server where you attach it to a Customer upon Customer creation.
Then after that you create the PaymentIntent to charge the Customer/PaymentMethod
So you need to find your code where you are attaching the token to the customer. This request specifically: https://dashboard.stripe.com/test/logs/req_1fxsjnf2iaEYQf
Here's the code at the top of the script:
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
$email = $_POST['stripeEmail'];
$_SESSION['display_amount'] = number_format($_SESSION['stripe_billing_amount'] / 100,2);
if (! isset($_SESSION['stripe_id']) || empty($_SESSION['stripe_id'])) {
// Use Stripe's library to make requests...
$customer = \Stripe\Customer::create(array(
'email' => $email,
'source' => $token
));
#debug($_SESSION);
$stripe_id = $customer->id;
} else {
$stripe_id = $_SESSION['stripe_id'];
}
And I'm pretty sure that part is not failing. Valid requests flow right through but we've had some issues where the payment process would throw the fatal error and debugging that led me here.