优化结构
This commit is contained in:
@@ -133,6 +133,35 @@ func (a *vendorPaymentAdapter) call(ctx context.Context, endpointKey string, pay
|
||||
}
|
||||
result := &bizpayment.PaymentResult{Provider: a.provider, Status: "created", TradeNo: tradeNo, Payload: ensureJSON(body)}
|
||||
if endpointKey != "query_url" {
|
||||
if object := jsonObject(body); object != nil {
|
||||
operation := strings.TrimSuffix(endpointKey, "_url")
|
||||
statusField := text(c, operation+"_status_field")
|
||||
if statusField == "" {
|
||||
statusField = text(c, "query_status_field")
|
||||
}
|
||||
state := ""
|
||||
if statusField != "" {
|
||||
state = stringAtPath(object, statusField)
|
||||
}
|
||||
if state == "" {
|
||||
for _, key := range []string{"status", "trade_status", "order_status", "pay_status", "refund_status"} {
|
||||
if value := stringAtPath(object, key); value != "" {
|
||||
state = value
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if state != "" {
|
||||
switch {
|
||||
case containsFold(configuredValues(c, operation+"_failure_values"), state):
|
||||
result.Status = "failed"
|
||||
case containsFold(configuredValues(c, operation+"_success_values"), state):
|
||||
result.Status = "created"
|
||||
default:
|
||||
result.Status = normalizePaymentStatus(state, "created")
|
||||
}
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
object := jsonObject(body)
|
||||
|
||||
Reference in New Issue
Block a user