From f5dc4836ce4fdc6b266bf8bd5cbb877ba32168ac Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Thu, 21 Jul 2016 11:00:15 +1000 Subject: [PATCH] change error handling --- booking.stripe.inc | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) 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'); } }