/** * Converts a Stripe exception into an error message. * * @param exception $exception * * @return string Error message. */ public static function error_message($exception) { if ($exception instanceof Stripe_CardError) { $body = $exception->getJsonBody(); $error = $body['error']; return sprintf(_x('Error code: <code>%1$s</code>. %2$s.', 's2member-front', 's2member'), esc_html(trim($error['code'], '.')), esc_html(trim($error['message'], '.'))); } if ($exception instanceof Stripe_InvalidRequestError) { return _x('Invalid parameters to Stripe; please contact the site owner.', 's2member-front', 's2member'); } if ($exception instanceof Stripe_AuthenticationError) { return _x('Invalid Stripe API keys; please contact the site owner.', 's2member-front', 's2member'); } if ($exception instanceof Stripe_ApiConnectionError) { return _x('Network communication failure with Stripe; please try again.', 's2member-front', 's2member'); } if ($exception instanceof Stripe_Error) { return _x('Stripe API error; please try again.', 's2member-front', 's2member'); } return _x('Stripe error; please try again.', 's2member-front', 's2member'); }