2024-07-15 13:42:18 +08:00
|
|
|
package com.ai.da.controller;
|
|
|
|
|
|
|
|
|
|
import com.ai.da.common.response.Response;
|
2024-11-18 16:20:25 +08:00
|
|
|
import com.ai.da.model.dto.ProductPurchaseDTO;
|
2024-07-15 13:42:18 +08:00
|
|
|
import com.ai.da.service.StripeService;
|
2024-07-16 16:59:58 +08:00
|
|
|
import com.paypal.http.HttpResponse;
|
|
|
|
|
import com.paypal.payments.Refund;
|
2024-11-18 16:20:25 +08:00
|
|
|
import com.stripe.exception.StripeException;
|
2024-07-15 13:42:18 +08:00
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2024-11-18 16:20:25 +08:00
|
|
|
import org.simpleframework.xml.core.Validate;
|
2024-07-15 13:42:18 +08:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.ServletException;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
2024-11-18 16:20:25 +08:00
|
|
|
import javax.servlet.http.HttpServletResponse;
|
2024-07-15 13:42:18 +08:00
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
|
|
@Api(tags = "Stripe模块")
|
|
|
|
|
@Slf4j
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/api/stripe")
|
|
|
|
|
public class StripeController {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private StripeService stripeService;
|
|
|
|
|
|
|
|
|
|
@ApiOperation("创建支付链接")
|
2024-11-18 16:20:25 +08:00
|
|
|
@PostMapping("/createOrder")
|
|
|
|
|
public Response<String> pay(@Validate @RequestBody ProductPurchaseDTO productPurchaseDTO) {
|
|
|
|
|
return Response.success(stripeService.pay(productPurchaseDTO));
|
2024-07-15 13:42:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("支付通知")
|
|
|
|
|
@PostMapping("/trade/notify")
|
2024-11-18 16:20:25 +08:00
|
|
|
public void callback(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
2024-07-15 13:42:18 +08:00
|
|
|
Boolean result = stripeService.notify(request);
|
|
|
|
|
if (result){
|
2024-11-18 16:20:25 +08:00
|
|
|
response.setStatus(HttpServletResponse.SC_OK);
|
2024-07-15 13:42:18 +08:00
|
|
|
}else {
|
2024-11-18 16:20:25 +08:00
|
|
|
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
2024-07-15 13:42:18 +08:00
|
|
|
}
|
|
|
|
|
}
|
2024-07-16 16:59:58 +08:00
|
|
|
|
|
|
|
|
@ApiOperation("申请退款")
|
|
|
|
|
@PostMapping("/trade/refund/{orderNo}/{reason}")
|
|
|
|
|
public Response<HttpResponse<Refund>> refund(@PathVariable String orderNo, @PathVariable String reason) throws IOException {
|
|
|
|
|
String response = stripeService.refund(null,orderNo,reason);
|
|
|
|
|
if (response.equals("退款成功")){
|
|
|
|
|
return Response.success();
|
|
|
|
|
}else {
|
|
|
|
|
return Response.fail("Request for refund failed.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-18 16:20:25 +08:00
|
|
|
@ApiOperation("获取订阅")
|
|
|
|
|
@PostMapping("/getSubscription")
|
|
|
|
|
public void getSubscription() {
|
|
|
|
|
try {
|
|
|
|
|
stripeService.getSubscription("xp", "xupei3360@163.com");
|
|
|
|
|
} catch (StripeException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation("取消订阅")
|
|
|
|
|
@PostMapping("/cancelSubscription")
|
|
|
|
|
public Response<String> cancelSubscription(@RequestParam String subscriptionId) {
|
|
|
|
|
stripeService.cancelSubscription(subscriptionId);
|
|
|
|
|
return Response.success("success");
|
|
|
|
|
}
|
2024-07-15 13:42:18 +08:00
|
|
|
}
|