Skip to content

Commit

Permalink
fix:payment error
Browse files Browse the repository at this point in the history
Signed-off-by: 晓杰 <[email protected]>
  • Loading branch information
xiao-jay committed Dec 23, 2022
1 parent b6dbb45 commit 576b8b2
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pkg/pay/wechat_payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ const (
AppID = "AppID"
NotifyCallbackURL = "NotifyCallbackURL"

StatusSuccess = "SUCCESS"
StatusProcessing = "PROCESSING"
StatusNotPay = "NOTPAY"
StatusFail = "FAILED"
StatusSuccess = "SUCCESS"
StatusProcessing = "PROCESSING"
StatusNotPay = "NOTPAY"
StatusFail = "FAILED"
DefaultCallbackURL = "https://sealos.io/payment/wechat/callback"
)

func NewClient(ctx context.Context, opts ...core.ClientOption) (*core.Client, error) {
Expand All @@ -49,7 +50,7 @@ func NewClient(ctx context.Context, opts ...core.ClientOption) (*core.Client, er
mchAPIv3Key := os.Getenv(MchAPIv3Key) // 商户APIv3密钥
mchPrivateKey, err := utils.LoadPrivateKey(os.Getenv(WechatPrivateKey))
if err != nil {
log.Print("mchID: ", mchID, "\nmchCertificateSerialNumber: ", mchCertificateSerialNumber, "\nmchAPIv3Key: ", mchAPIv3Key, "\nprivate key is: ", os.Getenv(WechatPrivateKey))
log.Print("private key is: ", os.Getenv(WechatPrivateKey))
return nil, fmt.Errorf("load merchant private key error: %v", err)
}
opts = append(opts, option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key))
Expand Down Expand Up @@ -92,6 +93,11 @@ func WechatPay(amount int64, user, tradeNO, describe, callback string) (string,
if describe == "" {
describe = "sealos cloud recharge"
}

if callback == "" {
callback = DefaultCallbackURL
}

svc := native.NativeApiService{Client: client}
resp, _, err := svc.Prepay(ctx,
native.PrepayRequest{
Expand Down

0 comments on commit 576b8b2

Please sign in to comment.