修复支付
This commit is contained in:
parent
3027590239
commit
8544ca34d0
@ -166,9 +166,42 @@ public class PayWebApplicationCommodityV2QueryExe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private PayCountry getPayCountry(PayWebApplicationCommodityCmd cmd) {
|
private PayCountry getPayCountry(PayWebApplicationCommodityCmd cmd) {
|
||||||
return Objects.isNull(cmd.getPayCountryId())
|
if (Objects.isNull(cmd.getPayCountryId())) {
|
||||||
? payCountryService.getShelfSortMax()
|
return payCountryService.getShelfSortMax();
|
||||||
: payCountryService.getById(cmd.getPayCountryId());
|
}
|
||||||
|
|
||||||
|
PayCountry payCountry = payCountryService.getById(cmd.getPayCountryId());
|
||||||
|
if (Objects.isNull(payCountry)) {
|
||||||
|
return getUsablePayCountryByCountryId(cmd.getPayCountryId());
|
||||||
|
}
|
||||||
|
if (isUsablePayCountry(payCountry)) {
|
||||||
|
return payCountry;
|
||||||
|
}
|
||||||
|
return Optional.ofNullable(getUsablePayCountryByCountryId(payCountry.getCountryId()))
|
||||||
|
.orElse(payCountry);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PayCountry getUsablePayCountryByCountryId(Long countryId) {
|
||||||
|
if (Objects.isNull(countryId)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return payCountryService.query()
|
||||||
|
.eq(PayCountry::getShelf, Boolean.TRUE)
|
||||||
|
.eq(PayCountry::getCountryId, countryId)
|
||||||
|
.orderByDesc(PayCountry::getSort)
|
||||||
|
.list()
|
||||||
|
.stream()
|
||||||
|
.filter(this::isUsablePayCountry)
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isUsablePayCountry(PayCountry payCountry) {
|
||||||
|
return Objects.nonNull(payCountry)
|
||||||
|
&& StringUtils.isNotBlank(payCountry.getCurrency())
|
||||||
|
&& CollectionUtils.isNotEmpty(
|
||||||
|
payCountryChannelDetailsService.listChannelCode(payCountry.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<PayChannelDetailsCO> getPayChannels(List<PayChannel> payChannels,
|
private List<PayChannelDetailsCO> getPayChannels(List<PayChannel> payChannels,
|
||||||
|
|||||||
@ -38,7 +38,9 @@ public class PayWebOpenPayCountryQueryExe {
|
|||||||
);
|
);
|
||||||
return payCountries.stream().map(payCountry -> new PayCountryCO()
|
return payCountries.stream().map(payCountry -> new PayCountryCO()
|
||||||
.setId(payCountry.getId())
|
.setId(payCountry.getId())
|
||||||
|
.setPayCountryId(payCountry.getId())
|
||||||
.setCountryId(payCountry.getCountryId())
|
.setCountryId(payCountry.getCountryId())
|
||||||
|
.setCurrency(payCountry.getCurrency())
|
||||||
.setCountry(countryCodeMap.get(payCountry.getCountryId()))
|
.setCountry(countryCodeMap.get(payCountry.getCountryId()))
|
||||||
).collect(Collectors.toList());
|
).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import com.red.circle.order.inner.asserts.PayErrorCode;
|
|||||||
import com.red.circle.order.inner.model.enums.inapp.InAppPurchaseReceiptType;
|
import com.red.circle.order.inner.model.enums.inapp.InAppPurchaseReceiptType;
|
||||||
import com.red.circle.other.inner.endpoint.sys.SysCountryCodeClient;
|
import com.red.circle.other.inner.endpoint.sys.SysCountryCodeClient;
|
||||||
import com.red.circle.other.inner.model.dto.sys.SysCountryCodeDTO;
|
import com.red.circle.other.inner.model.dto.sys.SysCountryCodeDTO;
|
||||||
|
import com.red.circle.tool.core.collection.CollectionUtils;
|
||||||
import com.red.circle.tool.core.num.ArithmeticUtils;
|
import com.red.circle.tool.core.num.ArithmeticUtils;
|
||||||
import com.red.circle.tool.core.sequence.IdWorkerUtils;
|
import com.red.circle.tool.core.sequence.IdWorkerUtils;
|
||||||
import com.red.circle.tool.core.text.StringUtils;
|
import com.red.circle.tool.core.text.StringUtils;
|
||||||
@ -70,14 +71,16 @@ public class PayWebPlaceAnOrderCmdExe {
|
|||||||
ResponseAssert.notNull(PayErrorCode.UNKNOWN_APPLICATION, application);
|
ResponseAssert.notNull(PayErrorCode.UNKNOWN_APPLICATION, application);
|
||||||
PayApplicationCommodity commodity = getAppCommodity(cmd);
|
PayApplicationCommodity commodity = getAppCommodity(cmd);
|
||||||
|
|
||||||
|
PayCountry payCountry = getPayCountry(cmd.getPayCountryId());
|
||||||
|
// 不支持地区
|
||||||
|
ResponseAssert.notNull(PayErrorCode.REGION_NOT_SUPPORTED, payCountry);
|
||||||
|
cmd.setPayCountryId(payCountry.getId());
|
||||||
|
|
||||||
PayCountryChannelDetails channelDetails = payCountryChannelDetailsService
|
PayCountryChannelDetails channelDetails = payCountryChannelDetailsService
|
||||||
.getSuggestScoreMax(cmd.getPayCountryId(), cmd.getChannelCode(),
|
.getSuggestScoreMax(cmd.getPayCountryId(), cmd.getChannelCode(),
|
||||||
commodity.getAmountUsd());
|
commodity.getAmountUsd());
|
||||||
// 没有合适的支付方式
|
// 没有合适的支付方式
|
||||||
ResponseAssert.notNull(PayErrorCode.NO_SUITABLE_PAYMENT_CHANNEL, channelDetails);
|
ResponseAssert.notNull(PayErrorCode.NO_SUITABLE_PAYMENT_CHANNEL, channelDetails);
|
||||||
PayCountry payCountry = payCountryService.getById(cmd.getPayCountryId());
|
|
||||||
// 不支持地区
|
|
||||||
ResponseAssert.notNull(PayErrorCode.REGION_NOT_SUPPORTED, payCountry);
|
|
||||||
SysCountryCodeDTO sysCountryCode = ResponseAssert.requiredSuccess(
|
SysCountryCodeDTO sysCountryCode = ResponseAssert.requiredSuccess(
|
||||||
sysCountryCodeClient.getById(payCountry.getCountryId())
|
sysCountryCodeClient.getById(payCountry.getCountryId())
|
||||||
);
|
);
|
||||||
@ -131,6 +134,41 @@ public class PayWebPlaceAnOrderCmdExe {
|
|||||||
return details;
|
return details;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PayCountry getPayCountry(Long payCountryId) {
|
||||||
|
PayCountry payCountry = payCountryService.getById(payCountryId);
|
||||||
|
if (Objects.isNull(payCountry)) {
|
||||||
|
return getUsablePayCountryByCountryId(payCountryId);
|
||||||
|
}
|
||||||
|
if (isUsablePayCountry(payCountry)) {
|
||||||
|
return payCountry;
|
||||||
|
}
|
||||||
|
PayCountry compatiblePayCountry = getUsablePayCountryByCountryId(payCountry.getCountryId());
|
||||||
|
return Objects.nonNull(compatiblePayCountry) ? compatiblePayCountry : payCountry;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PayCountry getUsablePayCountryByCountryId(Long countryId) {
|
||||||
|
if (Objects.isNull(countryId)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return payCountryService.query()
|
||||||
|
.eq(PayCountry::getShelf, Boolean.TRUE)
|
||||||
|
.eq(PayCountry::getCountryId, countryId)
|
||||||
|
.orderByDesc(PayCountry::getSort)
|
||||||
|
.list()
|
||||||
|
.stream()
|
||||||
|
.filter(this::isUsablePayCountry)
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isUsablePayCountry(PayCountry payCountry) {
|
||||||
|
return Objects.nonNull(payCountry)
|
||||||
|
&& StringUtils.isNotBlank(payCountry.getCurrency())
|
||||||
|
&& CollectionUtils.isNotEmpty(
|
||||||
|
payCountryChannelDetailsService.listChannelCode(payCountry.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取实时汇率,失败时返回配置的汇率
|
* 获取实时汇率,失败时返回配置的汇率
|
||||||
* @param payCountry 支付国家配置
|
* @param payCountry 支付国家配置
|
||||||
|
|||||||
@ -8,10 +8,12 @@ import com.red.circle.order.app.dto.clientobject.pay.UserProfileAndCountryCO;
|
|||||||
import com.red.circle.order.app.dto.clientobject.pay.WebSiteUseProfileCO;
|
import com.red.circle.order.app.dto.clientobject.pay.WebSiteUseProfileCO;
|
||||||
import com.red.circle.order.app.dto.cmd.PayWebUserCmd;
|
import com.red.circle.order.app.dto.cmd.PayWebUserCmd;
|
||||||
import com.red.circle.order.infra.database.rds.entity.pay.PayCountry;
|
import com.red.circle.order.infra.database.rds.entity.pay.PayCountry;
|
||||||
|
import com.red.circle.order.infra.database.rds.service.pay.PayCountryChannelDetailsService;
|
||||||
import com.red.circle.order.infra.database.rds.service.pay.PayCountryService;
|
import com.red.circle.order.infra.database.rds.service.pay.PayCountryService;
|
||||||
import com.red.circle.order.inner.model.enums.PayApplicationCommodityType;
|
import com.red.circle.order.inner.model.enums.PayApplicationCommodityType;
|
||||||
import com.red.circle.other.inner.endpoint.sys.SysCountryCodeClient;
|
import com.red.circle.other.inner.endpoint.sys.SysCountryCodeClient;
|
||||||
import com.red.circle.other.inner.model.dto.sys.SysCountryCodeDTO;
|
import com.red.circle.other.inner.model.dto.sys.SysCountryCodeDTO;
|
||||||
|
import com.red.circle.tool.core.collection.CollectionUtils;
|
||||||
import com.red.circle.tool.core.parse.DataTypeUtils;
|
import com.red.circle.tool.core.parse.DataTypeUtils;
|
||||||
import com.red.circle.tool.core.regex.RegexConstant;
|
import com.red.circle.tool.core.regex.RegexConstant;
|
||||||
import com.red.circle.tool.core.text.StringUtils;
|
import com.red.circle.tool.core.text.StringUtils;
|
||||||
@ -42,6 +44,7 @@ public class UserProfileAndCountryQueryExe {
|
|||||||
private final UserRegionClient userRegionClient;
|
private final UserRegionClient userRegionClient;
|
||||||
private final FreightGoldClient freightGoldClient;
|
private final FreightGoldClient freightGoldClient;
|
||||||
private final PayCountryService payCountryService;
|
private final PayCountryService payCountryService;
|
||||||
|
private final PayCountryChannelDetailsService payCountryChannelDetailsService;
|
||||||
private final UserProfileClient userProfileClient;
|
private final UserProfileClient userProfileClient;
|
||||||
private final SysCountryCodeClient sysCountryCodeClient;
|
private final SysCountryCodeClient sysCountryCodeClient;
|
||||||
private final RegionRelationClient regionRelationClient;
|
private final RegionRelationClient regionRelationClient;
|
||||||
@ -82,6 +85,7 @@ public class UserProfileAndCountryQueryExe {
|
|||||||
|
|
||||||
Map<Long, SysCountryCodeDTO> mapCountryCode = getMapCountryCode(payCountryList);
|
Map<Long, SysCountryCodeDTO> mapCountryCode = getMapCountryCode(payCountryList);
|
||||||
ResponseAssert.notEmpty(CommonErrorCode.NOT_SUPPORTED_REGION, mapCountryCode);
|
ResponseAssert.notEmpty(CommonErrorCode.NOT_SUPPORTED_REGION, mapCountryCode);
|
||||||
|
Map<Long, PayCountry> compatiblePayCountryMap = getCompatiblePayCountryMap(payCountryList);
|
||||||
|
|
||||||
return new UserProfileAndCountryCO()
|
return new UserProfileAndCountryCO()
|
||||||
.setCountryList(payCountryList.stream().map(country -> {
|
.setCountryList(payCountryList.stream().map(country -> {
|
||||||
@ -90,9 +94,13 @@ public class UserProfileAndCountryQueryExe {
|
|||||||
if (Objects.isNull(countryCode)) {
|
if (Objects.isNull(countryCode)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
PayCountry compatiblePayCountry = compatiblePayCountryMap
|
||||||
|
.getOrDefault(country.getCountryId(), country);
|
||||||
return new PayCountryCO()
|
return new PayCountryCO()
|
||||||
.setId(country.getId())
|
.setId(country.getId())
|
||||||
|
.setPayCountryId(compatiblePayCountry.getId())
|
||||||
.setCountryId(country.getCountryId())
|
.setCountryId(country.getCountryId())
|
||||||
|
.setCurrency(compatiblePayCountry.getCurrency())
|
||||||
.setCountry(countryCode);
|
.setCountry(countryCode);
|
||||||
|
|
||||||
}).filter(Objects::nonNull).collect(Collectors.toList()))
|
}).filter(Objects::nonNull).collect(Collectors.toList()))
|
||||||
@ -125,6 +133,29 @@ public class UserProfileAndCountryQueryExe {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<Long, PayCountry> getCompatiblePayCountryMap(List<PayCountry> payCountryList) {
|
||||||
|
if (CollectionUtils.isEmpty(payCountryList)) {
|
||||||
|
return java.util.Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PayCountry> candidates = payCountryService.query()
|
||||||
|
.eq(PayCountry::getShelf, Boolean.TRUE)
|
||||||
|
.in(PayCountry::getCountryId, payCountryList.stream().map(PayCountry::getCountryId)
|
||||||
|
.collect(Collectors.toSet()))
|
||||||
|
.orderByDesc(PayCountry::getSort)
|
||||||
|
.list();
|
||||||
|
if (CollectionUtils.isEmpty(candidates)) {
|
||||||
|
return java.util.Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
return candidates.stream()
|
||||||
|
.filter(country -> StringUtils.isNotBlank(country.getCurrency()))
|
||||||
|
.filter(country -> CollectionUtils.isNotEmpty(
|
||||||
|
payCountryChannelDetailsService.listChannelCode(country.getId())))
|
||||||
|
.collect(Collectors.toMap(PayCountry::getCountryId, country -> country,
|
||||||
|
(left, right) -> left));
|
||||||
|
}
|
||||||
|
|
||||||
private List<RegionRelationDTO> getRegionRelationList(UserProfileDTO userProfile,
|
private List<RegionRelationDTO> getRegionRelationList(UserProfileDTO userProfile,
|
||||||
String regionId) {
|
String regionId) {
|
||||||
return ResponseAssert.requiredSuccess(
|
return ResponseAssert.requiredSuccess(
|
||||||
|
|||||||
@ -30,12 +30,23 @@ public class PayCountryCO extends ClientObject {
|
|||||||
@JsonSerialize(using = ToStringSerializer.class)
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 可用于支付接口的支付国家ID.
|
||||||
|
*/
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long payCountryId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 国家id.
|
* 国家id.
|
||||||
*/
|
*/
|
||||||
@JsonSerialize(using = ToStringSerializer.class)
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
private Long countryId;
|
private Long countryId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 国家货币.
|
||||||
|
*/
|
||||||
|
private String currency;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 国家信息.
|
* 国家信息.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user