80 lines
2.2 KiB
Go
80 lines
2.2 KiB
Go
package payment
|
|
|
|
import (
|
|
"net/url"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestResolveBaseCheckoutURL_YearlyOnetimeUSD(t *testing.T) {
|
|
cfg := WaffoConfig{
|
|
StoreSlug: "opsxshell-pwsi6m4n",
|
|
ProductIDYearly: "PROD_1BIezCi932IbgCzRIV8hcJ",
|
|
ProductIDPerpetual: "PROD_0pcnzzT4nalEkkcdyIUoD5",
|
|
Currency: "CNY",
|
|
CurrencyYearly: "CNY", // 即使配置写 CNY,已知测试商品仍强制 USD // Logan.Li
|
|
CurrencyPerpetual: "USD",
|
|
Environment: "test",
|
|
SuccessURL: "opsxshell://pro/activated",
|
|
}
|
|
u, err := resolveBaseCheckoutURL(cfg, "yearly")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(u.Path, "PROD_1BIezCi932IbgCzRIV8hcJ") {
|
|
t.Fatalf("yearly product missing: %s", u.String())
|
|
}
|
|
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"))
|
|
}
|
|
}
|
|
|
|
func TestResolveBaseCheckoutURL_PerpetualOnetimeUSD(t *testing.T) {
|
|
cfg := WaffoConfig{
|
|
StoreSlug: "opsxshell-pwsi6m4n",
|
|
ProductIDYearly: "PROD_1BIezCi932IbgCzRIV8hcJ",
|
|
ProductIDPerpetual: "PROD_0pcnzzT4nalEkkcdyIUoD5",
|
|
Currency: "CNY",
|
|
CurrencyYearly: "CNY",
|
|
CurrencyPerpetual: "CNY",
|
|
Environment: "test",
|
|
SuccessURL: "opsxshell://pro/activated",
|
|
}
|
|
u, err := resolveBaseCheckoutURL(cfg, "perpetual")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(u.Path, "PROD_0pcnzzT4nalEkkcdyIUoD5") {
|
|
t.Fatalf("perpetual product missing: %s", u.String())
|
|
}
|
|
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"))
|
|
}
|
|
}
|
|
|
|
func TestBuildCheckoutURL_HostedFallbackWithoutSlug(t *testing.T) {
|
|
cfg := WaffoConfig{
|
|
CheckoutURL: "https://pancake.waffo.ai/store/opsxshell-pwsi6m4n/product/PROD_1BIezCi932IbgCzRIV8hcJ?type=onetime¤cy=CNY&test=true",
|
|
SuccessURL: "http://l123.91ai.io/api/v1/purchase/success",
|
|
}
|
|
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 u.Query().Get("orderNo") != "ORD1" {
|
|
t.Fatalf("orderNo missing: %s", raw)
|
|
}
|
|
}
|