change error handling
This commit is contained in:
@@ -180,18 +180,34 @@ function booking_stripeform_validate_form_payment($form, &$form_state) {
|
||||
|
||||
// Create the charge on Stripe's servers - this will charge the user's card
|
||||
try {
|
||||
$charge = \Stripe\Stripe_Charge::create(array(
|
||||
$charge = \Stripe\Charge::create(array(
|
||||
"amount" => $amount,
|
||||
"currency" => "usd",
|
||||
"card" => $token,
|
||||
"description" => 'test charge',
|
||||
));
|
||||
|
||||
if ($charge && $charge->paid) {
|
||||
watchdog('booking', 'Charge created successfully');
|
||||
$form_state['stripeform_charge'] = $charge;
|
||||
} catch(\Stripe\Stripe_CardError $e) {
|
||||
// The card has been declined
|
||||
watchdog('stripeform', $e->getMessage());
|
||||
form_set_error('form', $e->getMessage());
|
||||
//drupal_goto('bookingfinal');
|
||||
}
|
||||
else {
|
||||
drupal_set_message('Card does not seem to have been charged successfully. Please try again', 'error');
|
||||
}
|
||||
}
|
||||
catch(\Stripe\Error\Card $e) {
|
||||
$e_json = $e->getJsonBody();
|
||||
$error = $e_json['error'];
|
||||
watchdog('booking', $e->getMessage());
|
||||
drupal_set_message($error['message'], 'error');
|
||||
}
|
||||
catch (\Stripe\Error\ApiConnection $e) {
|
||||
watchdog('booking', $e->getMessage());
|
||||
drupal_set_message($error['message'], 'error');
|
||||
}
|
||||
catch (\Stripe\Error\Api $e) {
|
||||
watchdog('booking', $e->getMessage());
|
||||
drupal_set_message($error['message'], 'error');
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user