service/library/payclients/yeepaycli/client_test.go

74 lines
3.8 KiB
Go
Raw Normal View History

2024-05-23 11:06:46 +08:00
package yeepaycli
import (
"context"
2024-05-27 19:37:52 +08:00
"encoding/json"
2024-05-27 16:50:58 +08:00
"fmt"
"service/app/mix/conf"
2024-05-23 11:06:46 +08:00
"service/bizcommon/util"
"service/library/configcenter"
"service/library/idgenerator"
"testing"
)
2024-05-27 16:50:58 +08:00
func TestMain(m *testing.M) {
cfg := new(conf.ConfigSt)
err := configcenter.LoadConfig("/Users/erwin/wishpalv2/service/etc/mix/mix-local.yaml", cfg)
if err != nil {
fmt.Printf("%v\n", err)
}
Init(cfg.Yeepay)
m.Run()
}
2024-05-23 11:06:46 +08:00
func TestInit(t *testing.T) {
cfg := &configcenter.YeepayClientConfig{
Appid: "app_10090316660",
ParentMerchantNo: "10090316660",
MerchantNo: "10090326142",
2024-05-27 09:55:23 +08:00
NotifyUrl: "https://testapi.tiefen.fun/ext",
PrivateKey: "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC8Zfd0RVnpmPuodc0N8XLLI8DWT4hTAyOlwbE5LLiiguG5W0AghvddreO73T51BGK4V05Taxdpv7j7KNl39OUzKA0tpmoLwC4f6II1Op4tY05NnUgOFbno01vE7cN5BWLwVA35dfgQm1jtzXECdTufavYH/qPCzpvd7OTbmdHonMVjanjz+XOfnFowxq8ap3F63ocF4LR3KalsC/cTvW7LYnendjjiFGbMm7DlLEUtHRZ0EzrmM6SVxXRcibKZd7Dy6QpNXLu615cJLui6eS/zmxG2pUoNI31ajh+ZybZ61/Lwsq3JylmXHoSu1WkydfHnIEbr1PasaoD//7BzySQzAgMBAAECggEAFZoRehT7nsPKU0ISnX8qXO2ADnK3HGGXREnFwtsEXqnoLOMwIqqnEWg/XQqcvzkeAqoMEpeMazUvBilkahM79pYokKvsq+VAxKrZxzWt7mFdGJwop2jJVM9rTdS/XZCHDCxvH8PtiiXt1/J++zuq9vgCNt91MoCTMaqYgS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+08:00
}
Init(cfg)
c := GetDefaultYeepayClient()
param := &AggPayParam{
Description: "cc",
OutTradeNo: idgenerator.GenOrderId(),
TotalAmount: 100,
RedirectUrl: "",
PayWay: "H5_PAY",
2024-05-27 09:55:23 +08:00
//PayChannel: "WECHAT",
PayChannel: "ALIPAY",
Ip: "127.0.0.1",
2024-05-23 11:06:46 +08:00
}
resp, err := c.AggPay(context.Background(), param)
t.Log(util.ToJson(param))
t.Log(err)
t.Log(util.ToJson(resp))
}
2024-05-27 19:37:52 +08:00
func TestYeepayClient_ParseNotify(t *testing.T) {
s := "{\"channelOrderId\":\"362024052722001417931448328101\",\"orderId\":\"1795054273042591744\",\"bankOrderId\":\"705784025745240527\",\"paySuccessDate\":\"2024-05-27 19:27:51\",\"channel\":\"ALIPAY\",\"payWay\":\"USER_SCAN\",\"uniqueOrderNo\":\"1013202405270000011947326367\",\"merchantName\":\"揽星网络\",\"orderAmount\":\"1.00\",\"payAmount\":\"1.00\",\"payerInfo\":\"{\\\"bankCardNo\\\":\\\"\\\",\\\"bankId\\\":\\\"ALIPAY\\\",\\\"buyerLogonId\\\":\\\"132****6120\\\",\\\"cardType\\\":\\\"DEBIT\\\",\\\"mobilePhoneNo\\\":\\\"\\\",\\\"userID\\\":\\\"2088422859817936\\\"}\",\"realPayAmount\":\"1.00\",\"parentMerchantNo\":\"10090316660\",\"tradeType\":\"REALTIME\",\"merchantNo\":\"10090326142\",\"status\":\"SUCCESS\"}"
var paymentInfo YeepayNotify
err := json.Unmarshal([]byte(s), &paymentInfo)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Payment Info:", paymentInfo)
}
2024-05-30 09:48:09 +08:00
func TestYeepayClient_QueryRefund(t *testing.T) {
cli := GetDefaultYeepayClient()
resp, err := cli.QueryRefund(nil, &QueryRefundParam{
OutTradeNo: "1795300011844579328",
RefundRequestId: "1795652043868880896",
})
t.Log(err)
t.Log(util.ToJson(resp))
}