|
@@ -5,6 +5,7 @@ import java.util.*;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
|
|
import com.huifu.adapay.core.util.StringUtil;
|
|
|
import com.huifu.adapay.model.PaymentReverse;
|
|
@@ -13,6 +14,8 @@ import com.ym.mec.thirdparty.adapay.entity.BaseResult;
|
|
|
import com.ym.mec.thirdparty.adapay.entity.HfMerchantConfig;
|
|
|
import com.ym.mec.thirdparty.exception.ThirdpartyException;
|
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.joda.time.DateTime;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
@@ -198,4 +201,59 @@ public class Payment {
|
|
|
}
|
|
|
return BaseResult.succeed(res);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ 针对已经创建的 支付对象,您可以调用关单接口进行交易的关闭。调用此接口后,该用户订单将不再能支付成功。 对于关单功能的使用有如下规则:
|
|
|
+ 1.存在关单记录,不能再次关单
|
|
|
+ 2.交易时间 1分钟 内无法关单成功
|
|
|
+ 3.正扫交易时间超过 2小时 无法关单成功
|
|
|
+ 4.支付宝正扫接口,如果用户没有扫码,订单不能关闭成功(二维码给用户展示,如果用户没有用手机去扫码,那这笔就不能关单; 如果用户扫过了的话(无需支付成功)就可以关单了)—-微信正扫无此条限制
|
|
|
+ 5.网银和快捷类交易都不支持关单操作
|
|
|
+ 对于已经成功付款的订单,请使用 退款对象 接口进行退款处理。我们建议您只有针对未支付的订单调用关单接口。
|
|
|
+ * @param transNo 交易流水号
|
|
|
+ * @param reason 原因
|
|
|
+ * @param merchantKey 商户Key
|
|
|
+ * @return Map<String, Object>
|
|
|
+ */
|
|
|
+ public static Map<String ,Object> closeWithKey(String transNo, String reason, String merchantKey) {
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+
|
|
|
+ params.put("payment_id", transNo);
|
|
|
+ params.put("reason", reason);
|
|
|
+ //params.put("notify_url", adapayPaymentConfig.getPayNotifyUrl());
|
|
|
+
|
|
|
+ Map<String, Object> paymentClose = new HashMap<>();
|
|
|
+ try {
|
|
|
+ paymentClose = com.huifu.adapay.model.Payment.close(params, merchantKey);
|
|
|
+ } catch (BaseAdaPayException e) {
|
|
|
+ LOGGER.info("请求汇付[关单]接口失败:{}", e.getMessage());
|
|
|
+ result.put("status", "failed");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ if (StringUtils.equals(paymentClose.get("status").toString(), "failed")) {
|
|
|
+ LOGGER.error("调用汇付[关单]接口同步返回,出现异常:{}", paymentClose);
|
|
|
+
|
|
|
+ // 忽略关单异常
|
|
|
+ // channel_close_fail 通道关单失败
|
|
|
+ // close_order_exists 关单记录已存在,不允许重复关单
|
|
|
+ List<String> errorCodes = Lists.newArrayList("close_order_exists"); // "channel_close_fail", "frequent_request"
|
|
|
+ // 关单记录已存在,不允许重复关单,重复关单会不抛出异常,只记录异常信息
|
|
|
+ if (errorCodes.contains(paymentClose.get("error_code").toString())) {
|
|
|
+ LOGGER.warn("调用汇付[关单]接口同步返回,出现异常:{}", paymentClose);
|
|
|
+
|
|
|
+ result.put("status", "success");
|
|
|
+ }
|
|
|
+ result.put("status", "failed");
|
|
|
+ // throw new PaymentException(paymentClose.get("error_msg").toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
}
|