java - 使用 REST 获取 PayPal 帐户历史记录

标签 java paypal paypal-ipn paypal-sandbox

我想使用 Java PayPal SDK 来获取帐户历史记录。我尝试了这个简单的代码:

    public void randomDatabaseData() throws SQLException, FileNotFoundException, IOException, PayPalRESTException {
    String clientID = "test";
    String clientSecret = "test";

    String accessToken = null;
    try {
        Map<String, String> map = new HashMap<String, String>();
        map.put("mode", "live");
        try {
            accessToken = new OAuthTokenCredential(clientID, clientSecret, map).getAccessToken();
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(accessToken);
        transactionSearch(accessToken);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

public TransactionSearchResponseType transactionSearch(String accessToken) {

    TransactionSearchReq transactionSearchReq = new TransactionSearchReq();
    TransactionSearchRequestType transactionSearchRequest = new TransactionSearchRequestType(
            "2012-12-25T00:00:00+0530");
    transactionSearchReq.setTransactionSearchRequest(transactionSearchRequest);
    PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService();
    service.setTokenSecret(accessToken);

    TransactionSearchResponseType transactionSearchResponse = null;
    try {
        transactionSearchResponse = service.transactionSearch(transactionSearchReq);
    } catch (Exception e) {
        System.out.println("Error Message : " + e.getMessage());
    }
    if (transactionSearchResponse.getAck().getValue().equalsIgnoreCase("success")) {

        Iterator<PaymentTransactionSearchResultType> iterator = transactionSearchResponse
                .getPaymentTransactions().iterator();
        while (iterator.hasNext()) {
            PaymentTransactionSearchResultType searchResult = iterator.next();

            System.out.println("Transaction ID : " + searchResult.getTransactionID());
        }
    } else {
        List<ErrorType> errorList = transactionSearchResponse.getErrors();
        System.out.println("API Error Message : " + errorList.get(0).getLongMessage());
    }

    return transactionSearchResponse;
}

但是当我运行代码时,我得到了他的错误堆栈:
    Error Message : configurationMap cannot be null
java.lang.NullPointerException
    at com.crm.web.tickets.GenearateTicketsTest.transactionSearch(GenearateTicketsTest.java:161)
    at com.crm.web.tickets.GenearateTicketsTest.randomDatabaseData(GenearateTicketsTest.java:139)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

我该如何修复此代码?我在 PayPal 网站中配置了客户端 ID 和 key ,但仍然出现错误。

最佳答案

我建议您使用 TransactionSearch API 根据您的搜索日期范围获取付款历史记录。

关于java - 使用 REST 获取 PayPal 帐户历史记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37511773/

相关文章:

php - 使用信用卡支付 Paypal

php - Paypal IPN 沙盒 - 在交易完成前完成接收状态

paypal - Paypal :您可以使用api请求新的IPN吗?

firebase-realtime-database - 如何将Paypal IPN分配给Google Cloud功能?

java - Spring WS 客户端发送 HTTPS 请求

java - 在两个或多个noSQL数据库上处理事务的方法是什么?

java - 使用Java正则表达式查找多个字符串匹配

java - 计算java中月份和年份的总天数

c# - 错误 : PayPal: Prop is required: payment

php - 交易金额明细(小计,税金,运费)必须总计总计指定的金额-PayPal PHP SDK