use crate::payments::Error;
use stripe::StripeError;

impl From<StripeError> for Error {
    fn from(e: StripeError) -> Self {
        match e {
            StripeError::Stripe(ref e2, _code) => {
                let message = match e2.message {
                    Some(ref message) => message.clone(),
                    None => e.to_string(),
                };
                Error::internal(message)
            }
            StripeError::Timeout => Error::internal("Timeout communicating with Stripe".to_string()),
            _ => Error::internal(e.to_string()),
        }
    }
}
