fix: 支付货币对接
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -39,7 +39,7 @@ public class SysConfigServiceImpl implements ISysConfigService
|
||||
|
||||
private static final String DEFAULT_SYS_PAY_CURRENCY_VALUE = "USD";
|
||||
private static final String DEFAULT_SYS_PAY_CURRENCY_SYMBOL_VALUE = "$";
|
||||
private static final String[] DEFAULT_SYS_PAY_PAYMENT_METHOD_VALUE = {"paypal"};
|
||||
private static final String[] DEFAULT_SYS_PAY_PAYMENT_METHOD_VALUE = {"paypal, stripe"};
|
||||
|
||||
/**
|
||||
* 项目启动时,初始化参数到缓存
|
||||
|
||||
@@ -12,10 +12,12 @@ import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.wfc.common.core.constant.CacheConstants;
|
||||
import org.wfc.common.core.domain.R;
|
||||
import org.wfc.common.core.web.controller.BaseController;
|
||||
import org.wfc.common.core.web.domain.AjaxResult;
|
||||
import org.wfc.common.core.web.page.TableDataInfo;
|
||||
import org.wfc.common.redis.service.RedisService;
|
||||
import org.wfc.common.security.annotation.InnerAuth;
|
||||
import org.wfc.common.security.utils.SecurityUtils;
|
||||
import org.wfc.user.domain.UOrder;
|
||||
@@ -47,6 +49,9 @@ public class UOrderController extends BaseController {
|
||||
@Autowired
|
||||
private IURateLimitService uRateLimitService;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@GetMapping("/page")
|
||||
public TableDataInfo page(UOrder uOrder) {
|
||||
startPage();
|
||||
@@ -59,8 +64,19 @@ public class UOrderController extends BaseController {
|
||||
startPage();
|
||||
List<UOrder> list = uOrderService.list(Wrappers.<UOrder>lambdaQuery()
|
||||
.eq(UOrder::getUserId, SecurityUtils.getUserId()).eq(UOrder::getType, 1)
|
||||
.eq(UOrder::getStatus, 1)
|
||||
.orderByDesc(UOrder::getCreateTime));
|
||||
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@GetMapping("/packagePage")
|
||||
public TableDataInfo packagePage() {
|
||||
startPage();
|
||||
List<UOrder> list = uOrderService.list(Wrappers.<UOrder>lambdaQuery()
|
||||
.eq(UOrder::getUserId, SecurityUtils.getUserId()).eq(UOrder::getType, 0)
|
||||
.eq(UOrder::getStatus, 1)
|
||||
.orderByDesc(UOrder::getCreateTime));
|
||||
for (UOrder uOrder : list) {
|
||||
if (ObjectUtil.isNull(uOrder.getPackageId())) {
|
||||
continue;
|
||||
@@ -74,22 +90,6 @@ public class UOrderController extends BaseController {
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@GetMapping("/packagePage")
|
||||
public TableDataInfo packagePage() {
|
||||
startPage();
|
||||
List<UOrder> list = uOrderService.list(Wrappers.<UOrder>lambdaQuery()
|
||||
.eq(UOrder::getUserId, SecurityUtils.getUserId()).eq(UOrder::getType, 0)
|
||||
.orderByDesc(UOrder::getCreateTime));
|
||||
for (UOrder uOrder : list) {
|
||||
if (ObjectUtil.isNull(uOrder.getPackageId())) {
|
||||
continue;
|
||||
}
|
||||
UPackage uPackage = uPackageService.getById(uOrder.getPackageId());
|
||||
uOrder.setUPackage(uPackage);
|
||||
}
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public AjaxResult list(UOrder uOrder) {
|
||||
List<UOrder> list = uOrderService.list();
|
||||
@@ -98,7 +98,12 @@ public class UOrderController extends BaseController {
|
||||
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getById(@PathVariable("id") Long id) {
|
||||
return success(uOrderService.getById(id));
|
||||
Object cacheMapValue = redisService.getCacheMapValue(CacheConstants.SYS_PAY_CONFIG_KEY, CacheConstants.SYS_PAY_CURRENCY_KEY);
|
||||
UOrder order = uOrderService.getById(id);
|
||||
if (cacheMapValue != null) {
|
||||
order.setCurrency(cacheMapValue.toString());
|
||||
}
|
||||
return success(order);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
|
||||
@@ -48,4 +48,7 @@ public class UOrder extends BaseData {
|
||||
|
||||
@TableField(exist = false)
|
||||
private UPackage uPackage;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String currency;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user