From 373464db26c23f02f933d4928fc5fa56ff17d853 Mon Sep 17 00:00:00 2001 From: erio Date: Thu, 9 Apr 2026 01:24:15 +0800 Subject: [PATCH] fix(payment): add cid and fix double-slash in easypay redirect mode createRedirectPayment was missing the cid parameter (channel ID) that createAPIPayment already included via resolveCID(). This caused EasyPay to use a default channel instead of the configured one (e.g. 13256/13264). Also trim trailing slash from apiBase to prevent double-slash in URLs. --- backend/internal/payment/provider/easypay.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/backend/internal/payment/provider/easypay.go b/backend/internal/payment/provider/easypay.go index ec072fd935..8e060bce88 100644 --- a/backend/internal/payment/provider/easypay.go +++ b/backend/internal/payment/provider/easypay.go @@ -70,13 +70,15 @@ func (e *EasyPay) CreatePayment(ctx context.Context, req payment.CreatePaymentRe // TradeNo is empty; it arrives via the notify callback after payment. func (e *EasyPay) createRedirectPayment(req payment.CreatePaymentRequest) (*payment.CreatePaymentResponse, error) { notifyURL, returnURL := e.resolveURLs(req) - payType := req.PaymentType params := map[string]string{ - "pid": e.config["pid"], "type": payType, + "pid": e.config["pid"], "type": req.PaymentType, "out_trade_no": req.OrderID, "notify_url": notifyURL, "return_url": returnURL, "name": req.Subject, "money": req.Amount, } + if cid := e.resolveCID(req.PaymentType); cid != "" { + params["cid"] = cid + } params["sign"] = easyPaySign(params, e.config["pkey"]) params["sign_type"] = "MD5" @@ -84,7 +86,8 @@ func (e *EasyPay) createRedirectPayment(req payment.CreatePaymentRequest) (*paym for k, v := range params { q.Set(k, v) } - payURL := e.config["apiBase"] + "/submit.php?" + q.Encode() + base := strings.TrimRight(e.config["apiBase"], "/") + payURL := base + "/submit.php?" + q.Encode() return &payment.CreatePaymentResponse{PayURL: payURL}, nil } @@ -106,7 +109,7 @@ func (e *EasyPay) createAPIPayment(ctx context.Context, req payment.CreatePaymen params["sign"] = easyPaySign(params, e.config["pkey"]) params["sign_type"] = "MD5" - body, err := e.post(ctx, e.config["apiBase"]+"/mapi.php", params) + body, err := e.post(ctx, strings.TrimRight(e.config["apiBase"], "/")+"/mapi.php", params) if err != nil { return nil, fmt.Errorf("easypay create: %w", err) }