| | |
| | | package com.tourguide.modules.order.payment; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.tourguide.common.huifu.biz.DouGongRefundBiz; |
| | | import com.tourguide.modules.order.entity.TourOrder; |
| | | import com.tourguide.modules.order.entity.TourOrderPaymentAttempt; |
| | |
| | | try { |
| | | Map<String, Object> response = refundBiz.refund(order.getRefundOrderNo(), amount, |
| | | paymentAttempt.getReqDate(), paymentAttempt.getReqSeqId()); |
| | | String responseCode = stringValue(response.get("resp_code")); |
| | | String responseCode = responseValue(response, "resp_code", "code"); |
| | | if (!SUCCESS_CODE.equals(responseCode)) { |
| | | String description = stringValue(response.get("resp_desc")); |
| | | String description = responseValue(response, "resp_desc", "msg"); |
| | | throw new IllegalStateException(StringUtils.hasText(description) |
| | | ? description : "Huifu refund request failed"); |
| | | } |
| | |
| | | private String stringValue(Object value) { |
| | | return value == null ? null : String.valueOf(value); |
| | | } |
| | | |
| | | private String responseValue(Map<String, Object> response, String... keys) { |
| | | if (response == null) return null; |
| | | for (String key : keys) { |
| | | String value = stringValue(response.get(key)); |
| | | if (StringUtils.hasText(value)) return value; |
| | | } |
| | | for (String nestedKey : new String[]{"data", "resp_data"}) { |
| | | Object nested = response.get(nestedKey); |
| | | if (nested instanceof Map) { |
| | | @SuppressWarnings("unchecked") |
| | | Map<String, Object> nestedMap = (Map<String, Object>) nested; |
| | | String value = responseValue(nestedMap, keys); |
| | | if (StringUtils.hasText(value)) return value; |
| | | } else if (nested instanceof String && StringUtils.hasText((String) nested)) { |
| | | try { |
| | | String value = responseValue(JSONObject.parseObject((String) nested), keys); |
| | | if (StringUtils.hasText(value)) return value; |
| | | } catch (RuntimeException ignored) { |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | } |