Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PayPal SDK going from payment review page to profilepage

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?

like image 359
Kleber Mota Avatar asked May 26 '17 00:05

Kleber Mota


People also ask

What can I do with the PayPal SDK?

The JavaScript SDK displays PayPal-supported payment methods on your page to give your buyers a personalized and streamlined checkout experience. You can use the JavaScript SDK to render buttons, payment method icons ( marks ), and credit and debit card form fields ( hosted-fields ).

What is PayPal’s payment review feature?

Enjoy greater security and peace of mind with PayPal’s free Payment Review feature, designed to reduce losses due to unauthorised transactions. What is Payment Review? A new payment status alerting sellers to potential, high-risk transactions before they ship their items. How does Payment Review work?

Does PayPal SDK log every request and response to eclipse console?

By default PayPal SDK enables DEBUG mode and hence it logs each and every request and response to Eclipse Console. For detailed information I’ve kept DEBUG mode on and provided detailed result of our getAuthorization Call here. 13:22:28.013 [main] DEBUG com.paypal.base.ConfigManager - sdk_config.properties not present. Skipping...

How do I know if my PayPal payment has been received?

Within minutes of receiving payments for your items, PayPal will email you to notify you of the payment status. We’ll provide you with one of the following notifications via email and in your PayPal account:


1 Answers

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.

like image 86
aphid Avatar answered Oct 14 '22 19:10

aphid