117 lines
4.6 KiB
Java
117 lines
4.6 KiB
Java
package com.ai.da.controller;
|
|
|
|
import com.ai.da.common.response.Response;
|
|
import com.ai.da.model.dto.ProductPurchaseDTO;
|
|
import com.ai.da.service.StripeService;
|
|
import com.paypal.http.HttpResponse;
|
|
import com.paypal.payments.Refund;
|
|
import com.stripe.exception.StripeException;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import springfox.documentation.annotations.ApiIgnore;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.ServletException;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.validation.Valid;
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
@Api(tags = "Stripe模块")
|
|
@Slf4j
|
|
@RestController
|
|
@RequestMapping("/api/stripe")
|
|
@ApiIgnore
|
|
public class StripeController {
|
|
|
|
@Resource
|
|
private StripeService stripeService;
|
|
|
|
@ApiOperation("创建支付链接")
|
|
@PostMapping("/createOrder")
|
|
public Response<String> pay(@Valid @RequestBody ProductPurchaseDTO productPurchaseDTO, HttpServletRequest request) {
|
|
return Response.success(stripeService.pay(productPurchaseDTO, request));
|
|
}
|
|
|
|
@ApiOperation("支付通知")
|
|
@PostMapping("/trade/notify")
|
|
public void callback(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
|
Boolean result = stripeService.notify(request);
|
|
if (result){
|
|
response.setStatus(HttpServletResponse.SC_OK);
|
|
}else {
|
|
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
|
}
|
|
}
|
|
|
|
@ApiOperation("申请退款")
|
|
@GetMapping("/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.");
|
|
}
|
|
}
|
|
|
|
@ApiOperation("获取订阅")
|
|
@GetMapping("/getSubscription")
|
|
public Response<List<String>> getSubscription(@RequestParam String name, @RequestParam String email) {
|
|
try {
|
|
return Response.success(stripeService.getSubscriptionIds(name, email));
|
|
} catch (StripeException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
|
|
@ApiOperation("取消订阅")
|
|
@GetMapping("/cancelSubscription")
|
|
public Response<String> cancelSubscription(@RequestParam String subscriptionId, @RequestParam(required = false) String reason) {
|
|
stripeService.cancelSubscription(subscriptionId, reason);
|
|
return Response.success("success");
|
|
}
|
|
/*@ApiOperation("临时 取消订阅")
|
|
@GetMapping("/cancelSubscriptionTemp")
|
|
public Response<String> cancelSubscriptionTemp(@RequestParam String subscriptionId) {
|
|
stripeService.cancelSubscriptionTemp(subscriptionId);
|
|
return Response.success("success");
|
|
}
|
|
|
|
@ApiOperation("创建订阅 临时")
|
|
@GetMapping("/createSubscriptionTemp")
|
|
public Response<String> createSubscriptionTemp(@RequestParam String name, @RequestParam String email) {
|
|
return Response.success(stripeService.createSubscriptionTemp(name, email));
|
|
}
|
|
|
|
@ApiOperation("修改用户默认支付方式 临时")
|
|
@GetMapping("/changeCustomerPayment")
|
|
public Response<String> changeCustomerPayment(@RequestParam String name, @RequestParam String email) {
|
|
return Response.success(stripeService.changeCustomerPayment(name, email));
|
|
}
|
|
|
|
@ApiOperation("临时 发送续订失败邮件")
|
|
@GetMapping("/sendRenewalFailEmail")
|
|
public Response<Boolean> sendRenewalFailEmail(@RequestParam String invoiceId, @RequestParam String subscriptionId, @RequestParam String orderNo) {
|
|
return Response.success(stripeService.sendRenewalFailEmail(invoiceId, subscriptionId,orderNo));
|
|
}
|
|
|
|
@ApiOperation("临时 查询指定用户绑定的付款方式")
|
|
@GetMapping("/getCustomerPaymentMethod")
|
|
public Response<List<Map<String,String>>> getCustomerPaymentMethod(@RequestParam String name, @RequestParam String email) {
|
|
return Response.success(stripeService.getCustomerPaymentMethod(name, email));
|
|
}
|
|
|
|
@ApiOperation("临时 解绑指定用户绑定的所有付款方式")
|
|
@GetMapping("/detachCustomerAllPaymentMethod")
|
|
public Response<String> detachCustomerAllPaymentMethod(@RequestParam String name, @RequestParam String email) {
|
|
return Response.success(stripeService.detachCustomerAllPaymentMethod(name, email));
|
|
}*/
|
|
|
|
|
|
}
|