2
0

fix: 支付货币对接

This commit is contained in:
caiyuchao
2025-04-28 14:31:08 +08:00
parent 0fa1439304
commit 095dacb873
7 changed files with 44 additions and 30 deletions

View File

@@ -1,5 +1,6 @@
package org.wfc.payment.pay.paypal.service.impl;
import cn.hutool.core.util.StrUtil;
import com.paypal.sdk.PaypalServerSdkClient;
import com.paypal.sdk.controllers.OrdersController;
import com.paypal.sdk.exceptions.ApiException;
@@ -37,7 +38,12 @@ public class PaypalServiceImpl implements IPayPalService {
@Override
public Order createOrder(Long orderId) throws IOException, ApiException {
String amount = getAmountByOrder(orderId);
UOrderVo orderVo = getAmountByOrder(orderId);
String amount = orderVo.getOrderAmount().setScale(2, RoundingMode.HALF_UP).toString();
String currency = "USD";
if (StrUtil.isNotBlank(orderVo.getCurrency())) {
currency = orderVo.getCurrency();
}
CreateOrderInput createOrderInput = new CreateOrderInput.Builder(
null,
new OrderRequest.Builder(
@@ -45,7 +51,7 @@ public class PaypalServiceImpl implements IPayPalService {
Arrays.asList(
new PurchaseUnitRequest.Builder(
new AmountWithBreakdown.Builder(
"USD",
currency,
amount)
.build())
.build()))
@@ -59,13 +65,9 @@ public class PaypalServiceImpl implements IPayPalService {
return apiResponse.getResult();
}
private String getAmountByOrder(Long orderId) {
private UOrderVo getAmountByOrder(Long orderId) {
R<UOrderVo> orderRes = remoteUUserService.getOrderById(orderId);
UOrderVo orderVo = orderRes.getData();
if (orderVo == null) {
return null;
}
return orderVo.getOrderAmount().setScale(2, RoundingMode.HALF_UP).toString();
return orderRes.getData();
}
@Override

View File

@@ -1,5 +1,6 @@
package org.wfc.payment.pay.stripe.service.impl;
import cn.hutool.core.util.StrUtil;
import com.stripe.Stripe;
import com.stripe.exception.SignatureVerificationException;
import com.stripe.exception.StripeException;
@@ -53,6 +54,10 @@ public class StripeServiceImpl implements IStripeService {
Long totalFee = orderVo.getOrderAmount().multiply(BigDecimal.valueOf(100)).setScale(0, RoundingMode.HALF_UP).longValue();
String productName = orderVo.getType() == 0 ? "Package" : "Recharge";
String currency = "usd";
if (StrUtil.isNotBlank(orderVo.getCurrency())) {
currency = orderVo.getCurrency().toLowerCase();
}
SessionCreateParams params =
SessionCreateParams.builder()
.setMode(SessionCreateParams.Mode.PAYMENT)
@@ -64,7 +69,7 @@ public class StripeServiceImpl implements IStripeService {
.setQuantity(1L)
.setPriceData(
SessionCreateParams.LineItem.PriceData.builder()
.setCurrency("usd")
.setCurrency(currency)
.setUnitAmount(totalFee)
.setProductData(
SessionCreateParams.LineItem.PriceData.ProductData.builder()