|
@@ -4,8 +4,12 @@ package com.fdkankan.pay.controller;
|
|
import cn.hutool.log.Log;
|
|
import cn.hutool.log.Log;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.fdkankan.pay.common.ResultData;
|
|
import com.fdkankan.pay.common.ResultData;
|
|
|
|
+import com.fdkankan.pay.entity.Order;
|
|
|
|
+import com.fdkankan.pay.entity.PaypalWebhookLog;
|
|
import com.fdkankan.pay.entity.StripeWebhookLog;
|
|
import com.fdkankan.pay.entity.StripeWebhookLog;
|
|
|
|
+import com.fdkankan.pay.service.IOrderService;
|
|
import com.fdkankan.pay.service.IStripeWebhookLogService;
|
|
import com.fdkankan.pay.service.IStripeWebhookLogService;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
@@ -13,6 +17,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
* 前端控制器
|
|
* 前端控制器
|
|
@@ -23,22 +29,53 @@ import org.springframework.web.bind.annotation.RestController;
|
|
*/
|
|
*/
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/service/pay/stripe")
|
|
@RequestMapping("/service/pay/stripe")
|
|
|
|
+@Slf4j
|
|
public class StripeController {
|
|
public class StripeController {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
IStripeWebhookLogService stripeWebhookLogService;
|
|
IStripeWebhookLogService stripeWebhookLogService;
|
|
|
|
+ @Autowired
|
|
|
|
+ IOrderService orderService;
|
|
|
|
|
|
@PostMapping("/webhook")
|
|
@PostMapping("/webhook")
|
|
public ResultData webhook(@RequestBody JSONObject webhookObj){
|
|
public 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);
|
|
stripeWebhookLog.setMsg(webhookObj.toJSONString());
|
|
stripeWebhookLog.setMsg(webhookObj.toJSONString());
|
|
|
|
+ stripeWebhookLogService.save(stripeWebhookLog);
|
|
|
|
|
|
|
|
+ switch (type){
|
|
|
|
+ case "checkout.session.completed"://支付完成
|
|
|
|
+ JSONObject jsonObject = webhookObj.getJSONObject("data");
|
|
|
|
+ JSONObject jsonObject1 = jsonObject.getJSONObject("object");
|
|
|
|
+ String id = jsonObject1.getString("id");
|
|
|
|
+ String trade_no = jsonObject1.getString("payment_intent");
|
|
|
|
+ JSONObject jsonObject2 = jsonObject1.getJSONObject("metadata");
|
|
|
|
+ String orderId = jsonObject2.getString("orderId");
|
|
|
|
+ log.info("订单号为:id:{},trade_no:{},orderId:{}",id,trade_no,orderId);
|
|
|
|
+ Order order = orderService.getByOrderSn(orderId);
|
|
|
|
+ if(order != null){
|
|
|
|
+ orderService.payResult(order,true,trade_no,null);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case "checkout.session.expired"://过期
|
|
|
|
+ break;
|
|
|
|
+ case "payment_intent.created"://创建订单 这里事件就是图二选着的事件
|
|
|
|
+ break;
|
|
|
|
+ case "payment_intent.canceled"://取消订单
|
|
|
|
+ break;
|
|
|
|
+ case "payment_intent.succeeded"://支付成功
|
|
|
|
+ break;
|
|
|
|
+ case "payment_intent.payment_failed"://支付失败
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ default:
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
|
|
- stripeWebhookLogService.save(stripeWebhookLog);
|
|
|
|
return ResultData.ok();
|
|
return ResultData.ok();
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|