better register messages and stripe payments fix

This commit is contained in:
ntr 2019-09-08 14:01:03 +10:00
parent e69764d294
commit c4fd68a47f
2 changed files with 29 additions and 9 deletions

View File

@ -40,12 +40,12 @@ pub enum MnmlHttpError {
BadRequest, BadRequest,
#[fail(display="not found")] #[fail(display="not found")]
NotFound, NotFound,
#[fail(display="account name taken or invalid")]
AccountNameNotProvided,
#[fail(display="account name not provided")] #[fail(display="account name not provided")]
AccountNotFound, AccountNameNotProvided,
#[fail(display="account name unavailable")]
AccountNameUnavailable,
#[fail(display="account not found")] #[fail(display="account not found")]
AccountNameTaken, AccountNotFound,
#[fail(display="password does not match")] #[fail(display="password does not match")]
PasswordNotMatch, PasswordNotMatch,
#[fail(display="password unacceptable. must be > 11 characters")] #[fail(display="password unacceptable. must be > 11 characters")]
@ -66,7 +66,21 @@ impl From<bcrypt::BcryptError> for MnmlHttpError {
impl From<postgres::Error> for MnmlHttpError { impl From<postgres::Error> for MnmlHttpError {
fn from(err: postgres::Error) -> Self { fn from(err: postgres::Error) -> Self {
warn!("{:?}", err); warn!("{:?}", err);
MnmlHttpError::DbError
match err.as_db() {
Some(db) => {
let constraint = match db.constraint {
Some(ref c) => c,
None => return MnmlHttpError::DbError,
};
match constraint.as_ref() {
"accounts_name_unique" => MnmlHttpError::AccountNameUnavailable,
_ => MnmlHttpError::DbError,
}
},
_ => MnmlHttpError::DbError,
}
} }
} }
@ -109,7 +123,7 @@ impl From<MnmlHttpError> for IronError {
MnmlHttpError::DbError => (m_err.compat(), status::InternalServerError), MnmlHttpError::DbError => (m_err.compat(), status::InternalServerError),
MnmlHttpError::AccountNameNotProvided | MnmlHttpError::AccountNameNotProvided |
MnmlHttpError::AccountNameTaken | MnmlHttpError::AccountNameUnavailable |
MnmlHttpError::AccountNotFound | MnmlHttpError::AccountNotFound |
MnmlHttpError::BadRequest | MnmlHttpError::BadRequest |
MnmlHttpError::PasswordUnacceptable => (m_err.compat(), status::BadRequest), MnmlHttpError::PasswordUnacceptable => (m_err.compat(), status::BadRequest),

View File

@ -164,9 +164,15 @@ impl StripeData {
Ok(self) Ok(self)
}, },
StripeData::Purchase { account, customer: _, amount, checkout: _ } => { StripeData::Purchase { account, customer: _, amount, checkout: _ } => {
let credits = amount let credits = match amount {
500 => 50,
1000 => 110,
2000 => 250,
5000 => 660,
_ => amount
.checked_div(CREDITS_COST_CENTS) .checked_div(CREDITS_COST_CENTS)
.expect("credits cost 0"); .expect("credits cost 0"),
};
account::credit(tx, *account, credits)?; account::credit(tx, *account, credits)?;