cancel
Showing results for 
Search instead for 
Did you mean: 

Moving to live

New Community Member

Moving to live

Hello, folks, I am developing a Spring MVC app which needs to connect with Paypal. In order to do this without read a lot of documentation I based my app in a very good example I found in internet. Here I leave the link for anyone who can be looking for a good Spring example:

 

https://github.com/masasdani/paypal-springboot

 

Using this I was able to create and test Paypal payment gateway on the Sandbox. But now I had to move to live. In order to do this I changed my properties file in this way:

 

 

paypal.mode=live
paypal.client.app=My live Token

Then I ran my app and it seemed to work well. Because I was able to buy my own products and currently I owe money to myself ;-). 

But suddenly people who is testing my site told me they were not allowed to reach Paypal, but redirected to main page. So, being my controller is having next method:

 

 

	@RequestMapping(method = RequestMethod.POST, value = "pay")
	public String pay(HttpServletRequest request, @RequestParam("org") String org ){
		Order order = (Order)request.getSession().getAttribute("order");
		String cancelUrl = URLUtils.getBaseURl(request) + "/" + PAYPAL_CANCEL_URL;
		String successUrl = URLUtils.getBaseURl(request) + "/" + PAYPAL_SUCCESS_URL;
		BigDecimal total = order.getlTransaction().getTotal();
		order.setOrg(org);

		try {
			Payment payment = paypalService.createPayment(
					total.doubleValue(), 
					PAYPAL_CURRENCY_EURO, 
					PaypalPaymentMethod.paypal, 
					PaypalPaymentIntent.sale,
					"payment description", 
					cancelUrl, 
					successUrl);
			for(Links links : payment.getLinks()){
				log.error("LINK: href="+links.getHref()+" /rel= "+links.getRel());
				if(links.getRel().equals("approval_url")){
					return "redirect:" + links.getHref();
				}
			}
		} catch (PayPalRESTException e) {
			log.error(e.getMessage());
		}
		log.error("LINK: no derivo a terminar el pago");
		return "redirect:/";
	}

 

 Seems as something goes wrong trying to find approval_url or or it throw a PayPalRESTException, what would explain why my code were redirecting to /.

 

In the next link:

https://developer.paypal.com/docs/classic/lifecycle/goingLive/#

I found that to move live is necessary to update links to Production Paypal endpoints. But as far as I know those links are not in my code. I guess they should be inside the SDK I added to my pom.xml

 

		<dependency>
			<groupId>com.paypal.sdk</groupId>
			<artifactId>rest-api-sdk</artifactId>
			<version>1.4.2</version>
		</dependency>

 

If this post seems a little bit confused is because I am confused. I am not sure if the problem with my app is for the lack of links to Production Paypal endpoints or some other mistake. But which really is confusing me is had been able to make a payment using the same app. 

Today checking logs I found this:

 

exec-75]:com.paypal.base.HttpConnection.executeWithStream()166 Error code : 401 with response : {"error":"invalid_token","error_description":"Access Token not found in cache"}

Please enlight me .