fix(upgrade): close payment and oidc compatibility gaps
This commit is contained in:
@@ -200,14 +200,7 @@ func (w *Wxpay) CreatePayment(ctx context.Context, req payment.CreatePaymentRequ
|
||||
case wxpayModeJSAPI:
|
||||
return w.prepayJSAPI(ctx, client, req, notifyURL, totalFen)
|
||||
case wxpayModeH5:
|
||||
resp, err := w.prepayH5(ctx, client, req, notifyURL, totalFen)
|
||||
if err == nil {
|
||||
return resp, nil
|
||||
}
|
||||
if wxpayShouldFallbackToNative(err) {
|
||||
return w.prepayNativeFallback(ctx, client, req, notifyURL, totalFen)
|
||||
}
|
||||
return nil, err
|
||||
return w.prepayH5(ctx, client, req, notifyURL, totalFen)
|
||||
case wxpayModeNative:
|
||||
return w.prepayNative(ctx, client, req, notifyURL, totalFen)
|
||||
default:
|
||||
@@ -292,23 +285,6 @@ func (w *Wxpay) prepayH5(ctx context.Context, c *core.Client, req payment.Create
|
||||
return &payment.CreatePaymentResponse{TradeNo: req.OrderID, PayURL: h5URL}, nil
|
||||
}
|
||||
|
||||
func (w *Wxpay) prepayNativeFallback(ctx context.Context, c *core.Client, req payment.CreatePaymentRequest, notifyURL string, totalFen int64) (*payment.CreatePaymentResponse, error) {
|
||||
resp, err := w.prepayNative(ctx, c, req, notifyURL, totalFen)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("wxpay native fallback after NO_AUTH: %w", err)
|
||||
}
|
||||
nativeURL := strings.TrimSpace(resp.PayURL)
|
||||
if nativeURL == "" {
|
||||
nativeURL = strings.TrimSpace(resp.QRCode)
|
||||
}
|
||||
if nativeURL == "" {
|
||||
return resp, nil
|
||||
}
|
||||
resp.PayURL = nativeURL
|
||||
resp.QRCode = nativeURL
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func buildWxpayH5Info(config map[string]string) *h5.H5Info {
|
||||
tp := wxpayH5Type
|
||||
info := &h5.H5Info{Type: &tp}
|
||||
@@ -321,10 +297,6 @@ func buildWxpayH5Info(config map[string]string) *h5.H5Info {
|
||||
return info
|
||||
}
|
||||
|
||||
func wxpayShouldFallbackToNative(err error) bool {
|
||||
return err != nil && strings.Contains(err.Error(), wxpayErrNoAuth)
|
||||
}
|
||||
|
||||
func resolveWxpayCreateMode(req payment.CreatePaymentRequest) (string, error) {
|
||||
if strings.TrimSpace(req.OpenID) != "" {
|
||||
return wxpayModeJSAPI, nil
|
||||
|
||||
Reference in New Issue
Block a user