diff --git a/booking.stripe.inc b/booking.stripe.inc index 9c9fcdc..3736c69 100644 --- a/booking.stripe.inc +++ b/booking.stripe.inc @@ -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', )); - - $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()); + if ($charge && $charge->paid) { + watchdog('booking', 'Charge created successfully'); + $form_state['stripeform_charge'] = $charge; + //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'); } }