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,
#[fail(display="not found")]
NotFound,
#[fail(display="account name taken or invalid")]
AccountNameNotProvided,
#[fail(display="account name not provided")]
AccountNotFound,
AccountNameNotProvided,
#[fail(display="account name unavailable")]
AccountNameUnavailable,
#[fail(display="account not found")]
AccountNameTaken,
AccountNotFound,
#[fail(display="password does not match")]
PasswordNotMatch,
#[fail(display="password unacceptable. must be > 11 characters")]
@ -66,7 +66,21 @@ impl From<bcrypt::BcryptError> for MnmlHttpError {
impl From<postgres::Error> for MnmlHttpError {
fn from(err: postgres::Error) -> Self {
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::AccountNameNotProvided |
MnmlHttpError::AccountNameTaken |
MnmlHttpError::AccountNameUnavailable |
MnmlHttpError::AccountNotFound |
MnmlHttpError::BadRequest |
MnmlHttpError::PasswordUnacceptable => (m_err.compat(), status::BadRequest),

View File

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