java - 如何使用java和paypal api在沙盒模式下进行批量支付?

标签 java paypal

我今天一直在寻找示例/教程/文档 其中解释了如何使用 paypal api 和 java 进行批量支付。我检查了 Paypal 网站,尽管我看到的只是什么是大规模支付的概述以及它们如何工作以及它们存在的原因的理论解释。是否有任何资源/教程展示如何使用 java 和 paypal api 进行批量支付,并使用实际代码和/或 java 文档清楚地解释了在沙盒模式下进行批量支付所需的内容?我将非常感谢对此的任何帮助。

最佳答案

我将 Mass Payout API 与 Spring Boot 集成。以下是主要摘录,不依赖于框架。

首先,我们添加合适的 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("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ed989e889fad88808c8481c38e8280" rel="noreferrer noopener nofollow">[email protected]</a>")
       .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();

在此响应中,您可以找到一个链接,需要访问该链接才能了解有关此付款(无论成功与否)的详细信息。

值得注意的是,Paypal 现在不支持同时对多个收件人进行同步处理

关于java - 如何使用java和paypal api在沙盒模式下进行批量支付?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41620417/

相关文章:

java - 创建所有可能的项目百分比列表?

php - Paypal 一个用户支付给门户和门户支付给另一个用户

php - paypal iPN 和 custom 不会将自定义变量添加到数据库

java - org.hibernate.MappingException : Unknown entity:

java - 如何在 java 中运行一个线程,让我知道另一个线程何时死亡?

java - 有没有什么方法可以在 servlet 中获取 jetty 上的所有有效 session key 值?

ios - "The PayPal iOS SDK is currently available in the US",具体是什么意思?

rest - PayPal:无法创建沙箱帐户和 REST API 帐户

c# - Json 中的键和值

java - 无法使用 HtmlUnit 和 Jsoup 组合下载完整文档(使用 Java)