feat: add refund
This commit is contained in:
@@ -78,10 +78,22 @@ type PrepayData struct {
|
||||
}
|
||||
|
||||
// PaySignOfJSAPI
|
||||
func (pay *PrepayData) PaySignOfJSAPI() (*wechat.JSAPIPayParams, error) {
|
||||
func (pay *PrepayData) PaySignOfJSAPI() (*, error) {
|
||||
return pay.client.payClient.PaySignOfJSAPI(pay.AppID, pay.PrepayID)
|
||||
}
|
||||
|
||||
func (c *Client) Refund(ctx context.Context, f func(*BodyMap)) (*wechat.RefundOrderResponse,error ){
|
||||
bm := NewBodyMap(c.config)
|
||||
f(bm)
|
||||
|
||||
resp, err := c.payClient.V3Refund(ctx, bm.bm)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.Response, nil
|
||||
}
|
||||
|
||||
func (c *Client) V3TransactionJsapi(ctx context.Context, f func(*BodyMap)) (*PrepayData, error) {
|
||||
bm := NewBodyMap(c.config)
|
||||
f(bm)
|
||||
@@ -149,11 +161,12 @@ func NewBodyMap(c *w.Config) *BodyMap {
|
||||
bm := make(gopay.BodyMap)
|
||||
bm.Set("appid", c.AppID).
|
||||
Set("mchid", c.Pay.MchID).
|
||||
Set("notify_url", c.Pay.NotifyURL).
|
||||
SetBodyMap("amount", func(bm gopay.BodyMap) {
|
||||
bm.Set("total", 1).
|
||||
Set("currency", "CNY")
|
||||
})
|
||||
Set("notify_url", c.Pay.NotifyURL)
|
||||
// .
|
||||
// SetBodyMap("amount", func(bm gopay.BodyMap) {
|
||||
// bm.Set("total", 1).
|
||||
// Set("currency", "CNY")
|
||||
// })
|
||||
return &BodyMap{
|
||||
bm: bm,
|
||||
}
|
||||
@@ -184,6 +197,44 @@ func (b *BodyMap) OutTradeNo(outTradeNo string) *BodyMap {
|
||||
return b.Set("out_trade_no", outTradeNo)
|
||||
}
|
||||
|
||||
// TransactionID
|
||||
func (b *BodyMap) TransactionID(transactionID string) *BodyMap {
|
||||
return b.Set("transaction_id", transactionID)
|
||||
}
|
||||
|
||||
// OutRefundNo
|
||||
func (b *BodyMap) OutRefundNo(outRefundNo string) *BodyMap {
|
||||
return b.Set("out_refund_no", outRefundNo)
|
||||
}
|
||||
|
||||
// RefundReason
|
||||
func (b *BodyMap) RefundReason(refundReason string) *BodyMap {
|
||||
return b.Set("reason", refundReason)
|
||||
}
|
||||
|
||||
// RefundAmount
|
||||
func (b *BodyMap) RefundAmount(total, refund int64, currency CURRENCY) *BodyMap {
|
||||
return b.SetBodyMap("amount", func(bm gopay.BodyMap) {
|
||||
bm.
|
||||
Set("total", total).
|
||||
Set("refund", refund).
|
||||
Set("currency", currency.String())
|
||||
})
|
||||
}
|
||||
|
||||
func (b *BodyMap) CNYRefundAmount(total, refund int64) *BodyMap {
|
||||
return b.RefundAmount(total, refund, CNY)
|
||||
}
|
||||
|
||||
// RefundGoodsInfo
|
||||
func (b *BodyMap) RefundGoodsInfo(name string) *BodyMap {
|
||||
return b.Set("goods_detail", []map[string]any{
|
||||
{
|
||||
"goods_name": name,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// Amount
|
||||
func (b *BodyMap) Amount(total int64, currency CURRENCY) *BodyMap {
|
||||
return b.SetBodyMap("amount", func(bm gopay.BodyMap) {
|
||||
|
||||
Reference in New Issue
Block a user