在缓存 401 live 中找不到 PayPal 访问令牌

问题描述 投票:0回答:1

所以我编写了paypal结帐控制器方法,我将其设置为一个按钮,当您按下网站上的按钮时,它会加载到paypal结帐网站,您可以登录并付款,并且它工作正常,给了我钱并向他们提供购买的物品。但一天后它就无法工作了,每次我点击贝宝结账时都会抛出错误。

错误

2019-06-26 00:15:35.600 ERROR 17396 --- [http-nio-8080-exec-2] com.paypal.base.HttpConnection           : Response code: 401    Error response: {"error":"invalid_token","error_description":"Access Token not found in cache"}

2019-06-26 00:15:35.608 ERROR 17396 --- [http-nio-8080-exec-2] c.r.api.controllers.PaymentController    : Response code: 401    Error response: {"error":"invalid_token","error_description":"Access Token not found in cache"}
@RequestMapping(method = RequestMethod.POST, value = "/pay/")
    public String pay(ModelAndView modelAndView, HttpServletRequest request, @RequestParam(name = "id") int id){
        String cancelUrl = "https://realmlands.com" + "/" + PAYPAL_CANCEL_URL;
        String successUrl = "https://realmlands.com" + "/" + PAYPAL_SUCCESS_URL;
        try {
            if (id == 2) {
                Payment payment = paypalService.createPayment(
                        49.99,
                        "USD",
                        PaypalPaymentMethod.paypal,
                        PaypalPaymentIntent.sale,
                        "added founder pack to your account.",
                        cancelUrl,
                        successUrl);
                for(Links links : payment.getLinks()){
                    if(links.getRel().equals("approval_url")){
                        return "redirect:" + links.getHref();
                    }
                }
            } else {
                Payment payment = paypalService.createPayment(
                        9.99,
                        "USD",
                        PaypalPaymentMethod.paypal,
                        PaypalPaymentIntent.sale,
                        "adds 31 days of premium time.",
                        cancelUrl,
                        successUrl);
                for(Links links : payment.getLinks()){
                    if(links.getRel().equals("approval_url")){
                        return "redirect:" + links.getHref();
                    }
                }
            }
        } catch (PayPalRESTException e) {
            modelAndView.addObject("errorMessage", e.getDetails().getMessage());
            log.error(e.getMessage());
        }
        return "redirect:/dashboard/store";
    }

如果它工作过一次,它应该已经有一个令牌了。

java spring spring-boot spring-mvc paypal
1个回答
0
投票

Paypal的token有效期为9小时,所以我通过清除缓存找到了解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.