Merge branch 'dev/dev_xp' into dev/dev
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
package com.ai.da.service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Map;
|
||||
|
||||
public interface AliPayService {
|
||||
String tradeCreate(Integer amount,String returnUrl);
|
||||
String tradeCreate(Integer amount,String returnUrl, HttpServletRequest request);
|
||||
|
||||
String tradeNotify(Map<String, String> params);
|
||||
|
||||
|
||||
@@ -2,9 +2,11 @@ package com.ai.da.service;
|
||||
|
||||
import com.ai.da.model.dto.AlipayHKCallbackDTO;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public interface AlipayHKService {
|
||||
|
||||
String createOrder(Integer amount, String wallet);
|
||||
String createOrder(Integer amount, String wallet, HttpServletRequest request);
|
||||
|
||||
String callback(String paramString);
|
||||
|
||||
|
||||
@@ -8,13 +8,14 @@ import com.ai.da.mapper.primary.entity.OrderInfo;
|
||||
import com.ai.da.model.dto.QueryPageByTimeDTO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
public interface OrderInfoService extends IService<OrderInfo> {
|
||||
|
||||
OrderInfo createOrderByProductId(Integer productId, String paymentType);
|
||||
OrderInfo createOrderByProductId(Integer productId, String paymentType, HttpServletRequest request);
|
||||
|
||||
OrderInfo createOrderByProductId(Integer amount, String paymentType, ProductEnum product);
|
||||
OrderInfo createOrderByProductId(Integer amount, String paymentType, ProductEnum product, HttpServletRequest request);
|
||||
|
||||
void saveCodeUrl(String orderNo, String codeUrl);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Map;
|
||||
|
||||
public interface PayPalCheckoutService {
|
||||
|
||||
HashMap<String, String> createOrder(Integer amount,String returnUrl) throws SerializeException;
|
||||
HashMap<String, String> createOrder(Integer amount,String returnUrl, HttpServletRequest request) throws SerializeException;
|
||||
|
||||
// String callback(@SuppressWarnings("rawtypes") Map map);
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.Map;
|
||||
|
||||
public interface StripeService {
|
||||
|
||||
String pay(ProductPurchaseDTO productPurchaseDTO);
|
||||
String pay(ProductPurchaseDTO productPurchaseDTO, HttpServletRequest request);
|
||||
|
||||
Boolean notify(HttpServletRequest request);
|
||||
|
||||
@@ -48,5 +48,5 @@ public interface StripeService {
|
||||
|
||||
String detachCustomerAllPaymentMethod(String name, String email);
|
||||
|
||||
String getIp2(HttpServletRequest request);
|
||||
// Map getIp(HttpServletRequest request);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -54,21 +55,21 @@ public class AliPayServiceImpl implements AliPayService {
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public String tradeCreate(Integer amount, String returnUrl) {
|
||||
public String tradeCreate(Integer amount, String returnUrl, HttpServletRequest request) {
|
||||
|
||||
try {
|
||||
//生成订单
|
||||
log.info("生成订单");
|
||||
OrderInfo orderInfo = orderInfoService.createOrderByProductId(amount, PayTypeEnum.ALIPAY.getType());
|
||||
OrderInfo orderInfo = orderInfoService.createOrderByProductId(amount, PayTypeEnum.ALIPAY.getType(), request);
|
||||
|
||||
//调用支付宝接口
|
||||
AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
|
||||
AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
|
||||
//配置需要的公共请求参数
|
||||
//支付完成后,支付宝发起异步通知的地址
|
||||
request.setNotifyUrl(config.getProperty("alipay.notify-url"));
|
||||
alipayRequest.setNotifyUrl(config.getProperty("alipay.notify-url"));
|
||||
//支付完成后,我们想让页面跳转回aida的页面,配置returnUrl
|
||||
// request.setReturnUrl(config.getProperty("alipay.return-url"));
|
||||
request.setReturnUrl(returnUrl);
|
||||
// alipayRequest.setReturnUrl(config.getProperty("alipay.return-url"));
|
||||
alipayRequest.setReturnUrl(returnUrl);
|
||||
|
||||
//组装当前业务方法的请求参数
|
||||
JSONObject bizContent = new JSONObject();
|
||||
@@ -79,10 +80,10 @@ public class AliPayServiceImpl implements AliPayService {
|
||||
bizContent.put("subject", "积分购买");
|
||||
bizContent.put("product_code", "FAST_INSTANT_TRADE_PAY");
|
||||
|
||||
request.setBizContent(bizContent.toString());
|
||||
alipayRequest.setBizContent(bizContent.toString());
|
||||
|
||||
//执行请求,调用支付宝接口
|
||||
AlipayTradePagePayResponse response = alipayClient.pageExecute(request);
|
||||
AlipayTradePagePayResponse response = alipayClient.pageExecute(alipayRequest);
|
||||
|
||||
if(response.isSuccess()){
|
||||
log.info("调用成功,返回结果 ===> " + response.getBody());
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
@@ -64,7 +65,7 @@ public class AlipayHKServiceImpl implements AlipayHKService {
|
||||
* 创建订单
|
||||
*/
|
||||
@Override
|
||||
public String createOrder(Integer amount, String wallet){
|
||||
public String createOrder(Integer amount, String wallet , HttpServletRequest request){
|
||||
|
||||
try{
|
||||
HashMap<String, Object> param = new HashMap<>();
|
||||
@@ -80,7 +81,7 @@ public class AlipayHKServiceImpl implements AlipayHKService {
|
||||
log.info("alipay-hk 创建订单,参数信息: {}", param);
|
||||
// 生成订单
|
||||
log.info("创建订单");
|
||||
OrderInfo orderInfo = orderInfoService.createOrderByProductId(amount, PayTypeEnum.ALIPAY_HK.getType());
|
||||
OrderInfo orderInfo = orderInfoService.createOrderByProductId(amount, PayTypeEnum.ALIPAY_HK.getType(), request);
|
||||
/*// 加密
|
||||
AlipayHKRequestDTO alipayHKRequestDTO = alipayHKEncryptionUtil.AESCBCWithRSA(param, AlipayHKConstant.CREATE_ORDER);
|
||||
// 请求Alipay服务端
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.ai.da.common.enums.OrderStatusEnum;
|
||||
import com.ai.da.common.enums.ProductEnum;
|
||||
import com.ai.da.common.response.PageBaseResponse;
|
||||
import com.ai.da.common.utils.OrderNoUtils;
|
||||
import com.ai.da.common.utils.RequestInfoUtil;
|
||||
import com.ai.da.mapper.primary.OrderInfoMapper;
|
||||
import com.ai.da.mapper.primary.PaymentInfoMapper;
|
||||
import com.ai.da.mapper.primary.ProductMapper;
|
||||
@@ -25,11 +26,14 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@@ -42,7 +46,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
private PaymentInfoMapper paymentInfoMapper;
|
||||
|
||||
@Override
|
||||
public OrderInfo createOrderByProductId(Integer amount, String paymentType) {
|
||||
public OrderInfo createOrderByProductId(Integer amount, String paymentType, HttpServletRequest request) {
|
||||
|
||||
|
||||
//查找已存在但未支付的订单
|
||||
@@ -64,14 +68,28 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
// orderInfo.setProductId(amount);
|
||||
// orderInfo.setTotalFee(Integer.parseInt(CreditsEventsEnum.PRICE.getValue()) * amount); // 元 HKD
|
||||
orderInfo.setTotalFee(Float.parseFloat(CreditsEventsEnum.PRICE.getValue()) * amount); // 元 HKD
|
||||
orderInfo.setOrderStatus(OrderStatusEnum.NOT_PAY.getType()); //未支付
|
||||
orderInfo.setPaymentType(paymentType);
|
||||
setIPLocation(paymentType, request, orderInfo);
|
||||
baseMapper.insert(orderInfo);
|
||||
|
||||
return orderInfo;
|
||||
}
|
||||
|
||||
public OrderInfo createOrderByProductId(Integer amount, String paymentType, ProductEnum product) {
|
||||
private void setIPLocation(String paymentType, HttpServletRequest request, OrderInfo orderInfo) {
|
||||
orderInfo.setOrderStatus(OrderStatusEnum.NOT_PAY.getType()); //未支付
|
||||
orderInfo.setPaymentType(paymentType);
|
||||
if (!Objects.isNull(request)){
|
||||
String ipAddress = RequestInfoUtil.getIpAddress(request);
|
||||
if (!StringUtil.isNullOrEmpty(ipAddress)) {
|
||||
Map ipLocation = RequestInfoUtil.getIPLocation(ipAddress);
|
||||
if (ipLocation != null && !ipLocation.get("status").equals("fail")) {
|
||||
orderInfo.setCountry(ipLocation.get("country").toString());
|
||||
orderInfo.setCity(ipLocation.get("city").toString());
|
||||
orderInfo.setIpAddress(ipLocation.get("query").toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public OrderInfo createOrderByProductId(Integer amount, String paymentType, ProductEnum product, HttpServletRequest request) {
|
||||
|
||||
//获取商品信息
|
||||
// Product product = productMapper.selectById(amount);
|
||||
@@ -92,10 +110,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
// orderInfo.setProductId(amount);
|
||||
// orderInfo.setTotalFee(Integer.parseInt(CreditsEventsEnum.PRICE.getValue()) * amount); // 元 HKD
|
||||
orderInfo.setTotalFee((float) (product.getPrice() * amount)); // 元 HKD
|
||||
orderInfo.setOrderStatus(OrderStatusEnum.NOT_PAY.getType()); //未支付
|
||||
orderInfo.setPaymentType(paymentType);
|
||||
setIPLocation(paymentType, request, orderInfo);
|
||||
baseMapper.insert(orderInfo);
|
||||
|
||||
return orderInfo;
|
||||
}
|
||||
|
||||
|
||||
@@ -84,17 +84,17 @@ public class PayPalCheckoutServiceImpl implements PayPalCheckoutService {
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public HashMap<String, String> createOrder(Integer amount, String returnUrl) throws SerializeException {
|
||||
public HashMap<String, String> createOrder(Integer amount, String returnUrl, HttpServletRequest request) throws SerializeException {
|
||||
// 生成订单
|
||||
log.info("生成订单");
|
||||
OrderInfo orderInfo = orderInfoService.createOrderByProductId(amount, PayTypeEnum.PAYPAL.getType());
|
||||
OrderInfo orderInfo = orderInfoService.createOrderByProductId(amount, PayTypeEnum.PAYPAL.getType(), request);
|
||||
|
||||
OrdersCreateRequest request = new OrdersCreateRequest();
|
||||
request.header("prefer", "return=representation");
|
||||
request.requestBody(buildRequestBody(String.valueOf(orderInfo.getTotalFee()), returnUrl));
|
||||
OrdersCreateRequest paypalRequest = new OrdersCreateRequest();
|
||||
paypalRequest.header("prefer", "return=representation");
|
||||
paypalRequest.requestBody(buildRequestBody(String.valueOf(orderInfo.getTotalFee()), returnUrl));
|
||||
HttpResponse<Order> response = null;
|
||||
try {
|
||||
response = payPalClient.client(mode, clientId, clientSecret).execute(request);
|
||||
response = payPalClient.client(mode, clientId, clientSecret).execute(paypalRequest);
|
||||
} catch (Exception e) {
|
||||
log.error("调用paypal订单创建失败,失败原因 ===> {}", e.getMessage());
|
||||
throw new BusinessException("Order creation failed");
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.ai.da.common.context.UserContext;
|
||||
import com.ai.da.common.enums.PayTypeEnum;
|
||||
import com.ai.da.common.response.PageBaseResponse;
|
||||
import com.ai.da.mapper.primary.PaymentInfoMapper;
|
||||
import com.ai.da.mapper.primary.entity.OrderInfo;
|
||||
import com.ai.da.mapper.primary.entity.PaymentInfo;
|
||||
import com.ai.da.model.dto.AlipayHKCallbackDTO;
|
||||
import com.ai.da.model.dto.QueryPageByTimeDTO;
|
||||
@@ -44,6 +45,9 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
|
||||
@Resource
|
||||
private StripeService stripeService;
|
||||
|
||||
@Resource
|
||||
private OrderInfoService orderInfoService;
|
||||
|
||||
/**
|
||||
* 记录支付日志:微信支付
|
||||
* @param plainText
|
||||
@@ -111,7 +115,13 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
|
||||
Gson gson = new Gson();
|
||||
String json = gson.toJson(params, HashMap.class);
|
||||
paymentInfo.setContent(json);
|
||||
|
||||
// 获取订单信息
|
||||
OrderInfo orderByOrderNo = orderInfoService.getOrderByOrderNo(orderNo);
|
||||
if (!Objects.isNull(orderByOrderNo)){
|
||||
paymentInfo.setCountry(orderByOrderNo.getCountry());
|
||||
paymentInfo.setCity(orderByOrderNo.getCity());
|
||||
paymentInfo.setIpAddress(orderByOrderNo.getIpAddress());
|
||||
}
|
||||
baseMapper.insert(paymentInfo);
|
||||
}
|
||||
|
||||
@@ -128,13 +138,19 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
|
||||
paymentInfo.setPaymentType(PayTypeEnum.PAYPAL.getType());
|
||||
paymentInfo.setTransactionId(order.id());
|
||||
paymentInfo.setTradeState(order.status());
|
||||
// todo 确认这里的数据单位是不是元
|
||||
// 确认这里的数据单位是不是元
|
||||
paymentInfo.setPayerTotal(totalAmountFloat);
|
||||
|
||||
Gson gson = new Gson();
|
||||
String json = gson.toJson(order, Order.class);
|
||||
paymentInfo.setContent(json);
|
||||
|
||||
// 获取订单信息
|
||||
OrderInfo orderByOrderNo = orderInfoService.getOrderByOrderNo(order.id());
|
||||
if (!Objects.isNull(orderByOrderNo)){
|
||||
paymentInfo.setCountry(orderByOrderNo.getCountry());
|
||||
paymentInfo.setCity(orderByOrderNo.getCity());
|
||||
paymentInfo.setIpAddress(orderByOrderNo.getIpAddress());
|
||||
}
|
||||
baseMapper.insert(paymentInfo);
|
||||
}
|
||||
|
||||
@@ -164,7 +180,13 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
|
||||
Gson gson = new Gson();
|
||||
String json = gson.toJson(alipayHKCallbackDTO);
|
||||
paymentInfo.setContent(json);
|
||||
|
||||
// 获取订单信息
|
||||
OrderInfo orderByOrderNo = orderInfoService.getOrderByOrderNo(orderNo);
|
||||
if (!Objects.isNull(orderByOrderNo)){
|
||||
paymentInfo.setCountry(orderByOrderNo.getCountry());
|
||||
paymentInfo.setCity(orderByOrderNo.getCity());
|
||||
paymentInfo.setIpAddress(orderByOrderNo.getIpAddress());
|
||||
}
|
||||
baseMapper.insert(paymentInfo);
|
||||
}
|
||||
|
||||
@@ -186,7 +208,13 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
|
||||
Gson gson = new Gson();
|
||||
String json = gson.toJson(session);
|
||||
paymentInfo.setContent(json);
|
||||
|
||||
// 获取订单信息
|
||||
OrderInfo orderByOrderNo = orderInfoService.getOrderByOrderNo(orderId);
|
||||
if (!Objects.isNull(orderByOrderNo)){
|
||||
paymentInfo.setCountry(orderByOrderNo.getCountry());
|
||||
paymentInfo.setCity(orderByOrderNo.getCity());
|
||||
paymentInfo.setIpAddress(orderByOrderNo.getIpAddress());
|
||||
}
|
||||
baseMapper.insert(paymentInfo);
|
||||
}
|
||||
|
||||
@@ -228,7 +256,10 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
|
||||
String type = invoice.getBillingReason().equals("subscription_create") ? "new" :
|
||||
invoice.getBillingReason().equals("subscription_cycle") ? "renewal" : invoice.getBillingReason();
|
||||
|
||||
// 获取支付方式
|
||||
Map<String, String> paymentMethod = stripeService.getPaymentMethodByInvoiceId(invoiceId);
|
||||
// 获取订单信息
|
||||
OrderInfo orderByOrderNo = orderInfoService.getOrderByOrderNo(orderNo);
|
||||
|
||||
paymentInfo = new PaymentInfo();
|
||||
paymentInfo.setOrderNo(orderNo);
|
||||
@@ -246,7 +277,11 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
|
||||
paymentInfo.setLast4(paymentMethod.get("last4"));
|
||||
paymentInfo.setHostedInvoiceUrl(invoice.getHostedInvoiceUrl());
|
||||
paymentInfo.setCreateTime(LocalDateTime.now());
|
||||
|
||||
if (!Objects.isNull(orderByOrderNo)){
|
||||
paymentInfo.setCountry(orderByOrderNo.getCountry());
|
||||
paymentInfo.setCity(orderByOrderNo.getCity());
|
||||
paymentInfo.setIpAddress(orderByOrderNo.getIpAddress());
|
||||
}
|
||||
baseMapper.insert(paymentInfo);
|
||||
}else {
|
||||
paymentInfo.setTradeState(status);
|
||||
@@ -298,9 +333,11 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
|
||||
if (Objects.isNull(paymentInfo)){
|
||||
Stripe.apiKey = privateKey;
|
||||
|
||||
String orderNo = charge.getDescription().replace("AiDA - ", "");
|
||||
OrderInfo orderByOrderNo = orderInfoService.getOrderByOrderNo(orderNo);
|
||||
Float divide = new BigDecimal(charge.getAmount()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).floatValue();
|
||||
paymentInfo = new PaymentInfo();
|
||||
paymentInfo.setOrderNo(charge.getDescription().replace("AiDA - ", ""));
|
||||
paymentInfo.setOrderNo(orderNo);
|
||||
paymentInfo.setTransactionId(charge.getInvoice());
|
||||
paymentInfo.setPaymentType(PayTypeEnum.STRIPE.getType());
|
||||
paymentInfo.setTradeState(charge.getStatus());
|
||||
@@ -309,6 +346,11 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
|
||||
paymentInfo.setPaymentMethod(paymentMethod);
|
||||
paymentInfo.setLast4(last4);
|
||||
paymentInfo.setCreateTime(LocalDateTime.now());
|
||||
if (!Objects.isNull(orderByOrderNo)){
|
||||
paymentInfo.setCountry(orderByOrderNo.getCountry());
|
||||
paymentInfo.setCity(orderByOrderNo.getCity());
|
||||
paymentInfo.setIpAddress(orderByOrderNo.getIpAddress());
|
||||
}
|
||||
baseMapper.insert(paymentInfo);
|
||||
}else {
|
||||
paymentInfo.setTradeState(charge.getStatus());
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.ai.da.common.constant.CommonConstant;
|
||||
import com.ai.da.common.context.UserContext;
|
||||
import com.ai.da.common.enums.*;
|
||||
import com.ai.da.common.utils.DateUtil;
|
||||
import com.ai.da.common.utils.RequestInfoUtil;
|
||||
import com.ai.da.common.utils.SendEmailUtil;
|
||||
import com.ai.da.mapper.primary.AccountMapper;
|
||||
import com.ai.da.mapper.primary.PaymentInfoMapper;
|
||||
@@ -18,7 +17,6 @@ import com.ai.da.model.dto.ProductPurchaseDTO;
|
||||
import com.ai.da.model.dto.SubscriptionEmailParamsDTO;
|
||||
import com.ai.da.service.*;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.google.gson.Gson;
|
||||
@@ -38,12 +36,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
@@ -85,7 +79,7 @@ public class StripeServiceImpl implements StripeService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String pay(ProductPurchaseDTO productPurchaseDTO) {
|
||||
public String pay(ProductPurchaseDTO productPurchaseDTO, HttpServletRequest request) {
|
||||
Stripe.apiKey = privateKey;
|
||||
|
||||
ProductEnum productEnum;
|
||||
@@ -102,9 +96,9 @@ public class StripeServiceImpl implements StripeService {
|
||||
case "Year":
|
||||
productEnum = ProductEnum.AnnualSubscription;
|
||||
break;
|
||||
case "Day":
|
||||
/*case "Day":
|
||||
productEnum = ProductEnum.DailySubscription;
|
||||
break;
|
||||
break;*/
|
||||
default:
|
||||
throw new BusinessException("unknown subscription type");
|
||||
}
|
||||
@@ -113,7 +107,8 @@ public class StripeServiceImpl implements StripeService {
|
||||
throw new BusinessException("unknown product type");
|
||||
}
|
||||
log.info("生成订单");
|
||||
OrderInfo orderInfo = orderInfoService.createOrderByProductId(productPurchaseDTO.getQuantity(), PayTypeEnum.STRIPE.getType(), productEnum);
|
||||
OrderInfo orderInfo = orderInfoService.createOrderByProductId(productPurchaseDTO.getQuantity(),
|
||||
PayTypeEnum.STRIPE.getType(), productEnum, request);
|
||||
String payType;
|
||||
if (productPurchaseDTO.getAutoRenewal()){
|
||||
payType = "recurring";
|
||||
@@ -356,7 +351,6 @@ public class StripeServiceImpl implements StripeService {
|
||||
// 发送续订失败邮件
|
||||
response = sendRenewalFailEmail(invoice.getId(), null, paymentInfo.getOrderNo());
|
||||
}
|
||||
|
||||
}
|
||||
}else if (stripeObject instanceof Charge) {
|
||||
Charge charge = (Charge) stripeObject;
|
||||
@@ -1005,12 +999,11 @@ public class StripeServiceImpl implements StripeService {
|
||||
}
|
||||
}
|
||||
|
||||
// todo 新建一个订阅 使用不会成功的付款方式
|
||||
|
||||
// 新建一个订阅 使用不会成功的付款方式(仅供测试使用)
|
||||
public String createSubscriptionTemp(String name, String email){
|
||||
Stripe.apiKey = privateKey;
|
||||
try {
|
||||
OrderInfo orderInfo = orderInfoService.createOrderByProductId(1, PayTypeEnum.STRIPE.getType(), ProductEnum.DailySubscription);
|
||||
OrderInfo orderInfo = orderInfoService.createOrderByProductId(1, PayTypeEnum.STRIPE.getType(), ProductEnum.DailySubscription, null);
|
||||
|
||||
// String customerId = getCustomer(name, email);
|
||||
String paymentMethodCode = "pm_card_mastercard";
|
||||
@@ -1030,8 +1023,7 @@ public class StripeServiceImpl implements StripeService {
|
||||
.setInvoiceSettings(
|
||||
CustomerUpdateParams.InvoiceSettings.builder()
|
||||
.setDefaultPaymentMethod(paymentMethod.getId())
|
||||
.build()
|
||||
)
|
||||
.build())
|
||||
.build();
|
||||
updatedCustomer.update(params);
|
||||
|
||||
@@ -1041,8 +1033,7 @@ public class StripeServiceImpl implements StripeService {
|
||||
.addItem(
|
||||
SubscriptionCreateParams.Item.builder()
|
||||
.setPrice("price_1QFXkf02n1TEydyNtA4TQ3Yz") // 替换为实际的价格 ID
|
||||
.build()
|
||||
)
|
||||
.build())
|
||||
.setDescription("AiDA - " + orderInfo.getOrderNo())
|
||||
.build();
|
||||
Subscription subscription = Subscription.create(subscriptionParams);
|
||||
@@ -1151,96 +1142,12 @@ public class StripeServiceImpl implements StripeService {
|
||||
}
|
||||
}
|
||||
|
||||
public String getIp2(HttpServletRequest request) {
|
||||
/*String ip = request.getHeader("X-Forwarded-For");
|
||||
String ipAddress = "";
|
||||
if(StringUtils.isNotEmpty(ip) && !"unKnown".equalsIgnoreCase(ip)){
|
||||
//多次反向代理后会有多个ip值,第一个ip才是真实ip
|
||||
int index = ip.indexOf(",");
|
||||
if(index != -1){
|
||||
ipAddress = ip.substring(0,index);
|
||||
}else{
|
||||
ipAddress = ip;
|
||||
}
|
||||
}
|
||||
ip = request.getHeader("X-Real-IP");
|
||||
if(StringUtils.isNotEmpty(ip) && !"unKnown".equalsIgnoreCase(ip)){
|
||||
ipAddress = ip;
|
||||
}
|
||||
if (!StringUtil.isNullOrEmpty(ipAddress)) {
|
||||
getIPLocation(ipAddress);
|
||||
}*/
|
||||
String ipAddress = RequestInfoUtil.getIpAddress(request);
|
||||
if (!StringUtil.isNullOrEmpty(ipAddress)) {
|
||||
return getIPLocation(ipAddress);
|
||||
}
|
||||
|
||||
return request.getRemoteAddr();
|
||||
}
|
||||
|
||||
/* 免费 API 服务可能有请求频率限制,如果你需要处理大量 IP 地址,可能需要考虑使用付费服务或购买 IP 地理位置数据库。此外,始终要遵守 API 提供商的使用条款和隐私政策。*/
|
||||
|
||||
public String getIPLocation(String ip) {
|
||||
// String ip = "117.143.125.1"; // 替换为你想查询的 IP 地址
|
||||
// String ip = "194.5.48.180"; // 替换为你想查询的 IP 地址
|
||||
String apiURL = "http://ip-api.com/json/" + ip;
|
||||
|
||||
try {
|
||||
URL url = new URL(apiURL);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setRequestProperty("Accept", "application/json");
|
||||
|
||||
if (conn.getResponseCode() != 200) {
|
||||
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
|
||||
}
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
String output;
|
||||
StringBuilder outputBuilder = new StringBuilder();
|
||||
System.out.println("Output from Server .... \n");
|
||||
while ((output = br.readLine()) != null) {
|
||||
outputBuilder.append(output);
|
||||
System.out.println(output);
|
||||
}
|
||||
conn.disconnect();
|
||||
Map map = JSONObject.parseObject(outputBuilder.toString(), Map.class);
|
||||
log.info("map: {}", map);
|
||||
return JSON.toJSONString(map);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String ip = "117.143.125.1"; // 替换为你想查询的 IP 地址
|
||||
// String ip = "194.5.48.180"; // 替换为你想查询的 IP 地址
|
||||
String apiURL = "http://ip-api.com/json/" + ip;
|
||||
|
||||
try {
|
||||
URL url = new URL(apiURL);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setRequestProperty("Accept", "application/json");
|
||||
|
||||
if (conn.getResponseCode() != 200) {
|
||||
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
|
||||
}
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
String output;
|
||||
System.out.println("Output from Server .... \n");
|
||||
StringBuilder outputBuilder = new StringBuilder();
|
||||
while ((output = br.readLine()) != null) {
|
||||
outputBuilder.append(output);
|
||||
System.out.println(output);
|
||||
}
|
||||
conn.disconnect();
|
||||
Map map = JSONObject.parseObject(outputBuilder.toString(), Map.class);
|
||||
log.info("map: {}", map);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// public String getIp(HttpServletRequest request) {
|
||||
// String ipAddress = RequestInfoUtil.getIpAddress(request);
|
||||
// if (!StringUtil.isNullOrEmpty(ipAddress)) {
|
||||
// return getIPLocation(ipAddress);
|
||||
// }
|
||||
//
|
||||
// return request.getRemoteAddr();
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user