gpt4 book ai didi

java - PayPal SDK 从付款审核页面到个人资料页面

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:27:57 25 4
gpt4 key购买 nike

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

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

enter image description here

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

enter image description here

这是我的代码:

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;

谁能告诉我,我在这里缺少什么?

最佳答案

尝试打印这个值:

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

结果应该是https://www.yoursite.com/paypal/checkout/<number>/?guid=<number> , 或者指向那里的页面(省略 https:// 以节省字节可能没问题,具体取决于您的服务器配置)。

您应该尝试的其他测试:

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

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

关于java - PayPal SDK 从付款审核页面到个人资料页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44191800/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com