@@ -23,17 +23,31 @@ import (
23
23
"github.com/apex/log"
24
24
"github.com/apex/up/internal/account"
25
25
"github.com/apex/up/internal/cli/root"
26
+ "github.com/apex/up/internal/colors"
26
27
"github.com/apex/up/internal/stats"
27
28
"github.com/apex/up/internal/userconfig"
28
29
"github.com/apex/up/internal/util"
29
30
"github.com/apex/up/platform/event"
30
31
"github.com/apex/up/reporter"
31
32
)
32
33
33
- var (
34
- api = env .GetDefault ("APEX_TEAMS_API" , "https://teams.apex.sh" )
35
- a = account .New (api )
36
- )
34
+ // api endpoint.
35
+ var api = env .GetDefault ("APEX_TEAMS_API" , "https://teams.apex.sh" )
36
+
37
+ // api client.
38
+ var a = account .New (api )
39
+
40
+ // plan amounts.
41
+ var amounts = map [string ]int {
42
+ "monthly" : 2000 ,
43
+ "annually" : 21600 ,
44
+ }
45
+
46
+ // plan amount select options.
47
+ var amountOptions = map [string ]string {
48
+ "Monthly at $20.00 USD" : "monthly" ,
49
+ "Annually at 216.00 USD" : "annually" ,
50
+ }
37
51
38
52
func init () {
39
53
cmd := root .Command ("team" , "Manage team members, plans, and billing." )
@@ -207,7 +221,7 @@ func status(cmd *kingpin.Cmd) {
207
221
util .LogName ("coupon" , d .Coupon .ID )
208
222
}
209
223
210
- util .LogName ("amount" , "$%0.2f/mo USD" , float64 (p .Amount )/ 100 )
224
+ util .LogName ("amount" , "%s USD per %s " , currency (p .Amount ), p . Interval )
211
225
util .LogName ("owner" , team .Owner )
212
226
util .LogName ("created" , p .CreatedAt .Format ("January 2, 2006" ))
213
227
if p .Canceled {
@@ -301,8 +315,7 @@ func login(cmd *kingpin.Cmd) {
301
315
// ensure we have a team if already signed-in
302
316
if t != nil && * team == "" {
303
317
util .Log ("Already signed in as %s on team %s." , t .Email , t .ID )
304
- util .Log ("Use `up team login --team <id>` to join a team" )
305
- util .Log ("if you have received an invite." )
318
+ util .Log ("Use `up team login --team <id>` to join a team." )
306
319
return nil
307
320
}
308
321
@@ -394,8 +407,21 @@ func subscribe(cmd *kingpin.Cmd) {
394
407
395
408
defer util .Pad ()()
396
409
397
- // TODO: fetch from plan
398
- amount := 2000
410
+ // plan
411
+ util .LogTitle ("Subscription" )
412
+ util .Log ("Choose a monthly billing period, or 10%% off annually." )
413
+ println ()
414
+
415
+ var interval string
416
+ err = survey .AskOne (& survey.Select {
417
+ Message : "Plan:" ,
418
+ Options : keys (amountOptions ),
419
+ }, & interval , survey .Required )
420
+
421
+ // amount
422
+ interval = amountOptions [interval ]
423
+ amount := amounts [interval ]
424
+
399
425
util .LogTitle ("Coupon" )
400
426
util .Log ("Enter a coupon, or press enter to skip this step" )
401
427
util .Log ("and move on to adding a credit card." )
@@ -424,7 +450,8 @@ func subscribe(cmd *kingpin.Cmd) {
424
450
util .LogClear ("Coupon is invalid" )
425
451
} else {
426
452
amount = coupon .Discount (amount )
427
- util .LogClear ("Savings: %s" , coupon .Description ())
453
+ msg := colors .Gray (fmt .Sprintf ("%s — now %s %s" , coupon .Description (), currency (amount ), interval ))
454
+ util .LogClear ("Savings: %s" , msg )
428
455
}
429
456
}
430
457
@@ -455,9 +482,8 @@ func subscribe(cmd *kingpin.Cmd) {
455
482
456
483
// confirm
457
484
var ok bool
458
- total := fmt .Sprintf ("%0.2f" , float64 (amount )/ 100 )
459
485
err = survey .AskOne (& survey.Confirm {
460
- Message : fmt .Sprintf ("Subscribe to Up Pro for $%s/mo USD?" , total ),
486
+ Message : fmt .Sprintf ("Subscribe to Up Pro for %s USD %s ?" , currency ( amount ), interval ),
461
487
}, & ok , nil )
462
488
463
489
if err != nil {
@@ -471,10 +497,11 @@ func subscribe(cmd *kingpin.Cmd) {
471
497
}
472
498
473
499
stats .Track ("Subscribe" , map [string ]interface {}{
474
- "coupon" : couponID ,
500
+ "coupon" : couponID ,
501
+ "interval" : interval ,
475
502
})
476
503
477
- if err := a .AddPlan (t .Token , "up" , "pro" , couponID ); err != nil {
504
+ if err := a .AddPlan (t .Token , "up" , interval , couponID ); err != nil {
478
505
return errors .Wrap (err , "subscribing" )
479
506
}
480
507
@@ -527,7 +554,7 @@ func unsubscribe(cmd *kingpin.Cmd) {
527
554
528
555
stats .Track ("Unsubscribe" , nil )
529
556
530
- if err := a .RemovePlan (config .Token , "up" , "pro" ); err != nil {
557
+ if err := a .RemovePlan (config .Token , "up" ); err != nil {
531
558
return errors .Wrap (err , "unsubscribing" )
532
559
}
533
560
@@ -701,3 +728,21 @@ func feedback() (string, error) {
701
728
}
702
729
return s , nil
703
730
}
731
+
732
+ // currency returns formatted currency.
733
+ func currency (n int ) string {
734
+ return fmt .Sprintf ("$%0.2f" , float64 (n )/ 100 )
735
+ }
736
+
737
+ // keys returns the keys of a string map.
738
+ func keys (m map [string ]string ) (v []string ) {
739
+ for k := range m {
740
+ v = append (v , k )
741
+ }
742
+
743
+ sort .Slice (v , func (i int , j int ) bool {
744
+ return v [i ] > v [j ]
745
+ })
746
+
747
+ return
748
+ }
0 commit comments