【发布时间】: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 不知道将客户返回到哪里。