Skip to content

Commit

Permalink
Improved error handling on server side in Stripe plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
cheesegrits committed Jan 16, 2017
1 parent f0238a3 commit fe9dd61
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ PLG_FORM_STRIPE_DIALOG_NAME_LABEL="Dialog Name"
PLG_FORM_STRIPE_PAY="Pay"
PLG_FORM_STRIPE_ZIPCODE_CHECK_DESC="Require user to enter ZIP code in Stripe payment process for verification against card"
PLG_FORM_STRIPE_ZIPCODE_CHECK_LABEL="Zip Code Validation"
PLG_FORM_STRIPE_DECLINED="Your payment was declined with the message: %s";
PLG_FORM_STRIPE_ERROR_DECLINED="Your payment was declined by the Stripe payment processing service with the message: %s";
PLG_FORM_STRIPE_ERROR_INTERNAL="There was an internal error reported by the Stripe payment processing servers, please try again later."
PLG_FORM_STRIPE_ERROR_RATE_LIMITED="This site has exceeded the rate limiting for Stripe payment processing, please try again later"
PLG_FORM_STRIPE_ERROR_AUTHENTICATION="There was an error aithenticating with the Stripe payment processor, please inform the site administrators"
PLG_FORM_STRIPE_ERROR_NETWORK="This site was unable to connect to the Stripe payment processing servers, please try later"
PLG_FORM_STRIPE_CUSTOMERS="Customer Data"
PLG_FORM_STRIPE_CUSTOMERS_CONNECTION_DESC="OPTIONAL - connection for Stripe customer ID table"
PLG_FORM_STRIPE_CUSTOMERS_CONNECTION_LABEL="Connection"
Expand Down
22 changes: 11 additions & 11 deletions plugins/fabrik_form/stripe/stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,45 +231,45 @@ public function onBeforeStore()
print('Param is:' . $err['param'] . "\n");
print('Message is:' . $err['message'] . "\n");
*/
$this->log('fabrik.form.stripe.charge.declined', json_encode($body));
$chargeErrMsg = FText::sprintf('PLG_FORM_STRIPE_DECLINED', $err['message']);
$this->doLog('fabrik.form.stripe.charge.declined', json_encode($body));
$chargeErrMsg = FText::sprintf('PLG_FORM_STRIPE_ERROR_DECLINED', $err['message']);
}
catch (\Stripe\Error\RateLimit $e)
{
// Too many requests made to the API too quickly
$chargeErrMsg = JText::_('PLG_FORM_STRIPE_RATE_LIMITED');
$chargeErrMsg = JText::_('PLG_FORM_STRIPE_ERROR_RATE_LIMITED');
}
catch (\Stripe\Error\InvalidRequest $e)
{
// Invalid parameters were supplied to Stripe's API
$chargeErrMsg = JText::_('PLG_FORM_STRIPE_INTERNAL_ERR');
$chargeErrMsg = JText::_('PLG_FORM_STRIPE_ERROR_INTERNAL');
}
catch (\Stripe\Error\Authentication $e)
{
// Authentication with Stripe's API failed
// (maybe you changed API keys recently)
$chargeErrMsg = JText::_('PLG_FORM_STRIPE_INTERNAL_ERR');
$chargeErrMsg = JText::_('PLG_FORM_STRIPE_ERROR_AUTHENTICATION');
}
catch (\Stripe\Error\ApiConnection $e)
{
// Network communication with Stripe failed
$chargeErrMsg = JText::_('PLG_FORM_STRIPE_INTERNAL_ERR');
$chargeErrMsg = JText::_('PLG_FORM_STRIPE_ERROR_NETWORK');
}
catch (\Stripe\Error\Base $e)
{
// Display a very generic error to the user, and maybe send
// yourself an email
$chargeErrMsg = JText::_('PLG_FORM_STRIPE_INTERNAL_ERR');
$chargeErrMsg = JText::_('PLG_FORM_STRIPE_ERROR_INTERNAL');
}
catch (Exception $e)
{
// Something else happened, completely unrelated to Stripe
$chargeErrMsg = JText::_('PLG_FORM_STRIPE_INTERNAL_ERR');
$chargeErrMsg = JText::_('PLG_FORM_STRIPE_ERROR_INTERNAL');
}

if (!empty($chargeErrMsg))
{
$this->app->enqueueMessage($chargeErrMsg, 'message');
$formModel->setFormErrorMsg($chargeErrMsg);

return false;
}
Expand Down Expand Up @@ -503,7 +503,7 @@ public function getBottomContent()
print('Param is:' . $err['param'] . "\n");
print('Message is:' . $err['message'] . "\n");
*/
$this->log('fabrik.form.stripe.charge.declined', json_encode($body));
$this->doLog('fabrik.form.stripe.charge.declined', json_encode($body));
$chargeErrMsg = FText::sprintf('PLG_FORM_STRIPE_DECLINED', $err['message']);
}
catch (\Stripe\Error\RateLimit $e)
Expand Down Expand Up @@ -813,7 +813,7 @@ private function updateCustomerId($userId, $customerId, $opts)
}
catch (Exception $e)
{
$this->log('fabrik.form.stripe.customer.error', $e->getMessage());
$this->doLog('fabrik.form.stripe.customer.error', $e->getMessage());
$this->app->enqueueMessage($e->getMessage(), 'error');

return false;
Expand Down

0 comments on commit fe9dd61

Please sign in to comment.