| | |
| | | if (!settlementService.handleBankCardCallback(data)) throw new BusinessException(ErrorCode.NOT_FOUND, "Unknown Huifu merchant business callback"); |
| | | return ResponseEntity.ok("RECV_ORD_ID_" + no); |
| | | } |
| | | |
| | | @PostMapping(value = "/merchant-onboarding-notify", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.TEXT_PLAIN_VALUE) |
| | | public ResponseEntity<String> merchantOnboardingNotify(@RequestParam Map<String, String> form) { |
| | | String payload = form.get("resp_data"), signature = form.get("sign"); |
| | | if (!signatureService.verifyCallbackPayload(payload, signature)) throw new BusinessException(ErrorCode.FORBIDDEN, "Invalid Huifu merchant onboarding callback signature"); |
| | | @SuppressWarnings("unchecked") Map<String, Object> data = JSON.parseObject(payload, Map.class); |
| | | String no = data.get("req_seq_id") == null ? "" : String.valueOf(data.get("req_seq_id")).trim(); |
| | | if (!settlementService.handleOnboardingCallback(data)) throw new BusinessException(ErrorCode.NOT_FOUND, "Unknown Huifu merchant onboarding callback"); |
| | | return ResponseEntity.ok("RECV_ORD_ID_" + no); |
| | | } |
| | | |
| | | @PostMapping(value = "/merchant-wechat-config-notify", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.TEXT_PLAIN_VALUE) |
| | | public ResponseEntity<String> merchantWechatConfigNotify(@RequestParam Map<String, String> form) { |
| | | Map<String, Object> data = verifiedData(form, "WeChat merchant configuration"); |
| | | if (!settlementService.handleWechatConfigCallback(data)) throw new BusinessException(ErrorCode.NOT_FOUND, "Unknown Huifu WeChat merchant configuration callback"); |
| | | return ResponseEntity.ok("RECV_ORD_ID_" + acknowledgementId(data)); |
| | | } |
| | | |
| | | @PostMapping(value = "/merchant-business-open-notify", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.TEXT_PLAIN_VALUE) |
| | | public ResponseEntity<String> merchantBusinessOpenNotify(@RequestParam Map<String, String> form) { |
| | | Map<String, Object> data = verifiedData(form, "merchant business opening"); |
| | | if (!settlementService.handleBusinessOpenCallback(data)) throw new BusinessException(ErrorCode.NOT_FOUND, "Unknown Huifu merchant business opening callback"); |
| | | return ResponseEntity.ok("RECV_ORD_ID_" + acknowledgementId(data)); |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | private Map<String, Object> verifiedData(Map<String, String> form, String operation) { |
| | | String payload = form.get("resp_data"), signature = form.get("sign"); |
| | | if (!signatureService.verifyCallbackPayload(payload, signature)) throw new BusinessException(ErrorCode.FORBIDDEN, "Invalid Huifu " + operation + " callback signature"); |
| | | Map<String, Object> callback = JSON.parseObject(payload, Map.class); |
| | | Object nested = callback.get("data"); |
| | | if (nested instanceof Map<?, ?> value) return (Map<String, Object>) value; |
| | | if (nested instanceof String value && !value.isBlank()) return JSON.parseObject(value, Map.class); |
| | | return callback; |
| | | } |
| | | |
| | | private String acknowledgementId(Map<String, Object> data) { |
| | | Object value = data.get("ord_id"); |
| | | if (value == null || String.valueOf(value).isBlank()) value = data.get("req_seq_id"); |
| | | return value == null ? "" : String.valueOf(value).trim(); |
| | | } |
| | | } |