按档位分别拼 Waffo currency,避免永久商品用 CNY 报不可用。 Co-authored-by: Cursor <cursoragent@cursor.com>
70 lines
1.8 KiB
Go
70 lines
1.8 KiB
Go
package payment
|
|
|
|
import (
|
|
"net/url"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestBuildCheckoutURL_YearlyOnetimeCNY(t *testing.T) {
|
|
cfg := WaffoConfig{
|
|
StoreSlug: "opsxshell-pwsi6m4n",
|
|
ProductIDYearly: "PROD_1BIezCi932IbgCzRIV8hcJ",
|
|
ProductIDPerpetual: "PROD_0pcnzzT4nalEkkcdyIUoD5",
|
|
Currency: "CNY",
|
|
CurrencyYearly: "CNY",
|
|
CurrencyPerpetual: "USD",
|
|
Environment: "test",
|
|
SuccessURL: "opsxshell://pro/activated",
|
|
}
|
|
raw, err := BuildCheckoutURL(cfg, "ORD1", "dev-1", "a@b.c", "", "yearly")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
u, err := url.Parse(raw)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(u.Path, "PROD_1BIezCi932IbgCzRIV8hcJ") {
|
|
t.Fatalf("yearly product missing: %s", raw)
|
|
}
|
|
q := u.Query()
|
|
if q.Get("type") != "onetime" {
|
|
t.Fatalf("type=%s want onetime", q.Get("type"))
|
|
}
|
|
if q.Get("currency") != "CNY" {
|
|
t.Fatalf("currency=%s want CNY", q.Get("currency"))
|
|
}
|
|
}
|
|
|
|
func TestBuildCheckoutURL_PerpetualOnetimeUSD(t *testing.T) {
|
|
cfg := WaffoConfig{
|
|
StoreSlug: "opsxshell-pwsi6m4n",
|
|
ProductIDYearly: "PROD_1BIezCi932IbgCzRIV8hcJ",
|
|
ProductIDPerpetual: "PROD_0pcnzzT4nalEkkcdyIUoD5",
|
|
Currency: "CNY",
|
|
CurrencyYearly: "CNY",
|
|
CurrencyPerpetual: "USD",
|
|
Environment: "test",
|
|
SuccessURL: "opsxshell://pro/activated",
|
|
}
|
|
raw, err := BuildCheckoutURL(cfg, "ORD2", "dev-1", "a@b.c", "", "perpetual")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
u, err := url.Parse(raw)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(u.Path, "PROD_0pcnzzT4nalEkkcdyIUoD5") {
|
|
t.Fatalf("perpetual product missing: %s", raw)
|
|
}
|
|
q := u.Query()
|
|
if q.Get("type") != "onetime" {
|
|
t.Fatalf("type=%s want onetime", q.Get("type"))
|
|
}
|
|
if q.Get("currency") != "USD" {
|
|
t.Fatalf("currency=%s want USD", q.Get("currency"))
|
|
}
|
|
}
|