修复拉卡拉退款成功状态识别
This commit is contained in:
@@ -612,17 +612,21 @@ func normalizePaymentStatus(raw map[string]string) string {
|
||||
|
||||
func normalizeRefundStatus(raw map[string]string) string {
|
||||
value := strings.ToUpper(firstNonEmpty(raw["refund_status"], raw["trade_state"], raw["trade_status"], raw["status"]))
|
||||
if value == "" && responseOK(raw) {
|
||||
return "refunded"
|
||||
}
|
||||
switch value {
|
||||
case "SUCCESS", "REFUND_SUCCESS", "TRADE_SUCCESS", "REFUNDED", "S", "11":
|
||||
return "refunded"
|
||||
case "FAIL", "FAILED", "REFUND_FAIL", "TRADE_FAIL", "F", "12":
|
||||
return "failed"
|
||||
default:
|
||||
return "refunding"
|
||||
}
|
||||
if hasSuccessResponseCode(raw) {
|
||||
return "refunded"
|
||||
}
|
||||
return "refunding"
|
||||
}
|
||||
|
||||
func hasSuccessResponseCode(raw map[string]string) bool {
|
||||
code := firstNonEmpty(raw["code"], raw["resp_code"], raw["result_code"], raw["return_code"])
|
||||
return code != "" && responseOK(raw)
|
||||
}
|
||||
|
||||
func responseOK(raw map[string]string) bool {
|
||||
|
||||
@@ -87,6 +87,28 @@ func TestNormalizeRefundStatusTreatsSuccessCodeAsRefunded(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeRefundStatusTreatsSuccessCodeWithRefundingAsRefunded(t *testing.T) {
|
||||
status := normalizeRefundStatus(map[string]string{
|
||||
"code": "BBS00000",
|
||||
"msg": "成功",
|
||||
"status": "refunding",
|
||||
"refund_amount": "960",
|
||||
"trade_no": "20260610110110001231120132051564",
|
||||
})
|
||||
if status != "refunded" {
|
||||
t.Fatalf("normalizeRefundStatus() = %q, want refunded", status)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeRefundStatusKeepsUnknownWithoutCodeAsRefunding(t *testing.T) {
|
||||
status := normalizeRefundStatus(map[string]string{
|
||||
"status": "processing",
|
||||
})
|
||||
if status != "refunding" {
|
||||
t.Fatalf("normalizeRefundStatus() = %q, want refunding", status)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreatePaymentOmitsCounterParamWhenPayModeBlank(t *testing.T) {
|
||||
body := captureCreatePaymentBody(t, "")
|
||||
reqData := body["req_data"].(map[string]any)
|
||||
|
||||
Reference in New Issue
Block a user