今天,我一直在寻找示例/教程/文档,这说明了如何使用paypal api和java进行大规模支付。我已经检查了贝宝的网站,虽然我看到的都是什么是大规模支付概述和理论解释,他们如何工作,为什么他们存在。是否有任何资源/教程显示如何使用java和paypal使用实际代码和/或java文档进行大规模支付,这些文档清楚地解释了在沙箱模式下进行大规模支付所需的内容?我将非常感谢在这方面的任何帮助。
发布于 2017-06-12 15:40:59
我将批量支付API与Spring集成在一起。以下是不依赖于框架的主要摘录。
首先,添加适当的Maven依赖项:
<dependency>
<groupId>com.paypal.sdk</groupId>
<artifactId>rest-api-sdk</artifactId>
<version>1.13.1</version>
</dependency>现在,我们可以创建一个Payout对象,并以PayoutItem的形式添加多个收件人,如下所示:
Payout payout = new Payout();
PayoutSenderBatchHeader senderBatchHeader = new PayoutSenderBatchHeader();
senderBatchHeader.setEmailSubject("PayPal Email Header");
Currency amount = new Currency();
//Transaction of 1 unit with US Dollars as unit.
amount.setValue("1").setCurrency("USD");完成后,您可以开始添加收件人:
PayoutItem sendTo = new PayoutItem();
//This can be "Phone" and specify PayPal mobile number on setReceiver
sendTo.setRecipientType("Email")
.setReceiver("user@email.com")
.setNote("Thanks.").setAmount(amount);
List<PayoutItem> items = new ArrayList<>();
items.add(sendTo);
//Add more recipients to items list but with same currency as handling
//different currencies in single batch isn't possible
payout.setSenderBatchHeader(senderBatchHeader).setItems(items);现在,它已经完成,最后执行请求:
//paypalMode can be either "sandbox" or "live"
APIContext apiContext = new APIContext(
paypalClientId, paypalClientSecret, paypalMode);
PayoutBatch batch = payout.create(apiContext);
String batchId = batch.getBatchHeader().getPayoutBatchId();付款请求现在已经执行,但是是异步的。检查JSON字符串响应如下:
String jsonResponseStr = Payout.getLastResponse();在此响应中,您可以找到一个需要访问的link,以获得有关此支出的详细信息,如果它成功与否。
值得注意的是,贝宝现在不支持多个收件人同时进行同步处理。
https://stackoverflow.com/questions/41620417
复制相似问题