| | |
| | | |
| | | public Map<String, Object> createMiniProgramPayment(HuifuMiniProgramPaymentCommand command) { |
| | | ensureConfigured(); |
| | | ensureCollectingMerchant(command.huifuId()); |
| | | initializeSdk(); |
| | | V3TradePaymentJspayRequest request = new V3TradePaymentJspayRequest(); |
| | | request.setReqDate(REQUEST_DATE.format(LocalDateTime.now())); |
| | | request.setReqSeqId(command.paymentNo()); |
| | | request.setHuifuId(properties.getMerchantId().trim()); |
| | | request.setHuifuId(command.huifuId().trim()); |
| | | request.setGoodsDesc(command.goodsDescription()); |
| | | request.setTransAmt(BigDecimal.valueOf(command.amountInCent(), 2).toPlainString()); |
| | | request.setTradeType("T_MINIAPP"); |
| | |
| | | log.info("Huifu mini-program payment request: {}", logJson(Map.of( |
| | | "req_date", REQUEST_DATE.format(LocalDateTime.now()), |
| | | "req_seq_id", command.paymentNo(), |
| | | "huifu_id", properties.getMerchantId().trim(), |
| | | "huifu_id", command.huifuId().trim(), |
| | | "goods_desc", command.goodsDescription(), |
| | | "trans_amt", BigDecimal.valueOf(command.amountInCent(), 2).toPlainString(), |
| | | "trade_type", "T_MINIAPP", |
| | |
| | | |
| | | public Map<String, Object> queryMiniProgramPayment(HuifuPaymentQueryCommand command) { |
| | | ensureConfigured(); |
| | | ensureCollectingMerchant(command.huifuId()); |
| | | initializeSdk(); |
| | | V3TradePaymentScanpayQueryRequest request = new V3TradePaymentScanpayQueryRequest(); |
| | | request.setHuifuId(properties.getMerchantId().trim()); |
| | | request.setHuifuId(command.huifuId().trim()); |
| | | request.setOrgReqDate(command.requestDate()); |
| | | request.setOrgReqSeqId(command.paymentNo()); |
| | | if (!blank(command.providerTransactionNo())) request.setOrgHfSeqId(command.providerTransactionNo()); |
| | |
| | | } |
| | | } |
| | | |
| | | /** A payment must always be collected by the order's own sub-merchant, never by the platform. */ |
| | | private void ensureCollectingMerchant(String huifuId) { |
| | | if (blank(huifuId)) throw new BusinessException(ErrorCode.CONFLICT, "订单缺少收款子商户,请重新下单"); |
| | | } |
| | | |
| | | private void initializeSdk() { |
| | | if (initialized) return; |
| | | synchronized (SDK_INIT_LOCK) { |