PayPal SDK going from payment review page to profilepage

Kleber Mota :

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?

aphid :

Try printing this value:

System.out.println(url+"/paypal/checkout/"+clientId+"/?guid=" + guid);

The result should be https://www.yoursite.com/paypal/checkout/<number>/?guid=<number>, or a page that would direct there (leaving out https:// to save on bytes could be okay depending on your server configuration).

Additional tests you should try:

  1. Try cancelling on your site.
  2. Try cancelling the payment on paypal's site.

Iff one works but the second does not, then paypal is not redirecting properly, which probably means you're not giving it the right string. Also see comment by @Emile.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=470456&siteId=1