Files
zooqueenandHanzo Dev 6c4f4d660b A sandbox read takes Square's sandbox names only
thirdparty/square.FromEnv is the one reader of the deployment's Square
account: SQUARE_SANDBOX_* for sandbox, SQUARE_* for production, never
mixed. The five readers (the org processor, the public tenant config,
the unified provider's env seed, the standalone init and payment links)
call it, so an empty sandbox set is an unconfigured processor and a
sandbox token is never paired with a production location.

The resolver tests now set the sandbox names they expect and keep the
production ones as hostile values a sandbox org must not show.

Co-authored-by: Hanzo Dev <[email protected]>
2026-10-16 07:27:17 -07:00

47 lines
1.5 KiB
Go

package square
import (
"os"
"strings"
)
// Credentials is the deployment's own Square account of one kind, as its
// environment names it.
type Credentials struct {
AccessToken string
LocationID string
ApplicationID string
}
// FromEnv reads the deployment's Square credentials of one kind: the
// SQUARE_SANDBOX_* names for sandbox, the SQUARE_* names for production.
//
// The two sets never mix. A sandbox read consults no production name, so a
// sandbox set left empty is an unconfigured processor, never the production
// account: a sandbox request that fell back to SQUARE_ACCESS_TOKEN would send
// a real merchant's token to Square's sandbox host, or, with the sandbox token
// and the production location, pair two accounts' halves.
func FromEnv(sandbox bool) Credentials {
if sandbox {
return Credentials{
AccessToken: envValue("SQUARE_SANDBOX_ACCESS_TOKEN"),
LocationID: envValue("SQUARE_SANDBOX_LOCATION_ID"),
ApplicationID: envValue("SQUARE_SANDBOX_APPLICATION_ID"),
}
}
return Credentials{
AccessToken: envValue("SQUARE_ACCESS_TOKEN"),
LocationID: envValue("SQUARE_LOCATION_ID"),
ApplicationID: envValue("SQUARE_APPLICATION_ID"),
}
}
// SandboxEnv reports whether the deployment's SQUARE_ENVIRONMENT names
// Square's sandbox ("sandbox" or "test", any case).
func SandboxEnv() bool {
env := strings.ToLower(envValue("SQUARE_ENVIRONMENT"))
return env == "sandbox" || env == "test"
}
func envValue(name string) string { return strings.TrimSpace(os.Getenv(name)) }