feat: add callback
This commit is contained in:
@@ -2,6 +2,7 @@ package wepay
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rsa"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"time"
|
||||
@@ -55,11 +56,23 @@ func (c *Client) GetClient() *wechat.ClientV3 {
|
||||
return c.payClient
|
||||
}
|
||||
|
||||
// WxPublicKeyMap
|
||||
func (c *Client) WxPublicKeyMap() map[string]*rsa.PublicKey {
|
||||
return c.payClient.WxPublicKeyMap()
|
||||
}
|
||||
|
||||
type PrepayData struct {
|
||||
client *Client
|
||||
|
||||
AppID string `json:"app_id"`
|
||||
PrepayID string `json:"prepay_id"`
|
||||
}
|
||||
|
||||
// PaySignOfJSAPI
|
||||
func (pay *PrepayData) PaySignOfJSAPI() (*wechat.JSAPIPayParams, error) {
|
||||
return pay.client.payClient.PaySignOfJSAPI(pay.AppID, pay.PrepayID)
|
||||
}
|
||||
|
||||
func (c *Client) V3TransactionJsapi(ctx context.Context, f func(*BodyMap)) (*PrepayData, error) {
|
||||
bm := NewBodyMap(c.config)
|
||||
f(bm)
|
||||
@@ -76,6 +89,8 @@ func (c *Client) V3TransactionJsapi(ctx context.Context, f func(*BodyMap)) (*Pre
|
||||
}
|
||||
|
||||
return &PrepayData{
|
||||
client: c,
|
||||
|
||||
AppID: c.config.AppID,
|
||||
PrepayID: resp.Response.PrepayId,
|
||||
}, nil
|
||||
|
||||
@@ -45,8 +45,11 @@ func (s *WePayTestSuite) Test_PrePay() {
|
||||
})
|
||||
So(err, ShouldBeNil)
|
||||
So(resp, ShouldNotBeNil)
|
||||
|
||||
s.T().Logf("prepay response: %+v", resp)
|
||||
|
||||
sign, err := resp.PaySignOfJSAPI()
|
||||
So(err, ShouldBeNil)
|
||||
s.T().Logf("Sign: %+v", sign)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user