0

I am doing a test querying a Token that does not exist in Stripe "To show the user a message that the Token is not valid" and I get a 500 error.

Note: I understand that I can do it from the Frontend side, but I would like to validate it from the Backend side

$stripe = new \Stripe\StripeClient(
  'sk_test_svj1t9Fw2aprNnOPvGFgEa'
);
$stripe->tokens->retrieve(
  'tok_1JabfXogSs37OlpFP2a',
  []
);

I have added the code inside a try catch, and I have not been able to catch the error.

try {
  if( $stripe->tokens->retrieve('tok_1JabfXogSs37OlpFP2a',[]) ) {
   throw new Exception('The token is not valid.');
  }
} catch (Error $e) {
  echo $e->getMessage();
}

Is there any way to show a message when the token has expired?

Learning and sharing
  • 1,378
  • 3
  • 25
  • 45

0 Answers0