|
@@ -6,10 +6,7 @@ import com.alibaba.fastjson.JSONObject;
|
|
import com.fdkankan.pay.common.AutoPayUtil;
|
|
import com.fdkankan.pay.common.AutoPayUtil;
|
|
import com.fdkankan.pay.common.ResultData;
|
|
import com.fdkankan.pay.common.ResultData;
|
|
import com.fdkankan.pay.entity.*;
|
|
import com.fdkankan.pay.entity.*;
|
|
-import com.fdkankan.pay.service.IAutopayOrderService;
|
|
|
|
-import com.fdkankan.pay.service.IAutopayOrderSonService;
|
|
|
|
-import com.fdkankan.pay.service.IOrderService;
|
|
|
|
-import com.fdkankan.pay.service.IStripeWebhookLogService;
|
|
|
|
|
|
+import com.fdkankan.pay.service.*;
|
|
import com.fdkankan.pay.util.CacheUtil;
|
|
import com.fdkankan.pay.util.CacheUtil;
|
|
import com.fdkankan.rabbitmq.util.RabbitMqProducer;
|
|
import com.fdkankan.rabbitmq.util.RabbitMqProducer;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -46,9 +43,11 @@ public class StripeController {
|
|
IAutopayOrderSonService autopayOrderSonService;
|
|
IAutopayOrderSonService autopayOrderSonService;
|
|
@Autowired
|
|
@Autowired
|
|
RabbitMqProducer rabbitMqProducer;
|
|
RabbitMqProducer rabbitMqProducer;
|
|
|
|
+ @Autowired
|
|
|
|
+ IStripeCustomerService stripeCustomerService;
|
|
|
|
|
|
@PostMapping("/webhook")
|
|
@PostMapping("/webhook")
|
|
- public ResultData webhook(@RequestBody JSONObject webhookObj){
|
|
|
|
|
|
+ public synchronized ResultData webhook(@RequestBody JSONObject webhookObj){
|
|
StripeWebhookLog stripeWebhookLog = new StripeWebhookLog();
|
|
StripeWebhookLog stripeWebhookLog = new StripeWebhookLog();
|
|
String type = webhookObj.getString("type");
|
|
String type = webhookObj.getString("type");
|
|
stripeWebhookLog.setEventType(type);
|
|
stripeWebhookLog.setEventType(type);
|
|
@@ -62,7 +61,10 @@ public class StripeController {
|
|
String trade_no = null;
|
|
String trade_no = null;
|
|
String status = null;
|
|
String status = null;
|
|
String orderId = null;
|
|
String orderId = null;
|
|
|
|
+ String customer = null;
|
|
|
|
+ String customer_email = null;
|
|
AutopayOrder autopayOrder = null;
|
|
AutopayOrder autopayOrder = null;
|
|
|
|
+ Order order = null;
|
|
switch (type){
|
|
switch (type){
|
|
case "checkout.session.completed"://支付完成
|
|
case "checkout.session.completed"://支付完成
|
|
jsonObject = webhookObj.getJSONObject("data");
|
|
jsonObject = webhookObj.getJSONObject("data");
|
|
@@ -72,12 +74,21 @@ public class StripeController {
|
|
String mode = jsonObject1.getString("mode");
|
|
String mode = jsonObject1.getString("mode");
|
|
subscriptionId = jsonObject1.getString("subscription");
|
|
subscriptionId = jsonObject1.getString("subscription");
|
|
status = jsonObject1.getString("status");
|
|
status = jsonObject1.getString("status");
|
|
|
|
+ customer = jsonObject1.getString("customer");
|
|
|
|
+ customer_email = jsonObject1.getString("customer_email");
|
|
JSONObject jsonObject2 = jsonObject1.getJSONObject("metadata");
|
|
JSONObject jsonObject2 = jsonObject1.getJSONObject("metadata");
|
|
orderId = jsonObject2.getString("orderId");
|
|
orderId = jsonObject2.getString("orderId");
|
|
- log.info("订单号为:id:{},trade_no:{},orderId:{}",id,trade_no,orderId);
|
|
|
|
- Order order = orderService.getByOrderSn(orderId);
|
|
|
|
|
|
+
|
|
|
|
+ stripeCustomerService.saveByEmail(customer_email,customer);
|
|
|
|
+
|
|
|
|
+ log.info("订单号为:id:{},trade_no:{},orderId:{},subscriptionId:{}",id,trade_no,orderId,subscriptionId);
|
|
|
|
+ order = orderService.getByOrderSn(orderId);
|
|
if( order != null){
|
|
if( order != null){
|
|
- orderService.payResult(order,true,trade_no,null);
|
|
|
|
|
|
+ if("subscription".equals(mode)){
|
|
|
|
+ orderService.payResult(order,true,subscriptionId,null);
|
|
|
|
+ }else {
|
|
|
|
+ orderService.payResult(order,true,trade_no,null);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case "checkout.session.expired"://过期
|
|
case "checkout.session.expired"://过期
|
|
@@ -105,12 +116,19 @@ public class StripeController {
|
|
default:
|
|
default:
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
+ if(subscriptionId == null){
|
|
|
|
+ return ResultData.ok();
|
|
|
|
+ }
|
|
String autoEven = AutoPayUtil.getAutoEven(type);
|
|
String autoEven = AutoPayUtil.getAutoEven(type);
|
|
|
|
|
|
- autopayOrder = autopayOrderService.getBySubscriptionId(subscriptionId);
|
|
|
|
|
|
+ autopayOrder = autopayOrderService.getByOrderSn(orderId);
|
|
if(autopayOrder == null ){
|
|
if(autopayOrder == null ){
|
|
return ResultData.ok();
|
|
return ResultData.ok();
|
|
}
|
|
}
|
|
|
|
+ if(autopayOrder.getSubscriptionId() == null){
|
|
|
|
+ autopayOrderService.setSubscriptionId(autopayOrder.getId(),subscriptionId);
|
|
|
|
+ return ResultData.ok();
|
|
|
|
+ }
|
|
|
|
|
|
AutopayOrderSon orderSnSon = null;
|
|
AutopayOrderSon orderSnSon = null;
|
|
if("PAY.COMPLETED".equals(autoEven)){
|
|
if("PAY.COMPLETED".equals(autoEven)){
|