|
@@ -18,6 +18,7 @@ import com.yonge.toolset.utils.string.StringUtil;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
@@ -90,21 +91,29 @@ public class PaymentSdk {
|
|
|
* @return 关闭的支付对象
|
|
|
* @throws Exception 异常
|
|
|
*/
|
|
|
- public Map<String, Object> closePayment(String paymentId) throws Exception {
|
|
|
- Map<String, Object> payment = new HashMap<>();
|
|
|
+ public HttpResponseResult<Map<String, Object>> closePayment(String paymentId, String reason, String expend) {
|
|
|
Map<String, Object> paymentParams = new HashMap<>(10);
|
|
|
paymentParams.put("payment_id", paymentId);
|
|
|
- paymentParams.put("reason", "reason");
|
|
|
- paymentParams.put("expend", "expend");
|
|
|
- paymentParams.put("notify_url", "notify_url");
|
|
|
- payment = com.huifu.adapay.model.Payment.close(paymentParams);
|
|
|
+ paymentParams.put("reason", reason);
|
|
|
+ paymentParams.put("expend", expend);
|
|
|
+ paymentParams.put("notify_url", HuifuConfiguration.getHuifuProperties().getNotifyUrl());
|
|
|
|
|
|
- String error_code = (String) payment.get("error_code");
|
|
|
- if (null != error_code) {
|
|
|
- String errorMsg = (String) payment.get("error_msg");
|
|
|
- throw new ThirdpartyException(errorMsg);
|
|
|
+ Map<String, Object> res;
|
|
|
+ try {
|
|
|
+ res = Payment.close(paymentParams);
|
|
|
+ } catch (BaseAdaPayException e) {
|
|
|
+ return HttpResponseResult.failed(e.getMessage());
|
|
|
}
|
|
|
- return payment;
|
|
|
+ if (CollectionUtils.isEmpty(res)) {
|
|
|
+ return HttpResponseResult.failed("请求失败");
|
|
|
+ }
|
|
|
+ log.info("汇付[关闭支付对象] Resp:{}", res);
|
|
|
+ String errorCode = (String) res.get("error_code");
|
|
|
+ if (null != errorCode) {
|
|
|
+ String errorMsg = (String) res.get("error_msg");
|
|
|
+ return HttpResponseResult.failed(errorMsg);
|
|
|
+ }
|
|
|
+ return HttpResponseResult.succeed(res);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -171,6 +180,7 @@ public class PaymentSdk {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 退款
|
|
|
*
|
|
@@ -207,4 +217,44 @@ public class PaymentSdk {
|
|
|
}
|
|
|
return HttpResponseResult.succeed(res);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查看退款订单
|
|
|
+ *
|
|
|
+ * {
|
|
|
+ * "status": "succeeded",
|
|
|
+ * "prod_mode": "true",
|
|
|
+ * "refunds": [
|
|
|
+ * {
|
|
|
+ * "payment_id": "002112019110811022810038712892084113408",
|
|
|
+ * "refund_id": "0021120191108110337980038713178955902976",
|
|
|
+ * "refund_order_no": "refundOrderNo00211201911081103379",
|
|
|
+ * "trans_status": "P",
|
|
|
+ * "refund_amt": "0.01",
|
|
|
+ * "fee_amt": ""
|
|
|
+ * }
|
|
|
+ * ]
|
|
|
+ * }
|
|
|
+ */
|
|
|
+ public HttpResponseResult<Map<String, Object>> selectRefundPayment(String refundId) {
|
|
|
+
|
|
|
+ Map<String, Object> refundParams = new HashMap<>(2);
|
|
|
+ refundParams.put("refund_id", refundId);
|
|
|
+ Map<String, Object> res;
|
|
|
+ try {
|
|
|
+ res = Refund.query(refundParams);
|
|
|
+ } catch (BaseAdaPayException e) {
|
|
|
+ return HttpResponseResult.failed(e.getMessage());
|
|
|
+ }
|
|
|
+ if (null == res) {
|
|
|
+ return HttpResponseResult.failed("请求失败");
|
|
|
+ }
|
|
|
+ log.info("汇付[查看退款对象] Resp:{}", res);
|
|
|
+ String errorCode = (String) res.get("error_code");
|
|
|
+ if (null != errorCode) {
|
|
|
+ String errorMsg = (String) res.get("error_msg");
|
|
|
+ return HttpResponseResult.failed(errorMsg);
|
|
|
+ }
|
|
|
+ return HttpResponseResult.succeed(res);
|
|
|
+ }
|
|
|
}
|