Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
stripe: fix test mode links (#262)
Browse files Browse the repository at this point in the history
Previously Link handled the case of a blank account incorrectly,
assuming it was "live" when the key was test.

Closes: #244
  • Loading branch information
bmizerany committed Feb 23, 2023
1 parent b80919a commit 1559fe1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions cmd/tier/tier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func TestPushLinks(t *testing.T) {
}
}`)
tt.Run("push", "-")
tt.GrepStdout("https://dashboard.stripe.com/acct_state/prices/price_123", "expected URL")
tt.GrepStdout("https://dashboard.stripe.com/acct_state/test/prices/price_123", "expected URL")

// get out of isolation
if err := os.Remove("tier.state"); err != nil {
Expand All @@ -323,7 +323,7 @@ func TestPushLinks(t *testing.T) {
}
}`)
tt.Run("push", "-")
tt.GrepStdout("https://dashboard.stripe.com/acct_profile/prices/price_123", "expected URL")
tt.GrepStdout("https://dashboard.stripe.com/acct_profile/test/prices/price_123", "expected URL")

// assume default dashboard URL is okay if STRIPE_API_KEY is set
tt.SetStdinString(`{
Expand Down
16 changes: 10 additions & 6 deletions stripe/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ func MakeID(parts ...string) string {
// If live is true, a link to the live dashboard is returned, otherwise a test
// link is returned.
func Link(live bool, accountID string, parts ...string) (string, error) {
var base string
if !live && accountID == "" {
base = "https://dashboard.stripe.com/test"
} else {
base = "https://dashboard.stripe.com"
base, err := url.JoinPath("https://dashboard.stripe.com", accountID)
if err != nil {
return "", err
}
if !live {
base, err = url.JoinPath(base, "test")
if err != nil {
return "", err
}
}
return url.JoinPath(base, append([]string{accountID}, parts...)...)
return url.JoinPath(base, parts...)
}

type Error struct {
Expand Down
2 changes: 1 addition & 1 deletion stripe/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestLink(t *testing.T) {
}{
{true, "acct_123", "foo", "https://dashboard.stripe.com/acct_123/foo"},
{true, "", "foo", "https://dashboard.stripe.com/foo"},
{false, "acct_123", "foo", "https://dashboard.stripe.com/acct_123/foo"},
{false, "acct_123", "foo", "https://dashboard.stripe.com/acct_123/test/foo"},
{false, "", "foo", "https://dashboard.stripe.com/test/foo"},
}
for _, tc := range cases {
Expand Down

0 comments on commit 1559fe1

Please sign in to comment.