So I wrote the paypal checkout controller method, I set it up to a button, and when you press the button on the website, it loads to the paypal checkout site, you can login and pay, and it works fine, gives me the money and gives them their items bought. But after a day it fails to work, and everytime I click the paypal checkout it throws an error.
The Error
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";
}
It should already have a token if it worked once.