租赁资金账户资金充值功能,对接项目的支付接口,application-rental.yml添加配置NILE和主网的对接配置
This commit is contained in:
1 parent
911a3634ee
commit
e73f099734
20 files changed
+878
-9
No files matched your search
+16
-3
@@ -41,7 +41,7 @@ import java.util.regex.Pattern;
|
||||
public class PaymentOrderOpenApiService {
|
||||
private static final long ORDER_TTL_MILLIS = 10L * 60L * 1000L;
|
||||
private static final Pattern PARAMETER_PATTERN = Pattern.compile(
|
||||
"(?:^|&)(amount|notify_url|order_id|redirect_url|walletUserName)=");
|
||||
"(?:^|&)(amount|notify_url|order_id|redirect_url|walletUserName|network|amount_currency)=");
|
||||
private static final List<String> REQUIRED_PARAMETERS = Arrays.asList(
|
||||
"amount", "notify_url", "order_id", "walletUserName");
|
||||
private static final DefaultRedisScript<Long> RELEASE_SCRIPT = new DefaultRedisScript<Long>(
|
||||
@@ -58,6 +58,7 @@ public class PaymentOrderOpenApiService {
|
||||
/** 对外创建订单成功后返回的公共收银台入口。 */
|
||||
@Value("${payment.checkout-url:http://192.168.3.103/public/usdtCheckout}")
|
||||
private String checkoutUrl;
|
||||
@Autowired private TronServiceProvider tronServiceProvider;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public PaymentOrderCreateResult createOrder(DecryptResult request) {
|
||||
@@ -67,7 +68,12 @@ public class PaymentOrderOpenApiService {
|
||||
String notifyUrl = required(parameters, "notify_url");
|
||||
String redirectUrl = trimToNull(parameters.get("redirect_url"));
|
||||
BigDecimal amount = parseAmount(required(parameters, "amount"));
|
||||
BigDecimal actualAmount = convertToUsdt(amount);
|
||||
boolean usdt = "USDT".equals(parameters.get("amount_currency"));
|
||||
if (parameters.containsKey("amount_currency") && !usdt) throw new CustomException("不支持的金额币种");
|
||||
BigDecimal actualAmount = usdt ? amount.setScale(2, RoundingMode.UNNECESSARY) : convertToUsdt(amount);
|
||||
String network = parameters.get("network");
|
||||
if (network == null) network = "nile".equals(tronServiceProvider.getCurrentService().type()) ? "NILE" : "MAINNET";
|
||||
if (!("NILE".equals(network) || "MAINNET".equals(network))) throw new CustomException("支付网络无效");
|
||||
validate(orderId, walletUserName, notifyUrl, redirectUrl);
|
||||
|
||||
// 锁定应用,使同一应用下的钱包领取和商户订单幂等检查串行执行。
|
||||
@@ -82,6 +88,12 @@ public class PaymentOrderOpenApiService {
|
||||
if (!Objects.equals(existingOrder.getAppId(), request.getAppId())) {
|
||||
throw new CustomException("商户订单号已存在");
|
||||
}
|
||||
if (existingOrder.getActualAmount().compareTo(actualAmount) != 0
|
||||
|| (existingOrder.getPaymentNetwork() != null && !Objects.equals(existingOrder.getPaymentNetwork(), network))
|
||||
|| !Objects.equals(existingOrder.getWalletUserName(), walletUserName)
|
||||
|| !Objects.equals(existingOrder.getNotifyUrl(), notifyUrl)) {
|
||||
throw new CustomException("同一支付单号参数不一致");
|
||||
}
|
||||
return result(existingOrder);
|
||||
}
|
||||
|
||||
@@ -103,6 +115,7 @@ public class PaymentOrderOpenApiService {
|
||||
|
||||
UsdtOrdersPlus order = new UsdtOrdersPlus();
|
||||
order.setTradeId(tradeId);
|
||||
order.setPaymentNetwork(network);
|
||||
order.setOrderId(orderId);
|
||||
order.setAmount(amount);
|
||||
order.setActualAmount(actualAmount);
|
||||
@@ -248,7 +261,7 @@ public class PaymentOrderOpenApiService {
|
||||
throw new CustomException("业务参数不能重复");
|
||||
}
|
||||
}
|
||||
if (!values.keySet().containsAll(REQUIRED_PARAMETERS) || values.size() > 5) {
|
||||
if (!values.keySet().containsAll(REQUIRED_PARAMETERS) || values.size() > 7) {
|
||||
throw new CustomException("业务参数不完整或包含不支持的参数");
|
||||
}
|
||||
return values;
|
||||
|
||||
Reference in new issue
Block a user