package tonglianpayapi

import (
	"testing"

	"git.rosy.net.cn/baseapi"
	"git.rosy.net.cn/baseapi/utils"
	"go.uber.org/zap"
)

var (
	api         *API
	sugarLogger *zap.SugaredLogger
)

func init() {
	logger, _ := zap.NewDevelopment()
	sugarLogger = logger.Sugar()
	baseapi.Init(sugarLogger)

	api = New("00183083", "18048531223", "56065105499TVAH")
}

func TestCreateUnitorderOrder(t *testing.T) {
	result, err := api.CreateUnitorderOrder(&CreateUnitorderOrderParam{
		CusID:     "",
		AppID:     "",
		Trxamt:    903,
		Reqsn:     "88511379245872",
		NotifyUrl: "http://callback.jxc4.com/tonglian/msg/",
		Acct:      "ojWb10K9G43un9OmdPhKuy6ho8LI",
		PayType:   "W06",
		SubAppID:  "wx4b5930c13f8b1170",
	})
	if err != nil {
		t.Fatal(err)
	}
	t.Log(utils.Format4Output(result, false))
}

func TestCreateH5UnitorderOrder(t *testing.T) {
	err := api.CreateH5UnitorderOrder(&CreateH5UnitorderOrderParam{
		Reqsn:     "88320943177180_4",
		Trxamt:    1,
		NotifyUrl: "https://print.jxc4.com/callback/msg",
		Returl:    "https://print.jxc4.com",
		Charset:   "UTF-8",
		Body:      "test",
	})
	if err != nil {
		t.Fatal(err)
	}
}

func TestPayRefund(t *testing.T) {
	api.PayRefund(&PayRefundParam{
		Trxamt: 1250,
		Reqsn:  utils.GetUUID(),
		// OldReqsn: orderPay.VendorOrderID,
		Remark:   "系统退款，商品数量错误",
		OldTrxID: "122094350000087981",
	})
}

//
//func TestMisPay(t *testing.T) {
//
//	custData := &CustDataDetail{
//		BusinessId:        BusinessTypeBUSIORDERTRANSQR,
//		Amount:            "1",
//		OrderNo:           "202504171111",
//		Memo:              "",
//		QrCode:            "",
//		TramsCheck:        "",
//		PageAppendContent: "",
//		ValidateInfo:      "",
//		BusInfo:           "",
//	}
//	param := &OnMisPayReq{
//		AppId:        api.appID,
//		BusinessId:   BusinessTypeBUSIORDERTRANSQR,
//		CustData:     "000000000002",
//		CashId:       "n502f01147",
//		StoreId:      "66666",
//		SignData:     "",
//		AppPackageNm: "",
//		AppClassNm:   "",
//		BusExtpara:   "",
//	}
//	custByte, _ := json.Marshal(custData)
//	param.CustData = string(custByte)
//
//	api.CreateMisPayOrder(param, custData)
//}
//
//func TestSignMd5(t *testing.T) {
//	custData := &CustDataDetail{
//		BusinessId:        "100000003",
//		Amount:            "000000000002",
//		OrderNo:           "123123213",
//		Memo:              "",
//		QrCode:            "",
//		TramsCheck:        "",
//		PageAppendContent: "",
//		ValidateInfo:      "",
//		BusInfo:           "",
//	}
//	licence := `9a432306-b93d-4d0d-aa7d-ac2bb89dee25-20200208002855`
//	sig := api.signMisParam("100000003", licence, custData)
//	fmt.Println(sig)
//}
