PayPal SDK going from payment review page to profilepage

Viewed 272

In my current Java/Spring project, I am in the phase of integration with PayPal. After configure a Java class to handle the payment process, following the instructions from here, I run my application and try to checkout an order with paypal.

I am redirected correctly to the PayPal login page, and after the login, to this payment review page:

enter image description here

but then after I click on "Continue", instead of finalizing the payment, I am redirected to my profile page.

enter image description here

Here is my code:

Paypal prop = this.paypalDao.get();
String clientId = prop.getClientID();
String clientSecret = prop.getClientSecret();
APIContext apiContext = new APIContext(clientId, clientSecret, "sandbox");

if(payerId != null) {
  if(guid != null) {
    Payment payment = new Payment();
    payment.setId(map.get(guid));

    PaymentExecution paymentExecution = new PaymentExecution();
    paymentExecution.setPayerId(payerId);
    payment.execute(apiContext, paymentExecution);

    String url = request.getContextPath();
    return url+"/orders";
  }
} else {
  List<Produto> lista_de_produtos = this.getListaDeProdutos(clienteId);

  Double total = 0.0;
  for(Produto produto : lista_de_produtos)
    total = total + produto.getPreco();
  DecimalFormat df = new DecimalFormat("0.00");
  String svalue = df.format(total).replace(',', '.');

  Details details = new Details();
  details.setSubtotal(svalue);

  Amount amount = new Amount();
  amount.setCurrency("BRL");
  amount.setTotal(svalue);
  amount.setDetails(details);

  Transaction transaction = new Transaction();
  transaction.setAmount(amount);
  transaction.setDescription(lista_de_produtos.toString());

  List<Transaction> transactions = new ArrayList<Transaction>();
  transactions.add(transaction);

  Payer payer = new Payer();
  payer.setPaymentMethod("paypal");

  Payment payment = new Payment();
  payment.setIntent("sale");
  payment.setPayer(payer);
  payment.setTransactions(transactions);

  RedirectUrls redirectUrls = new RedirectUrls();
  guid = UUID.randomUUID().toString();
  String url = request.getContextPath();
  redirectUrls.setCancelUrl( url+"/cart" );
  redirectUrls.setReturnUrl( url+"/paypal/checkout/"+clientId+"/?guid=" + guid );
  payment.setRedirectUrls(redirectUrls);

  Payment createdPayment = payment.create(apiContext);
  Iterator<Links> links = createdPayment.getLinks().iterator();
  while (links.hasNext()) {
    Links link = links.next();
    if (link.getRel().equalsIgnoreCase("approval_url")) {
      map.put("redirectURL", link.getHref());
      redirectURL = link.getHref();
    }
  }
  map.put(guid, createdPayment.getId());
  payment.setId(map.get(guid));
}

return redirectURL;

Can someone tell me, what am I missing here?

1 Answers
Related