解析所有发起购买的客户端ip地址
This commit is contained in:
@@ -7,10 +7,12 @@ import lombok.Getter;
|
|||||||
@Getter
|
@Getter
|
||||||
public enum CreditsEventsEnum {
|
public enum CreditsEventsEnum {
|
||||||
|
|
||||||
PRICE("price","6"),
|
// PRICE("price","6"),
|
||||||
|
PRICE("price","1"),// for test
|
||||||
// PRICE("price","0.1"),
|
// PRICE("price","0.1"),
|
||||||
|
|
||||||
BUY_CREDITS("Buy Credits","60"),
|
// BUY_CREDITS("Buy Credits","60"),
|
||||||
|
BUY_CREDITS("Buy Credits","10"),// for test
|
||||||
|
|
||||||
REFUND("Refund","60"),
|
REFUND("Refund","60"),
|
||||||
// BUY_CREDITS("Buy Credits","10"),
|
// BUY_CREDITS("Buy Credits","10"),
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
package com.ai.da.common.utils;
|
package com.ai.da.common.utils;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public class RequestInfoUtil {
|
public class RequestInfoUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,4 +54,58 @@ public class RequestInfoUtil {
|
|||||||
return ip;
|
return ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 免费 API 服务可能有请求频率限制,如果你需要处理大量 IP 地址,可能需要考虑使用付费服务或购买 IP 地理位置数据库。此外,始终要遵守 API 提供商的使用条款和隐私政策
|
||||||
|
* @param ip
|
||||||
|
* @return
|
||||||
|
* {
|
||||||
|
* "query": "24.48.0.1",
|
||||||
|
* "status": "success",
|
||||||
|
* "country": "Canada",
|
||||||
|
* "countryCode": "CA",
|
||||||
|
* "region": "QC",
|
||||||
|
* "regionName": "Quebec",
|
||||||
|
* "city": "Montreal",
|
||||||
|
* "zip": "H1L",
|
||||||
|
* "lat": 45.6026,
|
||||||
|
* "lon": -73.5167,
|
||||||
|
* "timezone": "America/Toronto",
|
||||||
|
* "isp": "Le Groupe Videotron Ltee",
|
||||||
|
* "org": "Videotron Ltee",
|
||||||
|
* "as": "AS5769 Videotron Ltee"
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
public static Map 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 map;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@@ -22,11 +23,11 @@ public class AliPayController {
|
|||||||
|
|
||||||
@ApiOperation("统一收单下单并支付页面接口的调用")
|
@ApiOperation("统一收单下单并支付页面接口的调用")
|
||||||
@PostMapping("/trade/page/pay/{amount}")
|
@PostMapping("/trade/page/pay/{amount}")
|
||||||
public Response<String> tradePagePay(@PathVariable Integer amount, @RequestParam String returnUrl){
|
public Response<String> tradePagePay(@PathVariable Integer amount, @RequestParam String returnUrl, HttpServletRequest request){
|
||||||
log.info("统一收单下单并支付页面接口的调用");
|
log.info("统一收单下单并支付页面接口的调用");
|
||||||
//支付宝开放平台接受 request 请求对象后
|
//支付宝开放平台接受 request 请求对象后
|
||||||
// 会为开发者生成一个html 形式的 form表单,包含自动提交的脚本
|
// 会为开发者生成一个html 形式的 form表单,包含自动提交的脚本
|
||||||
String formStr = aliPayService.tradeCreate(amount, returnUrl);
|
String formStr = aliPayService.tradeCreate(amount, returnUrl, request);
|
||||||
//我们将form表单字符串返回给前端程序,之后前端将会调用自动提交脚本,进行表单的提交
|
//我们将form表单字符串返回给前端程序,之后前端将会调用自动提交脚本,进行表单的提交
|
||||||
//此时,表单会自动提交到action属性所指向的支付宝开放平台中,从而为用户展示一个支付页面
|
//此时,表单会自动提交到action属性所指向的支付宝开放平台中,从而为用户展示一个支付页面
|
||||||
return Response.success(formStr);
|
return Response.success(formStr);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@RestController
|
@RestController
|
||||||
@@ -21,8 +22,8 @@ public class AlipayHKController {
|
|||||||
|
|
||||||
@ApiOperation(value = "创建订单")
|
@ApiOperation(value = "创建订单")
|
||||||
@PostMapping(value = "/createOrder/{wallet}/{amount}")
|
@PostMapping(value = "/createOrder/{wallet}/{amount}")
|
||||||
public Response<String> createOrder(@PathVariable Integer amount, @PathVariable String wallet) {
|
public Response<String> createOrder(@PathVariable Integer amount, @PathVariable String wallet, HttpServletRequest request) {
|
||||||
String order = alipayHKService.createOrder(amount, wallet);
|
String order = alipayHKService.createOrder(amount, wallet, request);
|
||||||
return Response.success(order);
|
return Response.success(order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ public class PayPalCheckoutController {
|
|||||||
|
|
||||||
@ApiOperation(value = "创建订单")
|
@ApiOperation(value = "创建订单")
|
||||||
@PostMapping(value = "/trade/{amount}")
|
@PostMapping(value = "/trade/{amount}")
|
||||||
public Response<HashMap<String, String>> createOrder(@PathVariable Integer amount, @RequestParam String returnUrl) throws SerializeException {
|
public Response<HashMap<String, String>> createOrder(@PathVariable Integer amount, @RequestParam String returnUrl, HttpServletRequest request) throws SerializeException {
|
||||||
HashMap<String, String> approvalUrl = payPalCheckoutService.createOrder(amount,returnUrl);
|
HashMap<String, String> approvalUrl = payPalCheckoutService.createOrder(amount, returnUrl, request);
|
||||||
return Response.success(approvalUrl);
|
return Response.success(approvalUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ public class StripeController {
|
|||||||
|
|
||||||
@ApiOperation("创建支付链接")
|
@ApiOperation("创建支付链接")
|
||||||
@PostMapping("/createOrder")
|
@PostMapping("/createOrder")
|
||||||
public Response<String> pay(@Valid @RequestBody ProductPurchaseDTO productPurchaseDTO) {
|
public Response<String> pay(@Valid @RequestBody ProductPurchaseDTO productPurchaseDTO, HttpServletRequest request) {
|
||||||
return Response.success(stripeService.pay(productPurchaseDTO));
|
return Response.success(stripeService.pay(productPurchaseDTO, request));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("支付通知")
|
@ApiOperation("支付通知")
|
||||||
@@ -75,7 +75,7 @@ public class StripeController {
|
|||||||
stripeService.cancelSubscription(subscriptionId, reason);
|
stripeService.cancelSubscription(subscriptionId, reason);
|
||||||
return Response.success("success");
|
return Response.success("success");
|
||||||
}
|
}
|
||||||
@ApiOperation("临时 取消订阅")
|
/*@ApiOperation("临时 取消订阅")
|
||||||
@GetMapping("/cancelSubscriptionTemp")
|
@GetMapping("/cancelSubscriptionTemp")
|
||||||
public Response<String> cancelSubscriptionTemp(@RequestParam String subscriptionId) {
|
public Response<String> cancelSubscriptionTemp(@RequestParam String subscriptionId) {
|
||||||
stripeService.cancelSubscriptionTemp(subscriptionId);
|
stripeService.cancelSubscriptionTemp(subscriptionId);
|
||||||
@@ -110,12 +110,7 @@ public class StripeController {
|
|||||||
@GetMapping("/detachCustomerAllPaymentMethod")
|
@GetMapping("/detachCustomerAllPaymentMethod")
|
||||||
public Response<String> detachCustomerAllPaymentMethod(@RequestParam String name, @RequestParam String email) {
|
public Response<String> detachCustomerAllPaymentMethod(@RequestParam String name, @RequestParam String email) {
|
||||||
return Response.success(stripeService.detachCustomerAllPaymentMethod(name, email));
|
return Response.success(stripeService.detachCustomerAllPaymentMethod(name, email));
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@ApiOperation("临时 获取ip")
|
|
||||||
@GetMapping("/getIp2")
|
|
||||||
public Response<String> getIp2(HttpServletRequest request) {
|
|
||||||
return Response.success(stripeService.getIp2(request));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,4 +29,10 @@ public class OrderInfo extends BaseEntity{
|
|||||||
private byte isFirstSubscription = 0;
|
private byte isFirstSubscription = 0;
|
||||||
|
|
||||||
private byte isCommissionCalculated = 0;
|
private byte isCommissionCalculated = 0;
|
||||||
|
|
||||||
|
private String ipAddress;
|
||||||
|
|
||||||
|
private String country;
|
||||||
|
|
||||||
|
private String city;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,4 +33,10 @@ public class PaymentInfo extends BaseEntity{
|
|||||||
|
|
||||||
// 发票托管页面
|
// 发票托管页面
|
||||||
private String hostedInvoiceUrl;
|
private String hostedInvoiceUrl;
|
||||||
|
|
||||||
|
private String ipAddress;
|
||||||
|
|
||||||
|
private String country;
|
||||||
|
|
||||||
|
private String city;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package com.ai.da.service;
|
package com.ai.da.service;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface AliPayService {
|
public interface AliPayService {
|
||||||
String tradeCreate(Integer amount,String returnUrl);
|
String tradeCreate(Integer amount,String returnUrl, HttpServletRequest request);
|
||||||
|
|
||||||
String tradeNotify(Map<String, String> params);
|
String tradeNotify(Map<String, String> params);
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ package com.ai.da.service;
|
|||||||
|
|
||||||
import com.ai.da.model.dto.AlipayHKCallbackDTO;
|
import com.ai.da.model.dto.AlipayHKCallbackDTO;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
public interface AlipayHKService {
|
public interface AlipayHKService {
|
||||||
|
|
||||||
String createOrder(Integer amount, String wallet);
|
String createOrder(Integer amount, String wallet, HttpServletRequest request);
|
||||||
|
|
||||||
String callback(String paramString);
|
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.ai.da.model.dto.QueryPageByTimeDTO;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface OrderInfoService extends IService<OrderInfo> {
|
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);
|
void saveCodeUrl(String orderNo, String codeUrl);
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
public interface PayPalCheckoutService {
|
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);
|
// String callback(@SuppressWarnings("rawtypes") Map map);
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
public interface StripeService {
|
public interface StripeService {
|
||||||
|
|
||||||
String pay(ProductPurchaseDTO productPurchaseDTO);
|
String pay(ProductPurchaseDTO productPurchaseDTO, HttpServletRequest request);
|
||||||
|
|
||||||
Boolean notify(HttpServletRequest request);
|
Boolean notify(HttpServletRequest request);
|
||||||
|
|
||||||
@@ -48,5 +48,5 @@ public interface StripeService {
|
|||||||
|
|
||||||
String detachCustomerAllPaymentMethod(String name, String email);
|
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 org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -54,21 +55,21 @@ public class AliPayServiceImpl implements AliPayService {
|
|||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@Override
|
@Override
|
||||||
public String tradeCreate(Integer amount, String returnUrl) {
|
public String tradeCreate(Integer amount, String returnUrl, HttpServletRequest request) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//生成订单
|
//生成订单
|
||||||
log.info("生成订单");
|
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
|
//支付完成后,我们想让页面跳转回aida的页面,配置returnUrl
|
||||||
// request.setReturnUrl(config.getProperty("alipay.return-url"));
|
// alipayRequest.setReturnUrl(config.getProperty("alipay.return-url"));
|
||||||
request.setReturnUrl(returnUrl);
|
alipayRequest.setReturnUrl(returnUrl);
|
||||||
|
|
||||||
//组装当前业务方法的请求参数
|
//组装当前业务方法的请求参数
|
||||||
JSONObject bizContent = new JSONObject();
|
JSONObject bizContent = new JSONObject();
|
||||||
@@ -79,10 +80,10 @@ public class AliPayServiceImpl implements AliPayService {
|
|||||||
bizContent.put("subject", "积分购买");
|
bizContent.put("subject", "积分购买");
|
||||||
bizContent.put("product_code", "FAST_INSTANT_TRADE_PAY");
|
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()){
|
if(response.isSuccess()){
|
||||||
log.info("调用成功,返回结果 ===> " + response.getBody());
|
log.info("调用成功,返回结果 ===> " + response.getBody());
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -64,7 +65,7 @@ public class AlipayHKServiceImpl implements AlipayHKService {
|
|||||||
* 创建订单
|
* 创建订单
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String createOrder(Integer amount, String wallet){
|
public String createOrder(Integer amount, String wallet , HttpServletRequest request){
|
||||||
|
|
||||||
try{
|
try{
|
||||||
HashMap<String, Object> param = new HashMap<>();
|
HashMap<String, Object> param = new HashMap<>();
|
||||||
@@ -80,7 +81,7 @@ public class AlipayHKServiceImpl implements AlipayHKService {
|
|||||||
log.info("alipay-hk 创建订单,参数信息: {}", param);
|
log.info("alipay-hk 创建订单,参数信息: {}", param);
|
||||||
// 生成订单
|
// 生成订单
|
||||||
log.info("创建订单");
|
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);
|
AlipayHKRequestDTO alipayHKRequestDTO = alipayHKEncryptionUtil.AESCBCWithRSA(param, AlipayHKConstant.CREATE_ORDER);
|
||||||
// 请求Alipay服务端
|
// 请求Alipay服务端
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.ai.da.common.enums.OrderStatusEnum;
|
|||||||
import com.ai.da.common.enums.ProductEnum;
|
import com.ai.da.common.enums.ProductEnum;
|
||||||
import com.ai.da.common.response.PageBaseResponse;
|
import com.ai.da.common.response.PageBaseResponse;
|
||||||
import com.ai.da.common.utils.OrderNoUtils;
|
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.OrderInfoMapper;
|
||||||
import com.ai.da.mapper.primary.PaymentInfoMapper;
|
import com.ai.da.mapper.primary.PaymentInfoMapper;
|
||||||
import com.ai.da.mapper.primary.ProductMapper;
|
import com.ai.da.mapper.primary.ProductMapper;
|
||||||
@@ -25,11 +26,14 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -42,7 +46,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||||||
private PaymentInfoMapper paymentInfoMapper;
|
private PaymentInfoMapper paymentInfoMapper;
|
||||||
|
|
||||||
@Override
|
@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.setProductId(amount);
|
||||||
// orderInfo.setTotalFee(Integer.parseInt(CreditsEventsEnum.PRICE.getValue()) * amount); // 元 HKD
|
// orderInfo.setTotalFee(Integer.parseInt(CreditsEventsEnum.PRICE.getValue()) * amount); // 元 HKD
|
||||||
orderInfo.setTotalFee(Float.parseFloat(CreditsEventsEnum.PRICE.getValue()) * amount); // 元 HKD
|
orderInfo.setTotalFee(Float.parseFloat(CreditsEventsEnum.PRICE.getValue()) * amount); // 元 HKD
|
||||||
orderInfo.setOrderStatus(OrderStatusEnum.NOT_PAY.getType()); //未支付
|
setIPLocation(paymentType, request, orderInfo);
|
||||||
orderInfo.setPaymentType(paymentType);
|
|
||||||
baseMapper.insert(orderInfo);
|
baseMapper.insert(orderInfo);
|
||||||
|
|
||||||
return 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);
|
// Product product = productMapper.selectById(amount);
|
||||||
@@ -92,10 +110,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||||||
// orderInfo.setProductId(amount);
|
// orderInfo.setProductId(amount);
|
||||||
// orderInfo.setTotalFee(Integer.parseInt(CreditsEventsEnum.PRICE.getValue()) * amount); // 元 HKD
|
// orderInfo.setTotalFee(Integer.parseInt(CreditsEventsEnum.PRICE.getValue()) * amount); // 元 HKD
|
||||||
orderInfo.setTotalFee((float) (product.getPrice() * amount)); // 元 HKD
|
orderInfo.setTotalFee((float) (product.getPrice() * amount)); // 元 HKD
|
||||||
orderInfo.setOrderStatus(OrderStatusEnum.NOT_PAY.getType()); //未支付
|
setIPLocation(paymentType, request, orderInfo);
|
||||||
orderInfo.setPaymentType(paymentType);
|
|
||||||
baseMapper.insert(orderInfo);
|
baseMapper.insert(orderInfo);
|
||||||
|
|
||||||
return orderInfo;
|
return orderInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,17 +84,17 @@ public class PayPalCheckoutServiceImpl implements PayPalCheckoutService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@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("生成订单");
|
log.info("生成订单");
|
||||||
OrderInfo orderInfo = orderInfoService.createOrderByProductId(amount, PayTypeEnum.PAYPAL.getType());
|
OrderInfo orderInfo = orderInfoService.createOrderByProductId(amount, PayTypeEnum.PAYPAL.getType(), request);
|
||||||
|
|
||||||
OrdersCreateRequest request = new OrdersCreateRequest();
|
OrdersCreateRequest paypalRequest = new OrdersCreateRequest();
|
||||||
request.header("prefer", "return=representation");
|
paypalRequest.header("prefer", "return=representation");
|
||||||
request.requestBody(buildRequestBody(String.valueOf(orderInfo.getTotalFee()), returnUrl));
|
paypalRequest.requestBody(buildRequestBody(String.valueOf(orderInfo.getTotalFee()), returnUrl));
|
||||||
HttpResponse<Order> response = null;
|
HttpResponse<Order> response = null;
|
||||||
try {
|
try {
|
||||||
response = payPalClient.client(mode, clientId, clientSecret).execute(request);
|
response = payPalClient.client(mode, clientId, clientSecret).execute(paypalRequest);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("调用paypal订单创建失败,失败原因 ===> {}", e.getMessage());
|
log.error("调用paypal订单创建失败,失败原因 ===> {}", e.getMessage());
|
||||||
throw new BusinessException("Order creation failed");
|
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.enums.PayTypeEnum;
|
||||||
import com.ai.da.common.response.PageBaseResponse;
|
import com.ai.da.common.response.PageBaseResponse;
|
||||||
import com.ai.da.mapper.primary.PaymentInfoMapper;
|
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.mapper.primary.entity.PaymentInfo;
|
||||||
import com.ai.da.model.dto.AlipayHKCallbackDTO;
|
import com.ai.da.model.dto.AlipayHKCallbackDTO;
|
||||||
import com.ai.da.model.dto.QueryPageByTimeDTO;
|
import com.ai.da.model.dto.QueryPageByTimeDTO;
|
||||||
@@ -44,6 +45,9 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
|
|||||||
@Resource
|
@Resource
|
||||||
private StripeService stripeService;
|
private StripeService stripeService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private OrderInfoService orderInfoService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 记录支付日志:微信支付
|
* 记录支付日志:微信支付
|
||||||
* @param plainText
|
* @param plainText
|
||||||
@@ -111,7 +115,13 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
|
|||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
String json = gson.toJson(params, HashMap.class);
|
String json = gson.toJson(params, HashMap.class);
|
||||||
paymentInfo.setContent(json);
|
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);
|
baseMapper.insert(paymentInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,13 +138,19 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
|
|||||||
paymentInfo.setPaymentType(PayTypeEnum.PAYPAL.getType());
|
paymentInfo.setPaymentType(PayTypeEnum.PAYPAL.getType());
|
||||||
paymentInfo.setTransactionId(order.id());
|
paymentInfo.setTransactionId(order.id());
|
||||||
paymentInfo.setTradeState(order.status());
|
paymentInfo.setTradeState(order.status());
|
||||||
// todo 确认这里的数据单位是不是元
|
// 确认这里的数据单位是不是元
|
||||||
paymentInfo.setPayerTotal(totalAmountFloat);
|
paymentInfo.setPayerTotal(totalAmountFloat);
|
||||||
|
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
String json = gson.toJson(order, Order.class);
|
String json = gson.toJson(order, Order.class);
|
||||||
paymentInfo.setContent(json);
|
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);
|
baseMapper.insert(paymentInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,7 +180,13 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
|
|||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
String json = gson.toJson(alipayHKCallbackDTO);
|
String json = gson.toJson(alipayHKCallbackDTO);
|
||||||
paymentInfo.setContent(json);
|
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);
|
baseMapper.insert(paymentInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +208,13 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
|
|||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
String json = gson.toJson(session);
|
String json = gson.toJson(session);
|
||||||
paymentInfo.setContent(json);
|
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);
|
baseMapper.insert(paymentInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,7 +256,10 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
|
|||||||
String type = invoice.getBillingReason().equals("subscription_create") ? "new" :
|
String type = invoice.getBillingReason().equals("subscription_create") ? "new" :
|
||||||
invoice.getBillingReason().equals("subscription_cycle") ? "renewal" : invoice.getBillingReason();
|
invoice.getBillingReason().equals("subscription_cycle") ? "renewal" : invoice.getBillingReason();
|
||||||
|
|
||||||
|
// 获取支付方式
|
||||||
Map<String, String> paymentMethod = stripeService.getPaymentMethodByInvoiceId(invoiceId);
|
Map<String, String> paymentMethod = stripeService.getPaymentMethodByInvoiceId(invoiceId);
|
||||||
|
// 获取订单信息
|
||||||
|
OrderInfo orderByOrderNo = orderInfoService.getOrderByOrderNo(orderNo);
|
||||||
|
|
||||||
paymentInfo = new PaymentInfo();
|
paymentInfo = new PaymentInfo();
|
||||||
paymentInfo.setOrderNo(orderNo);
|
paymentInfo.setOrderNo(orderNo);
|
||||||
@@ -246,7 +277,11 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
|
|||||||
paymentInfo.setLast4(paymentMethod.get("last4"));
|
paymentInfo.setLast4(paymentMethod.get("last4"));
|
||||||
paymentInfo.setHostedInvoiceUrl(invoice.getHostedInvoiceUrl());
|
paymentInfo.setHostedInvoiceUrl(invoice.getHostedInvoiceUrl());
|
||||||
paymentInfo.setCreateTime(LocalDateTime.now());
|
paymentInfo.setCreateTime(LocalDateTime.now());
|
||||||
|
if (!Objects.isNull(orderByOrderNo)){
|
||||||
|
paymentInfo.setCountry(orderByOrderNo.getCountry());
|
||||||
|
paymentInfo.setCity(orderByOrderNo.getCity());
|
||||||
|
paymentInfo.setIpAddress(orderByOrderNo.getIpAddress());
|
||||||
|
}
|
||||||
baseMapper.insert(paymentInfo);
|
baseMapper.insert(paymentInfo);
|
||||||
}else {
|
}else {
|
||||||
paymentInfo.setTradeState(status);
|
paymentInfo.setTradeState(status);
|
||||||
@@ -298,9 +333,11 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
|
|||||||
if (Objects.isNull(paymentInfo)){
|
if (Objects.isNull(paymentInfo)){
|
||||||
Stripe.apiKey = privateKey;
|
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();
|
Float divide = new BigDecimal(charge.getAmount()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).floatValue();
|
||||||
paymentInfo = new PaymentInfo();
|
paymentInfo = new PaymentInfo();
|
||||||
paymentInfo.setOrderNo(charge.getDescription().replace("AiDA - ", ""));
|
paymentInfo.setOrderNo(orderNo);
|
||||||
paymentInfo.setTransactionId(charge.getInvoice());
|
paymentInfo.setTransactionId(charge.getInvoice());
|
||||||
paymentInfo.setPaymentType(PayTypeEnum.STRIPE.getType());
|
paymentInfo.setPaymentType(PayTypeEnum.STRIPE.getType());
|
||||||
paymentInfo.setTradeState(charge.getStatus());
|
paymentInfo.setTradeState(charge.getStatus());
|
||||||
@@ -309,6 +346,11 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
|
|||||||
paymentInfo.setPaymentMethod(paymentMethod);
|
paymentInfo.setPaymentMethod(paymentMethod);
|
||||||
paymentInfo.setLast4(last4);
|
paymentInfo.setLast4(last4);
|
||||||
paymentInfo.setCreateTime(LocalDateTime.now());
|
paymentInfo.setCreateTime(LocalDateTime.now());
|
||||||
|
if (!Objects.isNull(orderByOrderNo)){
|
||||||
|
paymentInfo.setCountry(orderByOrderNo.getCountry());
|
||||||
|
paymentInfo.setCity(orderByOrderNo.getCity());
|
||||||
|
paymentInfo.setIpAddress(orderByOrderNo.getIpAddress());
|
||||||
|
}
|
||||||
baseMapper.insert(paymentInfo);
|
baseMapper.insert(paymentInfo);
|
||||||
}else {
|
}else {
|
||||||
paymentInfo.setTradeState(charge.getStatus());
|
paymentInfo.setTradeState(charge.getStatus());
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
##### PayPal
|
##### PayPal
|
||||||
|
|
||||||
# developer-sandbox-xp
|
# developer-sandbox-xp
|
||||||
#paypal.client-id=ATbaebYi7-GXWRWJqwRLYMzKEbwjh4BFRqD4Y13i4lZq0rplWIM_IpPrtPKpdkAt_KrPXd6IJTwsDqa5
|
paypal.client-id=ATbaebYi7-GXWRWJqwRLYMzKEbwjh4BFRqD4Y13i4lZq0rplWIM_IpPrtPKpdkAt_KrPXd6IJTwsDqa5
|
||||||
#paypal.client-secret=EHWWJqGmmbfjLXqCUpGrvxRYBPPtWvA3hR5ZaAyHlGSVJiHoQPS8skbNaJ9h39VObnchUbgiY2pPu__s
|
paypal.client-secret=EHWWJqGmmbfjLXqCUpGrvxRYBPPtWvA3hR5ZaAyHlGSVJiHoQPS8skbNaJ9h39VObnchUbgiY2pPu__s
|
||||||
#paypal.receiver.email=sb-ukxfk29608925@business.example.com
|
paypal.receiver.email=sb-ukxfk29608925@business.example.com
|
||||||
#paypal.mode=sandbox
|
paypal.mode=sandbox
|
||||||
# local
|
# local
|
||||||
#paypal.webhook_id=31797347YC028794L
|
paypal.webhook_id=31797347YC028794L
|
||||||
# dev
|
# dev
|
||||||
#paypal.webhook_id=51V87014T6406322F
|
#paypal.webhook_id=51V87014T6406322F
|
||||||
|
|
||||||
@@ -18,11 +18,11 @@
|
|||||||
#paypal.webhook_id=1WH327112B602422N
|
#paypal.webhook_id=1WH327112B602422N
|
||||||
|
|
||||||
# aida-live-kim
|
# aida-live-kim
|
||||||
paypal.client-id=ASWSIZ3MXJU5w5VOeOHeigWcSw6iinl30ZCipruziKpHclxP0ryf8-7VKG1Ba2VwZwa2DMvGEzTfCTgz
|
#paypal.client-id=ASWSIZ3MXJU5w5VOeOHeigWcSw6iinl30ZCipruziKpHclxP0ryf8-7VKG1Ba2VwZwa2DMvGEzTfCTgz
|
||||||
paypal.client-secret=EHQg_K5PSqmp4FJlzEcOEH_kFkmq4aBzaI7jridw53L6cOQRULBAnfv2KakRfrsqaU1PDSkO4Co9Vyxc
|
#paypal.client-secret=EHQg_K5PSqmp4FJlzEcOEH_kFkmq4aBzaI7jridw53L6cOQRULBAnfv2KakRfrsqaU1PDSkO4Co9Vyxc
|
||||||
paypal.receiver.email=kimwong@code-create.com.hk
|
#paypal.receiver.email=kimwong@code-create.com.hk
|
||||||
paypal.mode=live
|
#paypal.mode=live
|
||||||
paypal.webhook_id=1D107312EX592781K
|
#paypal.webhook_id=1D107312EX592781K
|
||||||
|
|
||||||
##### Stripe
|
##### Stripe
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user