优化结构
This commit is contained in:
@@ -13,7 +13,7 @@ func NormalizeStatus(value, fallback string) string {
|
||||
return "success"
|
||||
case "WAIT_BUYER_PAY", "USERPAYING", "NOTPAY", "PROCESSING", "PENDING", "CREATED", "CLIENT_PENDING", "ACCEPT", "ACCEPTED", "PAYING":
|
||||
return "pending"
|
||||
case "CLOSED", "TRADE_CLOSED", "CANCELLED", "CANCELED", "REVOKED", "REFUND", "FAILED", "FAIL", "REJECTED", "DENIED", "DECLINED", "ERROR", "PAYERROR":
|
||||
case "CLOSED", "TRADE_CLOSED", "CANCELLED", "CANCELED", "REVOKED", "FAILED", "FAIL", "REJECTED", "DENIED", "DECLINED", "ERROR", "PAYERROR":
|
||||
return "failed"
|
||||
default:
|
||||
return fallback
|
||||
@@ -22,7 +22,7 @@ func NormalizeStatus(value, fallback string) string {
|
||||
|
||||
func NormalizeRefundStatus(value, fallback string) string {
|
||||
switch strings.ToUpper(strings.TrimSpace(value)) {
|
||||
case "SUCCESS", "OK", "PAID", "REFUND_SUCCESS", "REFUNDED", "COMPLETED", "FINISHED":
|
||||
case "SUCCESS", "OK", "PAID", "REFUND_SUCCESS", "REFUNDED", "COMPLETED", "FINISHED", "TRADE_SUCCESS":
|
||||
return "success"
|
||||
case "WAIT_BUYER_PAY", "USERPAYING", "NOTPAY", "PROCESSING", "PENDING", "CREATED", "ACCEPT", "ACCEPTED", "PAYING":
|
||||
return "pending"
|
||||
|
||||
@@ -24,3 +24,15 @@ func TestNormalizeStatusSeparatesRefundStates(t *testing.T) {
|
||||
t.Fatalf("refund status = %q, want success", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeStatusDoesNotTreatRefundAsPaymentFailure(t *testing.T) {
|
||||
if got := NormalizeStatus("REFUND", "unknown"); got != "unknown" {
|
||||
t.Fatalf("NormalizeStatus(REFUND) = %q, want fallback", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeRefundStatusAcceptsTradeSuccess(t *testing.T) {
|
||||
if got := NormalizeRefundStatus("TRADE_SUCCESS", "unknown"); got != "success" {
|
||||
t.Fatalf("NormalizeRefundStatus(TRADE_SUCCESS) = %q, want success", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user