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{
		Reqsn:     "88320943177180",
		Trxamt:    10,
		NotifyUrl: "http://callback.test.jxc4.com/tlpay/msg/",
		Acct:      "ojWb10M_8kV8NT0aZJa6A5umG1c8",
		PayType:   PayTypeZfbJS,
	})
	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",
	})
}
