MCPcopy Create free account
hub / github.com/algolia/cli / offerBilling

Function offerBilling

pkg/cmd/application/create/create.go:433–466  ·  view source on GitHub ↗

offerBilling tells the user a paid plan needs billing and offers the billing page.

(opts *CreateOptions, client *dashboard.Client, plan dashboard.Plan)

Source from the content-addressed store, hash-verified

431
432// offerBilling tells the user a paid plan needs billing and offers the billing page.
433func offerBilling(opts *CreateOptions, client *dashboard.Client, plan dashboard.Plan) error {
434 cs := opts.IO.ColorScheme()
435 url := client.DashboardURL + "/account/billing/details"
436
437 fmt.Fprintf(
438 opts.IO.Out,
439 "\nThe %s plan requires a payment method on file before a paid application can be provisioned.\nThe CLI can't collect card details.\n",
440 cs.Bold(plan.Name),
441 )
442
443 if opts.IO.CanPrompt() && opts.IO.IsStdoutTTY() {
444 browser := opts.Browser
445 if browser == nil {
446 browser = pkgopen.Browser
447 }
448 open := true
449 if err := prompt.Confirm("Open the billing page to add a payment method?", &open); err != nil {
450 return err
451 }
452 if !open {
453 return nil
454 }
455 fmt.Fprintf(opts.IO.Out, "Opening %s\n", cs.Bold(url))
456 return browser(url)
457 }
458
459 fmt.Fprintf(
460 opts.IO.Out,
461 "Add a payment method here, then re-run with --plan %s:\n%s\n",
462 plan.ID,
463 url,
464 )
465 return fmt.Errorf("the %q plan requires a payment method; none is on file", plan.Name)
466}
467
468// callWithReauth runs fn, re-authenticating once and retrying on an expired session.
469func callWithReauth(

Callers 1

createApplicationFunction · 0.85

Calls 5

ColorSchemeMethod · 0.80
BoldMethod · 0.80
CanPromptMethod · 0.80
IsStdoutTTYMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected