package com.walker.pay.allinpaycloud;
|
|
import com.walker.infrastructure.utils.JsonUtils;
|
import com.walker.infrastructure.utils.StringUtils;
|
import com.walker.pay.Convertor;
|
import com.walker.pay.NotifyValue;
|
import com.walker.pay.ServiceProvider;
|
import com.walker.pay.allinpaycloud.util.TextUtils;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
|
/**
|
* 通商云订单通知转换器实现。
|
* @date 2023-02-26
|
*/
|
public class NotifyOrderConvertor implements Convertor<NotifyValue<?>> {
|
|
protected final transient Logger logger = LoggerFactory.getLogger(getClass());
|
|
@Override
|
public NotifyValue<Object> toGenericObject(Object data) {
|
if(!(data instanceof RequestNotify)){
|
throw new IllegalArgumentException("通知类型必须是'RequestNotify'");
|
}
|
RequestNotify requestNotify = (RequestNotify)data;
|
if(StringUtils.isEmpty(requestNotify.getBizContent())){
|
throw new IllegalArgumentException("通商云支付通知,未接收到 bizContent 业务数据:" + requestNotify, null);
|
}
|
|
String decodeBizContent = TextUtils.decodeFormUrlParameter(requestNotify.getBizContent());
|
logger.debug(decodeBizContent);
|
|
NotifyValue<Object> notifyValue = new NotifyValue<>();
|
notifyValue.setId(requestNotify.getNotifyId());
|
notifyValue.setSource(data);
|
notifyValue.setCreateTime(requestNotify.getNotifyTime());
|
notifyValue.setDataType(requestNotify.getNotifyType());
|
|
try {
|
NotifyOrder notifyOrder = JsonUtils.jsonStringToObject(decodeBizContent, NotifyOrder.class);
|
notifyValue.setBuyerId(notifyOrder.getBuyerBizUserId());
|
notifyValue.setOrderId(notifyOrder.getBizOrderNo());
|
notifyValue.setTradeNo(notifyOrder.getOrderNo());
|
// notifyValue.setVersion(orderNotifyInfo.get);
|
notifyValue.setServiceProvider(ServiceProvider.AllinPayCloud);
|
String payStatusValue = notifyOrder.getStatus();
|
if(payStatusValue.equals(Constants.SUB_CODE_OK)){
|
logger.debug("通知支付成功: " + notifyOrder);
|
notifyValue.setStatus(true);
|
}
|
notifyValue.setData(notifyOrder);
|
return notifyValue;
|
|
} catch (Exception e) {
|
throw new RuntimeException(e);
|
}
|
}
|
}
|