Kle*_*ota 6 java spring paypal
在我目前的Java/Spring项目中,我正处于与PayPal集成的阶段.在配置Java类来处理付款流程后,按照此处的说明,我运行我的应用程序并尝试使用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;
Run Code Online (Sandbox Code Playgroud)
有人能告诉我,我在这里错过了什么?
尝试打印这个值:
System.out.println(url+"/paypal/checkout/"+clientId+"/?guid=" + guid);
Run Code Online (Sandbox Code Playgroud)
结果应该是https://www.yoursite.com/paypal/checkout/<number>/?guid=<number>, 或者一个直接指向那里的页面(https://根据您的服务器配置,可以省略以节省字节)。
您应该尝试的其他测试:
如果第一个有效,但第二个无效,则 PayPal 未正确重定向,这可能意味着您没有为其提供正确的字符串。另请参阅@Emile 的评论。
| 归档时间: |
|
| 查看次数: |
172 次 |
| 最近记录: |