Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions rust/src/payments/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! `gddy payments` — payment method management.

use std::io::Write as _;

use cli_engine::{
CliCoreError, CommandResult, CommandSpec, GroupSpec, Module, RuntimeCommandSpec,
RuntimeGroupSpec, Tier,
Expand Down Expand Up @@ -37,19 +35,15 @@ fn add_command() -> RuntimeCommandSpec {
|ctx| async move {
let env = environments::resolve(&ctx.middleware.env).map_err(map_env_err)?;
let url = format!("{}/payment-methods/add-payment?plid=1", env.account_url);
if let Err(e) = open::that(&url) {
let mut stderr = std::io::stderr().lock();
drop(writeln!(
stderr,
"Failed to open browser. Visit manually:\n {url}"
));
return Err(CliCoreError::message(format!(
"failed to open browser: {e}"
)));
}
let opened = open::that(&url).is_ok();
Ok(CommandResult::new(json!({
"info": "Browser opened to the payment methods management page. \
Only credit card or Good-as-Gold can be used for domain purchases."
"url": url,
"info": if opened {
"Browser opened. Only credit card or Good-as-Gold can be used for domain purchases."
} else {
"Could not open browser. Visit the URL above to add a payment method. \
Only credit card or Good-as-Gold can be used for domain purchases."
}
})))
},
)
Expand Down