This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
package alipay
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestClientPreCreateTrade(t *testing.T) {
|
||||
t.Skipf("Skip TestClientPreCreateTrade")
|
||||
cfg := Config{
|
||||
InvoiceName: "XrayR",
|
||||
NotifyURL: "https://example.com/alipay/notify",
|
||||
Sandbox: true,
|
||||
}
|
||||
c := NewClient(cfg)
|
||||
order := Order{
|
||||
OrderNo: "20210701000001",
|
||||
Amount: 100,
|
||||
}
|
||||
qr, err := c.PreCreateTrade(context.Background(), order)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(qr)
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package epay
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestEpay(t *testing.T) {
|
||||
client := NewClient("", "http://127.0.0.1", "", "")
|
||||
order := Order{
|
||||
Name: "测试",
|
||||
OrderNo: "123456789",
|
||||
Amount: 1000,
|
||||
SignType: "md5",
|
||||
NotifyUrl: "http://127.0.0.1",
|
||||
ReturnUrl: "http://127.0.0.1",
|
||||
}
|
||||
url := client.CreatePayUrl(order)
|
||||
t.Logf("PayUrl: %s\n", url)
|
||||
|
||||
}
|
||||
|
||||
func TestQueryOrderStatus(t *testing.T) {
|
||||
t.Skipf("Skip TestQueryOrderStatus test")
|
||||
client := NewClient("Pid", "Url", "Key", "Type")
|
||||
orderNo := "123456789"
|
||||
status := client.QueryOrderStatus(orderNo)
|
||||
t.Logf("OrderNo: %s, Status: %v\n", orderNo, status)
|
||||
}
|
||||
|
||||
func TestVerifySign(t *testing.T) {
|
||||
t.Skipf("Skip TestVerifySign test")
|
||||
params := map[string]string{
|
||||
"pid": "1654",
|
||||
"trade_no": "2024121521150860990",
|
||||
"out_trade_no": "202412152115078262977262254",
|
||||
"type": "alipay",
|
||||
"name": "product",
|
||||
"money": "10",
|
||||
"trade_status": "TRADE_SUCCESS",
|
||||
"sign": "d3181f18ebdf9821f0ab6ee93faa82d1",
|
||||
"sign_type": "MD5",
|
||||
}
|
||||
|
||||
key := "LbTabbB580zWyhXhyyww7wwvy5u8k0wl"
|
||||
c := NewClient("Pid", "Url", key, "Type")
|
||||
if c.VerifySign(params) {
|
||||
t.Logf("Sign verification success!")
|
||||
} else {
|
||||
t.Error("Sign verification failed!")
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package payment
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func TestHttp(t *testing.T) {
|
||||
t.Skipf("Skip TestHttp test")
|
||||
router := gin.Default()
|
||||
router.LoadHTMLGlob("./*")
|
||||
router.GET("/stripe", func(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "stripe.html", gin.H{
|
||||
"title": "Gin HTML Example",
|
||||
"message": "Hello, Gin!",
|
||||
})
|
||||
})
|
||||
_ = router.Run(":8989")
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package payment
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestParsePlatform(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
input string
|
||||
expected Platform
|
||||
}{
|
||||
{name: "exact AppleIAP", input: "AppleIAP", expected: AppleIAP},
|
||||
{name: "snake apple_iap", input: "apple_iap", expected: AppleIAP},
|
||||
{name: "kebab apple-iap", input: "apple-iap", expected: AppleIAP},
|
||||
{name: "compact appleiap", input: "appleiap", expected: AppleIAP},
|
||||
{name: "trimmed value", input: " apple_iap ", expected: AppleIAP},
|
||||
{name: "legacy exact CryptoSaaS", input: "CryptoSaaS", expected: CryptoSaaS},
|
||||
{name: "snake crypto_saas", input: "crypto_saas", expected: CryptoSaaS},
|
||||
{name: "unsupported", input: "unknown_gateway", expected: UNSUPPORTED},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
got := ParsePlatform(testCase.input)
|
||||
if got != testCase.expected {
|
||||
t.Fatalf("ParsePlatform(%q) = %v, expected %v", testCase.input, got, testCase.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlatformStringIsCanonical(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
input Platform
|
||||
expected string
|
||||
}{
|
||||
{name: "stripe", input: Stripe, expected: "Stripe"},
|
||||
{name: "alipay", input: AlipayF2F, expected: "AlipayF2F"},
|
||||
{name: "epay", input: EPay, expected: "EPay"},
|
||||
{name: "balance", input: Balance, expected: "balance"},
|
||||
{name: "crypto", input: CryptoSaaS, expected: "CryptoSaaS"},
|
||||
{name: "apple", input: AppleIAP, expected: "AppleIAP"},
|
||||
{name: "unsupported", input: UNSUPPORTED, expected: "unsupported"},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
got := testCase.input.String()
|
||||
if got != testCase.expected {
|
||||
t.Fatalf("Platform.String() = %q, expected %q", got, testCase.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanonicalPlatformName(t *testing.T) {
|
||||
canonical, ok := CanonicalPlatformName("apple_iap")
|
||||
if !ok {
|
||||
t.Fatalf("expected apple_iap to be supported")
|
||||
}
|
||||
if canonical != "AppleIAP" {
|
||||
t.Fatalf("canonical name mismatch: got %q", canonical)
|
||||
}
|
||||
|
||||
_, ok = CanonicalPlatformName("not_exists")
|
||||
if ok {
|
||||
t.Fatalf("expected unsupported platform to return ok=false")
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package stripe
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stripe/stripe-go/v81"
|
||||
)
|
||||
|
||||
func TestStripeAlipay(t *testing.T) {
|
||||
t.Skipf("Skip TestStripeAlipay test")
|
||||
client := NewClient(Config{
|
||||
WebhookSecret: "",
|
||||
})
|
||||
order := Order{
|
||||
OrderNo: "JS20210719123456789",
|
||||
Subscribe: "测试",
|
||||
Amount: 100,
|
||||
Currency: string(stripe.CurrencyGBP),
|
||||
Payment: "alipay",
|
||||
}
|
||||
user := User{
|
||||
UserId: 1,
|
||||
Email: "tension@ppanel.dev",
|
||||
}
|
||||
result, err := client.CreatePaymentSheet(&order, &user)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
t.Logf("TradeNo: %s\n", result.ClientSecret)
|
||||
}
|
||||
|
||||
func TestStripeWechat(t *testing.T) {
|
||||
t.Skipf("Skip TestStripeWechat test")
|
||||
client := NewClient(Config{
|
||||
SecretKey: "SecretKey",
|
||||
PublicKey: "PublicKey",
|
||||
WebhookSecret: "",
|
||||
})
|
||||
order := Order{
|
||||
OrderNo: "JS20210719123456789",
|
||||
Subscribe: "测试",
|
||||
Amount: 100,
|
||||
Currency: string(stripe.CurrencyGBP),
|
||||
Payment: "wechat_pay",
|
||||
}
|
||||
user := User{
|
||||
UserId: 1,
|
||||
Email: "tension@ppanel.dev",
|
||||
}
|
||||
result, err := client.CreatePaymentSheet(&order, &user)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
t.Logf("TradeNo: %s\n", result.ClientSecret)
|
||||
}
|
||||
Reference in New Issue
Block a user