【问题标题】:PayPal SDK going from payment review page to profilepagePayPal SDK 从付款审核页面转到个人资料页面
【发布时间】:2017-10-26 18:29:48
【问题描述】:

在我当前的 Java/Spring 项目中,我正处于与 PayPal 集成的阶段。在配置一个 Java 类来处理支付过程之后,按照here 的说明,我运行我的应用程序并尝试使用 paypal 结帐。

我被正确重定向到 PayPal 登录页面,登录后,我被重定向到此付款审核页面:

但是当我点击“继续”后,我并没有完成付款,而是被重定向到我的个人资料页面。

这是我的代码:

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;

谁能告诉我,我在这里错过了什么?

【问题讨论】:

  • 至少在那里隐藏那些个人详细信息,例如电话、电子邮件 ID 等...
  • request.getContextPath() 返回什么?如果这是一个相对 url(没有域名),那么 PayPal 不知道将客户返回到哪里。

标签: java spring paypal


【解决方案1】:

尝试打印此值:

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

结果应该是https://www.yoursite.com/paypal/checkout/&lt;number&gt;/?guid=&lt;number&gt;,或者指向那里的页面(根据您的服务器配置,省略https:// 以节省字节可能没问题)。

您应该尝试的其他测试:

  1. 尝试在您的网站上取消。
  2. 尝试在贝宝网站上取消付款。

如果一个有效,但第二个无效,那么 paypal 没有正确重定向,这可能意味着您没有给它正确的字符串。另请参阅@Emile 的评论。

【讨论】:

  • leaving out "https://" to save on bytes...... wrong site? LOL :P
  • @HyperNeutrino 一些支付处理系统接受比官方标准更短的 URL 长度。例如。 255 个字符,因为银行在其旧后端使用固定字符串。节省的这 8 个字节有时会有所帮助。不过我没有在 paypal 上查找它,因此可能没有必要。
猜你喜欢
  • 2015-11-04
  • 1970-01-01
  • 2014-07-21
  • 2014-10-09
  • 2015-10-08
  • 2016-11-26
  • 2015-08-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多