Add optional payment

This commit is contained in:
eraden 2022-05-04 22:40:20 +02:00
parent b489b4435a
commit d23fe886ce
3 changed files with 36 additions and 2 deletions

View File

@ -37,7 +37,9 @@ impl std::ops::DerefMut for SharedAppConfig {
pub struct PaymentConfig {
payu_client_id: Option<pay_u::ClientId>,
payu_client_secret: Option<pay_u::ClientSecret>,
/// Create payu account and copy here merchant id
payu_client_merchant_id: Option<pay_u::MerchantPosId>,
/// Allow customers to pay on site
optional_payment: bool,
}
@ -50,8 +52,9 @@ impl Example for PaymentConfig {
payu_client_secret: Some(pay_u::ClientSecret::new(
"Create payu account and copy here client_secret",
)),
/// "Create payu account and copy here merchant id"
/// Create payu account and copy here merchant id
payu_client_merchant_id: Some(pay_u::MerchantPosId::from(0)),
/// Allow customers to pay on site
optional_payment: true,
}
}
@ -348,7 +351,10 @@ fn load(config_path: &str, opts: &impl UpdateConfig) -> SharedAppConfig {
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
let config = AppConfig::example();
std::fs::write(config_path, toml::to_string_pretty(&config).unwrap()).unwrap();
SharedAppConfig::new(config)
eprintln!("Config was automatically generated");
eprintln!("Please review ./bazzar.toml, fill all fields or provide all environment variables in .env");
eprintln!("And restart service.");
std::process::exit(1);
}
Err(e) => {
log::error!("{e:?}");
@ -357,6 +363,28 @@ fn load(config_path: &str, opts: &impl UpdateConfig) -> SharedAppConfig {
}
}
pub async fn config_info() -> crate::Result<()> {
println!(
r#"Environment variables:
PAYU_CLIENT_ID - PayU client id, you can obtain it by creating account (account requires one-time payment)
PAYU_CLIENT_SECRET - PayU client secret
PAYU_CLIENT_MERCHANT_ID - PayU client merchant id, you can obtain it by creating account (account requires one-time payment)
WEB_HOST - your domain name, it's required for PayU notifications, service emails and redirections
PASS_SALT - password encryption secret string, you can generate it with this CLI
SESSION_SECRET - 100 characters admin session encryption
JWT_SECRET - 100 characters user session encryption
BAZZAR_BIND - address to which server should be bind, typically 0.0.0.0
BAZZAR_PORT - port which server should use, typically 80
SENDGRID_SECRET - e-mail sending service secret
SENDGRID_API_KEY - e-mail sending service api key
SMTP_FROM - e-mail sending service authorized e-mail address used as sender e-mail address
DATABASE_URL - postgresql address (ex. postgres://postgres@localhost/bazzar)
"#
);
Ok(())
}
pub fn save(config_path: &str, config: &mut AppConfig) {
config.config_path = String::from(config_path);
std::fs::write(config_path, toml::to_string_pretty(&config).unwrap()).unwrap();

View File

@ -204,5 +204,6 @@ async fn main() -> Result<()> {
Command::GenerateHash(opts) => generate_hash(opts).await,
Command::CreateAccount(opts) => create_account(opts).await,
Command::TestMailer(opts) => test_mailer(opts).await,
Command::ConfigInfo(_) => config::config_info().await,
}
}

View File

@ -47,6 +47,8 @@ pub enum Command {
CreateAccount(CreateAccountOpts),
#[options(help = "Check mailer config")]
TestMailer(TestMailerOpts),
#[options(help = "Print config information")]
ConfigInfo(ConfigInfo),
}
impl UpdateConfig for Command {
@ -67,6 +69,7 @@ impl UpdateConfig for Command {
Command::TestMailer(opts) => {
opts.update_config(config);
}
Command::ConfigInfo(_) => {}
}
}
}
@ -77,6 +80,8 @@ impl Default for Command {
}
}
pub struct ConfigInfo {}
#[derive(Options, Debug)]
pub struct GenerateHashOpts {
pub help: bool,