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
|
// Create the charge on Stripe's servers - this will charge the user's card
|
||||||
try {
|
try {
|
||||||
$charge = \Stripe\Stripe_Charge::create(array(
|
$charge = \Stripe\Charge::create(array(
|
||||||
"amount" => $amount,
|
"amount" => $amount,
|
||||||
"currency" => "usd",
|
"currency" => "usd",
|
||||||
"card" => $token,
|
"card" => $token,
|
||||||
"description" => 'test charge',
|
"description" => 'test charge',
|
||||||
));
|
));
|
||||||
|
if ($charge && $charge->paid) {
|
||||||
$form_state['stripeform_charge'] = $charge;
|
watchdog('booking', 'Charge created successfully');
|
||||||
} catch(\Stripe\Stripe_CardError $e) {
|
$form_state['stripeform_charge'] = $charge;
|
||||||
// The card has been declined
|
//drupal_goto('bookingfinal');
|
||||||
watchdog('stripeform', $e->getMessage());
|
}
|
||||||
form_set_error('form', $e->getMessage());
|
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