Jump to content

Exception Handling Issue


Knucklehead00

Recommended Posts

I am trying to finish up the programming work for my site's integration with a payment processor called Stripe. The last step is catching HTTP error response codes that happen during the customer creation process.

 

In the code below, the exception will get throw when "Stripe_Customer::create" is reached if the credit card is declined or a sleuth of other things.

 

What I want to do is take the Exception message and pass it to Smarty. Can I not do this in the Exception block? Right now, the code in the Exception block is throwing a Server Error. If I take out the code and just do a "echo $e->getMessage;", then it works just fine.

 

Any help would be appreciated!

 

 

try {
$customer = Stripe_Customer::create(array(
"description" => es($_POST['fname']) . " " . es($_POST['lname']),
"email" => es($_POST['e-mail_add']),
"card" => es($_POST['stripeToken'])
));

// Validation information for card that was entered.
$cvcCheck = $customer->active_card->cvc_check;
$addressCheck = $customer->active_card->address_line1_check;
$zipCheck = $customer->active_card->address_zip_check;

// Validation checks for the card that was entered.
if($cvcCheck == 'fail'){
$error = true;
$smarty->assign("cvcError", true);
}

//If both the address and zip check failed or are left unchecked,
//then the card cannot be charged properly and an error should be
//displayed to the user.
//If only one of them fails, then the charge can still process through
//as long as the CvC is correct.
if(!$error && $addressCheck != 'pass' && $zipCheck != 'pass'){
$error = true;
$smarty->assign("addressError", true);
}

//Deleting the temporary customer.
$cu = Stripe_Customer::retrieve($customer->id);
$cu->delete();
}
catch (Exception $e){
$errorMessage = $e->getMessage();
$smarty->assign("cardError", true);
$smarty->assign("cardErrorMessage", $errorMessage);
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.