PayPal NVP / SOAP API TransactionSearchReq呼叫

时间:2018-05-27 12:13:45

标签: java soap paypal nvp

我目前正在尝试在Java中实现一个列出特定时间范围内所有PayPal事务的类。我正在使用NVP / SOAP API Merchant SDK(https://github.com/paypal/merchant-sdk-java),因为这似乎是列出“所有”交易的唯一可能性。根据有关stackoverflow的其他问题,REST SDK仅列出REST调用所做的事务,这在我的情况下是不合适的。

不幸的是,README文件中显示的github上的TransactionSearchReq调用的示例代码不完整,并且也没有该调用的其他示例实现。

所以我的问题是: 1)任何人都可以帮助提供示例代码吗? 2)商家NVP / API SDK是否满足2018年6月之前发生的PayPal(https://www.paypal-engineering.com/2016/05/12/upcoming-security-changes-notice/& https://www.paypal.com/au/webapps/mpp/tls-http-upgrade)新安全更新的要求?

1 个答案:

答案 0 :(得分:0)

回答问题1):

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import urn.ebay.api.PayPalAPI.*;
import urn.ebay.apis.eBLBaseComponents.PaymentTransactionSearchResultType;

public class PaymentManager {

public static void main(String[] args) {

    Map<String,String> configMap = new HashMap<String,String>();

    configMap.put("mode", "live");

    // Account Credential
    configMap.put("acct1.UserName", "...");
    configMap.put("acct1.Password", "...");
    configMap.put("acct1.Signature", "...-...");
    // Subject is optional, only required in case of third party permission
    //configMap.put("acct1.Subject", "");

    // Sample Certificate credential
    // configMap.put("acct2.UserName", "certuser_biz_api1.paypal.com");
    // configMap.put("acct2.Password", "D6JNKKULHN3G5B8A");
    // configMap.put("acct2.CertKey", "password");
    // configMap.put("acct2.CertPath", "resource/sdk-cert.p12");
    // configMap.put("acct2.AppId", "APP-80W284485P519543T");


    TransactionSearchReq txnreq = new TransactionSearchReq();
    TransactionSearchRequestType requestType = new TransactionSearchRequestType();

    requestType.setStartDate("2018-04-01T00:00:00.000Z"); 
    requestType.setEndDate("2018-04-05T23:59:59.000Z"); 
    requestType.setVersion("95.0");
    requestType.setTransactionID("");
    txnreq.setTransactionSearchRequest(requestType);

    PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configMap);

    try {
        TransactionSearchResponseType txnresponse = service.transactionSearch(txnreq, configMap.get("acct1.UserName"));

        List<PaymentTransactionSearchResultType> transactions = txnresponse.getPaymentTransactions();

        for (int i = 0; i < transactions.size(); i++) {
            System.out.println(transactions.get(i).getPayer());
        }

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
}